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

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 #include <GL/gl.h>
00078 #include <GL/glu.h>
00079 #include <list>
00080 #include <set>
00081 #include "CEGUIBase.h"
00082 #include "CEGUIRenderer.h"
00083 #include "CEGUITexture.h"
00084 
00085 
00086 #if defined(_WIN32)
00087 #  if defined(_DEBUG)
00088 #     pragma comment(lib, "CEGUIBase_d.lib")
00089 #  else
00090 #     pragma comment(lib, "CEGUIBase.lib")
00091 #  endif
00092 #endif
00093 
00094 #if defined(_MSC_VER)
00095 #       pragma warning(push)
00096 #       pragma warning(disable : 4251)
00097 #endif
00098 
00099 #define OGLRENDERER_VBUFF_CAPACITY      4096
00100 
00101 
00102 // Start of CEGUI namespace section
00103 namespace CEGUI
00104 {
00105 /*************************************************************************
00106         Forward refs
00107 *************************************************************************/
00108 class OpenGLTexture;
00109 
00114 class OPENGL_GUIRENDERER_API OpenGLRenderer : public Renderer
00115 {
00116 public:
00124     OpenGLRenderer(uint max_quads);
00125         OpenGLRenderer(uint max_quads,int width, int height);
00126 
00127 
00132     virtual ~OpenGLRenderer(void);
00133 
00134     // add's a quad to the list to be rendered
00135     virtual     void    addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00136 
00137     // perform final rendering for all queued renderable quads.
00138     virtual     void    doRender(void);
00139 
00140     // clear the queue
00141     virtual     void    clearRenderList(void);
00142 
00143 
00159     virtual void        setQueueingEnabled(bool setting)                {d_queueing = setting;}
00160 
00161 
00162     // create an empty texture
00163     virtual     Texture*        createTexture(void);
00164 
00165     // create a texture and load it with the specified file.
00166     virtual     Texture*        createTexture(const String& filename, const String& resourceGroup);
00167 
00168     // create a texture and set it to the specified size
00169     virtual     Texture*        createTexture(float size);
00170 
00171     // destroy the given texture
00172     virtual     void            destroyTexture(Texture* texture);
00173 
00174     // destroy all textures still active
00175     virtual void                destroyAllTextures(void);
00176 
00184     virtual bool        isQueueingEnabled(void) const   {return d_queueing;}
00185 
00186 
00194     virtual float       getWidth(void) const            {return d_display_area.getWidth();}
00195 
00196 
00204     virtual float       getHeight(void) const           {return d_display_area.getHeight();}
00205 
00206 
00214     virtual Size        getSize(void) const                     {return d_display_area.getSize();}
00215 
00216 
00225     virtual Rect        getRect(void) const                     {return d_display_area;}
00226 
00227 
00235     virtual     uint    getMaxTextureSize(void) const           {return d_maxTextureSize;}
00236 
00237 
00245     virtual     uint    getHorzScreenDPI(void) const    {return 96;}
00246 
00247 
00255     virtual     uint    getVertScreenDPI(void) const    {return 96;}
00256 
00257 
00258 private:
00259     /************************************************************************
00260                 Implementation Constants
00261     ************************************************************************/
00262     const static int                    VERTEX_PER_QUAD;                                                        
00263     const static int                    VERTEX_PER_TRIANGLE;                                            
00264     const static int                    VERTEXBUFFER_CAPACITY;                                          
00265     
00266     /*************************************************************************
00267                 Implementation Structs & classes
00268     *************************************************************************/
00269     struct MyQuad
00270     {
00271         float tex[2];
00272         long color;
00273         float vertex[3];
00274     };
00275 
00280     struct QuadInfo
00281     {
00282         uint            texid;  
00283         Rect            position;
00284         float           z;
00285         Rect            texPosition;
00286                 long            topLeftCol;
00287                 long            topRightCol;
00288                 long            bottomLeftCol;
00289                 long            bottomRightCol;
00290 
00291         QuadSplitMode   splitMode;
00292 
00293                 bool operator<(const QuadInfo& other) const
00294                 {
00295                         // this is intentionally reversed.
00296                         return z > other.z;
00297                 }
00298 
00299     };
00300 
00301 
00302     /*************************************************************************
00303                 Implementation Methods
00304     *************************************************************************/
00305     // setup states etc
00306     void        initPerFrameStates(void);
00307 
00308     // restore states
00309     void  exitPerFrameStates(void);
00310 
00311     // render whatever is in the vertex buffer
00312     void        renderVBuffer(void);
00313 
00314     // sort quads list according to texture
00315     void        sortQuads(void);
00316 
00317     // render a quad directly to the display
00318     void        renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00319 
00320         // convert colour value to whatever the OpenGL system is expecting.
00321         long    colourToOGL(const colour& col) const;
00322 
00323 
00324     /*************************************************************************
00325             Implementation Data
00326     *************************************************************************/
00327         typedef std::multiset<QuadInfo>         QuadList;
00328         QuadList d_quadlist;
00329 
00330         Rect            d_display_area;
00331 
00332         MyQuad          myBuff[OGLRENDERER_VBUFF_CAPACITY];
00333 
00334         bool            d_queueing;                     
00335         uint            d_currTexture;          
00336         int                     d_bufferPos;            
00337         bool            d_sorted;                       
00338 
00339         std::list<OpenGLTexture*>       d_texturelist;          
00340         int     d_maxTextureSize;               
00341 };
00342 
00343 } // End of  CEGUI namespace section
00344 
00345 #if defined(_MSC_VER)
00346 #       pragma warning(pop)
00347 #endif
00348 
00349 #endif  // end of guard _openglrenderer_h_

Generated on Wed Feb 16 12:41:08 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1