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
;
172 fprintf(stderr
, "unexpected texture format %s in %s\n",
173 _mesa_lookup_enum_by_nr(internalFormat
),
178 return NULL
; /* never get here */
182 void brwInitTextureFuncs( struct dd_function_table
*functions
)
184 functions
->ChooseTextureFormat
= brwChooseTextureFormat
;
187 void brw_FrameBufferTexInit( struct brw_context
*brw
)
189 struct intel_context
*intel
= &brw
->intel
;
190 GLcontext
*ctx
= &intel
->ctx
;
191 struct intel_region
*region
= intel
->front_region
;
192 struct gl_texture_object
*obj
;
193 struct gl_texture_image
*img
;
195 intel
->frame_buffer_texobj
= obj
=
196 ctx
->Driver
.NewTextureObject( ctx
, (GLuint
) -1, GL_TEXTURE_2D
);
198 obj
->MinFilter
= GL_NEAREST
;
199 obj
->MagFilter
= GL_NEAREST
;
201 img
= ctx
->Driver
.NewTextureImage( ctx
);
203 _mesa_init_teximage_fields( ctx
, GL_TEXTURE_2D
, img
,
204 region
->pitch
, region
->height
, 1, 0,
205 region
->cpp
== 4 ? GL_RGBA
: GL_RGB
);
207 _mesa_set_tex_image( obj
, GL_TEXTURE_2D
, 0, img
);
210 void brw_FrameBufferTexDestroy( struct brw_context
*brw
)
212 brw
->intel
.ctx
.Driver
.DeleteTexture( &brw
->intel
.ctx
,
213 brw
->intel
.frame_buffer_texobj
);