Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
RendererModules/OpenGL/Texture.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 _CEGUIOpenGLTexture_h_
28 #define _CEGUIOpenGLTexture_h_
29 
30 #include "../../Base.h"
31 #include "../../Renderer.h"
32 #include "../../Texture.h"
33 #include "CEGUI/RendererModules/OpenGL/RendererBase.h"
34 
35 #if defined(_MSC_VER)
36 # pragma warning(push)
37 # pragma warning(disable : 4251)
38 #endif
39 
40 // Start of CEGUI namespace section
41 namespace CEGUI
42 {
44 class OPENGL_GUIRENDERER_API OpenGLTexture : public Texture
45 {
46 public:
52  void setOpenGLTexture(GLuint tex, const Sizef& size);
53 
61  GLuint getOpenGLTexture() const;
62 
83  void setTextureSize(const Sizef& sz);
84 
92  void grabTexture();
93 
99  void restoreTexture();
100 
101  // implement abstract members from base class.
102  const String& getName() const;
103  const Sizef& getSize() const;
104  const Sizef& getOriginalDataSize() const;
105  const Vector2f& getTexelScaling() const;
106  void loadFromFile(const String& filename, const String& resourceGroup);
107  void loadFromMemory(const void* buffer, const Sizef& buffer_size,
108  PixelFormat pixel_format);
109  void blitFromMemory(const void* sourceData, const Rectf& area);
110  void blitToMemory(void* targetData);
111  bool isPixelFormatSupported(const PixelFormat fmt) const;
112 
113 protected:
114  // Friends (to allow construction and destruction)
116  friend Texture& OpenGLRendererBase::createTexture(const String&, const String&, const String&);
117  friend Texture& OpenGLRendererBase::createTexture(const String&, const Sizef&);
118  friend Texture& OpenGLRendererBase::createTexture(const String&, GLuint, const Sizef&);
120  friend void OpenGLRendererBase::destroyTexture(const String&);
121 
123  OpenGLTexture(OpenGLRendererBase& owner, const String& name);
125  OpenGLTexture(OpenGLRendererBase& owner, const String& name,
126  const String& filename, const String& resourceGroup);
128  OpenGLTexture(OpenGLRendererBase& owner, const String& name,
129  const Sizef& size);
131  OpenGLTexture(OpenGLRendererBase& owner, const String& name,
132  GLuint tex, const Sizef& size);
134  virtual ~OpenGLTexture();
135 
137  void generateOpenGLTexture();
138 
140  void updateCachedScaleValues();
141 
143  void cleanupOpenGLTexture();
144 
146  void initInternalPixelFormatFields(const PixelFormat fmt);
147 
149  void setTextureSize_impl(const Sizef& sz);
150 
151  void loadUncompressedTextureBuffer(const Rectf& dest_area,
152  const GLvoid* buffer) const;
153 
154  void loadCompressedTextureBuffer(const Rectf& dest_area,
155  const GLvoid* buffer) const;
156 
157  GLsizei getCompressedTextureSize(const Sizef& pixel_size) const;
158 
160  GLuint d_ogltexture;
164  uint8* d_grabBuffer;
172  const String d_name;
174  GLenum d_format;
179 };
180 
181 } // End of CEGUI namespace section
182 
183 #if defined(_MSC_VER)
184 # pragma warning(pop)
185 #endif
186 
187 #endif // end of guard _CEGUIOpenGLTexture_h_