source: OGRE/trunk/ogrenew/RenderSystems/GL/include/OgreGLTexture.h @ 690

Revision 690, 5.8 KB checked in by mattausch, 19 years ago (diff)

added ogre 1.07 main

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
26#ifndef __GLTEXTURE_H__
27#define __GLTEXTURE_H__
28
29#include "OgreGLPrerequisites.h"
30#include "OgrePlatform.h"
31#include "OgreRenderTexture.h"
32#include "OgreTexture.h"
33#include "OgreGLSupport.h"
34#include "OgreHardwarePixelBuffer.h"
35
36namespace Ogre {
37
38    class GLTexture : public Texture
39    {
40    public:
41        // Constructor
42        GLTexture(ResourceManager* creator, const String& name, ResourceHandle handle,
43            const String& group, bool isManual, ManualResourceLoader* loader,
44            GLSupport& support);
45
46        virtual ~GLTexture();     
47
48                void loadImage( const Image& img );
49        void createRenderTexture();
50                       
51                /// @copydoc Texture::getBuffer
52                HardwarePixelBufferSharedPtr getBuffer(size_t face, size_t mipmap);
53
54        // Takes the OGRE texture type (1d/2d/3d/cube) and returns the appropriate GL one
55        GLenum getGLTextureTarget(void) const;
56
57        GLuint getGLID() const
58        { return mTextureID; }
59
60    protected:
61                /// @copydoc Texture::createInternalResourcesImpl
62                void createInternalResourcesImpl(void);
63        /// @copydoc Resource::loadImpl
64        void loadImpl(void);
65        /// @copydoc Resource::freeInternalResourcesImpl
66        void freeInternalResourcesImpl(void);
67
68                /** internal method, create GLHardwarePixelBuffers for every face and
69                         mipmap level. This method must be called after the GL texture object was created,
70                        the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
71                        actually allocate the buffer
72                */
73                void _createSurfaceList();
74    private:
75        GLuint mTextureID;
76        GLSupport& mGLSupport;
77               
78                /// Vector of pointers to subsurfaces
79                typedef std::vector<HardwarePixelBufferSharedPtr> SurfaceList;
80                SurfaceList     mSurfaceList;
81    };
82
83    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to GLTexturePtr
84    @note Has to be a subclass since we need operator=.
85    We could templatise this instead of repeating per Resource subclass,
86    except to do so requires a form VC6 does not support i.e.
87    ResourceSubclassPtr<T> : public SharedPtr<T>
88    */
89    class GLTexturePtr : public SharedPtr<GLTexture>
90    {
91    public:
92        GLTexturePtr() : SharedPtr<GLTexture>() {}
93        explicit GLTexturePtr(GLTexture* rep) : SharedPtr<GLTexture>(rep) {}
94        GLTexturePtr(const GLTexturePtr& r) : SharedPtr<GLTexture>(r) {}
95        GLTexturePtr(const ResourcePtr& r) : SharedPtr<GLTexture>()
96        {
97                        // lock & copy other mutex pointer
98                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
99                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
100            pRep = static_cast<GLTexture*>(r.getPointer());
101            pUseCount = r.useCountPointer();
102            if (pUseCount)
103            {
104                ++(*pUseCount);
105            }
106        }
107
108        /// Operator used to convert a ResourcePtr to a GLTexturePtr
109        GLTexturePtr& operator=(const ResourcePtr& r)
110        {
111            if (pRep == static_cast<GLTexture*>(r.getPointer()))
112                return *this;
113            release();
114                        // lock & copy other mutex pointer
115                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
116                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
117            pRep = static_cast<GLTexture*>(r.getPointer());
118            pUseCount = r.useCountPointer();
119            if (pUseCount)
120            {
121                ++(*pUseCount);
122            }
123            return *this;
124        }
125        /// Operator used to convert a TexturePtr to a GLTexturePtr
126        GLTexturePtr& operator=(const TexturePtr& r)
127        {
128            if (pRep == static_cast<GLTexture*>(r.getPointer()))
129                return *this;
130            release();
131                        // lock & copy other mutex pointer
132                        OGRE_LOCK_MUTEX(*r.OGRE_AUTO_MUTEX_NAME)
133                        OGRE_COPY_AUTO_SHARED_MUTEX(r.OGRE_AUTO_MUTEX_NAME)
134            pRep = static_cast<GLTexture*>(r.getPointer());
135            pUseCount = r.useCountPointer();
136            if (pUseCount)
137            {
138                ++(*pUseCount);
139            }
140            return *this;
141        }
142    };
143
144    /// GL implementation of RenderTexture
145    class GLRenderTexture : public RenderTexture
146    {
147    public:
148        GLRenderTexture(const String& name, uint width, uint height, TextureType texType, PixelFormat format,
149                        const NameValuePairList *miscParams)
150            : RenderTexture(name, width, height, texType, format)
151        {
152            mGLTexture = mTexture;
153        }
154
155        void _copyToTexture(void);
156
157        bool requiresTextureFlipping() const { return true; }
158        virtual void writeContentsToFile( const String & filename );
159    protected:
160        GLTexturePtr mGLTexture;
161    };
162}
163
164#endif // __GLTEXTURE_H__
Note: See TracBrowser for help on using the repository browser.