1 #include "intel_context.h"
6 /* It works out that this function is fine for all the supported
7 * hardware. However, there is still a need to map the formats onto
8 * hardware descriptors.
10 /* Note that the i915 can actually support many more formats than
11 * these if we take the step of simply swizzling the colors
12 * immediately after sampling...
14 const struct gl_texture_format *
15 intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
16 GLenum format, GLenum type)
18 struct intel_context *intel = intel_context(ctx);
19 const GLboolean do32bpt = (intel->ctx.Visual.rgbBits == 32);
21 switch (internalFormat) {
24 case GL_COMPRESSED_RGBA:
25 if (format == GL_BGRA) {
26 if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) {
27 return &_mesa_texformat_argb8888;
29 else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
30 return &_mesa_texformat_argb4444;
32 else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
33 return &_mesa_texformat_argb1555;
36 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
40 case GL_COMPRESSED_RGB:
41 if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
42 return &_mesa_texformat_rgb565;
44 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
50 return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
54 return &_mesa_texformat_argb4444;
57 return &_mesa_texformat_argb1555;
63 return &_mesa_texformat_argb8888;
68 return &_mesa_texformat_rgb565;
75 case GL_COMPRESSED_ALPHA:
76 return &_mesa_texformat_a8;
84 case GL_COMPRESSED_LUMINANCE:
85 return &_mesa_texformat_l8;
88 case GL_LUMINANCE_ALPHA:
89 case GL_LUMINANCE4_ALPHA4:
90 case GL_LUMINANCE6_ALPHA2:
91 case GL_LUMINANCE8_ALPHA8:
92 case GL_LUMINANCE12_ALPHA4:
93 case GL_LUMINANCE12_ALPHA12:
94 case GL_LUMINANCE16_ALPHA16:
95 case GL_COMPRESSED_LUMINANCE_ALPHA:
96 return &_mesa_texformat_al88;
103 case GL_COMPRESSED_INTENSITY:
104 return &_mesa_texformat_i8;
107 if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
108 return &_mesa_texformat_ycbcr;
110 return &_mesa_texformat_ycbcr_rev;
112 case GL_COMPRESSED_RGB_FXT1_3DFX:
113 return &_mesa_texformat_rgb_fxt1;
114 case GL_COMPRESSED_RGBA_FXT1_3DFX:
115 return &_mesa_texformat_rgba_fxt1;
119 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
120 return &_mesa_texformat_rgb_dxt1;
122 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
123 return &_mesa_texformat_rgba_dxt1;
127 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
128 return &_mesa_texformat_rgba_dxt3;
130 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
131 return &_mesa_texformat_rgba_dxt5;
133 case GL_DEPTH_COMPONENT:
134 case GL_DEPTH_COMPONENT16:
135 case GL_DEPTH_COMPONENT24:
136 case GL_DEPTH_COMPONENT32:
137 return &_mesa_texformat_z16;
139 case GL_DEPTH_STENCIL_EXT:
140 case GL_DEPTH24_STENCIL8_EXT:
141 return &_mesa_texformat_z24_s8;
146 case GL_SRGB_ALPHA_EXT:
147 case GL_SRGB8_ALPHA8_EXT:
148 case GL_SLUMINANCE_EXT:
149 case GL_SLUMINANCE8_EXT:
150 case GL_SLUMINANCE_ALPHA_EXT:
151 case GL_SLUMINANCE8_ALPHA8_EXT:
152 case GL_COMPRESSED_SRGB_EXT:
153 case GL_COMPRESSED_SRGB_ALPHA_EXT:
154 case GL_COMPRESSED_SLUMINANCE_EXT:
155 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
156 return &_mesa_texformat_srgba8;
157 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
158 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
159 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
160 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
161 return &_mesa_texformat_srgb_dxt1;
165 fprintf(stderr, "unexpected texture format %s in %s\n",
166 _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
170 return NULL; /* never get here */
173 int intel_compressed_num_bytes(GLuint mesaFormat)
178 case MESA_FORMAT_RGB_FXT1:
179 case MESA_FORMAT_RGBA_FXT1:
180 case MESA_FORMAT_RGB_DXT1:
181 case MESA_FORMAT_RGBA_DXT1:
185 case MESA_FORMAT_RGBA_DXT3:
186 case MESA_FORMAT_RGBA_DXT5: