openglrenderer.h

00001 /************************************************************************
00002         filename:       openglrenderer.h
00003         created:        9/4/2004
00004         author:         Mark Strom
00005                                 mwstrom@gmail.com
00006 
00007         purpose:        Interface to Renderer implemented via Opengl
00008 *************************************************************************/
00009 /*************************************************************************
00010     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00011     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00012 
00013     This library is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU Lesser General Public
00015     License as published by the Free Software Foundation; either
00016     version 2.1 of the License, or (at your option) any later version.
00017 
00018     This library is distributed in the hope that it will be useful,
00019     but WITHOUT ANY WARRANTY; without even the implied warranty of
00020     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021     Lesser General Public License for more details.
00022 
00023     You should have received a copy of the GNU Lesser General Public
00024     License along with this library; if not, write to the Free Software
00025     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 *************************************************************************/
00027 #ifndef _openglrenderer_h_
00028 #define _openglrenderer_h_
00029 
00030 #include "CEGUIBase.h"
00031 
00032 #if defined( __WIN32__ ) || defined( _WIN32 )
00033 #   ifdef OPENGL_GUIRENDERER_EXPORTS
00034 #       define OPENGL_GUIRENDERER_API __declspec(dllexport)
00035 #   else
00036 #       define OPENGL_GUIRENDERER_API __declspec(dllimport)
00037 #   endif
00038 #else
00039 #   define OPENGL_GUIRENDERER_API
00040 #endif
00041 
00042 
00043 #if defined(_WIN32)//  All this taken from glut.h
00044 #  ifndef APIENTRY
00045 #   define GLUT_APIENTRY_DEFINED
00046 #   if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
00047 #    define APIENTRY    __stdcall
00048 #   else
00049 #    define APIENTRY
00050 #   endif
00051 #  endif
00052 /* XXX This is from Win32's <winnt.h> */
00053 #  ifndef CALLBACK
00054 #   if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__)
00055 #    define CALLBACK __stdcall
00056 #   else
00057 #    define CALLBACK
00058 #   endif
00059 #  endif
00060 /* XXX Hack for lcc compiler.  It doesn't support __declspec(dllimport), just __stdcall. */
00061 #  if defined( __LCC__ )
00062 #   undef WINGDIAPI
00063 #   define WINGDIAPI __stdcall
00064 #  else
00065 /* XXX This is from Win32's <wingdi.h> and <winnt.h> */
00066 #   ifndef WINGDIAPI
00067 #    define GLUT_WINGDIAPI_DEFINED
00068 #    define WINGDIAPI __declspec(dllimport)
00069 #   endif
00070 #  endif
00071 /* XXX This is from Win32's <ctype.h> */
00072 #  ifndef _WCHAR_T_DEFINED
00073 typedef unsigned short wchar_t;
00074 #   define _WCHAR_T_DEFINED
00075 #  endif
00076 # endif //win32 end glut.h stuff
00077 
00078 /* XXX Hack for finding headers in Apple's OpenGL framework. */
00079 #if defined( __APPLE__ )
00080 #include <OpenGL/gl.h>
00081 #include <OpenGL/glu.h>
00082 #else /* __APPLE__ */
00083 #include <GL/gl.h>
00084 #include <GL/glu.h>
00085 #endif /* __APPLE__ */
00086 #include <list>
00087 #include <set>
00088 
00089 #include "CEGUIRenderer.h"
00090 #include "CEGUITexture.h"
00091 
00092 
00093 #if defined(_WIN32)
00094 #  if defined(_DEBUG)
00095 #     pragma comment(lib, "CEGUIBase_d.lib")
00096 #  else
00097 #     pragma comment(lib, "CEGUIBase.lib")
00098 #  endif
00099 #endif
00100 
00101 #if defined(_MSC_VER)
00102 #       pragma warning(push)
00103 #       pragma warning(disable : 4251)
00104 #endif
00105 
00106 #define OGLRENDERER_VBUFF_CAPACITY      4096
00107 
00108 
00109 // Start of CEGUI namespace section
00110 namespace CEGUI
00111 {
00112 /*************************************************************************
00113         Forward refs
00114 *************************************************************************/
00115 class OpenGLTexture;
00116 
00121 class OPENGL_GUIRENDERER_API OpenGLRenderer : public Renderer
00122 {
00123 public:
00131     OpenGLRenderer(uint max_quads);
00132         OpenGLRenderer(uint max_quads,int width, int height);
00133 
00134 
00139     virtual ~OpenGLRenderer(void);
00140 
00141     // add's a quad to the list to be rendered
00142     virtual     void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00143 
00144     // perform final rendering for all queued renderable quads.
00145     virtual     void    doRender(void);
00146 
00147     // clear the queue
00148     virtual     void    clearRenderList(void);
00149 
00150 
00166     virtual void        setQueueingEnabled(bool setting)                {d_queueing = setting;}
00167 
00168 
00169     // create an empty texture
00170     virtual     Texture*        createTexture(void);
00171 
00172     // create a texture and load it with the specified file.
00173     virtual     Texture*        createTexture(const String& filename, const String& resourceGroup);
00174 
00175     // create a texture and set it to the specified size
00176     virtual     Texture*        createTexture(float size);
00177 
00178     // destroy the given texture
00179     virtual     void            destroyTexture(Texture* texture);
00180 
00181     // destroy all textures still active
00182     virtual void                destroyAllTextures(void);
00183 
00191     virtual bool        isQueueingEnabled(void) const   {return d_queueing;}
00192 
00193 
00201     virtual float       getWidth(void) const            {return d_display_area.getWidth();}
00202 
00203 
00211     virtual float       getHeight(void) const           {return d_display_area.getHeight();}
00212 
00213 
00221     virtual Size        getSize(void) const                     {return d_display_area.getSize();}
00222 
00223 
00232     virtual Rect        getRect(void) const                     {return d_display_area;}
00233 
00234 
00242     virtual     uint    getMaxTextureSize(void) const           {return d_maxTextureSize;}
00243 
00244 
00252     virtual     uint    getHorzScreenDPI(void) const    {return 96;}
00253 
00254 
00262     virtual     uint    getVertScreenDPI(void) const    {return 96;}
00263 
00264 
00282         void    setDisplaySize(const Size& sz);
00283 
00284 
00291     void grabTextures(void);
00292 
00293 
00298     void restoreTextures(void);
00299 
00300 
00301 private:
00302     /************************************************************************
00303                 Implementation Constants
00304     ************************************************************************/
00305     static const int                    VERTEX_PER_QUAD;                                                        
00306     static const int                    VERTEX_PER_TRIANGLE;                                            
00307     static const int                    VERTEXBUFFER_CAPACITY;                                          
00308     
00309     /*************************************************************************
00310                 Implementation Structs & classes
00311     *************************************************************************/
00312     struct MyQuad
00313     {
00314         float tex[2];
00315         long color;
00316         float vertex[3];
00317     };
00318 
00323     struct QuadInfo
00324     {
00325         GLuint          texid;  
00326         Rect            position;
00327         float           z;
00328         Rect            texPosition;
00329                 long            topLeftCol;
00330                 long            topRightCol;
00331                 long            bottomLeftCol;
00332                 long            bottomRightCol;
00333 
00334         QuadSplitMode   splitMode;
00335 
00336                 bool operator<(const QuadInfo& other) const
00337                 {
00338                         // this is intentionally reversed.
00339                         return z > other.z;
00340                 }
00341 
00342     };
00343 
00344 
00345     /*************************************************************************
00346                 Implementation Methods
00347     *************************************************************************/
00348     // setup states etc
00349     void        initPerFrameStates(void);
00350 
00351     // restore states
00352     void  exitPerFrameStates(void);
00353 
00354     // render whatever is in the vertex buffer
00355     void        renderVBuffer(void);
00356 
00357     // sort quads list according to texture
00358     void        sortQuads(void);
00359 
00360     // render a quad directly to the display
00361     void        renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00362 
00363         // convert colour value to whatever the OpenGL system is expecting.
00364         long    colourToOGL(const colour& col) const;
00365 
00366         // set the module ID string
00367         void setModuleIdentifierString();
00368 
00369 
00370     /*************************************************************************
00371             Implementation Data
00372     *************************************************************************/
00373         typedef std::multiset<QuadInfo>         QuadList;
00374         QuadList d_quadlist;
00375 
00376         Rect            d_display_area;
00377 
00378         MyQuad          myBuff[OGLRENDERER_VBUFF_CAPACITY];
00379 
00380         bool            d_queueing;                     
00381         uint            d_currTexture;          
00382         int                     d_bufferPos;            
00383         bool            d_sorted;                       
00384 
00385         std::list<OpenGLTexture*>       d_texturelist;          
00386         GLint       d_maxTextureSize;           
00387 };
00388 
00389 } // End of  CEGUI namespace section
00390 
00391 #if defined(_MSC_VER)
00392 #       pragma warning(pop)
00393 #endif
00394 
00395 #endif  // end of guard _openglrenderer_h_

Generated on Sat Nov 26 09:34:49 2005 for Crazy Eddies GUI System by  doxygen 1.4.5