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 #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
00103 namespace CEGUI
00104 {
00105
00106
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
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
00138 virtual void doRender(void);
00139
00140
00141 virtual void clearRenderList(void);
00142
00143
00159 virtual void setQueueingEnabled(bool setting) {d_queueing = setting;}
00160
00161
00162
00163 virtual Texture* createTexture(void);
00164
00165
00166 virtual Texture* createTexture(const String& filename, const String& resourceGroup);
00167
00168
00169 virtual Texture* createTexture(float size);
00170
00171
00172 virtual void destroyTexture(Texture* texture);
00173
00174
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
00261
00262 const static int VERTEX_PER_QUAD;
00263 const static int VERTEX_PER_TRIANGLE;
00264 const static int VERTEXBUFFER_CAPACITY;
00265
00266
00267
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
00296 return z > other.z;
00297 }
00298
00299 };
00300
00301
00302
00303
00304
00305
00306 void initPerFrameStates(void);
00307
00308
00309 void exitPerFrameStates(void);
00310
00311
00312 void renderVBuffer(void);
00313
00314
00315 void sortQuads(void);
00316
00317
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
00321 long colourToOGL(const colour& col) const;
00322
00323
00324
00325
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 }
00344
00345 #if defined(_MSC_VER)
00346 # pragma warning(pop)
00347 #endif
00348
00349 #endif // end of guard _openglrenderer_h_