OgreD3D9Texture.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 __D3D9TEXTURE_H__
29 #define __D3D9TEXTURE_H__
30 
31 #include "OgreD3D9Prerequisites.h"
32 #include "OgreTexture.h"
33 #include "OgreRenderTexture.h"
34 #include "OgreImage.h"
35 #include "OgreException.h"
37 #include "OgreD3D9Resource.h"
38 
39 namespace Ogre {
41  {
42  protected:
43 
45  {
47  IDirect3DTexture9* pNormTex;
49  IDirect3DCubeTexture9* pCubeTex;
51  IDirect3DVolumeTexture9* pVolumeTex;
53  IDirect3DBaseTexture9* pBaseTex;
55  IDirect3DSurface9* pFSAASurface;
56  };
57 
59  typedef DeviceToTextureResourcesMap::iterator DeviceToTextureResourcesIterator;
60 
63 
64 
69  String mCubeFaceNames[6];
71  D3DPOOL mD3DPool;
72  // Dynamic textures?
74 
79  D3DMULTISAMPLE_TYPE mFSAAType;
80  DWORD mFSAAQuality;
81 
82  // needed to store data between prepareImpl and loadImpl
84 
86  void _loadCubeTex(IDirect3DDevice9* d3d9Device, const LoadedStreams &loadedStreams);
88  void _loadNormTex(IDirect3DDevice9* d3d9Device, const LoadedStreams &loadedStreams);
90  void _loadVolumeTex(IDirect3DDevice9* d3d9Device, const LoadedStreams &loadedStreams);
91 
93  LoadedStreams _prepareCubeTex();
95  LoadedStreams _prepareNormTex();
97  LoadedStreams _prepareVolumeTex();
98 
100  void _createNormTex(IDirect3DDevice9* d3d9Device);
102  void _createCubeTex(IDirect3DDevice9* d3d9Device);
104  void _createVolumeTex(IDirect3DDevice9* d3d9Device);
105 
107  D3DFORMAT _chooseD3DFormat(IDirect3DDevice9* d3d9Device);
108 
110  size_t calculateSize(void) const;
112  void createInternalResources(void);
114  void freeInternalResources(void);
116  void createInternalResourcesImpl(void);
118  void createInternalResourcesImpl(IDirect3DDevice9* d3d9Device);
120  void freeInternalResourcesImpl(void);
122  void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
124  void _setFinalAttributes(IDirect3DDevice9* d3d9Device, TextureResources* textureResources,
125  unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
127  D3DTEXTUREFILTERTYPE _getBestFilterMethod(IDirect3DDevice9* d3d9Device);
129  bool _canUseDynamicTextures(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
131  bool _canAutoGenMipmaps(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
133  bool _canUseHardwareGammaCorrection(IDirect3DDevice9* d3d9Device, DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat, bool forwriting);
134 
136  String _getCubeFaceName(unsigned char face) const
137  { assert(face < 6); return mCubeFaceNames[face]; }
138 
141  void _createSurfaceList(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
142 
144  void loadImpl();
146  void loadImpl(IDirect3DDevice9* d3d9Device);
148  void prepareImpl();
150  void unprepareImpl();
152  void postLoadImpl();
153 
155  TextureResources* getTextureResources(IDirect3DDevice9* d3d9Device);
156 
158  TextureResources* allocateTextureResources(IDirect3DDevice9* d3d9Device);
159 
161  void createTextureResources(IDirect3DDevice9* d3d9Device);
162 
164  void freeTextureResources(IDirect3DDevice9* d3d9Device, TextureResources* textureResources);
165 
166  void determinePool();
167 
173 
175  public:
177  D3D9Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
178  const String& group, bool isManual, ManualResourceLoader* loader);
180  ~D3D9Texture();
181 
183  void copyToTexture( TexturePtr& target );
184 
185 
187  HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
188 
190  IDirect3DBaseTexture9 *getTexture();
192  IDirect3DTexture9 *getNormTexture();
194  IDirect3DCubeTexture9 *getCubeTexture();
195 
203  bool isHardwareGammaReadToBeUsed() const { return mHwGamma && mHwGammaReadSupported; }
204 
206  bool useDefaultPool();
207 
208  // Called immediately after the Direct3D device has been created.
209  virtual void notifyOnDeviceCreate(IDirect3DDevice9* d3d9Device);
210 
211  // Called before the Direct3D device is going to be destroyed.
212  virtual void notifyOnDeviceDestroy(IDirect3DDevice9* d3d9Device);
213 
214  // Called immediately after the Direct3D device has entered a lost state.
215  virtual void notifyOnDeviceLost(IDirect3DDevice9* d3d9Device);
216 
217  // Called immediately after the Direct3D device has been reset
218  virtual void notifyOnDeviceReset(IDirect3DDevice9* d3d9Device);
219  };
220 
223  {
224  public:
225  D3D9RenderTexture(const String &name, D3D9HardwarePixelBuffer *buffer, bool writeGamma, uint fsaa);
227 
228  virtual void update(bool swap);
229 
230  virtual void getCustomAttribute( const String& name, void *pData );
231 
232  bool requiresTextureFlipping() const { return false; }
233 
235  void swapBuffers();
236 
237  };
238 
239 }
240 
241 #endif
Ogre::ResourceHandle
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
Ogre::Texture
Abstract class representing a Texture resource.
Definition: OgreTexture.h:102
Ogre::D3D9HardwarePixelBuffer
Definition: OgreD3D9HardwarePixelBuffer.h:40
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::D3D9Texture::TextureResources::pBaseTex
IDirect3DBaseTexture9 * pBaseTex
actual texture pointer
Definition: OgreD3D9Texture.h:53
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::D3D9Texture::_getCubeFaceName
String _getCubeFaceName(unsigned char face) const
internal method, the cube map face name for the spec. face index
Definition: OgreD3D9Texture.h:136
Ogre::D3D9Texture::mHwGammaWriteSupported
bool mHwGammaWriteSupported
Is hardware gamma supported (write)?
Definition: OgreD3D9Texture.h:78
OgreD3D9Prerequisites.h
Ogre::D3D9Texture::mLoadedStreams
LoadedStreams mLoadedStreams
Vector of pointers to streams that were pulled from disk by prepareImpl but have yet to be pushed int...
Definition: OgreD3D9Texture.h:172
Ogre::D3D9Texture::SurfaceList
vector< HardwarePixelBufferSharedPtr >::type SurfaceList
Vector of pointers to subsurfaces.
Definition: OgreD3D9Texture.h:66
OgreException.h
Ogre::D3D9Texture::DeviceToTextureResourcesIterator
DeviceToTextureResourcesMap::iterator DeviceToTextureResourcesIterator
Definition: OgreD3D9Texture.h:59
OgreImage.h
Ogre::D3D9Texture
Definition: OgreD3D9Texture.h:40
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::D3D9Texture::TextureResources::pVolumeTex
IDirect3DVolumeTexture9 * pVolumeTex
Volume texture.
Definition: OgreD3D9Texture.h:51
OgreD3D9HardwarePixelBuffer.h
Ogre::D3D9Resource
Represents a Direct3D rendering resource.
Definition: OgreD3D9Resource.h:40
Ogre::D3D9Texture::mFSAAQuality
DWORD mFSAAQuality
Definition: OgreD3D9Texture.h:80
Ogre::D3D9RenderTexture
RenderTexture implementation for D3D9.
Definition: OgreD3D9Texture.h:222
Ogre::PixelFormat
PixelFormat
The pixel format used for images, textures, and render surfaces.
Definition: OgrePixelFormat.h:43
Ogre::D3D9Texture::mSurfaceList
SurfaceList mSurfaceList
Definition: OgreD3D9Texture.h:67
OgreTexture.h
Ogre::D3D9Texture::LoadedStreams
SharedPtr< vector< MemoryDataStreamPtr >::type > LoadedStreams
Definition: OgreD3D9Texture.h:83
Ogre::D3D9Texture::TextureResources::pFSAASurface
IDirect3DSurface9 * pFSAASurface
Optional FSAA surface.
Definition: OgreD3D9Texture.h:55
OgreD3D9Resource.h
Ogre::D3D9Texture::mDynamicTextures
bool mDynamicTextures
Definition: OgreD3D9Texture.h:73
Ogre::ResourceManager
Defines a generic resource handler.
Definition: OgreResourceManager.h:122
Ogre::D3D9Texture::mMapDeviceToTextureResources
DeviceToTextureResourcesMap mMapDeviceToTextureResources
Map between device to texture resources.
Definition: OgreD3D9Texture.h:62
Ogre::D3D9Texture::TextureResources::pNormTex
IDirect3DTexture9 * pNormTex
1D/2D normal texture pointer
Definition: OgreD3D9Texture.h:47
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgrePrerequisites.h:310
Ogre::D3D9Texture::TextureResources
Definition: OgreD3D9Texture.h:44
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
std::swap
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Definition: OgreSmallVector.h:802
OgreRenderTexture.h
Ogre::HardwarePixelBufferSharedPtr
Shared pointer implementation used to share pixel buffers.
Definition: OgreHardwarePixelBuffer.h:193
_OgreD3D9Export
#define _OgreD3D9Export
Definition: OgreD3D9Prerequisites.h:118
Ogre::RenderTexture
This class represents a RenderTarget that renders to a Texture.
Definition: OgreRenderTexture.h:48
Ogre::D3D9RenderTexture::~D3D9RenderTexture
~D3D9RenderTexture()
Definition: OgreD3D9Texture.h:226
Ogre::D3D9Texture::DeviceToTextureResourcesMap
map< IDirect3DDevice9 *, TextureResources * >::type DeviceToTextureResourcesMap
Definition: OgreD3D9Texture.h:58
Ogre::D3D9Texture::TextureResources::pCubeTex
IDirect3DCubeTexture9 * pCubeTex
cubic texture pointer
Definition: OgreD3D9Texture.h:49
Ogre::D3D9Texture::isHardwareGammaReadToBeUsed
bool isHardwareGammaReadToBeUsed() const
Indicates whether the hardware gamma is actually enabled and supported.
Definition: OgreD3D9Texture.h:203
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::D3D9Texture::mHwGammaReadSupported
bool mHwGammaReadSupported
Is hardware gamma supported (read)?
Definition: OgreD3D9Texture.h:76
Ogre::ManualResourceLoader
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Ogre::D3D9RenderTexture::requiresTextureFlipping
bool requiresTextureFlipping() const
Definition: OgreD3D9Texture.h:232
Ogre::D3D9Texture::mD3DPool
D3DPOOL mD3DPool
The memory pool being used.
Definition: OgreD3D9Texture.h:71
Ogre::D3D9Texture::mFSAAType
D3DMULTISAMPLE_TYPE mFSAAType
Definition: OgreD3D9Texture.h:79

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