OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 __D3D8TEXTURE_H__
29 #define __D3D8TEXTURE_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:
41 
42 
44  //LPDIRECT3D11 *mpD3D;
45  // 1D texture pointer
46  ID3D11Texture1D *mp1DTex;
47  // 2D texture pointer
48  ID3D11Texture2D *mp2DTex;
50  ID3D11Texture3D *mp3DTex;
52  ID3D11Resource *mpTex;
53 
54  ID3D11ShaderResourceView* mpShaderResourceView;
55 
56  // is dynamic
57  bool mIsDynamic;
58 
62  //D3DDEVICE_CREATION_PARAMETERS mDevCreParams;
64  DXGI_FORMAT mBBPixelFormat;
66  //D3DPOOL mD3DPool;
68  //D3DCAPS9 mDevCaps;
69  // Dynamic textures?
74 
75  D3D11_SHADER_RESOURCE_VIEW_DESC mSRVDesc;
77  void _loadTex();
78 
80  void _create1DTex();
82  void _create2DTex();
84  void _create3DTex();
85 
87  DXGI_FORMAT _chooseD3DFormat();
88 
90  void createInternalResourcesImpl(void);
92  void freeInternalResourcesImpl(void);
94  void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
96  void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
97 
99  String _getCubeFaceName(unsigned char face) const
100  { assert(face < 6); return mCubeFaceNames[face]; }
101 
104  void _createSurfaceList(void);
105 
107  void loadImpl();
108  public:
110  D3D11Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
111  const String& group, bool isManual, ManualResourceLoader* loader,
112  D3D11Device & device);
114  ~D3D11Texture();
115 
117  void copyToTexture( TexturePtr& target );
119  void loadImage( const Image &img );
120 
121 
123  HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
124 
125  ID3D11Resource *getTextureResource()
126  { assert(mpTex); return mpTex; }
128  ID3D11ShaderResourceView *getTexture()
129  { assert(mpShaderResourceView); return mpShaderResourceView; }
130  /*/// retrieves a pointer to the normal 1D/2D texture
131  IDirect3DTexture9 *getNormTexture()
132  { assert(mpNormTex); return mpNormTex; }
134  IDirect3DCubeTexture9 *getCubeTexture()
135  { assert(mpCubeTex); return mpCubeTex; }
136  */
137 
138 
140  bool releaseIfDefaultPool(void);
142  bool recreateIfDefaultPool(D3D11Device & device);
143 
144  ID3D11Texture1D * GetTex1D() {return mp1DTex;};
145  ID3D11Texture2D * GetTex2D() {return mp2DTex;};
146  ID3D11Texture3D * GetTex3D() {return mp3DTex;};
147 
148  D3D11_SHADER_RESOURCE_VIEW_DESC getShaderResourceViewDesc() const;
149 
150 
151  };
152 
159  class D3D11TexturePtr : public SharedPtr<D3D11Texture>
160  {
161  public:
166  {
167  // lock & copy other mutex pointer
168  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
169  {
170  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
171  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
172  pRep = static_cast<D3D11Texture*>(r.getPointer());
174  if (pUseCount)
175  {
176  ++(*pUseCount);
177  }
178  }
179  }
180 
183  {
184  if (pRep == static_cast<D3D11Texture*>(r.getPointer()))
185  return *this;
186  release();
187  // lock & copy other mutex pointer
188  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
189  {
190  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
191  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
192  pRep = static_cast<D3D11Texture*>(r.getPointer());
194  if (pUseCount)
195  {
196  ++(*pUseCount);
197  }
198  }
199  return *this;
200  }
203  {
204  if (pRep == static_cast<D3D11Texture*>(r.getPointer()))
205  return *this;
206  release();
207  // lock & copy other mutex pointer
208  OGRE_MUTEX_CONDITIONAL(r.OGRE_AUTO_MUTEX_NAME)
209  {
210  OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
211  OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
212  pRep = static_cast<D3D11Texture*>(r.getPointer());
214  if (pUseCount)
215  {
216  ++(*pUseCount);
217  }
218  }
219  return *this;
220  }
221  };
222 
225  {
227  ID3D11RenderTargetView * mRenderTargetView;
228  ID3D11DepthStencilView * mDepthStencilView;
229  public:
230  D3D11RenderTexture(const String &name, D3D11HardwarePixelBuffer *buffer, D3D11Device & device );
231  virtual ~D3D11RenderTexture();
232 
233  void rebind(D3D11HardwarePixelBuffer *buffer);
234 
235  virtual void getCustomAttribute( const String& name, void *pData );
236 
237  bool requiresTextureFlipping() const { return false; }
238  };
239 
240 }
241 
242 #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
T * getPointer() const
D3D11Device & mDevice
D3DDevice pointer.
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.
ID3D11RenderTargetView * mRenderTargetView
Interface describing a manual resource loader.
Definition: OgreResource.h:512
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)
DXGI_FORMAT mBBPixelFormat
device creation parameters
vector< HardwarePixelBufferSharedPtr >::type SurfaceList
Vector of pointers to subsurfaces.
PixelFormat
The pixel format used for images, textures, and render surfaces.
ID3D11DepthStencilView * mDepthStencilView
void _loadTex()
internal method, load a normal texture
ID3D11Texture1D * mp1DTex
D3D11 pointer.
Specialisation of SharedPtr to allow SharedPtr to be assigned to TexturePtr.
Definition: OgreTexture.h:440
ID3D11Resource * getTextureResource()
ID3D11ShaderResourceView * mpShaderResourceView
bool recreateIfDefaultPool(D3D11Device &device)
For dealing with lost devices - recreate the resource if in the default pool (and return true) ...
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:39
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
ID3D11Texture2D * mp2DTex
void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format)
internal method, set Texture class source image protected attributes
Abstract class representing a Texture resource.
Definition: OgreTexture.h:101
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