OGRE  1.9
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 
35 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 && !defined(_WIN32_WINNT_WIN8)
36  #ifndef USE_D3DX11_LIBRARY
37  #define USE_D3DX11_LIBRARY
38  #endif
39 #endif
40 
41 namespace Ogre {
42  class D3D11Texture : public Texture
43  {
44  protected:
45  // needed to store data between prepareImpl and loadImpl
47 
50 
52  //LPDIRECT3D11 *mpD3D;
53  // 1D texture pointer
54  ID3D11Texture1D *mp1DTex;
55  // 2D texture pointer
56  ID3D11Texture2D *mp2DTex;
58  ID3D11Texture3D *mp3DTex;
60  ID3D11Resource *mpTex;
61 
62  ID3D11ShaderResourceView* mpShaderResourceView;
63 
65 
66  template<typename fromtype, typename totype>
67  void _queryInterface(fromtype *from, totype **to)
68  {
69  HRESULT hr = from->QueryInterface(__uuidof(totype), (void **)to);
70 
71  if(FAILED(hr) || mDevice.isError())
72  {
73  this->freeInternalResources();
74  String errorDescription = mDevice.getErrorDescription(hr);
75  OGRE_EXCEPT_EX(Exception::ERR_RENDERINGAPI_ERROR, hr, "Can't get base texture\nError Description:" + errorDescription,
76  "D3D11Texture::_queryInterface" );
77  }
78  }
79 
80 #ifdef USE_D3DX11_LIBRARY
81  void _loadDDS(DataStreamPtr &dstream);
82 #endif
83  void _create1DResourceView();
84  void _create2DResourceView();
85  void _create3DResourceView();
86 
87  // is dynamic
88  bool mIsDynamic;
89 
93  //D3DDEVICE_CREATION_PARAMETERS mDevCreParams;
95  DXGI_FORMAT mBBPixelFormat;
97  //D3DPOOL mD3DPool;
99  //D3DCAPS9 mDevCaps;
100  // Dynamic textures?
105 
106  D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
108  void _loadTex(LoadedStreams & loadedStreams);
109 
111  void _create1DTex();
113  void _create2DTex();
115  void _create3DTex();
116 
118  DXGI_FORMAT _chooseD3DFormat();
119 
121  void createInternalResources(void);
123  void createInternalResourcesImpl(void);
125  void freeInternalResources(void);
127  void freeInternalResourcesImpl(void);
129  void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
131  void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags);
132 
134  String _getCubeFaceName(unsigned char face) const
135  { assert(face < 6); return mCubeFaceNames[face]; }
136 
139  void _createSurfaceList(void);
140 
141 
143  void prepareImpl(void);
145  void unprepareImpl(void);
147  void loadImpl();
149  void postLoadImpl();
150 
159  public:
161  D3D11Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
162  const String& group, bool isManual, ManualResourceLoader* loader,
163  D3D11Device & device);
165  ~D3D11Texture();
166 
168  void copyToTexture( TexturePtr& target );
170  void loadImage( const Image &img );
171 
172 
174  HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
175 
176  ID3D11Resource *getTextureResource()
177  { assert(mpTex); return mpTex; }
179  ID3D11ShaderResourceView *getTexture()
180  { assert(mpShaderResourceView); return mpShaderResourceView; }
181  /*/// retrieves a pointer to the normal 1D/2D texture
182  IDirect3DTexture9 *getNormTexture()
183  { assert(mpNormTex); return mpNormTex; }
185  IDirect3DCubeTexture9 *getCubeTexture()
186  { assert(mpCubeTex); return mpCubeTex; }
187  */
188 
189 
191  bool releaseIfDefaultPool(void);
193  bool recreateIfDefaultPool(D3D11Device & device);
194 
195  ID3D11Texture1D * GetTex1D() {return mp1DTex;};
196  ID3D11Texture2D * GetTex2D() {return mp2DTex;};
197  ID3D11Texture3D * GetTex3D() {return mp3DTex;};
198 
199  D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const;
200 
202 
203  };
204 
207  {
209  ID3D11RenderTargetView * mRenderTargetView;
210  ID3D11DepthStencilView * mDepthStencilView;
211  public:
212  D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device & device );
213  virtual ~D3D11RenderTexture();
214 
215  void rebind(D3D11HardwarePixelBuffer *buffer);
216 
217  virtual void getCustomAttribute( const String& name, void *pData );
218 
219  bool requiresTextureFlipping() const { return false; }
220  };
221 
222 }
223 
224 #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
#define OGRE_EXCEPT_EX(code, num, desc, src)
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
ID3D11RenderTargetView * mRenderTargetView
Interface describing a manual resource loader.
Definition: OgreResource.h:514
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)
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:61
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:41
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
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:102
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