Crazy Eddie's GUI System  0.8.4
Texture.h
00001 /***********************************************************************
00002     created:    Sun Jan 11 2009
00003     author:     Paul D Turner
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUIOpenGLTexture_h_
00028 #define _CEGUIOpenGLTexture_h_
00029 
00030 #include "../../Base.h"
00031 #include "../../Renderer.h"
00032 #include "../../Texture.h"
00033 #include "CEGUI/RendererModules/OpenGL/RendererBase.h"
00034 
00035 #if defined(_MSC_VER)
00036 #       pragma warning(push)
00037 #       pragma warning(disable : 4251)
00038 #endif
00039 
00040 // Start of CEGUI namespace section
00041 namespace CEGUI
00042 {
00044 class OPENGL_GUIRENDERER_API OpenGLTexture : public Texture
00045 {
00046 public:
00052     void setOpenGLTexture(GLuint tex, const Sizef& size);
00053 
00061     GLuint getOpenGLTexture() const;
00062 
00083     void setTextureSize(const Sizef& sz);
00084 
00092     void grabTexture();
00093 
00099     void restoreTexture();
00100 
00101     // implement abstract members from base class.
00102     const String& getName() const;
00103     const Sizef& getSize() const;
00104     const Sizef& getOriginalDataSize() const;
00105     const Vector2f& getTexelScaling() const;
00106     void loadFromFile(const String& filename, const String& resourceGroup);
00107     void loadFromMemory(const void* buffer, const Sizef& buffer_size,
00108                         PixelFormat pixel_format);
00109     void blitFromMemory(const void* sourceData, const Rectf& area);
00110     void blitToMemory(void* targetData);
00111     bool isPixelFormatSupported(const PixelFormat fmt) const;
00112 
00113 protected:
00114     // Friends (to allow construction and destruction)
00115     friend Texture& OpenGLRendererBase::createTexture(const String&);
00116     friend Texture& OpenGLRendererBase::createTexture(const String&, const String&, const String&);
00117     friend Texture& OpenGLRendererBase::createTexture(const String&, const Sizef&);
00118     friend Texture& OpenGLRendererBase::createTexture(const String&, GLuint, const Sizef&);
00119     friend void OpenGLRendererBase::destroyTexture(Texture&);
00120     friend void OpenGLRendererBase::destroyTexture(const String&);
00121 
00123     OpenGLTexture(OpenGLRendererBase& owner, const String& name);
00125     OpenGLTexture(OpenGLRendererBase& owner, const String& name,
00126                   const String& filename, const String& resourceGroup);
00128     OpenGLTexture(OpenGLRendererBase& owner, const String& name,
00129                   const Sizef& size);
00131     OpenGLTexture(OpenGLRendererBase& owner, const String& name,
00132                   GLuint tex, const Sizef& size);
00134     virtual ~OpenGLTexture();
00135 
00137     void generateOpenGLTexture();
00138 
00140     void updateCachedScaleValues();
00141 
00143     void cleanupOpenGLTexture();
00144 
00146     void initInternalPixelFormatFields(const PixelFormat fmt);
00147 
00149     void setTextureSize_impl(const Sizef& sz);
00150 
00151     void loadUncompressedTextureBuffer(const Rectf& dest_area,
00152                                        const GLvoid* buffer) const;
00153 
00154     void loadCompressedTextureBuffer(const Rectf& dest_area,
00155                                      const GLvoid* buffer) const;
00156 
00157     GLsizei getCompressedTextureSize(const Sizef& pixel_size) const;
00158 
00160     GLuint d_ogltexture;
00162     Sizef d_size;
00164     uint8* d_grabBuffer;
00166     Sizef d_dataSize;
00168     Vector2f d_texelScaling;
00170     OpenGLRendererBase& d_owner;
00172     const String d_name;
00174     GLenum d_format;
00176     GLenum d_subpixelFormat;
00178     bool d_isCompressed;
00179 };
00180 
00181 } // End of  CEGUI namespace section
00182 
00183 #if defined(_MSC_VER)
00184 #       pragma warning(pop)
00185 #endif
00186 
00187 #endif // end of guard _CEGUIOpenGLTexture_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends