Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

openglrenderer.h

Go to the documentation of this file.
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 
00031 #if defined( __WIN32__ ) || defined( _WIN32 )
00032 #   ifdef OPENGL_GUIRENDERER_EXPORTS
00033 #       define OPENGL_GUIRENDERER_API __declspec(dllexport)
00034 #   else
00035 #       define OPENGL_GUIRENDERER_API __declspec(dllimport)
00036 #   endif
00037 #else
00038 #   define OPENGL_GUIRENDERER_API
00039 #endif
00040 
00041 
00042 #if defined(_WIN32)//  All this taken from glut.h
00043 #  ifndef APIENTRY
00044 #   define GLUT_APIENTRY_DEFINED
00045 #   if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__)
00046 #    define APIENTRY    __stdcall
00047 #   else
00048 #    define APIENTRY
00049 #   endif
00050 #  endif
00051 /* XXX This is from Win32's <winnt.h> */
00052 #  ifndef CALLBACK
00053 #   if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__)
00054 #    define CALLBACK __stdcall
00055 #   else
00056 #    define CALLBACK
00057 #   endif
00058 #  endif
00059 /* XXX Hack for lcc compiler.  It doesn't support __declspec(dllimport), just __stdcall. */
00060 #  if defined( __LCC__ )
00061 #   undef WINGDIAPI
00062 #   define WINGDIAPI __stdcall
00063 #  else
00064 /* XXX This is from Win32's <wingdi.h> and <winnt.h> */
00065 #   ifndef WINGDIAPI
00066 #    define GLUT_WINGDIAPI_DEFINED
00067 #    define WINGDIAPI __declspec(dllimport)
00068 #   endif
00069 #  endif
00070 /* XXX This is from Win32's <ctype.h> */
00071 #  ifndef _WCHAR_T_DEFINED
00072 typedef unsigned short wchar_t;
00073 #   define _WCHAR_T_DEFINED
00074 #  endif
00075 # endif //win32 end glut.h stuff
00076 
00077 /* XXX Hack for finding headers in Apple's OpenGL framework. */
00078 #if defined( __APPLE__ )
00079 #include <OpenGL/gl.h>
00080 #include <OpenGL/glu.h>
00081 #else /* __APPLE__ */
00082 #include <GL/gl.h>
00083 #include <GL/glu.h>
00084 #endif /* __APPLE__ */
00085 #include <list>
00086 #include <set>
00087 #include "CEGUIBase.h"
00088 #include "CEGUIRenderer.h"
00089 #include "CEGUITexture.h"
00090 
00091 
00092 #if defined(_WIN32)
00093 #  if defined(_DEBUG)
00094 #     pragma comment(lib, "CEGUIBase_d.lib")
00095 #  else
00096 #     pragma comment(lib, "CEGUIBase.lib")
00097 #  endif
00098 #endif
00099 
00100 #if defined(_MSC_VER)
00101 #       pragma warning(push)
00102 #       pragma warning(disable : 4251)
00103 #endif
00104 
00105 #define OGLRENDERER_VBUFF_CAPACITY      4096
00106 
00107 
00108 // Start of CEGUI namespace section
00109 namespace CEGUI
00110 {
00111 /*************************************************************************
00112         Forward refs
00113 *************************************************************************/
00114 class OpenGLTexture;
00115 
00120 class OPENGL_GUIRENDERER_API OpenGLRenderer : public Renderer
00121 {
00122 public:
00130     OpenGLRenderer(uint max_quads);
00131         OpenGLRenderer(uint max_quads,int width, int height);
00132 
00133 
00138     virtual ~OpenGLRenderer(void);
00139 
00140     // add's a quad to the list to be rendered
00141     virtual     void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00142 
00143     // perform final rendering for all queued renderable quads.
00144     virtual     void    doRender(void);
00145 
00146     // clear the queue
00147     virtual     void    clearRenderList(void);
00148 
00149 
00165     virtual void        setQueueingEnabled(bool setting)                {d_queueing = setting;}
00166 
00167 
00168     // create an empty texture
00169     virtual     Texture*        createTexture(void);
00170 
00171     // create a texture and load it with the specified file.
00172     virtual     Texture*        createTexture(const String& filename, const String& resourceGroup);
00173 
00174     // create a texture and set it to the specified size
00175     virtual     Texture*        createTexture(float size);
00176 
00177     // destroy the given texture
00178     virtual     void            destroyTexture(Texture* texture);
00179 
00180     // destroy all textures still active
00181     virtual void                destroyAllTextures(void);
00182 
00190     virtual bool        isQueueingEnabled(void) const   {return d_queueing;}
00191 
00192 
00200     virtual float       getWidth(void) const            {return d_display_area.getWidth();}
00201 
00202 
00210     virtual float       getHeight(void) const           {return d_display_area.getHeight();}
00211 
00212 
00220     virtual Size        getSize(void) const                     {return d_display_area.getSize();}
00221 
00222 
00231     virtual Rect        getRect(void) const                     {return d_display_area;}
00232 
00233 
00241     virtual     uint    getMaxTextureSize(void) const           {return d_maxTextureSize;}
00242 
00243 
00251     virtual     uint    getHorzScreenDPI(void) const    {return 96;}
00252 
00253 
00261     virtual     uint    getVertScreenDPI(void) const    {return 96;}
00262 
00263 
00281         void    setDisplaySize(const Size& sz);
00282 
00283 
00284 private:
00285     /************************************************************************
00286                 Implementation Constants
00287     ************************************************************************/
00288     const static int                    VERTEX_PER_QUAD;                                                        
00289     const static int                    VERTEX_PER_TRIANGLE;                                            
00290     const static int                    VERTEXBUFFER_CAPACITY;                                          
00291     
00292     /*************************************************************************
00293                 Implementation Structs & classes
00294     *************************************************************************/
00295     struct MyQuad
00296     {
00297         float tex[2];
00298         long color;
00299         float vertex[3];
00300     };
00301 
00306     struct QuadInfo
00307     {
00308         GLuint          texid;  
00309         Rect            position;
00310         float           z;
00311         Rect            texPosition;
00312                 long            topLeftCol;
00313                 long            topRightCol;
00314                 long            bottomLeftCol;
00315                 long            bottomRightCol;
00316 
00317         QuadSplitMode   splitMode;
00318 
00319                 bool operator<(const QuadInfo& other) const
00320                 {
00321                         // this is intentionally reversed.
00322                         return z > other.z;
00323                 }
00324 
00325     };
00326 
00327 
00328     /*************************************************************************
00329                 Implementation Methods
00330     *************************************************************************/
00331     // setup states etc
00332     void        initPerFrameStates(void);
00333 
00334     // restore states
00335     void  exitPerFrameStates(void);
00336 
00337     // render whatever is in the vertex buffer
00338     void        renderVBuffer(void);
00339 
00340     // sort quads list according to texture
00341     void        sortQuads(void);
00342 
00343     // render a quad directly to the display
00344     void        renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00345 
00346         // convert colour value to whatever the OpenGL system is expecting.
00347         long    colourToOGL(const colour& col) const;
00348 
00349         // set the module ID string
00350         void setModuleIdentifierString();
00351 
00352 
00353     /*************************************************************************
00354             Implementation Data
00355     *************************************************************************/
00356         typedef std::multiset<QuadInfo>         QuadList;
00357         QuadList d_quadlist;
00358 
00359         Rect            d_display_area;
00360 
00361         MyQuad          myBuff[OGLRENDERER_VBUFF_CAPACITY];
00362 
00363         bool            d_queueing;                     
00364         uint            d_currTexture;          
00365         int                     d_bufferPos;            
00366         bool            d_sorted;                       
00367 
00368         std::list<OpenGLTexture*>       d_texturelist;          
00369         GLint       d_maxTextureSize;           
00370 };
00371 
00372 } // End of  CEGUI namespace section
00373 
00374 #if defined(_MSC_VER)
00375 #       pragma warning(pop)
00376 #endif
00377 
00378 #endif  // end of guard _openglrenderer_h_

Generated on Wed Sep 7 09:56:35 2005 for Crazy Eddies GUI System by  doxygen 1.4.3