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 #ifndef __D3D11TEXTURE_H__ 00029 #define __D3D11TEXTURE_H__ 00030 00031 #include "OgreD3D11Prerequisites.h" 00032 #include "OgreTexture.h" 00033 #include "OgreRenderTexture.h" 00034 00035 namespace Ogre { 00036 class D3D11Texture : public Texture 00037 { 00038 protected: 00039 // needed to store data between prepareImpl and loadImpl 00040 typedef SharedPtr<vector<MemoryDataStreamPtr>::type > LoadedStreams; 00041 00043 D3D11Device & mDevice; 00044 00046 //LPDIRECT3D11 *mpD3D; 00047 // 1D texture pointer 00048 ID3D11Texture1D *mp1DTex; 00049 // 2D texture pointer 00050 ID3D11Texture2D *mp2DTex; 00052 ID3D11Texture3D *mp3DTex; 00054 ID3D11Resource *mpTex; 00055 00056 ID3D11ShaderResourceView* mpShaderResourceView; 00057 00058 // is dynamic 00059 bool mIsDynamic; 00060 00062 String mCubeFaceNames[6]; 00064 //D3DDEVICE_CREATION_PARAMETERS mDevCreParams; 00066 DXGI_FORMAT mBBPixelFormat; 00068 //D3DPOOL mD3DPool; 00070 //D3DCAPS9 mDevCaps; 00071 // Dynamic textures? 00072 bool mDynamicTextures; 00074 typedef vector<HardwarePixelBufferSharedPtr>::type SurfaceList; 00075 SurfaceList mSurfaceList; 00076 00077 D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc; 00079 void _loadTex(LoadedStreams & loadedStreams); 00080 00082 void _create1DTex(); 00084 void _create2DTex(); 00086 void _create3DTex(); 00087 00089 DXGI_FORMAT _chooseD3DFormat(); 00090 00092 void createInternalResources(void); 00094 void createInternalResourcesImpl(void); 00096 void freeInternalResources(void); 00098 void freeInternalResourcesImpl(void); 00100 void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00102 void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format); 00103 00105 String _getCubeFaceName(unsigned char face) const 00106 { assert(face < 6); return mCubeFaceNames[face]; } 00107 00110 void _createSurfaceList(void); 00111 00112 00114 void prepareImpl(void); 00116 void unprepareImpl(void); 00118 void loadImpl(); 00120 void postLoadImpl(); 00121 00126 LoadedStreams mLoadedStreams; 00127 LoadedStreams _prepareNormTex(); 00128 LoadedStreams _prepareVolumeTex(); 00129 LoadedStreams _prepareCubeTex(); 00130 public: 00132 D3D11Texture(ResourceManager* creator, const String& name, ResourceHandle handle, 00133 const String& group, bool isManual, ManualResourceLoader* loader, 00134 D3D11Device & device); 00136 ~D3D11Texture(); 00137 00139 void copyToTexture( TexturePtr& target ); 00141 void loadImage( const Image &img ); 00142 00143 00145 HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap); 00146 00147 ID3D11Resource *getTextureResource() 00148 { assert(mpTex); return mpTex; } 00150 ID3D11ShaderResourceView *getTexture() 00151 { assert(mpShaderResourceView); return mpShaderResourceView; } 00152 /*/// retrieves a pointer to the normal 1D/2D texture 00153 IDirect3DTexture9 *getNormTexture() 00154 { assert(mpNormTex); return mpNormTex; } 00156 IDirect3DCubeTexture9 *getCubeTexture() 00157 { assert(mpCubeTex); return mpCubeTex; } 00158 */ 00159 00160 00162 bool releaseIfDefaultPool(void); 00164 bool recreateIfDefaultPool(D3D11Device & device); 00165 00166 ID3D11Texture1D * GetTex1D() {return mp1DTex;}; 00167 ID3D11Texture2D * GetTex2D() {return mp2DTex;}; 00168 ID3D11Texture3D * GetTex3D() {return mp3DTex;}; 00169 00170 D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const; 00171 00172 00173 }; 00174 00181 class D3D11TexturePtr : public SharedPtr<D3D11Texture> 00182 { 00183 public: 00184 D3D11TexturePtr() : SharedPtr<D3D11Texture>() {} 00185 explicit D3D11TexturePtr(D3D11Texture* rep) : SharedPtr<D3D11Texture>(rep) {} 00186 D3D11TexturePtr(const D3D11TexturePtr& r) : SharedPtr<D3D11Texture>(r) {} 00187 D3D11TexturePtr(const ResourcePtr& r) : SharedPtr<D3D11Texture>() 00188 { 00189 // lock & copy other mutex pointer 00190 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00191 { 00192 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00193 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00194 pRep = static_cast<D3D11Texture*>(r.getPointer()); 00195 pUseCount = r.useCountPointer(); 00196 if (pUseCount) 00197 { 00198 ++(*pUseCount); 00199 } 00200 } 00201 } 00202 00204 D3D11TexturePtr& operator=(const ResourcePtr& r) 00205 { 00206 if (pRep == static_cast<D3D11Texture*>(r.getPointer())) 00207 return *this; 00208 release(); 00209 // lock & copy other mutex pointer 00210 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00211 { 00212 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00213 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00214 pRep = static_cast<D3D11Texture*>(r.getPointer()); 00215 pUseCount = r.useCountPointer(); 00216 if (pUseCount) 00217 { 00218 ++(*pUseCount); 00219 } 00220 } 00221 return *this; 00222 } 00224 D3D11TexturePtr& operator=(const TexturePtr& r) 00225 { 00226 if (pRep == static_cast<D3D11Texture*>(r.getPointer())) 00227 return *this; 00228 release(); 00229 // lock & copy other mutex pointer 00230 OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME) 00231 { 00232 OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME) 00233 OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME) 00234 pRep = static_cast<D3D11Texture*>(r.getPointer()); 00235 pUseCount = r.useCountPointer(); 00236 if (pUseCount) 00237 { 00238 ++(*pUseCount); 00239 } 00240 } 00241 return *this; 00242 } 00243 }; 00244 00246 class D3D11RenderTexture : public RenderTexture 00247 { 00248 D3D11Device & mDevice; 00249 ID3D11RenderTargetView * mRenderTargetView; 00250 ID3D11DepthStencilView * mDepthStencilView; 00251 public: 00252 D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device & device ); 00253 virtual ~D3D11RenderTexture(); 00254 00255 void rebind(D3D11HardwarePixelBuffer *buffer); 00256 00257 virtual void getCustomAttribute( const String& name, void *pData ); 00258 00259 bool requiresTextureFlipping() const { return false; } 00260 }; 00261 00262 } 00263 00264 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 2012 21:48:49