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-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef _D3DTexture_H__
|
---|
26 | #define _D3DTexture_H__
|
---|
27 |
|
---|
28 | #include "OgreD3D7Prerequisites.h"
|
---|
29 | #include "OgreTexture.h"
|
---|
30 | #include "OgreRenderTarget.h"
|
---|
31 | #include "OgreRenderTexture.h"
|
---|
32 | #include "OgreRenderTargetListener.h"
|
---|
33 | #include "OgreD3D7HardwarePixelBuffer.h"
|
---|
34 |
|
---|
35 | namespace Ogre {
|
---|
36 |
|
---|
37 | /** Direct3D7-specific texture resource implementation.
|
---|
38 | */
|
---|
39 | class D3DTexture : public Texture
|
---|
40 | {
|
---|
41 | public:
|
---|
42 | // Constructor, called from D3DTextureManager
|
---|
43 | D3DTexture(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
44 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
45 | IDirect3DDevice7 * lpDirect3dDevice);
|
---|
46 | virtual ~D3DTexture();
|
---|
47 |
|
---|
48 | virtual void loadImage( const Image &img );
|
---|
49 | virtual void loadImage3D( const Image imgs[]);
|
---|
50 | virtual void copyToTexture(TexturePtr& target );
|
---|
51 |
|
---|
52 | /// D3D-specific member that returns the underlying surface.
|
---|
53 | LPDIRECTDRAWSURFACE7 getDDSurface(void);
|
---|
54 |
|
---|
55 | /// @copydoc Texture::getBuffer
|
---|
56 | HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
|
---|
57 |
|
---|
58 | /// Static pixelformat functions
|
---|
59 | static D3DX_SURFACEFORMAT OgreFormat_to_D3DXFormat( PixelFormat format );
|
---|
60 | static PixelFormat closestD3DXFormat( PixelFormat format );
|
---|
61 | static bool OgreFormat_to_DDPixelFormat( PixelFormat format, DDPIXELFORMAT & out );
|
---|
62 |
|
---|
63 | /// Restore this texture from a lost device
|
---|
64 | void restoreFromLostDevice(void);
|
---|
65 |
|
---|
66 | protected:
|
---|
67 | IDirect3DDevice7 * mD3DDevice; ///< A pointer to the Direct3D device.
|
---|
68 | IDirectDrawSurface7 * mSurface; ///< Surface of the (first) device-specific texture.
|
---|
69 | /// cube texture individual face names
|
---|
70 | String mCubeFaceNames[6];
|
---|
71 | /// Vector of pointers to subsurfaces
|
---|
72 | typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
|
---|
73 | SurfaceList mSurfaceList;
|
---|
74 | /// Are we restoring from a lost device?
|
---|
75 | bool mRestoring;
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | /// @copydoc Resource::loadImpl
|
---|
80 | void loadImpl(void);
|
---|
81 | /// @copydoc Texture::createInternalResourcesImpl
|
---|
82 | void createInternalResourcesImpl(void);
|
---|
83 | /// @copydoc Resource::freeInternalResourcesImpl
|
---|
84 | void freeInternalResourcesImpl(void);
|
---|
85 |
|
---|
86 | void createSurface2D(void);
|
---|
87 | void createSurface3D(void);
|
---|
88 |
|
---|
89 | /// internal method, return a D3D pixel format for texture creation
|
---|
90 | void _chooseD3DFormat(DDPIXELFORMAT &ddpf);
|
---|
91 |
|
---|
92 | /// internal method, construct full cube texture face names from a given string
|
---|
93 | void _constructCubeFaceNames(const String name);
|
---|
94 |
|
---|
95 | /// internal method, the cube map face name for the spec. face index
|
---|
96 | String _getCubeFaceName(unsigned char face) const
|
---|
97 | { assert(face < 6); return mCubeFaceNames[face]; }
|
---|
98 |
|
---|
99 | // Create the list of surfaces
|
---|
100 | void _createSurfaceList();
|
---|
101 | };
|
---|
102 |
|
---|
103 | /** Specialisation of SharedPtr to allow SharedPtr to be assigned to D3DTexturePtr
|
---|
104 | @note Has to be a subclass since we need operator=.
|
---|
105 | We could templatise this instead of repeating per Resource subclass,
|
---|
106 | except to do so requires a form VC6 does not support i.e.
|
---|
107 | ResourceSubclassPtr<T> : public SharedPtr<T>
|
---|
108 | */
|
---|
109 | class D3DTexturePtr : public SharedPtr<D3DTexture>
|
---|
110 | {
|
---|
111 | public:
|
---|
112 | D3DTexturePtr() : SharedPtr<D3DTexture>() {}
|
---|
113 | explicit D3DTexturePtr(D3DTexture* rep) : SharedPtr<D3DTexture>(rep) {}
|
---|
114 | D3DTexturePtr(const D3DTexturePtr& r) : SharedPtr<D3DTexture>(r) {}
|
---|
115 | D3DTexturePtr(const ResourcePtr& r) : SharedPtr<D3DTexture>()
|
---|
116 | {
|
---|
117 | // lock & copy other mutex pointer
|
---|
118 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
|
---|
119 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
|
---|
120 | pRep = static_cast<D3DTexture*>(r.getPointer());
|
---|
121 | pUseCount = r.useCountPointer();
|
---|
122 | if (pUseCount)
|
---|
123 | {
|
---|
124 | ++(*pUseCount);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | /// Operator used to convert a ResourcePtr to a D3DTexturePtr
|
---|
129 | D3DTexturePtr& operator=(const ResourcePtr& r)
|
---|
130 | {
|
---|
131 | if (pRep == static_cast<D3DTexture*>(r.getPointer()))
|
---|
132 | return *this;
|
---|
133 | release();
|
---|
134 | // lock & copy other mutex pointer
|
---|
135 | OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
|
---|
136 | OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
|
---|
137 | pRep = static_cast<D3DTexture*>(r.getPointer());
|
---|
138 | pUseCount = r.useCountPointer();
|
---|
139 | if (pUseCount)
|
---|
140 | {
|
---|
141 | ++(*pUseCount);
|
---|
142 | }
|
---|
143 | return *this;
|
---|
144 | }
|
---|
145 | /// Operator used to convert a TexturePtr to a D3DTexturePtr
|
---|
146 | D3DTexturePtr& operator=(const TexturePtr& r)
|
---|
147 | {
|
---|
148 | if (pRep == static_cast<D3DTexture*>(r.getPointer()))
|
---|
149 | return *this;
|
---|
150 | release();
|
---|
151 | pRep = static_cast<D3DTexture*>(r.getPointer());
|
---|
152 | pUseCount = r.useCountPointer();
|
---|
153 | if (pUseCount)
|
---|
154 | {
|
---|
155 | ++(*pUseCount);
|
---|
156 | }
|
---|
157 | return *this;
|
---|
158 | }
|
---|
159 | };
|
---|
160 |
|
---|
161 |
|
---|
162 | /// D3D7 implementation of RenderTexture
|
---|
163 | class D3D7RenderTexture : public RenderTexture
|
---|
164 | {
|
---|
165 | public:
|
---|
166 | D3D7RenderTexture( const String & name,
|
---|
167 | unsigned int width, unsigned int height,
|
---|
168 | TextureType texType, PixelFormat internalFormat,
|
---|
169 | const NameValuePairList *misc )
|
---|
170 | : RenderTexture( name, width, height, texType, internalFormat )
|
---|
171 | {
|
---|
172 | mPrivateTex = TextureManager::getSingleton().createManual(mName +
|
---|
173 | "_PRIVATE##", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
---|
174 | texType, mWidth, mHeight, 0, internalFormat, TU_RENDERTARGET);
|
---|
175 | mPrivateTex->createInternalResources();
|
---|
176 | }
|
---|
177 |
|
---|
178 | virtual ~D3D7RenderTexture()
|
---|
179 | {
|
---|
180 | mPrivateTex->unload();
|
---|
181 | TextureManager::getSingleton().remove(mPrivateTex->getName());
|
---|
182 | }
|
---|
183 |
|
---|
184 | bool requiresTextureFlipping() const { return false; }
|
---|
185 |
|
---|
186 | virtual void getCustomAttribute( const String& name, void* pData )
|
---|
187 | {
|
---|
188 | if( name == "DDBACKBUFFER" )
|
---|
189 | {
|
---|
190 | LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
|
---|
191 |
|
---|
192 | *pSurf = mPrivateTex->getDDSurface();
|
---|
193 | return;
|
---|
194 | }
|
---|
195 | else if( name == "DDFRONTBUFFER" )
|
---|
196 | {
|
---|
197 | LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
|
---|
198 |
|
---|
199 | *pSurf = mPrivateTex->getDDSurface();
|
---|
200 | return;
|
---|
201 | }
|
---|
202 | else if( name == "HWND" )
|
---|
203 | {
|
---|
204 | HWND *pHwnd = (HWND*)pData;
|
---|
205 |
|
---|
206 | *pHwnd = NULL;
|
---|
207 | return;
|
---|
208 | }
|
---|
209 | else if( name == "isTexture" )
|
---|
210 | {
|
---|
211 | bool *b = reinterpret_cast< bool * >( pData );
|
---|
212 | *b = true;
|
---|
213 |
|
---|
214 | return;
|
---|
215 | }
|
---|
216 | }
|
---|
217 | virtual void writeContentsToFile( const String & filename ) {}
|
---|
218 |
|
---|
219 | #ifdef GTP_VISIBILITY_MODIFIED_OGRE
|
---|
220 | uchar *getBufferContents(int &dimx, int &dimy) { dimx = dimy = 0; return NULL; };
|
---|
221 | #endif // GTP_VISIBILITY_MODIFIED_OGRE
|
---|
222 |
|
---|
223 | protected:
|
---|
224 | /// The texture to which rendering takes place.
|
---|
225 | D3DTexturePtr mPrivateTex;
|
---|
226 |
|
---|
227 | protected:
|
---|
228 | virtual void _copyToTexture()
|
---|
229 | {
|
---|
230 | // Copy the newly-rendered data to the public texture surface.
|
---|
231 | mPrivateTex->copyToTexture( mTexture );
|
---|
232 | }
|
---|
233 | };
|
---|
234 | }
|
---|
235 |
|
---|
236 | #endif
|
---|