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 
62  DeviceToTextureResourcesMap mMapDeviceToTextureResources;
63 
64 
67  SurfaceList mSurfaceList;
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 
172  LoadedStreams mLoadedStreams;
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
bool mHwGammaReadSupported
Is hardware gamma supported (read)?
IDirect3DBaseTexture9 * pBaseTex
actual texture pointer
vector< HardwarePixelBufferSharedPtr >::type SurfaceList
Vector of pointers to subsurfaces.
unsigned int uint
bool mHwGammaWriteSupported
Is hardware gamma supported (write)?
PixelFormat
The pixel format used for images, textures, and render surfaces.
Interface describing a manual resource loader.
Definition: OgreResource.h:514
Abstract class representing a Texture resource.
Definition: OgreTexture.h:102
unsigned long long int ResourceHandle
Definition: OgreResource.h:41
map< IDirect3DDevice9 *, TextureResources * >::type DeviceToTextureResourcesMap
#define _OgreD3D9Export
bool requiresTextureFlipping() const
IDirect3DTexture9 * pNormTex
1D/2D normal texture pointer
D3DMULTISAMPLE_TYPE mFSAAType
IDirect3DSurface9 * pFSAASurface
Optional FSAA surface.
IDirect3DVolumeTexture9 * pVolumeTex
Volume texture.
This class represents a RenderTarget that renders to a Texture.
_StringBase String
bool isHardwareGammaReadToBeUsed() const
Indicates whether the hardware gamma is actually enabled and supported.
Shared pointer implementation used to share pixel buffers.
String _getCubeFaceName(unsigned char face) const
internal method, the cube map face name for the spec. face index
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.
Defines a generic resource handler.
DeviceToTextureResourcesMap mMapDeviceToTextureResources
Map between device to texture resources.
This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info...
RenderTexture implementation for D3D9.
Reference-counted shared pointer, used for objects where implicit destruction is required.
DeviceToTextureResourcesMap::iterator DeviceToTextureResourcesIterator
SharedPtr< vector< MemoryDataStreamPtr >::type > LoadedStreams
LoadedStreams mLoadedStreams
Vector of pointers to streams that were pulled from disk by prepareImpl but have yet to be pushed int...
Represents a Direct3D rendering resource.
IDirect3DCubeTexture9 * pCubeTex
cubic texture pointer
D3DPOOL mD3DPool
The memory pool being used.
SurfaceList mSurfaceList

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 Sun Oct 22 2017 04:04:15