OgreGLES2Texture.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __GLES2Texture_H__
00030 #define __GLES2Texture_H__
00031 
00032 #include "OgreGLES2Prerequisites.h"
00033 #include "OgreGLES2Support.h"
00034 #include "OgrePlatform.h"
00035 #include "OgreRenderTexture.h"
00036 #include "OgreTexture.h"
00037 #include "OgreHardwarePixelBuffer.h"
00038 
00039 namespace Ogre {
00040     class _OgreGLES2Export GLES2Texture : public Texture
00041     {
00042         public:
00043             // Constructor
00044             GLES2Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
00045                 const String& group, bool isManual, ManualResourceLoader* loader, 
00046                 GLES2Support& support);
00047 
00048             virtual ~GLES2Texture();
00049 
00050             void createRenderTexture();
00052             HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
00053 
00054             // Takes the OGRE texture type (1d/2d/3d/cube) and returns the appropriate GL one
00055             GLenum getGLES2TextureTarget(void) const;
00056 
00057             GLuint getGLID() const
00058             {
00059                 return mTextureID;
00060             }
00061 
00062         protected:
00064             void createInternalResourcesImpl(void);
00066             void prepareImpl(void);
00068             void unprepareImpl(void);
00070             void loadImpl(void);
00072             void freeInternalResourcesImpl(void);
00073 
00079             void _createSurfaceList();
00080 
00082             typedef SharedPtr<vector<Image>::type > LoadedImages;
00083 
00088             LoadedImages mLoadedImages;
00089 
00090 
00091         private:
00092             GLuint mTextureID;
00093             GLES2Support& mGLSupport;
00094             
00096             typedef vector<HardwarePixelBufferSharedPtr>::type SurfaceList;
00097             SurfaceList mSurfaceList;
00098 
00099     };
00100 
00107     class _OgreGLES2Export GLES2TexturePtr : public SharedPtr<GLES2Texture>
00108     {
00109         public:
00110             GLES2TexturePtr() : SharedPtr<GLES2Texture>() {}
00111             explicit GLES2TexturePtr(GLES2Texture* rep) : SharedPtr<GLES2Texture>(rep) {}
00112             GLES2TexturePtr(const GLES2TexturePtr& r) : SharedPtr<GLES2Texture>(r) {}
00113 
00114             GLES2TexturePtr(const ResourcePtr& r) : SharedPtr<GLES2Texture>()
00115             {
00116                 // lock & copy other mutex pointer
00117                 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00118                 {
00119                     OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00120                     OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00121                     pRep = static_cast<GLES2Texture*>(r.getPointer());
00122                     pUseCount = r.useCountPointer();
00123                     if (pUseCount)
00124                     {
00125                         ++(*pUseCount);
00126                     }
00127                 }
00128             }
00129 
00130             GLES2TexturePtr(const TexturePtr& r) : SharedPtr<GLES2Texture>()
00131             {
00132                 *this = r;
00133             }
00134 
00136             GLES2TexturePtr& operator=(const ResourcePtr& r)
00137             {
00138                 if (pRep == static_cast<GLES2Texture*>(r.getPointer()))
00139                 {
00140                     return *this;
00141                 }
00142                 release();
00143                 // lock & copy other mutex pointer
00144                 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00145                 {
00146                     OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00147                     OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00148                     pRep = static_cast<GLES2Texture*>(r.getPointer());
00149                     pUseCount = r.useCountPointer();
00150                     if (pUseCount)
00151                     {
00152                         ++(*pUseCount);
00153                     }
00154                 }
00155                 else
00156                 {
00157                     // RHS must be a null pointer
00158                     assert(r.isNull() && "RHS must be null if it has no mutex!");
00159                     setNull();
00160                 }
00161                 return *this;
00162             }
00163 
00165             GLES2TexturePtr& operator=(const TexturePtr& r)
00166             {
00167                 if (pRep == static_cast<GLES2Texture*>(r.getPointer()))
00168                     return *this;
00169                 release();
00170                 // lock & copy other mutex pointer
00171                 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
00172                 {
00173                     OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
00174                     OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
00175                     pRep = static_cast<GLES2Texture*>(r.getPointer());
00176                     pUseCount = r.useCountPointer();
00177                     if (pUseCount)
00178                     {
00179                         ++(*pUseCount);
00180                     }
00181                 }
00182                 else
00183                 {
00184                     // RHS must be a null pointer
00185                     assert(r.isNull() && "RHS must be null if it has no mutex!");
00186                     setNull();
00187                 }
00188                 return *this;
00189             }
00190     };
00191 }
00192 
00193 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 2012 21:48:50