OSDN Git Service

Remove r500 stuff
[android-x86/external-mesa.git] / src / mesa / drivers / dri / intel / intel_tex_format.c
1 #include "intel_context.h"
2 #include "intel_tex.h"
3 #include "main/texformat.h"
4 #include "main/enums.h"
5
6
7 /**
8  * Choose hardware texture format given the user's glTexImage parameters.
9  *
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.
13  *
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...
17  */
18 const struct gl_texture_format *
19 intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
20                          GLenum format, GLenum type)
21 {
22    struct intel_context *intel = intel_context(ctx);
23    const GLboolean do32bpt = (intel->ctx.Visual.rgbBits >= 24);
24
25 #if 0
26    printf("%s intFmt=0x%x format=0x%x type=0x%x\n",
27           __FUNCTION__, internalFormat, format, type);
28 #endif
29
30    switch (internalFormat) {
31    case 4:
32    case GL_RGBA:
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;
37          }
38          else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
39             return &_mesa_texformat_argb4444;
40          }
41          else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
42             return &_mesa_texformat_argb1555;
43          }
44       }
45       return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
46
47    case 3:
48    case GL_RGB:
49    case GL_COMPRESSED_RGB:
50       if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
51          return &_mesa_texformat_rgb565;
52       }
53       return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
54
55    case GL_RGBA8:
56    case GL_RGB10_A2:
57    case GL_RGBA12:
58    case GL_RGBA16:
59       return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
60
61    case GL_RGBA4:
62    case GL_RGBA2:
63       return &_mesa_texformat_argb4444;
64
65    case GL_RGB5_A1:
66       return &_mesa_texformat_argb1555;
67
68    case GL_RGB8:
69    case GL_RGB10:
70    case GL_RGB12:
71    case GL_RGB16:
72       return &_mesa_texformat_argb8888;
73
74    case GL_RGB5:
75    case GL_RGB4:
76    case GL_R3_G3_B2:
77       return &_mesa_texformat_rgb565;
78
79    case GL_ALPHA:
80    case GL_ALPHA4:
81    case GL_ALPHA8:
82    case GL_ALPHA12:
83    case GL_ALPHA16:
84    case GL_COMPRESSED_ALPHA:
85       return &_mesa_texformat_a8;
86
87    case 1:
88    case GL_LUMINANCE:
89    case GL_LUMINANCE4:
90    case GL_LUMINANCE8:
91    case GL_LUMINANCE12:
92    case GL_LUMINANCE16:
93    case GL_COMPRESSED_LUMINANCE:
94       return &_mesa_texformat_l8;
95
96    case 2:
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;
106
107    case GL_INTENSITY:
108    case GL_INTENSITY4:
109    case GL_INTENSITY8:
110    case GL_INTENSITY12:
111    case GL_INTENSITY16:
112    case GL_COMPRESSED_INTENSITY:
113       return &_mesa_texformat_i8;
114
115    case GL_YCBCR_MESA:
116       if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
117          return &_mesa_texformat_ycbcr;
118       else
119          return &_mesa_texformat_ycbcr_rev;
120
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;
125
126    case GL_RGB_S3TC:
127    case GL_RGB4_S3TC:
128    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
129       return &_mesa_texformat_rgb_dxt1;
130
131    case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
132       return &_mesa_texformat_rgba_dxt1;
133
134    case GL_RGBA_S3TC:
135    case GL_RGBA4_S3TC:
136    case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
137       return &_mesa_texformat_rgba_dxt3;
138
139    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
140       return &_mesa_texformat_rgba_dxt5;
141
142    case GL_DEPTH_COMPONENT:
143    case GL_DEPTH_COMPONENT16:
144    case GL_DEPTH_COMPONENT24:
145    case GL_DEPTH_COMPONENT32:
146 #if 0
147       return &_mesa_texformat_z16;
148 #else
149       /* fall-through.
150        * 16bpp depth texture can't be paired with a stencil buffer so
151        * always used combined depth/stencil format.
152        */
153 #endif
154    case GL_DEPTH_STENCIL_EXT:
155    case GL_DEPTH24_STENCIL8_EXT:
156       return &_mesa_texformat_s8_z24;
157
158 #ifndef I915
159    case GL_SRGB_EXT:
160    case GL_SRGB8_EXT:
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;
177
178    case GL_DUDV_ATI:
179    case GL_DU8DV8_ATI:
180       return &_mesa_texformat_dudv8;
181 #endif
182
183    default:
184       fprintf(stderr, "unexpected texture format %s in %s\n",
185               _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
186       return NULL;
187    }
188
189    return NULL;                 /* never get here */
190 }
191
192 int intel_compressed_num_bytes(GLuint mesaFormat)
193 {
194    int bytes = 0;
195    switch(mesaFormat) {
196      
197    case MESA_FORMAT_RGB_FXT1:
198    case MESA_FORMAT_RGBA_FXT1:
199    case MESA_FORMAT_RGB_DXT1:
200    case MESA_FORMAT_RGBA_DXT1:
201      bytes = 2;
202      break;
203      
204    case MESA_FORMAT_RGBA_DXT3:
205    case MESA_FORMAT_RGBA_DXT5:
206      bytes = 4;
207    default:
208      break;
209    }
210    
211    return bytes;
212 }