source: OGRE/trunk/ogrenew/RenderSystems/GL/src/OgreGLPixelFormat.cpp @ 692

Revision 692, 9.6 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
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#include "OgreGLPixelFormat.h"
27#include "OgreRoot.h"
28#include "OgreRenderSystem.h"
29#include "OgreBitwise.h"
30
31namespace Ogre  {
32        //-----------------------------------------------------------------------------
33    GLenum GLPixelUtil::getGLOriginFormat(PixelFormat mFormat)
34    {
35        switch(mFormat)
36        {
37                        case PF_A8:
38                                return GL_ALPHA;
39            case PF_L8:
40                return GL_LUMINANCE;
41            case PF_L16:
42                return GL_LUMINANCE;
43                        case PF_BYTE_LA:
44                                return GL_LUMINANCE_ALPHA;
45                        case PF_R3G3B2:
46                                return GL_RGB;
47                        case PF_A1R5G5B5:
48                                return GL_BGRA;
49                        case PF_R5G6B5:
50                                return GL_RGB;
51                        case PF_B5G6R5:
52                                return GL_BGR;
53                        case PF_A4R4G4B4:
54                                return GL_BGRA;
55#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
56            // Formats are in native endian, so R8G8B8 on little endian is
57            // BGR, on big endian it is RGB.
58            case PF_R8G8B8:
59                return GL_RGB;
60            case PF_B8G8R8:
61                return GL_BGR;
62#else
63            case PF_R8G8B8:
64                return GL_BGR;
65            case PF_B8G8R8:
66                return GL_RGB;
67#endif
68                        case PF_X8R8G8B8:
69                        case PF_A8R8G8B8:
70                                return GL_BGRA;
71                        case PF_X8B8G8R8:
72            case PF_A8B8G8R8:
73                return GL_RGBA;
74            case PF_B8G8R8A8:
75                return GL_BGRA;
76                        case PF_R8G8B8A8:
77                                return GL_RGBA;
78            case PF_A2R10G10B10:
79                return GL_BGRA;
80            case PF_A2B10G10R10:
81                return GL_RGBA;
82                        case PF_FLOAT16_R:
83                return GL_LUMINANCE;
84            case PF_FLOAT16_RGB:
85                return GL_RGB;
86            case PF_FLOAT16_RGBA:
87                return GL_RGBA;
88                        case PF_FLOAT32_R:
89                return GL_LUMINANCE;
90            case PF_FLOAT32_RGB:
91                return GL_RGB;
92            case PF_FLOAT32_RGBA:
93                return GL_RGBA;
94                        case PF_SHORT_RGBA:
95                                return GL_RGBA;
96            case PF_DXT1:
97                return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
98            case PF_DXT3:
99                 return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
100            case PF_DXT5:
101                 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
102            default:
103                return 0;
104        }
105    }
106        //-----------------------------------------------------------------------------
107    GLenum GLPixelUtil::getGLOriginDataType(PixelFormat mFormat)
108    {
109        switch(mFormat)
110        {
111                        case PF_A8:
112            case PF_L8:
113            case PF_R8G8B8:
114            case PF_B8G8R8:
115                        case PF_BYTE_LA:
116                return GL_UNSIGNED_BYTE;
117                        case PF_R3G3B2:
118                                return GL_UNSIGNED_BYTE_3_3_2;
119                        case PF_A1R5G5B5:
120                                return GL_UNSIGNED_SHORT_1_5_5_5_REV;
121                        case PF_R5G6B5:
122                        case PF_B5G6R5:
123                                return GL_UNSIGNED_SHORT_5_6_5;
124                        case PF_A4R4G4B4:
125                                return GL_UNSIGNED_SHORT_4_4_4_4_REV;
126            case PF_L16:
127                return GL_UNSIGNED_SHORT;
128#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
129                        case PF_X8B8G8R8:
130                        case PF_A8B8G8R8:
131                return GL_UNSIGNED_INT_8_8_8_8_REV;
132                        case PF_X8R8G8B8:
133            case PF_A8R8G8B8:
134                                return GL_UNSIGNED_INT_8_8_8_8_REV;
135            case PF_B8G8R8A8:
136                return GL_UNSIGNED_BYTE;
137                        case PF_R8G8B8A8:
138                                return GL_UNSIGNED_BYTE;
139#else
140                        case PF_X8B8G8R8:
141                        case PF_A8B8G8R8:
142                return GL_UNSIGNED_BYTE;
143                        case PF_X8R8G8B8:
144            case PF_A8R8G8B8:
145                                return GL_UNSIGNED_BYTE;
146            case PF_B8G8R8A8:
147                return GL_UNSIGNED_INT_8_8_8_8;
148                        case PF_R8G8B8A8:
149                                return GL_UNSIGNED_INT_8_8_8_8;
150#endif
151            case PF_A2R10G10B10:
152                return GL_UNSIGNED_INT_2_10_10_10_REV;
153            case PF_A2B10G10R10:
154                return GL_UNSIGNED_INT_2_10_10_10_REV;
155                        case PF_FLOAT16_R:
156            case PF_FLOAT16_RGB:
157            case PF_FLOAT16_RGBA:
158                return GL_HALF_FLOAT_ARB;
159                        case PF_FLOAT32_R:
160            case PF_FLOAT32_RGB:
161            case PF_FLOAT32_RGBA:
162                return GL_FLOAT;
163                        case PF_SHORT_RGBA:
164                                return GL_UNSIGNED_SHORT;
165            default:
166                return 0;
167        }
168    }
169   
170    GLenum GLPixelUtil::getGLInternalFormat(PixelFormat mFormat)
171    {
172        switch(mFormat) {
173            case PF_L8:
174                return GL_LUMINANCE8;
175            case PF_L16:
176                return GL_LUMINANCE16;
177            case PF_A8:
178                return GL_ALPHA8;
179            case PF_A4L4:
180                return GL_LUMINANCE4_ALPHA4;
181                        case PF_BYTE_LA:
182                                return GL_LUMINANCE8_ALPHA8;
183                        case PF_R3G3B2:
184                                return GL_R3_G3_B2;
185                        case PF_A1R5G5B5:
186                                return GL_RGB5_A1;
187            case PF_R5G6B5:
188                        case PF_B5G6R5:
189                return GL_RGB5;
190            case PF_A4R4G4B4:
191                return GL_RGBA4;
192            case PF_R8G8B8:
193            case PF_B8G8R8:
194                        case PF_X8B8G8R8:
195                        case PF_X8R8G8B8:
196                return GL_RGB8;
197            case PF_A8R8G8B8:
198            case PF_B8G8R8A8:
199                return GL_RGBA8;
200            case PF_A2R10G10B10:
201            case PF_A2B10G10R10:
202                return GL_RGB10_A2;
203                        case PF_FLOAT16_R:
204                                return GL_LUMINANCE16F_ARB;
205            case PF_FLOAT16_RGB:
206                return GL_RGB16F_ARB;
207            case PF_FLOAT16_RGBA:
208                return GL_RGBA16F_ARB;
209                        case PF_FLOAT32_R:
210                                return GL_LUMINANCE32F_ARB;
211            case PF_FLOAT32_RGB:
212                return GL_RGB32F_ARB;
213            case PF_FLOAT32_RGBA:
214                return GL_RGBA32F_ARB;
215                        case PF_SHORT_RGBA:
216                                return GL_RGBA16;
217            case PF_DXT1:
218                return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
219            case PF_DXT3:
220                return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
221            case PF_DXT5:
222                return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
223            default:
224                return GL_NONE;
225        }
226    }
227
228    GLenum GLPixelUtil::getClosestGLInternalFormat(PixelFormat mFormat)
229    {
230        GLenum format = getGLInternalFormat(mFormat);
231        if(format==GL_NONE)
232            return GL_RGBA8;
233        else
234            return format;
235    }
236       
237        //-----------------------------------------------------------------------------         
238        PixelFormat GLPixelUtil::getClosestOGREFormat(GLenum fmt)
239        {
240                switch(fmt)
241                {
242                case GL_LUMINANCE8:
243                        return PF_L8;
244                case GL_LUMINANCE16:
245                        return PF_L16;
246                case GL_ALPHA8:
247                        return PF_A8;
248                case GL_LUMINANCE4_ALPHA4:
249                        // Unsupported by GL as input format, use the byte packed format
250                        return PF_BYTE_LA;
251                case GL_LUMINANCE8_ALPHA8:
252                        return PF_BYTE_LA;
253                case GL_R3_G3_B2:
254                        return PF_R3G3B2;
255                case GL_RGB5_A1:
256                        return PF_A1R5G5B5;
257                case GL_RGB5:
258                        return PF_R5G6B5;
259                case GL_RGBA4:
260                        return PF_A4R4G4B4;
261                case GL_RGB8:
262                        return PF_X8R8G8B8;
263                case GL_RGBA8:
264                        return PF_A8R8G8B8;
265                case GL_RGB10_A2:
266                        return PF_A2R10G10B10;
267                case GL_RGBA16:
268                        return PF_SHORT_RGBA;
269                case GL_LUMINANCE_FLOAT16_ATI:
270                        return PF_FLOAT16_R;
271                case GL_LUMINANCE_FLOAT32_ATI:
272                        return PF_FLOAT32_R;
273                case GL_RGB_FLOAT16_ATI: // GL_RGB16F_ARB
274                        return PF_FLOAT16_RGB;
275                case GL_RGBA_FLOAT16_ATI:
276                        return PF_FLOAT16_RGBA;
277                case GL_RGB_FLOAT32_ATI:
278                        return PF_FLOAT32_RGB;
279                case GL_RGBA_FLOAT32_ATI:
280                        return PF_FLOAT32_RGBA;
281                case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
282                        return PF_DXT1;
283                case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
284                        return PF_DXT3;
285                case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
286                        return PF_DXT5;
287                default:
288                        return PF_A8R8G8B8;
289                };
290        }
291        //-----------------------------------------------------------------------------
292
293        size_t GLPixelUtil::getMaxMipmaps(size_t width, size_t height, size_t depth, PixelFormat format)
294        {
295                size_t count = 0;
296                do {
297                        if(width>1)             width = width/2;
298                        if(height>1)    height = height/2;
299                        if(depth>1)             depth = depth/2;
300                        /*
301                        NOT needed, compressed formats will have mipmaps up to 1x1
302                        if(PixelUtil::isValidExtent(width, height, depth, format))
303                                count ++;
304                        else
305                                break;
306                        */
307                               
308                        count ++;
309                } while(!(width == 1 && height == 1 && depth == 1));
310               
311                return count;
312        }
313    //-----------------------------------------------------------------------------   
314    size_t GLPixelUtil::optionalPO2(size_t value)
315    {
316        const RenderSystemCapabilities *caps = Root::getSingleton().getRenderSystem()->getCapabilities();
317        if(caps->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
318            return value;
319        else
320            return Bitwise::firstPO2From((uint32)value);
321    }   
322
323       
324};
Note: See TracBrowser for help on using the repository browser.