Crazy Eddie's GUI System  0.8.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
RendererModules/OpenGLES/Renderer.h
1 /***********************************************************************
2  filename: CEGUIOpenGLESRenderer.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 _CEGUIOpenGLESRenderer_h_
29 #define _CEGUIOpenGLESRenderer_h_
30 
31 #include "CEGUI/Base.h"
32 #include "CEGUI/Renderer.h"
33 #include "CEGUI/Size.h"
34 #include "CEGUI/Vector.h"
35 #include "CEGUI/RendererModules/OpenGLES/GLES.h"
36 #include <vector>
37 #include <map>
38 
39 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
40 # ifdef CEGUIOPENGLESRENDERER_EXPORTS
41 # define OPENGLES_GUIRENDERER_API __declspec(dllexport)
42 # else
43 # define OPENGLES_GUIRENDERER_API __declspec(dllimport)
44 # endif
45 #else
46 # define OPENGLES_GUIRENDERER_API
47 #endif
48 
49 #if defined(_MSC_VER)
50 # pragma warning(push)
51 # pragma warning(disable : 4251)
52 #endif
53 
54 
55 // Start of CEGUI namespace section
56 namespace CEGUI
57 {
58 class OpenGLESTexture;
59 class OpenGLESTextureTarget;
60 class OpenGLESGeometryBuffer;
61 class OGLTextureTargetFactory;
62 
67 class OPENGLES_GUIRENDERER_API OpenGLESRenderer : public Renderer
68 {
69 public:
72  {
80  TTT_NONE
81  };
82 
106  static OpenGLESRenderer& bootstrapSystem(
107  const TextureTargetType tt_type = TTT_AUTO,
108  const int abi = CEGUI_VERSION_ABI);
109 
136  static OpenGLESRenderer& bootstrapSystem(
137  const Sizef& display_size,
138  const TextureTargetType tt_type = TTT_AUTO,
139  const int abi = CEGUI_VERSION_ABI);
140 
156  static void destroySystem();
157 
169  static OpenGLESRenderer& create(const TextureTargetType tt_type = TTT_AUTO,
170  const int abi = CEGUI_VERSION_ABI);
171 
186  static OpenGLESRenderer& create(const Sizef& display_size,
187  const TextureTargetType tt_type = TTT_AUTO,
188  const int abi = CEGUI_VERSION_ABI);
189 
197  static void destroy(OpenGLESRenderer& renderer);
198 
207  static bool isGLExtensionSupported( const char* extension );
208 
209  // implement Renderer interface
210  RenderTarget& getDefaultRenderTarget();
211  GeometryBuffer& createGeometryBuffer();
212  void destroyGeometryBuffer(const GeometryBuffer& buffer);
213  void destroyAllGeometryBuffers();
214  TextureTarget* createTextureTarget();
215  void destroyTextureTarget(TextureTarget* target);
216  void destroyAllTextureTargets();
217  Texture& createTexture(const String& name);
218  Texture& createTexture(const String& name,
219  const String& filename,
220  const String& resourceGroup);
221  Texture& createTexture(const String& name, const Sizef& size);
222  void destroyTexture(Texture& texture);
223  void destroyTexture(const String& name);
224  void destroyAllTextures();
225  Texture& getTexture(const String& name) const;
226  bool isTextureDefined(const String& name) const;
227  void beginRendering();
228  void endRendering();
229  void setDisplaySize(const Sizef& sz);
230  const Sizef& getDisplaySize() const;
231  const Vector2f& getDisplayDPI() const;
232  uint getMaxTextureSize() const;
233  const String& getIdentifierString() const;
234 
249  Texture& createTexture(const String& name, GLuint tex, const Sizef& sz);
250 
262  void enableExtraStateSettings(bool setting);
263 
271  void grabTextures();
272 
278  void restoreTextures();
279 
291  Sizef getAdjustedTextureSize(const Sizef& sz) const;
292 
298  static float getNextPOTSize(const float f);
299 
300 private:
309  OpenGLESRenderer(const TextureTargetType tt_type);
310 
322  OpenGLESRenderer(const Sizef& display_size, const TextureTargetType tt_type);
323 
328  virtual ~OpenGLESRenderer();
329 
331  void setupExtraStates();
332 
334  void cleanupExtraStates();
335 
337  void initialiseTextureTargetFactory(const TextureTargetType tt_type);
338 
340  void logTextureDestruction(const String& name);
341 
343  struct RenderStates
344  {
345  GLboolean glScissorTest;
346  GLboolean texturing;
347  GLboolean blend;
348  GLint arrayBuffer;
349  GLint texture;
350  GLint texEnvParam;
351  } glPreRenderStates;
352 
354  static String d_rendererID;
356  Sizef d_displaySize;
358  Vector2f d_displayDPI;
360  RenderTarget* d_defaultTarget;
362  typedef std::vector<TextureTarget*> TextureTargetList;
364  TextureTargetList d_textureTargets;
366  typedef std::vector<OpenGLESGeometryBuffer*> GeometryBufferList;
368  GeometryBufferList d_geometryBuffers;
370  typedef std::map<String, OpenGLESTexture*, StringFastLessCompare
371  CEGUI_MAP_ALLOC(String, OpenGLESTexture*)> TextureMap;
373  TextureMap d_textures;
375  uint d_maxTextureSize;
377  bool d_initExtraStates;
379  OGLTextureTargetFactory* d_textureTargetFactory;
380  };
381 
382 } // End of CEGUI namespace section
383 
384 #if defined(_MSC_VER)
385 # pragma warning(pop)
386 #endif
387 
388 #endif // end of guard _CEGUIOpenGLESRenderer_h_
389