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
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
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
00060 # if defined( __LCC__ )
00061 # undef WINGDIAPI
00062 # define WINGDIAPI __stdcall
00063 # else
00064
00065 # ifndef WINGDIAPI
00066 # define GLUT_WINGDIAPI_DEFINED
00067 # define WINGDIAPI __declspec(dllimport)
00068 # endif
00069 # endif
00070
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
00078 #if defined( __APPLE__ )
00079 #include <OpenGL/gl.h>
00080 #include <OpenGL/glu.h>
00081 #else
00082 #include <GL/gl.h>
00083 #include <GL/glu.h>
00084 #endif
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
00109 namespace CEGUI
00110 {
00111
00112
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
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
00144 virtual void doRender(void);
00145
00146
00147 virtual void clearRenderList(void);
00148
00149
00165 virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
00166
00167
00168
00169 virtual Texture* createTexture(void);
00170
00171
00172 virtual Texture* createTexture(const String& filename, const String& resourceGroup);
00173
00174
00175 virtual Texture* createTexture(float size);
00176
00177
00178 virtual void destroyTexture(Texture* texture);
00179
00180
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
00287
00288 const static int VERTEX_PER_QUAD;
00289 const static int VERTEX_PER_TRIANGLE;
00290 const static int VERTEXBUFFER_CAPACITY;
00291
00292
00293
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
00322 return z > other.z;
00323 }
00324
00325 };
00326
00327
00328
00329
00330
00331
00332 void initPerFrameStates(void);
00333
00334
00335 void exitPerFrameStates(void);
00336
00337
00338 void renderVBuffer(void);
00339
00340
00341 void sortQuads(void);
00342
00343
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
00347 long colourToOGL(const colour& col) const;
00348
00349
00350 void setModuleIdentifierString();
00351
00352
00353
00354
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 }
00373
00374 #if defined(_MSC_VER)
00375 # pragma warning(pop)
00376 #endif
00377
00378 #endif // end of guard _openglrenderer_h_