source: OGRE/trunk/ogrenew/RenderSystems/Direct3D9/include/OgreD3D9Texture.h @ 692

Revision 692, 9.3 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __D3D8TEXTURE_H__
26#define __D3D8TEXTURE_H__
27
28#include "OgreD3D9Prerequisites.h"
29#include "OgreTexture.h"
30#include "OgreRenderTexture.h"
31#include "OgreImage.h"
32#include "OgreException.h"
33#include "OgreD3D9HardwarePixelBuffer.h"
34
35#include "OgreNoMemoryMacros.h"
36#include <d3d9.h>
37#include <d3dx9.h>
38#include <dxerr9.h>
39#include "OgreMemoryMacros.h"
40
41namespace Ogre {
42        class D3D9Texture : public Texture
43        {
44        protected:
45                /// D3DDevice pointer
46                IDirect3DDevice9                *mpDev;         
47                /// D3D9 pointer
48                IDirect3D9                              *mpD3D;
49                /// 1D/2D normal texture pointer
50                IDirect3DTexture9               *mpNormTex;     
51                /// cubic texture pointer
52                IDirect3DCubeTexture9   *mpCubeTex;     
53        /// Volume texture
54        IDirect3DVolumeTexture9 *mpVolumeTex;
55        /// actual texture pointer
56                IDirect3DBaseTexture9   *mpTex;         
57
58                /// cube texture individual face names
59                String                                                  mCubeFaceNames[6];
60                /// device creation parameters
61                D3DDEVICE_CREATION_PARAMETERS   mDevCreParams;
62                /// back buffer pixel format
63                D3DFORMAT                                               mBBPixelFormat;
64                /// The memory pool being used
65                D3DPOOL                                                 mD3DPool;
66                /// device capabilities pointer
67                D3DCAPS9                                                mDevCaps;
68                // Dynamic textures?
69                bool                            mDynamicTextures;
70                /// Vector of pointers to subsurfaces
71                typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
72                SurfaceList                                             mSurfaceList;
73       
74        /// Initialise the device and get formats
75        void _initDevice(void);
76                /// internal method, load a cube texture
77                void _loadCubeTex();
78                /// internal method, load a normal texture
79                void _loadNormTex();
80                /// internal method, load a volume texture
81                void _loadVolumeTex();
82
83                /// internal method, create a blank normal 1D/2D texture
84                void _createNormTex();
85                /// internal method, create a blank cube texture
86                void _createCubeTex();
87                /// internal method, create a blank cube texture
88                void _createVolumeTex();
89
90                /// internal method, return a D3D pixel format for texture creation
91                D3DFORMAT _chooseD3DFormat();
92
93                /// @copydoc Texture::createInternalResourcesImpl
94                void createInternalResourcesImpl(void);
95                /// free internal resources
96                void freeInternalResourcesImpl(void);
97                /// internal method, set Texture class source image protected attributes
98                void _setSrcAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
99                /// internal method, set Texture class final texture protected attributes
100                void _setFinalAttributes(unsigned long width, unsigned long height, unsigned long depth, PixelFormat format);
101                /// internal method, return the best by hardware supported filter method
102                D3DTEXTUREFILTERTYPE _getBestFilterMethod();
103                /// internal method, return true if the device/texture combination can use dynamic textures
104                bool _canUseDynamicTextures(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
105                /// internal method, return true if the device/texture combination can auto gen. mip maps
106                bool _canAutoGenMipmaps(DWORD srcUsage, D3DRESOURCETYPE srcType, D3DFORMAT srcFormat);
107               
108                /// internal method, the cube map face name for the spec. face index
109                String _getCubeFaceName(unsigned char face) const
110                { assert(face < 6); return mCubeFaceNames[face]; }
111               
112                /// internal method, create D3D9HardwarePixelBuffers for every face and
113                /// mipmap level. This method must be called after the D3D texture object was created
114                void _createSurfaceList(void);
115
116        /// overriden from Resource
117        void loadImpl();
118        public:
119                /// constructor
120        D3D9Texture(ResourceManager* creator, const String& name, ResourceHandle handle,
121            const String& group, bool isManual, ManualResourceLoader* loader,
122            IDirect3DDevice9 *pD3DDevice);
123                /// destructor
124                ~D3D9Texture();
125
126                /// overriden from Texture
127                void copyToTexture( TexturePtr& target );
128                /// overriden from Texture
129                void loadImage( const Image &img );
130
131
132                /// @copydoc Texture::getBuffer
133                HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
134               
135                /// retrieves a pointer to the actual texture
136                IDirect3DBaseTexture9 *getTexture()
137                { assert(mpTex); return mpTex; }
138                /// retrieves a pointer to the normal 1D/2D texture
139                IDirect3DTexture9 *getNormTexture()
140                { assert(mpNormTex); return mpNormTex; }
141                /// retrieves a pointer to the cube texture
142                IDirect3DCubeTexture9 *getCubeTexture()
143                { assert(mpCubeTex); return mpCubeTex; }
144               
145               
146
147                /// For dealing with lost devices - release the resource if in the default pool (and return true)
148                bool releaseIfDefaultPool(void);
149                /// For dealing with lost devices - recreate the resource if in the default pool (and return true)
150                bool recreateIfDefaultPool(LPDIRECT3DDEVICE9 pDev);
151
152    };
153
154    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to D3D9TexturePtr
155    @note Has to be a subclass since we need operator=.
156    We could templatise this instead of repeating per Resource subclass,
157    except to do so requires a form VC6 does not support i.e.
158    ResourceSubclassPtr<T> : public SharedPtr<T>
159    */
160    class D3D9TexturePtr : public SharedPtr<D3D9Texture>
161    {
162    public:
163        D3D9TexturePtr() : SharedPtr<D3D9Texture>() {}
164        explicit D3D9TexturePtr(D3D9Texture* rep) : SharedPtr<D3D9Texture>(rep) {}
165        D3D9TexturePtr(const D3D9TexturePtr& r) : SharedPtr<D3D9Texture>(r) {}
166        D3D9TexturePtr(const ResourcePtr& r) : SharedPtr<D3D9Texture>()
167        {
168                        // lock & copy other mutex pointer
169                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
170                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
171            pRep = static_cast<D3D9Texture*>(r.getPointer());
172            pUseCount = r.useCountPointer();
173            if (pUseCount)
174            {
175                ++(*pUseCount);
176            }
177        }
178
179        /// Operator used to convert a ResourcePtr to a D3D9TexturePtr
180        D3D9TexturePtr& operator=(const ResourcePtr& r)
181        {
182            if (pRep == static_cast<D3D9Texture*>(r.getPointer()))
183                return *this;
184            release();
185                        // lock & copy other mutex pointer
186                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
187                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
188            pRep = static_cast<D3D9Texture*>(r.getPointer());
189            pUseCount = r.useCountPointer();
190            if (pUseCount)
191            {
192                ++(*pUseCount);
193            }
194            return *this;
195        }
196        /// Operator used to convert a TexturePtr to a D3D9TexturePtr
197        D3D9TexturePtr& operator=(const TexturePtr& r)
198        {
199            if (pRep == static_cast<D3D9Texture*>(r.getPointer()))
200                return *this;
201            release();
202                        // lock & copy other mutex pointer
203                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
204                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
205            pRep = static_cast<D3D9Texture*>(r.getPointer());
206            pUseCount = r.useCountPointer();
207            if (pUseCount)
208            {
209                ++(*pUseCount);
210            }
211            return *this;
212        }
213    };
214
215    /// RenderTexture implementation for D3D9
216    class D3D9RenderTexture : public RenderTexture
217    {
218    public:
219                D3D9RenderTexture(const String &name, D3D9HardwarePixelBuffer *buffer):
220                        RenderTexture(buffer, 0)
221                {
222                        mName = name;
223                }
224        ~D3D9RenderTexture() {}
225
226        void rebind(D3D9HardwarePixelBuffer *buffer)
227        {
228            mBuffer = buffer;
229            mWidth = mBuffer->getWidth();
230            mHeight = mBuffer->getHeight();
231            mColourDepth = Ogre::PixelUtil::getNumElemBits(mBuffer->getFormat());
232        }
233
234                virtual void getCustomAttribute( const String& name, void *pData )
235        {
236                        if(name == "DDBACKBUFFER")
237            {
238                IDirect3DSurface9 ** pSurf = (IDirect3DSurface9 **)pData;
239                                *pSurf = static_cast<D3D9HardwarePixelBuffer*>(mBuffer)->getSurface();
240                                return;
241            }
242            else if(name == "HWND")
243            {
244                HWND *pHwnd = (HWND*)pData;
245                *pHwnd = NULL;
246                return;
247            }
248                        else if(name == "BUFFER")
249                        {
250                                *static_cast<HardwarePixelBuffer**>(pData) = mBuffer;
251                                return;
252                        }
253                }
254
255                bool requiresTextureFlipping() const { return false; }
256        };
257
258}
259
260#endif
Note: See TracBrowser for help on using the repository browser.