intel_tex_format.c revision 77a5bcaff43df8d54e0e0ef833726e4b41d7eb36
177a5bcaff43df8d54e0e0ef833726e4b41d7eb36Eric Anholt#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 */
14const struct gl_texture_format *
15intelChooseTextureFormat(GLcontext * ctx, GLint internalFormat,
16                         GLenum format, GLenum type)
17{
18   struct intel_context *intel = intel_context(ctx);
19   const GLboolean do32bpt = (intel->intelScreen->cpp == 4);
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   default:
144      fprintf(stderr, "unexpected texture format %s in %s\n",
145              _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__);
146      return NULL;
147   }
148
149   return NULL;                 /* never get here */
150}
151
152int intel_compressed_num_bytes(GLuint mesaFormat)
153{
154   int bytes = 0;
155   switch(mesaFormat) {
156
157   case MESA_FORMAT_RGB_FXT1:
158   case MESA_FORMAT_RGBA_FXT1:
159   case MESA_FORMAT_RGB_DXT1:
160   case MESA_FORMAT_RGBA_DXT1:
161     bytes = 2;
162     break;
163
164   case MESA_FORMAT_RGBA_DXT3:
165   case MESA_FORMAT_RGBA_DXT5:
166     bytes = 4;
167   default:
168     break;
169   }
170
171   return bytes;
172}
173