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 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
152 return &_mesa_texformat_rgb_fxt1
;
158 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
159 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
160 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
161 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
162 return &_mesa_texformat_rgb_dxt1
; /* there is no rgba support? */
164 case GL_DEPTH_COMPONENT
:
165 case GL_DEPTH_COMPONENT16
:
166 case GL_DEPTH_COMPONENT24
:
167 case GL_DEPTH_COMPONENT32
:
168 return &_mesa_texformat_z16
;
171 fprintf(stderr
, "unexpected texture format %s in %s\n",
172 _mesa_lookup_enum_by_nr(internalFormat
),
177 return NULL
; /* never get here */
181 void brwInitTextureFuncs( struct dd_function_table
*functions
)
183 functions
->ChooseTextureFormat
= brwChooseTextureFormat
;
186 void brw_FrameBufferTexInit( struct brw_context
*brw
)
188 struct intel_context
*intel
= &brw
->intel
;
189 GLcontext
*ctx
= &intel
->ctx
;
190 struct intel_region
*region
= intel
->front_region
;
191 struct gl_texture_object
*obj
;
192 struct gl_texture_image
*img
;
194 intel
->frame_buffer_texobj
= obj
=
195 ctx
->Driver
.NewTextureObject( ctx
, (GLuint
) -1, GL_TEXTURE_2D
);
197 obj
->MinFilter
= GL_NEAREST
;
198 obj
->MagFilter
= GL_NEAREST
;
200 img
= ctx
->Driver
.NewTextureImage( ctx
);
202 _mesa_init_teximage_fields( ctx
, GL_TEXTURE_2D
, img
,
203 region
->pitch
, region
->height
, 1, 0,
204 region
->cpp
== 4 ? GL_RGBA
: GL_RGB
);
206 _mesa_set_tex_image( obj
, GL_TEXTURE_2D
, 0, img
);
209 void brw_FrameBufferTexDestroy( struct brw_context
*brw
)
211 brw
->intel
.ctx
.Driver
.DeleteTexture( &brw
->intel
.ctx
,
212 brw
->intel
.frame_buffer_texobj
);