1 #include "intel_context.h"
3 #include "main/texformat.h"
4 #include "main/enums.h"
8 * Choose hardware texture format given the user's glTexImage parameters.
10 * It works out that this function is fine for all the supported
11 * hardware. However, there is still a need to map the formats onto
12 * hardware descriptors.
14 * Note that the i915 can actually support many more formats than
15 * these if we take the step of simply swizzling the colors
16 * immediately after sampling...
18 const struct gl_texture_format *
19 intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
20 GLenum format, GLenum type)
22 struct intel_context *intel = intel_context(ctx);
23 const GLboolean do32bpt = (intel->ctx.Visual.rgbBits >= 24);
26 printf("%s intFmt=0x%x format=0x%x type=0x%x\n",
27 __FUNCTION__, internalFormat, format, type);
30 switch (internalFormat) {
33 case GL_COMPRESSED_RGBA:
34 if (format == GL_BGRA) {
35 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
36 return &_mesa_texformat_argb8888;
38 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
39 return &_mesa_texformat_argb4444;
41 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
42 return &_mesa_texformat_argb1555;
45 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
49 case GL_COMPRESSED_RGB:
50 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
51 return &_mesa_texformat_rgb565;
53 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
59 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
63 return &_mesa_texformat_argb4444;
66 return &_mesa_texformat_argb1555;
72 return &_mesa_texformat_argb8888;
77 return &_mesa_texformat_rgb565;
84 case GL_COMPRESSED_ALPHA:
85 return &_mesa_texformat_a8;
93 case GL_COMPRESSED_LUMINANCE:
94 return &_mesa_texformat_l8;
97 case GL_LUMINANCE_ALPHA:
98 case GL_LUMINANCE4_ALPHA4:
99 case GL_LUMINANCE6_ALPHA2:
100 case GL_LUMINANCE8_ALPHA8:
101 case GL_LUMINANCE12_ALPHA4:
102 case GL_LUMINANCE12_ALPHA12:
103 case GL_LUMINANCE16_ALPHA16:
104 case GL_COMPRESSED_LUMINANCE_ALPHA:
105 return &_mesa_texformat_al88;
112 case GL_COMPRESSED_INTENSITY:
113 return &_mesa_texformat_i8;
116 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
117 return &_mesa_texformat_ycbcr;
119 return &_mesa_texformat_ycbcr_rev;
121 case GL_COMPRESSED_RGB_FXT1_3DFX:
122 return &_mesa_texformat_rgb_fxt1;
123 case GL_COMPRESSED_RGBA_FXT1_3DFX:
124 return &_mesa_texformat_rgba_fxt1;
128 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
129 return &_mesa_texformat_rgb_dxt1;
131 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
132 return &_mesa_texformat_rgba_dxt1;
136 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
137 return &_mesa_texformat_rgba_dxt3;
139 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
140 return &_mesa_texformat_rgba_dxt5;
142 case GL_DEPTH_COMPONENT:
143 case GL_DEPTH_COMPONENT16:
144 case GL_DEPTH_COMPONENT24:
145 case GL_DEPTH_COMPONENT32:
147 return &_mesa_texformat_z16;
150 * 16bpp depth texture can't be paired with a stencil buffer so
151 * always used combined depth/stencil format.
154 case GL_DEPTH_STENCIL_EXT:
155 case GL_DEPTH24_STENCIL8_EXT:
156 return &_mesa_texformat_s8_z24;
161 case GL_SRGB_ALPHA_EXT:
162 case GL_SRGB8_ALPHA8_EXT:
163 case GL_SLUMINANCE_EXT:
164 case GL_SLUMINANCE8_EXT:
165 case GL_SLUMINANCE_ALPHA_EXT:
166 case GL_SLUMINANCE8_ALPHA8_EXT:
167 case GL_COMPRESSED_SRGB_EXT:
168 case GL_COMPRESSED_SRGB_ALPHA_EXT:
169 case GL_COMPRESSED_SLUMINANCE_EXT:
170 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
171 return &_mesa_texformat_srgba8;
172 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
173 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
174 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
175 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
176 return &_mesa_texformat_srgb_dxt1;
180 return &_mesa_texformat_dudv8;
184 fprintf(stderr, "unexpected texture format %s in %s\n",
185 _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
189 return NULL; /* never get here */
192 int intel_compressed_num_bytes(GLuint mesaFormat)
197 case MESA_FORMAT_RGB_FXT1:
198 case MESA_FORMAT_RGBA_FXT1:
199 case MESA_FORMAT_RGB_DXT1:
200 case MESA_FORMAT_RGBA_DXT1:
204 case MESA_FORMAT_RGBA_DXT3:
205 case MESA_FORMAT_RGBA_DXT5: