Crazy Eddies GUI System  0.7.8
CEGUIOpenGLRenderer.h
1 /***********************************************************************
2  filename: CEGUIOpenGLRenderer.h
3  created: Sun Jan 11 2009
4  author: Paul D Turner
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUIOpenGLRenderer_h_
29 #define _CEGUIOpenGLRenderer_h_
30 
31 #include "../../CEGUIBase.h"
32 #include "../../CEGUIRenderer.h"
33 #include "../../CEGUISize.h"
34 #include "../../CEGUIVector.h"
35 #include "CEGUIOpenGL.h"
36 #include <vector>
37 
38 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
39 # ifdef OPENGL_GUIRENDERER_EXPORTS
40 # define OPENGL_GUIRENDERER_API __declspec(dllexport)
41 # else
42 # define OPENGL_GUIRENDERER_API __declspec(dllimport)
43 # endif
44 #else
45 # define OPENGL_GUIRENDERER_API
46 #endif
47 
48 #if defined(_MSC_VER)
49 # pragma warning(push)
50 # pragma warning(disable : 4251)
51 #endif
52 
53 
54 // Start of CEGUI namespace section
55 namespace CEGUI
56 {
57 class OpenGLTexture;
58 class OpenGLTextureTarget;
59 class OpenGLGeometryBuffer;
60 class OGLTextureTargetFactory;
61 
66 class OPENGL_GUIRENDERER_API OpenGLRenderer : public Renderer
67 {
68 public:
71  {
79  TTT_NONE
80  };
81 
102  static OpenGLRenderer& bootstrapSystem(
103  const TextureTargetType tt_type = TTT_AUTO);
104 
128  static OpenGLRenderer& bootstrapSystem(const Size& display_size,
129  const TextureTargetType tt_type = TTT_AUTO);
130 
146  static void destroySystem();
147 
156  static OpenGLRenderer& create(const TextureTargetType tt_type = TTT_AUTO);
157 
169  static OpenGLRenderer& create(const Size& display_size,
170  const TextureTargetType tt_type = TTT_AUTO);
171 
179  static void destroy(OpenGLRenderer& renderer);
180 
181  // implement Renderer interface
182  RenderingRoot& getDefaultRenderingRoot();
183  GeometryBuffer& createGeometryBuffer();
184  void destroyGeometryBuffer(const GeometryBuffer& buffer);
185  void destroyAllGeometryBuffers();
186  TextureTarget* createTextureTarget();
187  void destroyTextureTarget(TextureTarget* target);
188  void destroyAllTextureTargets();
189  Texture& createTexture();
190  Texture& createTexture(const String& filename, const String& resourceGroup);
191  Texture& createTexture(const Size& size);
192  void destroyTexture(Texture& texture);
193  void destroyAllTextures();
194  void beginRendering();
195  void endRendering();
196  void setDisplaySize(const Size& sz);
197  const Size& getDisplaySize() const;
198  const Vector2& getDisplayDPI() const;
199  uint getMaxTextureSize() const;
200  const String& getIdentifierString() const;
201 
216  Texture& createTexture(GLuint tex, const Size& sz);
217 
229  void enableExtraStateSettings(bool setting);
230 
238  void grabTextures();
239 
245  void restoreTextures();
246 
258  Size getAdjustedTextureSize(const Size& sz) const;
259 
265  static float getNextPOTSize(const float f);
266 
268  void setupRenderingBlendMode(const BlendMode mode, const bool force = false);
269 
270 private:
279  OpenGLRenderer(const TextureTargetType tt_type);
280 
292  OpenGLRenderer(const Size& display_size, const TextureTargetType tt_type);
293 
298  virtual ~OpenGLRenderer();
299 
301  void setupExtraStates();
302 
304  void cleanupExtraStates();
305 
307  void initialiseTextureTargetFactory(const TextureTargetType tt_type);
308 
310  static String d_rendererID;
312  Size d_displaySize;
314  Vector2 d_displayDPI;
316  RenderingRoot* d_defaultRoot;
318  RenderTarget* d_defaultTarget;
320  typedef std::vector<TextureTarget*> TextureTargetList;
322  TextureTargetList d_textureTargets;
324  typedef std::vector<OpenGLGeometryBuffer*> GeometryBufferList;
326  GeometryBufferList d_geometryBuffers;
328  typedef std::vector<OpenGLTexture*> TextureList;
330  TextureList d_textures;
332  uint d_maxTextureSize;
334  bool d_initExtraStates;
336  OGLTextureTargetFactory* d_textureTargetFactory;
338  BlendMode d_activeBlendMode;
339  };
340 
341 } // End of CEGUI namespace section
342 
343 #if defined(_MSC_VER)
344 # pragma warning(pop)
345 #endif
346 
347 #endif // end of guard _CEGUIOpenGLRenderer_h_