00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _openglrenderer_h_
00032 #define _openglrenderer_h_
00033
00034 #include "CEGUIBase.h"
00035
00036 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
00037 # ifdef OPENGL_GUIRENDERER_EXPORTS
00038 # define OPENGL_GUIRENDERER_API __declspec(dllexport)
00039 # else
00040 # define OPENGL_GUIRENDERER_API __declspec(dllimport)
00041 # endif
00042 #else
00043 # define OPENGL_GUIRENDERER_API
00044 #endif
00045
00046
00047 #if defined(_WIN32)// All this taken from glut.h
00048 # ifndef APIENTRY
00049 # define GLUT_APIENTRY_DEFINED
00050 # if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED) || defined(__BORLANDC__) || defined(__LCC__) || defined(__GNUC__)
00051 # define APIENTRY __stdcall
00052 # else
00053 # define APIENTRY
00054 # endif
00055 # endif
00056
00057 # ifndef CALLBACK
00058 # if (defined(_M_MRX000) || defined(_M_IX86) || defined(_M_ALPHA) || defined(_M_PPC)) && !defined(MIDL_PASS) || defined(__LCC__) || defined(__GNUC__)
00059 # define CALLBACK __stdcall
00060 # else
00061 # define CALLBACK
00062 # endif
00063 # endif
00064
00065 # if defined( __LCC__ )
00066 # undef WINGDIAPI
00067 # define WINGDIAPI __stdcall
00068 # else
00069
00070 # ifndef WINGDIAPI
00071 # define GLUT_WINGDIAPI_DEFINED
00072 # define WINGDIAPI __declspec(dllimport)
00073 # endif
00074 # endif
00075
00076 # ifndef _WCHAR_T_DEFINED
00077 typedef unsigned short wchar_t;
00078 # define _WCHAR_T_DEFINED
00079 # endif
00080 # endif //win32 end glut.h stuff
00081
00082
00083 #if defined( __APPLE__ )
00084 #include <OpenGL/gl.h>
00085 #include <OpenGL/glu.h>
00086 #else
00087 #include <GL/gl.h>
00088 #include <GL/glu.h>
00089 #endif
00090 #include <list>
00091 #include <set>
00092
00093 #include "CEGUIRenderer.h"
00094 #include "CEGUITexture.h"
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 #if defined(_MSC_VER)
00106 # pragma warning(push)
00107 # pragma warning(disable : 4251)
00108 #endif
00109
00110 #define OGLRENDERER_VBUFF_CAPACITY 4096
00111
00112
00113
00114 namespace CEGUI
00115 {
00116
00117
00118
00119 class OpenGLTexture;
00120 class ImageCodec;
00121 class DynamicModule;
00122
00127 class OPENGL_GUIRENDERER_API OpenGLRenderer : public Renderer
00128 {
00129 public:
00141 OpenGLRenderer(uint max_quads, ImageCodec* codec = 0);
00159 OpenGLRenderer(uint max_quads,int width, int height, ImageCodec* codec = 0);
00160
00161
00166 virtual ~OpenGLRenderer(void);
00167
00168
00169 virtual void addQuad(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00170
00171
00172 virtual void doRender(void);
00173
00174
00175 virtual void clearRenderList(void);
00176
00177
00193 virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
00194
00195
00196
00197 virtual Texture* createTexture(void);
00198
00199
00200 virtual Texture* createTexture(const String& filename, const String& resourceGroup);
00201
00202
00203 virtual Texture* createTexture(float size);
00204
00205
00206 virtual void destroyTexture(Texture* texture);
00207
00208
00209 virtual void destroyAllTextures(void);
00210
00218 virtual bool isQueueingEnabled(void) const {return d_queueing;}
00219
00220
00228 virtual float getWidth(void) const {return d_display_area.getWidth();}
00229
00230
00238 virtual float getHeight(void) const {return d_display_area.getHeight();}
00239
00240
00248 virtual Size getSize(void) const {return d_display_area.getSize();}
00249
00250
00259 virtual Rect getRect(void) const {return d_display_area;}
00260
00261
00269 virtual uint getMaxTextureSize(void) const {return d_maxTextureSize;}
00270
00271
00279 virtual uint getHorzScreenDPI(void) const {return 96;}
00280
00281
00289 virtual uint getVertScreenDPI(void) const {return 96;}
00290
00291
00309 void setDisplaySize(const Size& sz);
00310
00311
00318 void grabTextures(void);
00319
00320
00325 void restoreTextures(void);
00326
00331 ImageCodec& getImageCodec(void);
00332
00333
00338 void setImageCodec(const String& codecName);
00339
00349 void setImageCodec(ImageCodec* codec);
00350
00351
00356 static void setDefaultImageCodecName(const String& codecName);
00357
00362 static const String& getDefaultImageCodecName();
00363
00364
00365 private:
00366
00367
00368
00369 static const int VERTEX_PER_QUAD;
00370 static const int VERTEX_PER_TRIANGLE;
00371 static const int VERTEXBUFFER_CAPACITY;
00372
00373
00374
00375
00376 struct MyQuad
00377 {
00378 float tex[2];
00379 uint32 color;
00380 float vertex[3];
00381 };
00382
00387 struct QuadInfo
00388 {
00389 GLuint texid;
00390 Rect position;
00391 float z;
00392 Rect texPosition;
00393 uint32 topLeftCol;
00394 uint32 topRightCol;
00395 uint32 bottomLeftCol;
00396 uint32 bottomRightCol;
00397
00398 QuadSplitMode splitMode;
00399
00400 bool operator<(const QuadInfo& other) const
00401 {
00402
00403 return z > other.z;
00404 }
00405
00406 };
00407
00408
00409
00410
00411
00412
00413 void initPerFrameStates(void);
00414
00415
00416 void exitPerFrameStates(void);
00417
00418
00419 void renderVBuffer(void);
00420
00421
00422 void sortQuads(void);
00423
00424
00425 void renderQuadDirect(const Rect& dest_rect, float z, const Texture* tex, const Rect& texture_rect, const ColourRect& colours, QuadSplitMode quad_split_mode);
00426
00427
00428 uint32 colourToOGL(const colour& col) const;
00429
00430
00431 void setModuleIdentifierString();
00432
00433
00434 void setupImageCodec(const String& codecName);
00435
00436
00437 void cleanupImageCodec();
00438
00439
00440
00441
00442 typedef std::multiset<QuadInfo> QuadList;
00443 QuadList d_quadlist;
00444
00445 Rect d_display_area;
00446
00447 MyQuad myBuff[OGLRENDERER_VBUFF_CAPACITY];
00448
00449 bool d_queueing;
00450 uint d_currTexture;
00451 int d_bufferPos;
00452 bool d_sorted;
00453
00454 std::list<OpenGLTexture*> d_texturelist;
00455 GLint d_maxTextureSize;
00456
00457 ImageCodec* d_imageCodec;
00458 DynamicModule* d_imageCodecModule;
00459
00460 static String d_defaultImageCodecName;
00461
00462
00463 };
00464
00465 }
00466
00467 #if defined(_MSC_VER)
00468 # pragma warning(pop)
00469 #endif
00470
00471 #endif // end of guard _openglrenderer_h_