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 #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
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
00061 # if defined( __LCC__ )
00062 # undef WINGDIAPI
00063 # define WINGDIAPI __stdcall
00064 # else
00065
00066 # ifndef WINGDIAPI
00067 # define GLUT_WINGDIAPI_DEFINED
00068 # define WINGDIAPI __declspec(dllimport)
00069 # endif
00070 # endif
00071
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
00079 #if defined( __APPLE__ )
00080 #include <OpenGL/gl.h>
00081 #include <OpenGL/glu.h>
00082 #else
00083 #include <GL/gl.h>
00084 #include <GL/glu.h>
00085 #endif
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
00110 namespace CEGUI
00111 {
00112
00113
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
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
00145 virtual void doRender(void);
00146
00147
00148 virtual void clearRenderList(void);
00149
00150
00166 virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
00167
00168
00169
00170 virtual Texture* createTexture(void);
00171
00172
00173 virtual Texture* createTexture(const String& filename, const String& resourceGroup);
00174
00175
00176 virtual Texture* createTexture(float size);
00177
00178
00179 virtual void destroyTexture(Texture* texture);
00180
00181
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
00304
00305 static const int VERTEX_PER_QUAD;
00306 static const int VERTEX_PER_TRIANGLE;
00307 static const int VERTEXBUFFER_CAPACITY;
00308
00309
00310
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
00339 return z > other.z;
00340 }
00341
00342 };
00343
00344
00345
00346
00347
00348
00349 void initPerFrameStates(void);
00350
00351
00352 void exitPerFrameStates(void);
00353
00354
00355 void renderVBuffer(void);
00356
00357
00358 void sortQuads(void);
00359
00360
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
00364 long colourToOGL(const colour& col) const;
00365
00366
00367 void setModuleIdentifierString();
00368
00369
00370
00371
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 }
00390
00391 #if defined(_MSC_VER)
00392 # pragma warning(pop)
00393 #endif
00394
00395 #endif // end of guard _openglrenderer_h_