OgreD3D11Texture.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-2013 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 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined(_WIN32_WINNT_WIN8)
00036     #ifndef USE_D3DX11_LIBRARY
00037         #define USE_D3DX11_LIBRARY
00038     #endif
00039 #endif
00040 
00041 namespace Ogre {
00042     class D3D11Texture : public Texture
00043     {
00044     protected:
00045         // needed to store data between prepareImpl and loadImpl
00046         typedef SharedPtr<vector<MemoryDataStreamPtr>::type > LoadedStreams;
00047 
00049         D3D11Device &   mDevice;    
00050 
00052         //LPDIRECT3D11              *mpD3D;
00053         // 1D texture pointer
00054         ID3D11Texture1D *mp1DTex;
00055         // 2D texture pointer
00056         ID3D11Texture2D *mp2DTex;
00058         ID3D11Texture3D *mp3DTex;   
00060         ID3D11Resource  *mpTex;     
00061 
00062         ID3D11ShaderResourceView* mpShaderResourceView;
00063 
00064         bool mAutoMipMapGeneration;
00065 
00066         template<typename fromtype, typename totype>
00067         void _queryInterface(fromtype *from, totype **to)
00068         {
00069             HRESULT hr = from->QueryInterface(__uuidof(totype), (void **)to);
00070 
00071             if(FAILED(hr) || mDevice.isError())
00072             {
00073                 this->freeInternalResources();
00074                 String errorDescription = mDevice.getErrorDescription();
00075                 OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't get base texture\nError Description:" + errorDescription, 
00076                     "D3D11Texture::_queryInterface" );
00077             }
00078         }
00079 
00080 #ifdef USE_D3DX11_LIBRARY       
00081         void _loadDDS(DataStreamPtr &dstream);
00082 #endif
00083         void _create1DResourceView();
00084         void _create2DResourceView();
00085         void _create3DResourceView();
00086 
00087         // is dynamic
00088         bool mIsDynamic; 
00089 
00091         String                          mCubeFaceNames[6];
00093         //D3DDEVICE_CREATION_PARAMETERS mDevCreParams;
00095         DXGI_FORMAT                     mBBPixelFormat;
00097         //D3DPOOL                           mD3DPool;
00099         //D3DCAPS9                      mDevCaps;
00100         // Dynamic textures?
00101         bool                            mDynamicTextures;
00103         typedef vector<HardwarePixelBufferSharedPtr>::type SurfaceList;
00104         SurfaceList                     mSurfaceList;
00105 
00106         D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
00108         void _loadTex(LoadedStreams & loadedStreams);
00109 
00111         void _create1DTex();
00113         void _create2DTex();
00115         void _create3DTex();
00116 
00118         DXGI_FORMAT _chooseD3DFormat();
00119 
00121         void createInternalResources(void);
00123         void createInternalResourcesImpl(void);
00125         void freeInternalResources(void);
00127         void freeInternalResourcesImpl(void);
00129         void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
00131         void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags);
00132 
00134         String _getCubeFaceName(unsigned char face) const
00135         { assert(face < 6); return mCubeFaceNames[face]; }
00136 
00139         void _createSurfaceList(void);
00140 
00141 
00143         void prepareImpl(void);
00145         void unprepareImpl(void);
00147         void loadImpl();
00149         void postLoadImpl();
00150 
00155         LoadedStreams mLoadedStreams;
00156         LoadedStreams _prepareNormTex();
00157         LoadedStreams _prepareVolumeTex();
00158         LoadedStreams _prepareCubeTex();
00159     public:
00161         D3D11Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
00162             const String& group, bool isManual, ManualResourceLoader* loader, 
00163             D3D11Device & device);
00165         ~D3D11Texture();
00166 
00168         void copyToTexture( TexturePtr& target );
00170         void loadImage( const Image &img );
00171 
00172 
00174         HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
00175 
00176         ID3D11Resource *getTextureResource() 
00177         { assert(mpTex); return mpTex; }
00179         ID3D11ShaderResourceView *getTexture() 
00180         { assert(mpShaderResourceView); return mpShaderResourceView; }
00181         /*/// retrieves a pointer to the normal 1D/2D texture
00182         IDirect3DTexture9 *getNormTexture()
00183         { assert(mpNormTex); return mpNormTex; }
00185         IDirect3DCubeTexture9 *getCubeTexture()
00186         { assert(mpCubeTex); return mpCubeTex; }
00187         */
00188 
00189 
00191         bool releaseIfDefaultPool(void);
00193         bool recreateIfDefaultPool(D3D11Device & device);
00194 
00195         ID3D11Texture1D * GetTex1D() {return mp1DTex;};
00196         ID3D11Texture2D * GetTex2D() {return mp2DTex;};
00197         ID3D11Texture3D * GetTex3D() {return mp3DTex;};
00198 
00199         D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const;
00200 
00201         bool HasAutoMipMapGenerationEnabled() const { return mAutoMipMapGeneration; }
00202 
00203     };
00204 
00206     class D3D11RenderTexture : public RenderTexture
00207     {
00208         D3D11Device & mDevice;
00209         ID3D11RenderTargetView * mRenderTargetView;
00210         ID3D11DepthStencilView * mDepthStencilView;
00211     public:
00212         D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device & device );
00213         virtual ~D3D11RenderTexture();
00214 
00215         void rebind(D3D11HardwarePixelBuffer *buffer);
00216 
00217         virtual void getCustomAttribute( const String& name, void *pData );
00218 
00219         bool requiresTextureFlipping() const { return false; }
00220     };
00221 
00222 }
00223 
00224 #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 Mon Jul 27 2020 13:40:41