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-2013 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();
75  OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "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
Ogre::D3D11RenderTexture::mDepthStencilView
ID3D11DepthStencilView * mDepthStencilView
Definition: OgreD3D11Texture.h:210
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
Ogre::D3D11Texture::GetTex2D
ID3D11Texture2D * GetTex2D()
Definition: OgreD3D11Texture.h:196
Ogre::Exception::ERR_RENDERINGAPI_ERROR
@ ERR_RENDERINGAPI_ERROR
Definition: OgreException.h:104
Ogre::Texture
Abstract class representing a Texture resource.
Definition: OgreTexture.h:102
Ogre::D3D11Texture::mp1DTex
ID3D11Texture1D * mp1DTex
D3D11 pointer.
Definition: OgreD3D11Texture.h:54
Ogre::D3D11RenderTexture::~D3D11RenderTexture
virtual ~D3D11RenderTexture()
Ogre::D3D11Texture::_create1DResourceView
void _create1DResourceView()
Ogre::D3D11Texture::SurfaceList
vector< HardwarePixelBufferSharedPtr >::type SurfaceList
Vector of pointers to subsurfaces.
Definition: OgreD3D11Texture.h:103
Ogre::D3D11Texture::freeInternalResourcesImpl
void freeInternalResourcesImpl(void)
free internal resources
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::D3D11Texture::mpShaderResourceView
ID3D11ShaderResourceView * mpShaderResourceView
Definition: OgreD3D11Texture.h:62
Ogre::D3D11Texture::mp2DTex
ID3D11Texture2D * mp2DTex
Definition: OgreD3D11Texture.h:56
Ogre::D3D11Texture::mDynamicTextures
bool mDynamicTextures
The memory pool being used.
Definition: OgreD3D11Texture.h:101
Ogre::D3D11Texture::_setFinalAttributes
void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format, UINT miscflags)
internal method, set Texture class final texture protected attributes
Ogre::Image
Class representing an image file.
Definition: OgreImage.h:61
Ogre::D3D11Texture::mp3DTex
ID3D11Texture3D * mp3DTex
cubic texture pointer
Definition: OgreD3D11Texture.h:58
Ogre::D3D11RenderTexture::getCustomAttribute
virtual void getCustomAttribute(const String &name, void *pData)
Gets a custom (maybe platform-specific) attribute.
Ogre::D3D11Texture::_queryInterface
void _queryInterface(fromtype *from, totype **to)
Definition: OgreD3D11Texture.h:67
Ogre::D3D11Texture::unprepareImpl
void unprepareImpl(void)
Internal function for undoing the 'prepare' action.
Ogre::D3D11Texture::getShaderResourceViewDesc
D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const
Ogre::D3D11Texture::copyToTexture
void copyToTexture(TexturePtr &target)
overridden from Texture
Ogre::D3D11Texture::releaseIfDefaultPool
bool releaseIfDefaultPool(void)
For dealing with lost devices - release the resource if in the default pool (and return true)
Ogre::D3D11Texture::prepareImpl
void prepareImpl(void)
Internal implementation of the meat of the 'prepare' action.
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::D3D11Device::isError
const bool isError() const
Definition: OgreD3D11Device.h:100
Ogre::D3D11Texture::_getCubeFaceName
String _getCubeFaceName(unsigned char face) const
internal method, the cube map face name for the spec. face index
Definition: OgreD3D11Texture.h:134
Ogre::D3D11Texture::getBuffer
HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap)
Return hardware pixel buffer for a surface.
Ogre::D3D11Texture::mBBPixelFormat
DXGI_FORMAT mBBPixelFormat
device creation parameters
Definition: OgreD3D11Texture.h:95
Ogre::D3D11Texture::LoadedStreams
SharedPtr< vector< MemoryDataStreamPtr >::type > LoadedStreams
Definition: OgreD3D11Texture.h:46
Ogre::D3D11Texture::getTexture
ID3D11ShaderResourceView * getTexture()
retrieves a pointer to the actual texture
Definition: OgreD3D11Texture.h:179
Ogre::D3D11RenderTexture::requiresTextureFlipping
bool requiresTextureFlipping() const
Definition: OgreD3D11Texture.h:219
Ogre::D3D11Texture::createInternalResourcesImpl
void createInternalResourcesImpl(void)
Implementation of creating internal texture resources.
Ogre::D3D11Texture::_loadTex
void _loadTex(LoadedStreams &loadedStreams)
internal method, load a normal texture
Ogre::D3D11Texture::_create3DTex
void _create3DTex()
internal method, create a blank cube texture
Ogre::D3D11Texture::postLoadImpl
void postLoadImpl()
overridden from Resource
Ogre::D3D11Device
Definition: OgreD3D11Device.h:36
OgreD3D11Prerequisites.h
Ogre::D3D11RenderTexture::rebind
void rebind(D3D11HardwarePixelBuffer *buffer)
Ogre::PixelFormat
PixelFormat
The pixel format used for images, textures, and render surfaces.
Definition: OgrePixelFormat.h:43
Ogre::D3D11Texture
Definition: OgreD3D11Texture.h:42
OgreTexture.h
Ogre::D3D11Texture::_createSurfaceList
void _createSurfaceList(void)
internal method, create D3D11HardwarePixelBuffers for every face and mipmap level.
Ogre::D3D11Texture::GetTex3D
ID3D11Texture3D * GetTex3D()
Definition: OgreD3D11Texture.h:197
Ogre::D3D11Texture::loadImage
void loadImage(const Image &img)
overridden from Texture
Ogre::D3D11Texture::mLoadedStreams
LoadedStreams mLoadedStreams
Vector of pointers to streams that were pulled from disk by prepareImpl but have yet to be pushed int...
Definition: OgreD3D11Texture.h:155
Ogre::D3D11Texture::_chooseD3DFormat
DXGI_FORMAT _chooseD3DFormat()
internal method, return a D3D pixel format for texture creation
Ogre::D3D11Texture::mSRVDesc
D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc
Definition: OgreD3D11Texture.h:106
Ogre::D3D11Texture::_create2DTex
void _create2DTex()
internal method, create a blank normal 2D texture
Ogre::D3D11RenderTexture::mRenderTargetView
ID3D11RenderTargetView * mRenderTargetView
Definition: OgreD3D11Texture.h:209
Ogre::D3D11RenderTexture
RenderTexture implementation for D3D11.
Definition: OgreD3D11Texture.h:206
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:122
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgrePrerequisites.h:310
Ogre::D3D11Texture::mpTex
ID3D11Resource * mpTex
actual texture pointer
Definition: OgreD3D11Texture.h:60
Ogre::D3D11Texture::freeInternalResources
void freeInternalResources(void)
Frees internal texture resources for this texture.
Ogre::D3D11Texture::mIsDynamic
bool mIsDynamic
Definition: OgreD3D11Texture.h:88
Ogre::D3D11Texture::mAutoMipMapGeneration
bool mAutoMipMapGeneration
Definition: OgreD3D11Texture.h:64
Ogre::D3D11HardwarePixelBuffer
Definition: OgreD3D11HardwarePixelBuffer.h:39
Ogre::D3D11RenderTexture::mDevice
D3D11Device & mDevice
Definition: OgreD3D11Texture.h:208
Ogre::D3D11Texture::HasAutoMipMapGenerationEnabled
bool HasAutoMipMapGenerationEnabled() const
Definition: OgreD3D11Texture.h:201
OgreRenderTexture.h
Ogre::D3D11Texture::_prepareCubeTex
LoadedStreams _prepareCubeTex()
Ogre::D3D11Texture::recreateIfDefaultPool
bool recreateIfDefaultPool(D3D11Device &device)
For dealing with lost devices - recreate the resource if in the default pool (and return true)
Ogre::HardwarePixelBufferSharedPtr
Shared pointer implementation used to share pixel buffers.
Definition: OgreHardwarePixelBuffer.h:193
Ogre::D3D11Texture::_create1DTex
void _create1DTex()
internal method, create a blank normal 1D Dtexture
Ogre::D3D11Texture::GetTex1D
ID3D11Texture1D * GetTex1D()
Definition: OgreD3D11Texture.h:195
Ogre::RenderTexture
This class represents a RenderTarget that renders to a Texture.
Definition: OgreRenderTexture.h:48
Ogre::D3D11Texture::getTextureResource
ID3D11Resource * getTextureResource()
Definition: OgreD3D11Texture.h:176
Ogre::D3D11Texture::loadImpl
void loadImpl()
overridden from Resource
Ogre::D3D11Texture::mSurfaceList
SurfaceList mSurfaceList
Definition: OgreD3D11Texture.h:104
Ogre::D3D11Texture::createInternalResources
void createInternalResources(void)
Creates the internal texture resources for this texture.
Ogre::D3D11Texture::_loadDDS
void _loadDDS(DataStreamPtr &dstream)
Ogre::D3D11Texture::_prepareNormTex
LoadedStreams _prepareNormTex()
Ogre::D3D11Texture::D3D11Texture
D3D11Texture(ResourceManager *creator, const String &name, ResourceHandle handle, const String &group, bool isManual, ManualResourceLoader *loader, D3D11Device &device)
constructor
Ogre::D3D11Texture::_create3DResourceView
void _create3DResourceView()
Ogre::D3D11RenderTexture::D3D11RenderTexture
D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device &device)
Ogre::D3D11Device::getErrorDescription
const String getErrorDescription(const HRESULT hr=NO_ERROR) const
OGRE_EXCEPT
#define OGRE_EXCEPT(num, desc, src)
Definition: OgreException.h:334
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::D3D11Texture::_create2DResourceView
void _create2DResourceView()
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Ogre::D3D11Texture::_prepareVolumeTex
LoadedStreams _prepareVolumeTex()
Ogre::D3D11Texture::mCubeFaceNames
String mCubeFaceNames[6]
cube texture individual face names
Definition: OgreD3D11Texture.h:91
Ogre::D3D11Texture::~D3D11Texture
~D3D11Texture()
destructor
Ogre::D3D11Texture::mDevice
D3D11Device & mDevice
D3DDevice pointer.
Definition: OgreD3D11Texture.h:49
Ogre::D3D11Texture::_setSrcAttributes
void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format)
internal method, set Texture class source image protected attributes

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 Tue Apr 13 2021 08:53:15