formats.h revision 5ab5f16919f6aaa19f5c92fd562e43dee18e30bc
1/*
2 * Mesa 3-D graphics library
3 * Version:  7.7
4 *
5 * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
6 * Copyright (c) 2008-2009  VMware, Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26/*
27 * Authors:
28 *   Brian Paul
29 */
30
31
32#ifndef FORMATS_H
33#define FORMATS_H
34
35
36#include "main/mtypes.h"
37
38
39
40/**
41 * Mesa texture/renderbuffer image formats.
42 */
43typedef enum
44{
45   MESA_FORMAT_NONE = 0,
46   /**
47    * \name Basic hardware formats
48    */
49   /*@{*/
50				/* msb <------ TEXEL BITS -----------> lsb */
51				/* ---- ---- ---- ---- ---- ---- ---- ---- */
52   MESA_FORMAT_RGBA8888,	/* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
53   MESA_FORMAT_RGBA8888_REV,	/* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
54   MESA_FORMAT_ARGB8888,	/* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
55   MESA_FORMAT_ARGB8888_REV,	/* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
56   MESA_FORMAT_RGB888,		/*           RRRR RRRR GGGG GGGG BBBB BBBB */
57   MESA_FORMAT_BGR888,		/*           BBBB BBBB GGGG GGGG RRRR RRRR */
58   MESA_FORMAT_RGB565,		/*                     RRRR RGGG GGGB BBBB */
59   MESA_FORMAT_RGB565_REV,	/*                     GGGB BBBB RRRR RGGG */
60   MESA_FORMAT_RGBA4444,        /*                     RRRR GGGG BBBB AAAA */
61   MESA_FORMAT_ARGB4444,	/*                     AAAA RRRR GGGG BBBB */
62   MESA_FORMAT_ARGB4444_REV,	/*                     GGGG BBBB AAAA RRRR */
63   MESA_FORMAT_RGBA5551,        /*                     RRRR RGGG GGBB BBBA */
64   MESA_FORMAT_ARGB1555,	/*                     ARRR RRGG GGGB BBBB */
65   MESA_FORMAT_ARGB1555_REV,	/*                     GGGB BBBB ARRR RRGG */
66   MESA_FORMAT_AL88,		/*                     AAAA AAAA LLLL LLLL */
67   MESA_FORMAT_AL88_REV,	/*                     LLLL LLLL AAAA AAAA */
68   MESA_FORMAT_RGB332,		/*                               RRRG GGBB */
69   MESA_FORMAT_A8,		/*                               AAAA AAAA */
70   MESA_FORMAT_L8,		/*                               LLLL LLLL */
71   MESA_FORMAT_I8,		/*                               IIII IIII */
72   MESA_FORMAT_CI8,		/*                               CCCC CCCC */
73   MESA_FORMAT_YCBCR,		/*                     YYYY YYYY UorV UorV */
74   MESA_FORMAT_YCBCR_REV,	/*                     UorV UorV YYYY YYYY */
75   MESA_FORMAT_Z24_S8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
76   MESA_FORMAT_S8_Z24,          /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
77   MESA_FORMAT_Z16,             /*                     ZZZZ ZZZZ ZZZZ ZZZZ */
78   MESA_FORMAT_Z32,             /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
79   MESA_FORMAT_S8,              /*                               SSSS SSSS */
80   /*@}*/
81
82#if FEATURE_EXT_texture_sRGB
83   /**
84    * \name 8-bit/channel sRGB formats
85    */
86   /*@{*/
87   MESA_FORMAT_SRGB8,
88   MESA_FORMAT_SRGBA8,
89   MESA_FORMAT_SARGB8,
90   MESA_FORMAT_SL8,
91   MESA_FORMAT_SLA8,
92#if FEATURE_texture_s3tc
93   MESA_FORMAT_SRGB_DXT1,
94   MESA_FORMAT_SRGBA_DXT1,
95   MESA_FORMAT_SRGBA_DXT3,
96   MESA_FORMAT_SRGBA_DXT5,
97#endif
98   /*@}*/
99#endif
100
101   /**
102    * \name Compressed texture formats.
103    */
104   /*@{*/
105#if FEATURE_texture_fxt1
106   MESA_FORMAT_RGB_FXT1,
107   MESA_FORMAT_RGBA_FXT1,
108#endif
109#if FEATURE_texture_s3tc
110   MESA_FORMAT_RGB_DXT1,
111   MESA_FORMAT_RGBA_DXT1,
112   MESA_FORMAT_RGBA_DXT3,
113   MESA_FORMAT_RGBA_DXT5,
114#endif
115   /*@}*/
116
117   /**
118    * \name Generic GLchan-based formats. (XXX obsolete!)
119    */
120   /*@{*/
121   MESA_FORMAT_RGBA,
122   MESA_FORMAT_RGB,
123   MESA_FORMAT_ALPHA,
124   MESA_FORMAT_LUMINANCE,
125   MESA_FORMAT_LUMINANCE_ALPHA,
126   MESA_FORMAT_INTENSITY,
127   /*@}*/
128
129   /**
130    * \name Floating point texture formats.
131    */
132   /*@{*/
133   MESA_FORMAT_RGBA_FLOAT32,
134   MESA_FORMAT_RGBA_FLOAT16,
135   MESA_FORMAT_RGB_FLOAT32,
136   MESA_FORMAT_RGB_FLOAT16,
137   MESA_FORMAT_ALPHA_FLOAT32,
138   MESA_FORMAT_ALPHA_FLOAT16,
139   MESA_FORMAT_LUMINANCE_FLOAT32,
140   MESA_FORMAT_LUMINANCE_FLOAT16,
141   MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
142   MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
143   MESA_FORMAT_INTENSITY_FLOAT32,
144   MESA_FORMAT_INTENSITY_FLOAT16,
145   /*@}*/
146
147   /**
148    * \name Signed fixed point texture formats.
149    */
150   /*@{*/
151   MESA_FORMAT_DUDV8,
152   MESA_FORMAT_SIGNED_RGBA8888,
153   MESA_FORMAT_SIGNED_RGBA8888_REV,
154   /*@}*/
155
156   MESA_FORMAT_COUNT,
157} gl_format;
158
159
160/**
161 * Information about texture formats.
162 */
163struct gl_format_info
164{
165   gl_format Name;
166
167   /**
168    * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
169    * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_COLOR_INDEX, GL_DEPTH_COMPONENT.
170    */
171   GLenum BaseFormat;
172
173   /**
174    * Logical data type: one of  GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
175    * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT.
176    */
177   GLenum DataType;
178
179   GLubyte RedBits;
180   GLubyte GreenBits;
181   GLubyte BlueBits;
182   GLubyte AlphaBits;
183   GLubyte LuminanceBits;
184   GLubyte IntensityBits;
185   GLubyte IndexBits;
186   GLubyte DepthBits;
187   GLubyte StencilBits;
188
189   /**
190    * To describe compressed formats.  If not compressed, Width=Height=1.
191    */
192   GLubyte BlockWidth, BlockHeight;
193   GLubyte BytesPerBlock;
194};
195
196
197
198extern GLuint
199_mesa_get_format_bytes(gl_format format);
200
201extern GLenum
202_mesa_get_format_base_format(gl_format format);
203
204extern GLboolean
205_mesa_is_format_compressed(gl_format format);
206
207extern void
208_mesa_format_to_type_and_comps2(gl_format format,
209                                GLenum *datatype, GLuint *comps);
210
211extern GLint
212_mesa_get_format_bits(gl_format format, GLenum pname);
213
214extern GLenum
215_mesa_get_format_datatype(gl_format format);
216
217
218extern void
219_mesa_test_formats(void);
220
221#endif /* FORMATS_H */
222