Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
RendererModules/OpenGLES/Renderer.h
1 /***********************************************************************
2  created: Sun Jan 11 2009
3  author: Paul D Turner
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _CEGUIOpenGLESRenderer_h_
28 #define _CEGUIOpenGLESRenderer_h_
29 
30 #include "CEGUI/Base.h"
31 #include "CEGUI/Renderer.h"
32 #include "CEGUI/Size.h"
33 #include "CEGUI/Vector.h"
34 #include "CEGUI/RendererModules/OpenGLES/GLES.h"
35 #include <vector>
36 #include <map>
37 
38 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
39 # ifdef CEGUIOPENGLESRENDERER_EXPORTS
40 # define OPENGLES_GUIRENDERER_API __declspec(dllexport)
41 # else
42 # define OPENGLES_GUIRENDERER_API __declspec(dllimport)
43 # endif
44 #else
45 # define OPENGLES_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 OpenGLESTexture;
58 class OpenGLESTextureTarget;
59 class OpenGLESGeometryBuffer;
60 class OGLTextureTargetFactory;
61 
66 class OPENGLES_GUIRENDERER_API OpenGLESRenderer : public Renderer
67 {
68 public:
71  {
79  TTT_NONE
80  };
81 
105  static OpenGLESRenderer& bootstrapSystem(
106  const TextureTargetType tt_type = TTT_AUTO,
107  const int abi = CEGUI_VERSION_ABI);
108 
135  static OpenGLESRenderer& bootstrapSystem(
136  const Sizef& display_size,
137  const TextureTargetType tt_type = TTT_AUTO,
138  const int abi = CEGUI_VERSION_ABI);
139 
155  static void destroySystem();
156 
168  static OpenGLESRenderer& create(const TextureTargetType tt_type = TTT_AUTO,
169  const int abi = CEGUI_VERSION_ABI);
170 
185  static OpenGLESRenderer& create(const Sizef& display_size,
186  const TextureTargetType tt_type = TTT_AUTO,
187  const int abi = CEGUI_VERSION_ABI);
188 
196  static void destroy(OpenGLESRenderer& renderer);
197 
206  static bool isGLExtensionSupported( const char* extension );
207 
208  // implement Renderer interface
209  RenderTarget& getDefaultRenderTarget();
210  GeometryBuffer& createGeometryBuffer();
211  void destroyGeometryBuffer(const GeometryBuffer& buffer);
212  void destroyAllGeometryBuffers();
213  TextureTarget* createTextureTarget();
214  void destroyTextureTarget(TextureTarget* target);
215  void destroyAllTextureTargets();
216  Texture& createTexture(const String& name);
217  Texture& createTexture(const String& name,
218  const String& filename,
219  const String& resourceGroup);
220  Texture& createTexture(const String& name, const Sizef& size);
221  void destroyTexture(Texture& texture);
222  void destroyTexture(const String& name);
223  void destroyAllTextures();
224  Texture& getTexture(const String& name) const;
225  bool isTextureDefined(const String& name) const;
226  void beginRendering();
227  void endRendering();
228  void setDisplaySize(const Sizef& sz);
229  const Sizef& getDisplaySize() const;
230  const Vector2f& getDisplayDPI() const;
231  uint getMaxTextureSize() const;
232  const String& getIdentifierString() const;
233 
248  Texture& createTexture(const String& name, GLuint tex, const Sizef& sz);
249 
261  void enableExtraStateSettings(bool setting);
262 
270  void grabTextures();
271 
277  void restoreTextures();
278 
290  Sizef getAdjustedTextureSize(const Sizef& sz) const;
291 
297  static float getNextPOTSize(const float f);
298 
299 private:
308  OpenGLESRenderer(const TextureTargetType tt_type);
309 
321  OpenGLESRenderer(const Sizef& display_size, const TextureTargetType tt_type);
322 
327  virtual ~OpenGLESRenderer();
328 
330  void setupExtraStates();
331 
333  void cleanupExtraStates();
334 
336  void initialiseTextureTargetFactory(const TextureTargetType tt_type);
337 
339  void logTextureDestruction(const String& name);
340 
342  struct RenderStates
343  {
344  GLboolean glScissorTest;
345  GLboolean texturing;
346  GLboolean blend;
347  GLint arrayBuffer;
348  GLint texture;
349  GLint texEnvParam;
350  } glPreRenderStates;
351 
353  static String d_rendererID;
355  Sizef d_displaySize;
357  Vector2f d_displayDPI;
359  RenderTarget* d_defaultTarget;
361  typedef std::vector<TextureTarget*> TextureTargetList;
363  TextureTargetList d_textureTargets;
365  typedef std::vector<OpenGLESGeometryBuffer*> GeometryBufferList;
367  GeometryBufferList d_geometryBuffers;
369  typedef std::map<String, OpenGLESTexture*, StringFastLessCompare
370  CEGUI_MAP_ALLOC(String, OpenGLESTexture*)> TextureMap;
372  TextureMap d_textures;
374  uint d_maxTextureSize;
376  bool d_initExtraStates;
378  OGLTextureTargetFactory* d_textureTargetFactory;
379  };
380 
381 } // End of CEGUI namespace section
382 
383 #if defined(_MSC_VER)
384 # pragma warning(pop)
385 #endif
386 
387 #endif // end of guard _CEGUIOpenGLESRenderer_h_
388