OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreD3D11Texture.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __D3D11TEXTURE_H__
29 #define __D3D11TEXTURE_H__
30 
31 #include "OgreD3D11Prerequisites.h"
32 #include "OgreTexture.h"
33 #include "OgreRenderTexture.h"
34 #include "OgreSharedPtr.h"
35 
36 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined(_WIN32_WINNT_WIN8)
37  #ifndef USE_D3DX11_LIBRARY
38  #define USE_D3DX11_LIBRARY
39  #endif
40 #endif
41 
42 namespace Ogre {
43  class D3D11Texture : public Texture
44  {
45  protected:
46  // needed to store data between prepareImpl and loadImpl
48 
51 
53  //LPDIRECT3D11 *mpD3D;
54  // 1D texture pointer
55  ID3D11Texture1D *mp1DTex;
56  // 2D texture pointer
57  ID3D11Texture2D *mp2DTex;
59  ID3D11Texture3D *mp3DTex;
61  ID3D11Resource *mpTex;
62 
63  ID3D11ShaderResourceView* mpShaderResourceView;
64 
66 
67  template<typename fromtype, typename totype>
68  void _queryInterface(fromtype *from, totype **to)
69  {
70  HRESULT hr = from->QueryInterface(__uuidof(totype), (void **)to);
71 
72  if(FAILED(hr) || mDevice.isError())
73  {
74  this->freeInternalResources();
75  String errorDescription = mDevice.getErrorDescription();
76  OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't get base texture\nError Description:" + errorDescription,
77  "D3D11Texture::_queryInterface" );
78  }
79  }
80  unsigned int mEffectIndex;
81 #ifdef USE_D3DX11_LIBRARY
82  void _loadDDS(DataStreamPtr &dstream);
83  //ID3DX11Effect mEffect;
84 #endif
85  void _create1DResourceView();
86  void _create2DResourceView();
87  void _create3DResourceView();
88 
89  // is dynamic
90  bool mIsDynamic;
91 
95  //D3DDEVICE_CREATION_PARAMETERS mDevCreParams;
97  DXGI_FORMAT mBBPixelFormat;
99  //D3DPOOL mD3DPool;
101  //D3DCAPS9 mDevCaps;
102  // Dynamic textures?
107 
108  D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
110  void _loadTex(LoadedStreams & loadedStreams);
111 
113  void _create1DTex();
115  void _create2DTex();
117  void _create3DTex();
118 
120  DXGI_FORMAT _chooseD3DFormat();
121 
123  void createInternalResources(void);
125  void createInternalResourcesImpl(void);
127  void freeInternalResources(void);
129  void freeInternalResourcesImpl(void);
131  void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
133  void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags);
134 
136  String _getCubeFaceName(unsigned char face) const
137  { assert(face < 6); return mCubeFaceNames[face]; }
138 
141  void _createSurfaceList(void);
142 
143 
145  void prepareImpl(void);
147  void unprepareImpl(void);
149  void loadImpl();
151  void postLoadImpl();
152 
161  public:
163  D3D11Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
164  const String& group, bool isManual, ManualResourceLoader* loader,
165  D3D11Device & device);
167  ~D3D11Texture();
168 
170  void copyToTexture( TexturePtr& target );
172  void loadImage( const Image &img );
173 
174 
176  HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
177 
178  ID3D11Resource *getTextureResource()
179  { assert(mpTex); return mpTex; }
181  ID3D11ShaderResourceView *getTexture()
182  { assert(mpShaderResourceView); return mpShaderResourceView; }
183  /*/// retrieves a pointer to the normal 1D/2D texture
184  IDirect3DTexture9 *getNormTexture()
185  { assert(mpNormTex); return mpNormTex; }
187  IDirect3DCubeTexture9 *getCubeTexture()
188  { assert(mpCubeTex); return mpCubeTex; }
189  */
190 
191 
193  bool releaseIfDefaultPool(void);
195  bool recreateIfDefaultPool(D3D11Device & device);
196 
197  ID3D11Texture1D * GetTex1D() {return mp1DTex;};
198  ID3D11Texture2D * GetTex2D() {return mp2DTex;};
199  ID3D11Texture3D * GetTex3D() {return mp3DTex;};
200 
201  D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const;
202 
204 
205  };
206 
209  {
211  ID3D11RenderTargetView * mRenderTargetView;
212  ID3D11DepthStencilView * mDepthStencilView;
213  public:
214  D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device & device );
215  virtual ~D3D11RenderTexture();
216 
217  void rebind(D3D11HardwarePixelBuffer *buffer);
218 
219  virtual void getCustomAttribute( const String& name, void *pData );
220 
221  bool requiresTextureFlipping() const { return false; }
222  };
223 
224 }
225 
226 #endif
ID3D11Texture3D * GetTex3D()
RenderTexture implementation for D3D11.
virtual void getCustomAttribute(const String &name, void *pData)
Gets a custom (maybe platform-specific) attribute.
void loadImage(const Image &img)
overridden from Texture
void freeInternalResources(void)
Frees internal texture resources for this texture.
const bool isError() const
void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags)
internal method, set Texture class final texture protected attributes
LoadedStreams _prepareVolumeTex()
D3D11Device & mDevice
D3DDevice pointer.
void unprepareImpl(void)
Internal function for undoing the 'prepare' action.
void _create2DTex()
internal method, create a blank normal 2D texture
void rebind(D3D11HardwarePixelBuffer *buffer)
bool releaseIfDefaultPool(void)
For dealing with lost devices - release the resource if in the default pool (and return true) ...
bool mDynamicTextures
The memory pool being used.
This class represents a RenderTarget that renders to a Texture.
void prepareImpl(void)
Internal implementation of the meat of the 'prepare' action.
const String getErrorDescription(const HRESULT hr=NO_ERROR) const
unsigned int mEffectIndex
ID3D11RenderTargetView * mRenderTargetView
Interface describing a manual resource loader.
Definition: OgreResource.h:498
void _create1DTex()
internal method, create a blank normal 1D Dtexture
String _getCubeFaceName(unsigned char face) const
internal method, the cube map face name for the spec. face index
ID3D11ShaderResourceView * getTexture()
retrieves a pointer to the actual texture
void _create1DResourceView()
String mCubeFaceNames[6]
cube texture individual face names
void _create3DTex()
internal method, create a blank cube texture
void freeInternalResourcesImpl(void)
free internal resources
void _create3DResourceView()
D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device &device)
LoadedStreams mLoadedStreams
Vector of pointers to streams that were pulled from disk by prepareImpl but have yet to be pushed int...
DXGI_FORMAT mBBPixelFormat
device creation parameters
void postLoadImpl()
overridden from Resource
vector< HardwarePixelBufferSharedPtr >::type SurfaceList
Vector of pointers to subsurfaces.
PixelFormat
The pixel format used for images, textures, and render surfaces.
void _queryInterface(fromtype *from, totype **to)
#define OGRE_EXCEPT(num, desc, src)
ID3D11DepthStencilView * mDepthStencilView
ID3D11Texture1D * mp1DTex
D3D11 pointer.
ID3D11Resource * getTextureResource()
ID3D11ShaderResourceView * mpShaderResourceView
bool recreateIfDefaultPool(D3D11Device &device)
For dealing with lost devices - recreate the resource if in the default pool (and return true) ...
LoadedStreams _prepareNormTex()
Shared pointer implementation used to share pixel buffers.
ID3D11Resource * mpTex
actual texture pointer
Class representing an image file.
Definition: OgreImage.h:60
D3D11Texture(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual, ManualResourceLoader *loader, D3D11Device &device)
constructor
DXGI_FORMAT _chooseD3DFormat()
internal method, return a D3D pixel format for texture creation
unsigned long long int ResourceHandle
Definition: OgreResource.h:39
SurfaceList mSurfaceList
void loadImpl()
overridden from Resource
ID3D11Texture1D * GetTex1D()
bool HasAutoMipMapGenerationEnabled() const
void copyToTexture(TexturePtr &target)
overridden from Texture
HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap)
Return hardware pixel buffer for a surface.
void _loadDDS(DataStreamPtr &dstream)
~D3D11Texture()
destructor
ID3D11Texture3D * mp3DTex
cubic texture pointer
D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc
void _createSurfaceList(void)
internal method, create D3D11HardwarePixelBuffers for every face and mipmap level.
ID3D11Texture2D * GetTex2D()
Defines a generic resource handler.
Reference-counted shared pointer, used for objects where implicit destruction is required.
_StringBase String
Definition: OgreCommon.h:53
SharedPtr< vector< MemoryDataStreamPtr >::type > LoadedStreams
ID3D11Texture2D * mp2DTex
void createInternalResources(void)
Creates the internal texture resources for this texture.
void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format)
internal method, set Texture class source image protected attributes
LoadedStreams _prepareCubeTex()
Abstract class representing a Texture resource.
Definition: OgreTexture.h:111
D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const
bool requiresTextureFlipping() const
void _create2DResourceView()
void createInternalResourcesImpl(void)
Implementation of creating internal texture resources.
void _loadTex(LoadedStreams &loadedStreams)
internal method, load a normal texture