formats.h revision 1165280cbd37dee1e499358633478ab869de21df
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 <GL/gl.h>
37
38/* OpenGL doesn't have GL_UNSIGNED_BYTE_4_4, so we must define our own type
39 * for GL_LUMINANCE4_ALPHA4. */
40#define MESA_UNSIGNED_BYTE_4_4 (GL_UNSIGNED_BYTE<<1)
41
42
43/**
44 * Mesa texture/renderbuffer image formats.
45 */
46typedef enum
47{
48   MESA_FORMAT_NONE = 0,
49
50   /**
51    * \name Basic hardware formats
52    */
53   /*@{*/
54				/* msb <------ TEXEL BITS -----------> lsb */
55				/* ---- ---- ---- ---- ---- ---- ---- ---- */
56   MESA_FORMAT_RGBA8888,	/* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
57   MESA_FORMAT_RGBA8888_REV,	/* AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
58   MESA_FORMAT_ARGB8888,	/* AAAA AAAA RRRR RRRR GGGG GGGG BBBB BBBB */
59   MESA_FORMAT_ARGB8888_REV,	/* BBBB BBBB GGGG GGGG RRRR RRRR AAAA AAAA */
60   MESA_FORMAT_XRGB8888,	/* xxxx xxxx RRRR RRRR GGGG GGGG BBBB BBBB */
61   MESA_FORMAT_XRGB8888_REV,	/* BBBB BBBB GGGG GGGG RRRR RRRR xxxx xxxx */
62   MESA_FORMAT_RGB888,		/*           RRRR RRRR GGGG GGGG BBBB BBBB */
63   MESA_FORMAT_BGR888,		/*           BBBB BBBB GGGG GGGG RRRR RRRR */
64   MESA_FORMAT_RGB565,		/*                     RRRR RGGG GGGB BBBB */
65   MESA_FORMAT_RGB565_REV,	/*                     GGGB BBBB RRRR RGGG */
66   MESA_FORMAT_ARGB4444,	/*                     AAAA RRRR GGGG BBBB */
67   MESA_FORMAT_ARGB4444_REV,	/*                     GGGG BBBB AAAA RRRR */
68   MESA_FORMAT_RGBA5551,        /*                     RRRR RGGG GGBB BBBA */
69   MESA_FORMAT_ARGB1555,	/*                     ARRR RRGG GGGB BBBB */
70   MESA_FORMAT_ARGB1555_REV,	/*                     GGGB BBBB ARRR RRGG */
71   MESA_FORMAT_AL44,		/*                               AAAA LLLL */
72   MESA_FORMAT_AL88,		/*                     AAAA AAAA LLLL LLLL */
73   MESA_FORMAT_AL88_REV,	/*                     LLLL LLLL AAAA AAAA */
74   MESA_FORMAT_AL1616,          /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
75   MESA_FORMAT_AL1616_REV,      /* LLLL LLLL LLLL LLLL AAAA AAAA AAAA AAAA */
76   MESA_FORMAT_RGB332,		/*                               RRRG GGBB */
77   MESA_FORMAT_A8,		/*                               AAAA AAAA */
78   MESA_FORMAT_A16,             /*                     AAAA AAAA AAAA AAAA */
79   MESA_FORMAT_L8,		/*                               LLLL LLLL */
80   MESA_FORMAT_L16,             /*                     LLLL LLLL LLLL LLLL */
81   MESA_FORMAT_I8,		/*                               IIII IIII */
82   MESA_FORMAT_I16,             /*                     IIII IIII IIII IIII */
83   MESA_FORMAT_CI8,		/*                               CCCC CCCC */
84   MESA_FORMAT_YCBCR,		/*                     YYYY YYYY UorV UorV */
85   MESA_FORMAT_YCBCR_REV,	/*                     UorV UorV YYYY YYYY */
86   MESA_FORMAT_R8,		/*                               RRRR RRRR */
87   MESA_FORMAT_RG88,		/*                     RRRR RRRR GGGG GGGG */
88   MESA_FORMAT_RG88_REV,	/*                     GGGG GGGG RRRR RRRR */
89   MESA_FORMAT_R16,		/*                     RRRR RRRR RRRR RRRR */
90   MESA_FORMAT_RG1616,		/* RRRR RRRR RRRR RRRR GGGG GGGG GGGG GGGG */
91   MESA_FORMAT_RG1616_REV,	/* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
92   MESA_FORMAT_ARGB2101010,     /* AARR RRRR RRRR GGGG GGGG GGBB BBBB BBBB */
93   MESA_FORMAT_Z24_S8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ SSSS SSSS */
94   MESA_FORMAT_S8_Z24,          /* SSSS SSSS ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
95   MESA_FORMAT_Z16,             /*                     ZZZZ ZZZZ ZZZZ ZZZZ */
96   MESA_FORMAT_X8_Z24,          /* xxxx xxxx ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
97   MESA_FORMAT_Z24_X8,          /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ xxxx xxxx */
98   MESA_FORMAT_Z32,             /* ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ ZZZZ */
99   MESA_FORMAT_S8,              /*                               SSSS SSSS */
100   /*@}*/
101
102   /**
103    * \name 8-bit/channel sRGB formats
104    */
105   /*@{*/
106   MESA_FORMAT_SRGB8,
107   MESA_FORMAT_SRGBA8,
108   MESA_FORMAT_SARGB8,
109   MESA_FORMAT_SL8,
110   MESA_FORMAT_SLA8,
111   MESA_FORMAT_SRGB_DXT1,
112   MESA_FORMAT_SRGBA_DXT1,
113   MESA_FORMAT_SRGBA_DXT3,
114   MESA_FORMAT_SRGBA_DXT5,
115   /*@}*/
116
117   /**
118    * \name Compressed texture formats.
119    */
120   /*@{*/
121   MESA_FORMAT_RGB_FXT1,
122   MESA_FORMAT_RGBA_FXT1,
123   MESA_FORMAT_RGB_DXT1,
124   MESA_FORMAT_RGBA_DXT1,
125   MESA_FORMAT_RGBA_DXT3,
126   MESA_FORMAT_RGBA_DXT5,
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   MESA_FORMAT_R_FLOAT32,
146   MESA_FORMAT_R_FLOAT16,
147   MESA_FORMAT_RG_FLOAT32,
148   MESA_FORMAT_RG_FLOAT16,
149   /*@}*/
150
151   /**
152    * \name Non-normalized signed integer formats.
153    * XXX Note: these are just stand-ins for some better hardware
154    * formats TBD such as BGRA or ARGB.
155    */
156   MESA_FORMAT_RGBA_INT8,
157   MESA_FORMAT_RGBA_INT16,
158   MESA_FORMAT_RGBA_INT32,
159
160   /**
161    * \name Non-normalized unsigned integer formats.
162    */
163   MESA_FORMAT_RGBA_UINT8,
164   MESA_FORMAT_RGBA_UINT16,
165   MESA_FORMAT_RGBA_UINT32,
166
167                                  /* msb <------ TEXEL BITS -----------> lsb */
168                                  /* ---- ---- ---- ---- ---- ---- ---- ---- */
169   /**
170    * \name Signed fixed point texture formats.
171    */
172   /*@{*/
173   MESA_FORMAT_DUDV8,             /*                     DUDU DUDU DVDV DVDV */
174   MESA_FORMAT_SIGNED_R8,         /*                               RRRR RRRR */
175   MESA_FORMAT_SIGNED_RG88_REV,   /*                     GGGG GGGG RRRR RRRR */
176   MESA_FORMAT_SIGNED_RGBX8888,   /* RRRR RRRR GGGG GGGG BBBB BBBB xxxx xxxx */
177   MESA_FORMAT_SIGNED_RGBA8888,   /* RRRR RRRR GGGG GGGG BBBB BBBB AAAA AAAA */
178   MESA_FORMAT_SIGNED_RGBA8888_REV,/*AAAA AAAA BBBB BBBB GGGG GGGG RRRR RRRR */
179   MESA_FORMAT_SIGNED_R16,        /*                     RRRR RRRR RRRR RRRR */
180   MESA_FORMAT_SIGNED_GR1616,     /* GGGG GGGG GGGG GGGG RRRR RRRR RRRR RRRR */
181   MESA_FORMAT_SIGNED_RGB_16,     /* ushort[0]=R, ushort[1]=G, ushort[2]=B */
182   MESA_FORMAT_SIGNED_RGBA_16,    /* ... */
183   MESA_FORMAT_RGBA_16,           /* ... */
184   /*@}*/
185
186   /*@{*/
187   MESA_FORMAT_RED_RGTC1,
188   MESA_FORMAT_SIGNED_RED_RGTC1,
189   MESA_FORMAT_RG_RGTC2,
190   MESA_FORMAT_SIGNED_RG_RGTC2,
191   /*@}*/
192
193   /*@{*/
194   MESA_FORMAT_L_LATC1,
195   MESA_FORMAT_SIGNED_L_LATC1,
196   MESA_FORMAT_LA_LATC2,
197   MESA_FORMAT_SIGNED_LA_LATC2,
198   /*@}*/
199
200   MESA_FORMAT_SIGNED_A8,         /*                               AAAA AAAA */
201   MESA_FORMAT_SIGNED_L8,         /*                               LLLL LLLL */
202   MESA_FORMAT_SIGNED_AL88,       /*                     AAAA AAAA LLLL LLLL */
203   MESA_FORMAT_SIGNED_I8,         /*                               IIII IIII */
204   MESA_FORMAT_SIGNED_A16,        /*                     AAAA AAAA AAAA AAAA */
205   MESA_FORMAT_SIGNED_L16,        /*                     LLLL LLLL LLLL LLLL */
206   MESA_FORMAT_SIGNED_AL1616,     /* AAAA AAAA AAAA AAAA LLLL LLLL LLLL LLLL */
207   MESA_FORMAT_SIGNED_I16,        /*                     IIII IIII IIII IIII */
208
209   MESA_FORMAT_RGB9_E5_FLOAT,
210   MESA_FORMAT_R11_G11_B10_FLOAT,
211
212   MESA_FORMAT_Z32_FLOAT,
213   MESA_FORMAT_Z32_FLOAT_X24S8,
214
215   MESA_FORMAT_COUNT
216} gl_format;
217
218
219extern const char *
220_mesa_get_format_name(gl_format format);
221
222extern GLint
223_mesa_get_format_bytes(gl_format format);
224
225extern GLint
226_mesa_get_format_bits(gl_format format, GLenum pname);
227
228extern GLenum
229_mesa_get_format_datatype(gl_format format);
230
231extern GLenum
232_mesa_get_format_base_format(gl_format format);
233
234extern void
235_mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh);
236
237extern GLboolean
238_mesa_is_format_compressed(gl_format format);
239
240extern GLboolean
241_mesa_is_format_packed_depth_stencil(gl_format format);
242
243extern GLboolean
244_mesa_is_format_integer_color(gl_format format);
245
246extern GLenum
247_mesa_get_format_color_encoding(gl_format format);
248
249extern GLuint
250_mesa_format_image_size(gl_format format, GLsizei width,
251                        GLsizei height, GLsizei depth);
252
253extern uint64_t
254_mesa_format_image_size64(gl_format format, GLsizei width,
255                          GLsizei height, GLsizei depth);
256
257extern GLint
258_mesa_format_row_stride(gl_format format, GLsizei width);
259
260extern void
261_mesa_format_to_type_and_comps(gl_format format,
262                               GLenum *datatype, GLuint *comps);
263
264extern void
265_mesa_test_formats(void);
266
267extern gl_format
268_mesa_get_srgb_format_linear(gl_format format);
269
270#endif /* FORMATS_H */
271