Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/OgreGLTextureManager.cpp @ 1

Last change on this file since 1 was 1, checked in by landauf, 17 years ago
File size: 7.0 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#include "OgreGLTextureManager.h"
31#include "OgreRoot.h"
32#include "OgreRenderSystem.h"
33#include "OgreGLRenderTexture.h"
34
35namespace Ogre {
36    //-----------------------------------------------------------------------------
37    GLTextureManager::GLTextureManager(GLSupport& support)
38        : TextureManager(), mGLSupport(support), mWarningTextureID(0)
39    {
40        // register with group manager
41        ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
42
43                createWarningTexture();
44    }
45    //-----------------------------------------------------------------------------
46    GLTextureManager::~GLTextureManager()
47    {
48        // unregister with group manager
49        ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
50                // Delete warning texture
51                glDeleteTextures(1, &mWarningTextureID);
52    }
53    //-----------------------------------------------------------------------------
54    Resource* GLTextureManager::createImpl(const String& name, ResourceHandle handle, 
55        const String& group, bool isManual, ManualResourceLoader* loader, 
56        const NameValuePairList* createParams)
57    {
58        return new GLTexture(this, name, handle, group, isManual, loader, mGLSupport);
59    }
60
61        //-----------------------------------------------------------------------------
62        void GLTextureManager::createWarningTexture()
63        {
64                // Generate warning texture
65                size_t width = 8;
66                size_t height = 8;
67                uint32 *data = new uint32[width*height];                // 0xXXRRGGBB
68                // Yellow/black stripes
69                for(size_t y=0; y<height; ++y)
70                {
71                        for(size_t x=0; x<width; ++x)
72                        {
73                                data[y*width+x] = (((x+y)%8)<4)?0x000000:0xFFFF00;
74                        }
75                }
76                // Create GL resource
77        glGenTextures(1, &mWarningTextureID);
78                glBindTexture(GL_TEXTURE_2D, mWarningTextureID);
79        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
80                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (void*)data);
81                // Free memory
82                delete [] data;
83        }
84        //-----------------------------------------------------------------------------
85        PixelFormat GLTextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage)
86        {
87                // Adjust requested parameters to capabilities
88        const RenderSystemCapabilities *caps = Root::getSingleton().getRenderSystem()->getCapabilities();
89
90                // Check compressed texture support
91                // if a compressed format not supported, revert to PF_A8R8G8B8
92                if(PixelUtil::isCompressed(format) &&
93            !caps->hasCapability( RSC_TEXTURE_COMPRESSION_DXT ))
94                {
95                        return PF_A8R8G8B8;
96                }
97                // if floating point textures not supported, revert to PF_A8R8G8B8
98                if(PixelUtil::isFloatingPoint(format) &&
99            !caps->hasCapability( RSC_TEXTURE_FLOAT ))
100                {
101                        return PF_A8R8G8B8;
102                }
103       
104        // Check if this is a valid rendertarget format
105                if( usage & TU_RENDERTARGET )
106        {
107            /// Get closest supported alternative
108            /// If mFormat is supported it's returned
109            return GLRTTManager::getSingleton().getSupportedAlternative(format);
110        }
111
112                // Supported
113                return format;
114
115               
116        }
117        //-----------------------------------------------------------------------------
118    bool GLTextureManager::isHardwareFilteringSupported(TextureType ttype, PixelFormat format, int usage,
119            bool preciseFormatOnly)
120    {
121        if (format == PF_UNKNOWN)
122            return false;
123
124        // Check natively format
125        PixelFormat nativeFormat = getNativeFormat(ttype, format, usage);
126        if (preciseFormatOnly && format != nativeFormat)
127            return false;
128
129        // Assume non-floating point is supported always
130        if (!PixelUtil::isFloatingPoint(nativeFormat))
131            return true;
132
133        // Hack: there are no elegant GL API to detects texture filtering supported,
134        // just hard code for cards based on vendor specifications.
135
136        // TODO: Add cards that 16 bits floating point flitering supported by
137        // hardware below
138        static const String sFloat16SupportedCards[] =
139        {
140            // GeForce 8 Series
141            "*GeForce*8800*",
142
143            // GeForce 7 Series
144            "*GeForce*7950*",
145            "*GeForce*7900*",
146            "*GeForce*7800*",
147            "*GeForce*7600*",
148            "*GeForce*7500*",
149            "*GeForce*7300*",
150
151            // GeForce 6 Series
152            "*GeForce*6800*",
153            "*GeForce*6700*",
154            "*GeForce*6600*",
155            "*GeForce*6500*",
156
157            ""                      // Empty string means end of list
158        };
159
160        // TODO: Add cards that 32 bits floating point flitering supported by
161        // hardware below
162        static const String sFloat32SupportedCards[] =
163        {
164            // GeForce 8 Series
165            "*GeForce*8800*",
166
167            ""                      // Empty string means end of list
168        };
169
170        PixelComponentType pct = PixelUtil::getComponentType(nativeFormat);
171        const String* supportedCards;
172        switch (pct)
173        {
174        case PCT_FLOAT16:
175            supportedCards = sFloat16SupportedCards;
176            break;
177        case PCT_FLOAT32:
178            supportedCards = sFloat32SupportedCards;
179            break;
180        default:
181            return false;
182        }
183
184        const GLubyte* pcRenderer = glGetString(GL_RENDERER);
185        String str = (const char*)pcRenderer;
186
187        for (; !supportedCards->empty(); ++supportedCards)
188        {
189            if (StringUtil::match(str, *supportedCards))
190            {
191                return true;
192            }
193        }
194
195        return false;
196    }
197
198}
Note: See TracBrowser for help on using the repository browser.