OSDN Git Service

i965: new integrated graphics chipset support
[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 "texformat.h"
4 #include "enums.h"
5
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.
9  */
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...
13  */
14 const struct gl_texture_format *
15 intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
16                          GLenum format, GLenum type)
17 {
18    struct intel_context *intel = intel_context(ctx);
19    const GLboolean do32bpt = (intel->ctx.Visual.rgbBits == 32);
20
21    switch (internalFormat) {
22    case 4:
23    case GL_RGBA:
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;
28          }
29          else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
30             return &_mesa_texformat_argb4444;
31          }
32          else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
33             return &_mesa_texformat_argb1555;
34          }
35       }
36       return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
37
38    case 3:
39    case GL_RGB:
40    case GL_COMPRESSED_RGB:
41       if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) {
42          return &_mesa_texformat_rgb565;
43       }
44       return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565;
45
46    case GL_RGBA8:
47    case GL_RGB10_A2:
48    case GL_RGBA12:
49    case GL_RGBA16:
50       return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
51
52    case GL_RGBA4:
53    case GL_RGBA2:
54       return &_mesa_texformat_argb4444;
55
56    case GL_RGB5_A1:
57       return &_mesa_texformat_argb1555;
58
59    case GL_RGB8:
60    case GL_RGB10:
61    case GL_RGB12:
62    case GL_RGB16:
63       return &_mesa_texformat_argb8888;
64
65    case GL_RGB5:
66    case GL_RGB4:
67    case GL_R3_G3_B2:
68       return &_mesa_texformat_rgb565;
69
70    case GL_ALPHA:
71    case GL_ALPHA4:
72    case GL_ALPHA8:
73    case GL_ALPHA12:
74    case GL_ALPHA16:
75    case GL_COMPRESSED_ALPHA:
76       return &_mesa_texformat_a8;
77
78    case 1:
79    case GL_LUMINANCE:
80    case GL_LUMINANCE4:
81    case GL_LUMINANCE8:
82    case GL_LUMINANCE12:
83    case GL_LUMINANCE16:
84    case GL_COMPRESSED_LUMINANCE:
85       return &_mesa_texformat_l8;
86
87    case 2:
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;
97
98    case GL_INTENSITY:
99    case GL_INTENSITY4:
100    case GL_INTENSITY8:
101    case GL_INTENSITY12:
102    case GL_INTENSITY16:
103    case GL_COMPRESSED_INTENSITY:
104       return &_mesa_texformat_i8;
105
106    case GL_YCBCR_MESA:
107       if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE)
108          return &_mesa_texformat_ycbcr;
109       else
110          return &_mesa_texformat_ycbcr_rev;
111
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;
116
117    case GL_RGB_S3TC:
118    case GL_RGB4_S3TC:
119    case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
120       return &_mesa_texformat_rgb_dxt1;
121
122    case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
123       return &_mesa_texformat_rgba_dxt1;
124
125    case GL_RGBA_S3TC:
126    case GL_RGBA4_S3TC:
127    case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
128       return &_mesa_texformat_rgba_dxt3;
129
130    case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
131       return &_mesa_texformat_rgba_dxt5;
132
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;
138
139    case GL_DEPTH_STENCIL_EXT:
140    case GL_DEPTH24_STENCIL8_EXT:
141       return &_mesa_texformat_z24_s8;
142
143 #ifndef I915
144    case GL_SRGB_EXT:
145    case GL_SRGB8_EXT:
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;
162 #endif
163
164    default:
165       fprintf(stderr, "unexpected texture format %s in %s\n",
166               _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
167       return NULL;
168    }
169
170    return NULL;                 /* never get here */
171 }
172
173 int intel_compressed_num_bytes(GLuint mesaFormat)
174 {
175    int bytes = 0;
176    switch(mesaFormat) {
177      
178    case MESA_FORMAT_RGB_FXT1:
179    case MESA_FORMAT_RGBA_FXT1:
180    case MESA_FORMAT_RGB_DXT1:
181    case MESA_FORMAT_RGBA_DXT1:
182      bytes = 2;
183      break;
184      
185    case MESA_FORMAT_RGBA_DXT3:
186    case MESA_FORMAT_RGBA_DXT5:
187      bytes = 4;
188    default:
189      break;
190    }
191    
192    return bytes;
193 }