2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
36 #include "simple_list.h"
41 #include "texformat.h"
44 #include "intel_context.h"
45 #include "intel_ioctl.h"
46 #include "intel_regions.h"
47 #include "brw_context.h"
48 #include "brw_defines.h"
53 static const struct gl_texture_format
*
54 brwChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
55 GLenum srcFormat
, GLenum srcType
)
57 switch ( internalFormat
) {
60 case GL_COMPRESSED_RGBA
:
61 if (srcFormat
== GL_BGRA
&& srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
)
62 return &_mesa_texformat_argb4444
;
63 else if (srcFormat
== GL_BGRA
&& srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
)
64 return &_mesa_texformat_argb1555
;
65 else if ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
66 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
) ||
67 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
))
68 return &_mesa_texformat_rgba8888_rev
;
70 return &_mesa_texformat_argb8888
;
76 return &_mesa_texformat_argb8888
;
82 /* Broadwater doesn't support RGB888 textures, so these must be
85 return &_mesa_texformat_argb8888
;
88 case GL_COMPRESSED_RGB
:
90 if (srcFormat
== GL_RGB
&&
91 srcType
== GL_UNSIGNED_SHORT_5_6_5
)
92 return &_mesa_texformat_rgb565
;
94 return &_mesa_texformat_argb8888
;
99 return &_mesa_texformat_argb1555
;
105 return &_mesa_texformat_argb4444
;
112 case GL_COMPRESSED_ALPHA
:
113 return &_mesa_texformat_a8
;
121 case GL_COMPRESSED_LUMINANCE
:
122 return &_mesa_texformat_l8
;
125 case GL_LUMINANCE_ALPHA
:
126 case GL_LUMINANCE4_ALPHA4
:
127 case GL_LUMINANCE6_ALPHA2
:
128 case GL_LUMINANCE8_ALPHA8
:
129 case GL_LUMINANCE12_ALPHA4
:
130 case GL_LUMINANCE12_ALPHA12
:
131 case GL_LUMINANCE16_ALPHA16
:
132 case GL_COMPRESSED_LUMINANCE_ALPHA
:
133 return &_mesa_texformat_al88
;
140 case GL_COMPRESSED_INTENSITY
:
141 return &_mesa_texformat_i8
;
144 if (srcType
== GL_UNSIGNED_SHORT_8_8_MESA
||
145 srcType
== GL_UNSIGNED_BYTE
)
146 return &_mesa_texformat_ycbcr
;
148 return &_mesa_texformat_ycbcr_rev
;
150 case GL_COMPRESSED_RGB_FXT1_3DFX
:
151 return &_mesa_texformat_rgb_fxt1
;
152 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
153 return &_mesa_texformat_rgba_fxt1
;
159 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
160 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
161 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
162 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
163 return &_mesa_texformat_rgb_dxt1
; /* there is no rgba support? */
165 case GL_DEPTH_COMPONENT
:
166 case GL_DEPTH_COMPONENT16
:
167 case GL_DEPTH_COMPONENT24
:
168 case GL_DEPTH_COMPONENT32
:
169 return &_mesa_texformat_z16
;
173 case GL_SRGB_ALPHA_EXT
:
174 case GL_SRGB8_ALPHA8_EXT
:
175 case GL_SLUMINANCE_EXT
:
176 case GL_SLUMINANCE8_EXT
:
177 case GL_SLUMINANCE_ALPHA_EXT
:
178 case GL_SLUMINANCE8_ALPHA8_EXT
:
179 case GL_COMPRESSED_SRGB_EXT
:
180 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
181 case GL_COMPRESSED_SLUMINANCE_EXT
:
182 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
183 return &_mesa_texformat_srgb_dxt1
;
184 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
185 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
186 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
187 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
188 return &_mesa_texformat_srgb_dxt1
;
191 fprintf(stderr
, "unexpected texture format %s in %s\n",
192 _mesa_lookup_enum_by_nr(internalFormat
),
197 return NULL
; /* never get here */
201 void brwInitTextureFuncs( struct dd_function_table
*functions
)
203 functions
->ChooseTextureFormat
= brwChooseTextureFormat
;
206 void brw_FrameBufferTexInit( struct brw_context
*brw
)
208 struct intel_context
*intel
= &brw
->intel
;
209 GLcontext
*ctx
= &intel
->ctx
;
210 struct intel_region
*region
= intel
->front_region
;
211 struct gl_texture_object
*obj
;
212 struct gl_texture_image
*img
;
214 intel
->frame_buffer_texobj
= obj
=
215 ctx
->Driver
.NewTextureObject( ctx
, (GLuint
) -1, GL_TEXTURE_2D
);
217 obj
->MinFilter
= GL_NEAREST
;
218 obj
->MagFilter
= GL_NEAREST
;
220 img
= ctx
->Driver
.NewTextureImage( ctx
);
222 _mesa_init_teximage_fields( ctx
, GL_TEXTURE_2D
, img
,
223 region
->pitch
, region
->height
, 1, 0,
224 region
->cpp
== 4 ? GL_RGBA
: GL_RGB
);
226 _mesa_set_tex_image( obj
, GL_TEXTURE_2D
, 0, img
);
229 void brw_FrameBufferTexDestroy( struct brw_context
*brw
)
231 brw
->intel
.ctx
.Driver
.DeleteTexture( &brw
->intel
.ctx
,
232 brw
->intel
.frame_buffer_texobj
);