source: obsolete/trunk/VUT/work/ogre_changes/RenderSystems/Direct3D7/include/OgreD3D7Texture.h @ 154

Revision 154, 8.2 KB checked in by mattausch, 19 years ago (diff)

added item buffer queries.

Line 
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 _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
35namespace 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::createInternalResources
56        void createInternalResources(void);
57
58                /// @copydoc Texture::getBuffer
59                HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
60
61                /// Static pixelformat functions
62                static D3DX_SURFACEFORMAT OgreFormat_to_D3DXFormat( PixelFormat format );
63                static PixelFormat closestD3DXFormat( PixelFormat format );
64                static bool OgreFormat_to_DDPixelFormat( PixelFormat format, DDPIXELFORMAT & out );
65    protected:
66        IDirect3DDevice7 * mD3DDevice;       ///< A pointer to the Direct3D device.
67        IDirectDrawSurface7 * mSurface;      ///< Surface of the (first) device-specific texture.
68                /// cube texture individual face names
69                String mCubeFaceNames[6];
70                /// Vector of pointers to subsurfaces
71                typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
72                SurfaceList                                             mSurfaceList;
73       
74
75        /// @copydoc Resource::loadImpl
76        void loadImpl(void);
77        /// @copydoc Resource::unloadImpl
78        void unloadImpl(void);
79               
80                void createSurface2D(void);
81                void createSurface3D(void);
82
83                /// internal method, return a D3D pixel format for texture creation
84                void _chooseD3DFormat(DDPIXELFORMAT &ddpf);
85
86                /// internal method, construct full cube texture face names from a given string
87                void _constructCubeFaceNames(const String name);
88
89                /// internal method, the cube map face name for the spec. face index
90                String _getCubeFaceName(unsigned char face) const
91                { assert(face < 6); return mCubeFaceNames[face]; }
92
93                // Create the list of surfaces
94                void _createSurfaceList();
95    };
96
97    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to D3DTexturePtr
98    @note Has to be a subclass since we need operator=.
99    We could templatise this instead of repeating per Resource subclass,
100    except to do so requires a form VC6 does not support i.e.
101    ResourceSubclassPtr<T> : public SharedPtr<T>
102    */
103    class D3DTexturePtr : public SharedPtr<D3DTexture>
104    {
105    public:
106        D3DTexturePtr() : SharedPtr<D3DTexture>() {}
107        explicit D3DTexturePtr(D3DTexture* rep) : SharedPtr<D3DTexture>(rep) {}
108        D3DTexturePtr(const D3DTexturePtr& r) : SharedPtr<D3DTexture>(r) {}
109        D3DTexturePtr(const ResourcePtr& r) : SharedPtr<D3DTexture>()
110        {
111                        // lock & copy other mutex pointer
112                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
113                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
114            pRep = static_cast<D3DTexture*>(r.getPointer());
115            pUseCount = r.useCountPointer();
116            if (pUseCount)
117            {
118                ++(*pUseCount);
119            }
120        }
121
122        /// Operator used to convert a ResourcePtr to a D3DTexturePtr
123        D3DTexturePtr& operator=(const ResourcePtr& r)
124        {
125            if (pRep == static_cast<D3DTexture*>(r.getPointer()))
126                return *this;
127            release();
128                        // lock & copy other mutex pointer
129                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
130                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
131            pRep = static_cast<D3DTexture*>(r.getPointer());
132            pUseCount = r.useCountPointer();
133            if (pUseCount)
134            {
135                ++(*pUseCount);
136            }
137            return *this;
138        }
139        /// Operator used to convert a TexturePtr to a D3DTexturePtr
140        D3DTexturePtr& operator=(const TexturePtr& r)
141        {
142            if (pRep == static_cast<D3DTexture*>(r.getPointer()))
143                return *this;
144            release();
145            pRep = static_cast<D3DTexture*>(r.getPointer());
146            pUseCount = r.useCountPointer();
147            if (pUseCount)
148            {
149                ++(*pUseCount);
150            }
151            return *this;
152        }
153    };
154
155
156    /// D3D7 implementation of RenderTexture
157    class D3D7RenderTexture : public RenderTexture
158    {
159    public:
160        D3D7RenderTexture( const String & name,
161                        unsigned int width, unsigned int height,
162                        TextureType texType, PixelFormat internalFormat,
163                        const NameValuePairList *misc )
164                        : RenderTexture( name, width, height, texType, internalFormat )
165        {
166            mPrivateTex = TextureManager::getSingleton().createManual(mName +
167                "_PRIVATE##", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
168                texType, mWidth, mHeight, 0, internalFormat, TU_RENDERTARGET);
169            mPrivateTex->createInternalResources();
170        }
171
172                virtual ~D3D7RenderTexture()
173                {
174                        mPrivateTex->unload();
175                        TextureManager::getSingleton().remove(mPrivateTex->getName());
176                }
177
178                bool requiresTextureFlipping() const { return false; }
179
180        virtual void getCustomAttribute( const String& name, void* pData )
181        {
182            if( name == "DDBACKBUFFER" )
183            {
184                LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
185
186                *pSurf = mPrivateTex->getDDSurface();
187                return;
188            }
189            else if( name == "DDFRONTBUFFER" )
190            {
191                LPDIRECTDRAWSURFACE7 *pSurf = (LPDIRECTDRAWSURFACE7*)pData;
192
193                *pSurf = mPrivateTex->getDDSurface();
194                return;
195            }
196            else if( name == "HWND" )
197            {
198                HWND *pHwnd = (HWND*)pData;
199
200                *pHwnd = NULL;
201                return;
202            }
203            else if( name == "isTexture" )
204            {
205                bool *b = reinterpret_cast< bool * >( pData );
206                *b = true;
207
208                return;
209            }
210        }
211        virtual void writeContentsToFile( const String & filename ) {}
212
213#ifdef GTP_VISIBILITY_MODIFIED_OGRE
214                uchar *getBufferContents(int &dimx, int &dimy) { dimx = dimy = 0; return NULL; };
215#endif // GTP_VISIBILITY_MODIFIED_OGRE
216
217    protected:
218        /// The texture to which rendering takes place.
219        D3DTexturePtr mPrivateTex;
220
221    protected:
222        virtual void _copyToTexture()
223        {
224            // Copy the newly-rendered data to the public texture surface.
225            mPrivateTex->copyToTexture( mTexture );
226        }
227    };
228}
229
230#endif
Note: See TracBrowser for help on using the repository browser.