Crazy Eddies GUI System  0.7.1
CEGUIOpenGLRenderer.h
1 /***********************************************************************
2  filename: CEGUIOpenGLRenderer.h
3  created: Sun Jan 11 2009
4  author: Paul D Turner
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2009 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 
90  static OpenGLRenderer& create(const TextureTargetType tt_type = TTT_AUTO);
91 
103  static OpenGLRenderer& create(const Size& display_size,
104  const TextureTargetType tt_type = TTT_AUTO);
105 
113  static void destroy(OpenGLRenderer& renderer);
114 
115  // implement Renderer interface
116  RenderingRoot& getDefaultRenderingRoot();
117  GeometryBuffer& createGeometryBuffer();
118  void destroyGeometryBuffer(const GeometryBuffer& buffer);
119  void destroyAllGeometryBuffers();
120  TextureTarget* createTextureTarget();
121  void destroyTextureTarget(TextureTarget* target);
122  void destroyAllTextureTargets();
123  Texture& createTexture();
124  Texture& createTexture(const String& filename, const String& resourceGroup);
125  Texture& createTexture(const Size& size);
126  void destroyTexture(Texture& texture);
127  void destroyAllTextures();
128  void beginRendering();
129  void endRendering();
130  void setDisplaySize(const Size& sz);
131  const Size& getDisplaySize() const;
132  const Vector2& getDisplayDPI() const;
133  uint getMaxTextureSize() const;
134  const String& getIdentifierString() const;
135 
150  Texture& createTexture(GLuint tex, const Size& sz);
151 
163  void enableExtraStateSettings(bool setting);
164 
172  void grabTextures();
173 
179  void restoreTextures();
180 
192  Size getAdjustedTextureSize(const Size& sz) const;
193 
199  static float getNextPOTSize(const float f);
200 
201 private:
210  OpenGLRenderer(const TextureTargetType tt_type);
211 
223  OpenGLRenderer(const Size& display_size, const TextureTargetType tt_type);
224 
229  virtual ~OpenGLRenderer();
230 
232  void setupExtraStates();
233 
235  void cleanupExtraStates();
236 
238  void initialiseTextureTargetFactory(const TextureTargetType tt_type);
239 
241  static String d_rendererID;
243  Size d_displaySize;
245  Vector2 d_displayDPI;
247  RenderingRoot* d_defaultRoot;
249  RenderTarget* d_defaultTarget;
251  typedef std::vector<TextureTarget*> TextureTargetList;
253  TextureTargetList d_textureTargets;
255  typedef std::vector<OpenGLGeometryBuffer*> GeometryBufferList;
257  GeometryBufferList d_geometryBuffers;
259  typedef std::vector<OpenGLTexture*> TextureList;
261  TextureList d_textures;
263  uint d_maxTextureSize;
265  bool d_initExtraStates;
267  OGLTextureTargetFactory* d_textureTargetFactory;
268  };
269 
270 } // End of CEGUI namespace section
271 
272 #if defined(_MSC_VER)
273 # pragma warning(pop)
274 #endif
275 
276 #endif // end of guard _CEGUIOpenGLRenderer_h_