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 __GLTEXTURE_H__ 00030 #define __GLTEXTURE_H__ 00031 00032 #include "OgreGLPrerequisites.h" 00033 #include "OgrePlatform.h" 00034 #include "OgreRenderTexture.h" 00035 #include "OgreTexture.h" 00036 #include "OgreGLSupport.h" 00037 #include "OgreHardwarePixelBuffer.h" 00038 00039 namespace Ogre { 00040 00041 class _OgreGLExport GLTexture : public Texture 00042 { 00043 public: 00044 // Constructor 00045 GLTexture(ResourceManager* creator, const String& name, ResourceHandle handle, 00046 const String& group, bool isManual, ManualResourceLoader* loader, 00047 GLSupport& support); 00048 00049 virtual ~GLTexture(); 00050 00051 void createRenderTexture(); 00052 00054 HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap); 00055 00056 // Takes the OGRE texture type (1d/2d/3d/cube) and returns the appropriate GL one 00057 GLenum getGLTextureTarget(void) const; 00058 00059 GLuint getGLID() const 00060 { 00061 return mTextureID; 00062 } 00063 00064 void getCustomAttribute(const String& name, void* pData); 00065 00066 protected: 00068 void createInternalResourcesImpl(void); 00070 void prepareImpl(void); 00072 void unprepareImpl(void); 00074 void loadImpl(void); 00076 void freeInternalResourcesImpl(void); 00077 00083 void _createSurfaceList(); 00084 00086 typedef SharedPtr<vector<Image>::type > LoadedImages; 00087 00092 LoadedImages mLoadedImages; 00093 00094 00095 private: 00096 GLuint mTextureID; 00097 GLSupport& mGLSupport; 00098 00100 typedef vector<HardwarePixelBufferSharedPtr>::type SurfaceList; 00101 SurfaceList mSurfaceList; 00102 }; 00103 00110 class _OgreGLExport GLTexturePtr : public SharedPtr<GLTexture> 00111 { 00112 public: 00113 GLTexturePtr() : SharedPtr<GLTexture>() {} 00114 explicit GLTexturePtr(GLTexture* rep) : SharedPtr<GLTexture>(rep) {} 00115 GLTexturePtr(const GLTexturePtr& r) : SharedPtr<GLTexture>(r) {} 00116 GLTexturePtr(const ResourcePtr& r) : SharedPtr<GLTexture>() 00117 { 00118 // lock & copy other mutex pointer 00119 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00120 { 00121 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00122 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00123 pRep = static_cast<GLTexture*>(r.getPointer()); 00124 pUseCount = r.useCountPointer(); 00125 if (pUseCount) 00126 { 00127 ++(*pUseCount); 00128 } 00129 } 00130 } 00131 GLTexturePtr(const TexturePtr& r) : SharedPtr<GLTexture>() 00132 { 00133 *this = r; 00134 } 00135 00137 GLTexturePtr& operator=(const ResourcePtr& r) 00138 { 00139 if (pRep == static_cast<GLTexture*>(r.getPointer())) 00140 return *this; 00141 release(); 00142 // lock & copy other mutex pointer 00143 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00144 { 00145 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00146 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00147 pRep = static_cast<GLTexture*>(r.getPointer()); 00148 pUseCount = r.useCountPointer(); 00149 if (pUseCount) 00150 { 00151 ++(*pUseCount); 00152 } 00153 } 00154 else 00155 { 00156 // RHS must be a null pointer 00157 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00158 setNull(); 00159 } 00160 return *this; 00161 } 00163 GLTexturePtr& operator=(const TexturePtr& r) 00164 { 00165 if (pRep == static_cast<GLTexture*>(r.getPointer())) 00166 return *this; 00167 release(); 00168 // lock & copy other mutex pointer 00169 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00170 { 00171 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00172 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00173 pRep = static_cast<GLTexture*>(r.getPointer()); 00174 pUseCount = r.useCountPointer(); 00175 if (pUseCount) 00176 { 00177 ++(*pUseCount); 00178 } 00179 } 00180 else 00181 { 00182 // RHS must be a null pointer 00183 assert(r.isNull() && "RHS must be null if it has no mutex!"); 00184 setNull(); 00185 } 00186 return *this; 00187 } 00188 }; 00189 } 00190 00191 #endif // __GLTEXTURE_H__
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:21