Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/RenderSystems/GL/include/OgreGLTexture.h @ 29

Last change on this file since 29 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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