OGRE  1.8
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-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 namespace Ogre {
36  class D3D11Texture : public Texture
37  {
38  protected:
39  // needed to store data between prepareImpl and loadImpl
41 
44 
46  //LPDIRECT3D11 *mpD3D;
47  // 1D texture pointer
48  ID3D11Texture1D *mp1DTex;
49  // 2D texture pointer
50  ID3D11Texture2D *mp2DTex;
52  ID3D11Texture3D *mp3DTex;
54  ID3D11Resource *mpTex;
55 
56  ID3D11ShaderResourceView* mpShaderResourceView;
57 
58  // is dynamic
59  bool mIsDynamic;
60 
64  //D3DDEVICE_CREATION_PARAMETERS mDevCreParams;
66  DXGI_FORMAT mBBPixelFormat;
68  //D3DPOOL mD3DPool;
70  //D3DCAPS9 mDevCaps;
71  // Dynamic textures?
76 
77  D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
79  void _loadTex(LoadedStreams & loadedStreams);
80 
82  void _create1DTex();
84  void _create2DTex();
86  void _create3DTex();
87 
89  DXGI_FORMAT _chooseD3DFormat();
90 
92  void createInternalResources(void);
94  void createInternalResourcesImpl(void);
96  void freeInternalResources(void);
98  void freeInternalResourcesImpl(void);
100  void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
102  void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
103 
105  String _getCubeFaceName(unsigned char face) const
106  { assert(face < 6); return mCubeFaceNames[face]; }
107 
110  void _createSurfaceList(void);
111 
112 
114  void prepareImpl(void);
116  void unprepareImpl(void);
118  void loadImpl();
120  void postLoadImpl();
121 
130  public:
132  D3D11Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
133  const String& group, bool isManual, ManualResourceLoader* loader,
134  D3D11Device & device);
136  ~D3D11Texture();
137 
139  void copyToTexture( TexturePtr& target );
141  void loadImage( const Image &img );
142 
143 
145  HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
146 
147  ID3D11Resource *getTextureResource()
148  { assert(mpTex); return mpTex; }
150  ID3D11ShaderResourceView *getTexture()
151  { assert(mpShaderResourceView); return mpShaderResourceView; }
152  /*/// retrieves a pointer to the normal 1D/2D texture
153  IDirect3DTexture9 *getNormTexture()
154  { assert(mpNormTex); return mpNormTex; }
156  IDirect3DCubeTexture9 *getCubeTexture()
157  { assert(mpCubeTex); return mpCubeTex; }
158  */
159 
160 
162  bool releaseIfDefaultPool(void);
164  bool recreateIfDefaultPool(D3D11Device & device);
165 
166  ID3D11Texture1D * GetTex1D() {return mp1DTex;};
167  ID3D11Texture2D * GetTex2D() {return mp2DTex;};
168  ID3D11Texture3D * GetTex3D() {return mp3DTex;};
169 
170  D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const;
171 
172 
173  };
174 
181  class D3D11TexturePtr : public SharedPtr<D3D11Texture>
182  {
183  public:
188  {
189  // lock & copy other mutex pointer
190  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
191  {
192  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
193  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
194  pRep = static_cast<D3D11Texture*>(r.getPointer());
196  if (pUseCount)
197  {
198  ++(*pUseCount);
199  }
200  }
201  }
202 
205  {
206  if (pRep == static_cast<D3D11Texture*>(r.getPointer()))
207  return *this;
208  release();
209  // lock & copy other mutex pointer
210  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
211  {
212  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
213  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
214  pRep = static_cast<D3D11Texture*>(r.getPointer());
216  if (pUseCount)
217  {
218  ++(*pUseCount);
219  }
220  }
221  return *this;
222  }
225  {
226  if (pRep == static_cast<D3D11Texture*>(r.getPointer()))
227  return *this;
228  release();
229  // lock & copy other mutex pointer
230  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
231  {
232  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
233  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
234  pRep = static_cast<D3D11Texture*>(r.getPointer());
236  if (pUseCount)
237  {
238  ++(*pUseCount);
239  }
240  }
241  return *this;
242  }
243  };
244 
247  {
249  ID3D11RenderTargetView * mRenderTargetView;
250  ID3D11DepthStencilView * mDepthStencilView;
251  public:
252  D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device & device );
253  virtual ~D3D11RenderTexture();
254 
255  void rebind(D3D11HardwarePixelBuffer *buffer);
256 
257  virtual void getCustomAttribute( const String& name, void *pData );
258 
259  bool requiresTextureFlipping() const { return false; }
260  };
261 
262 }
263 
264 #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)
overriden from Texture
void freeInternalResources(void)
Frees internal texture resources for this texture.
T * getPointer() const
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) ...
D3D11TexturePtr(D3D11Texture *rep)
bool mDynamicTextures
The memory pool being used.
This class represents a RenderTarget that renders to a Texture.
#define OGRE_MUTEX_CONDITIONAL(name)
D3D11TexturePtr & operator=(const ResourcePtr &r)
Operator used to convert a ResourcePtr to a D3D11TexturePtr.
void prepareImpl(void)
Internal implementation of the meat of the 'prepare' action.
ID3D11RenderTargetView * mRenderTargetView
Interface describing a manual resource loader.
Definition: OgreResource.h:513
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
String mCubeFaceNames[6]
cube texture individual face names
void _create3DTex()
internal method, create a blank cube texture
void freeInternalResourcesImpl(void)
free internal resources
Specialisation of SharedPtr to allow SharedPtr to be assigned to D3D11TexturePtr. ...
D3D11TexturePtr & operator=(const TexturePtr &r)
Operator used to convert a TexturePtr to a D3D11TexturePtr.
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()
overriden from Resource
vector< HardwarePixelBufferSharedPtr >::type SurfaceList
Vector of pointers to subsurfaces.
PixelFormat
The pixel format used for images, textures, and render surfaces.
ID3D11DepthStencilView * mDepthStencilView
ID3D11Texture1D * mp1DTex
D3D11 pointer.
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:443
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:40
SurfaceList mSurfaceList
void loadImpl()
overriden from Resource
ID3D11Texture1D * GetTex1D()
#define OGRE_LOCK_MUTEX(name)
void copyToTexture(TexturePtr &target)
overriden from Texture
HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap)
Return hardware pixel buffer for a surface.
~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.
unsigned int * useCountPointer() const
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgreSharedPtr.h:60
D3D11TexturePtr(const D3D11TexturePtr &r)
_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:104
D3D11TexturePtr(const ResourcePtr &r)
D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const
bool requiresTextureFlipping() const
#define OGRE_COPY_AUTO_SHARED_MUTEX(from)
void createInternalResourcesImpl(void)
Implementation of creating internal texture resources.
void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format)
internal method, set Texture class final texture protected attributes
void _loadTex(LoadedStreams &loadedStreams)
internal method, load a normal texture