2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
31 #include "simple_list.h"
36 #include "texformat.h"
37 #include "swrast/swrast.h"
39 #include "via_context.h"
41 #include "via_state.h"
42 #include "via_ioctl.h"
45 viaTextureObjectPtr
viaAllocTextureObject(struct gl_texture_object
*texObj
)
47 viaTextureObjectPtr t
;
49 t
= (viaTextureObjectPtr
)CALLOC_STRUCT(via_texture_object_t
);
53 /* Initialize non-image-dependent parts of the state:
64 static void viaTexImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
66 GLint width
, GLint border
,
67 GLenum format
, GLenum type
,
69 const struct gl_pixelstore_attrib
*packing
,
70 struct gl_texture_object
*texObj
,
71 struct gl_texture_image
*texImage
)
73 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
74 if (VIA_DEBUG
) fprintf(stderr
, "viaTexImage1D - in\n");
77 viaSwapOutTexObj(VIA_CONTEXT(ctx
), t
);
84 t
= viaAllocTextureObject(texObj
);
86 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "viaTexImage1D");
89 texObj
->DriverData
= t
;
91 _mesa_store_teximage1d(ctx
, target
, level
, internalFormat
,
92 width
, border
, format
, type
,
93 pixels
, packing
, texObj
, texImage
);
94 if (VIA_DEBUG
) fprintf(stderr
, "viaTexImage1D - out\n");
96 static void viaTexSubImage1D(GLcontext
*ctx
,
101 GLenum format
, GLenum type
,
102 const GLvoid
*pixels
,
103 const struct gl_pixelstore_attrib
*packing
,
104 struct gl_texture_object
*texObj
,
105 struct gl_texture_image
*texImage
)
108 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
111 viaSwapOutTexObj(VIA_CONTEXT(ctx
), t
);
113 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
114 format
, type
, pixels
, packing
, texObj
,
120 static void viaTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
121 GLint internalFormat
,
122 GLint width
, GLint height
, GLint border
,
123 GLenum format
, GLenum type
, const GLvoid
*pixels
,
124 const struct gl_pixelstore_attrib
*packing
,
125 struct gl_texture_object
*texObj
,
126 struct gl_texture_image
*texImage
)
128 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
129 if (VIA_DEBUG
) fprintf(stderr
, "viaTexImage2D - in\n");
132 viaSwapOutTexObj(VIA_CONTEXT(ctx
), t
);
139 t
= viaAllocTextureObject(texObj
);
141 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "viaTexImage2D");
144 texObj
->DriverData
= t
;
146 _mesa_store_teximage2d(ctx
, target
, level
, internalFormat
,
147 width
, height
, border
, format
, type
,
148 pixels
, packing
, texObj
, texImage
);
149 if (VIA_DEBUG
) fprintf(stderr
, "viaTexImage2D - out\n");
152 static void viaTexSubImage2D(GLcontext
*ctx
,
155 GLint xoffset
, GLint yoffset
,
156 GLsizei width
, GLsizei height
,
157 GLenum format
, GLenum type
,
158 const GLvoid
*pixels
,
159 const struct gl_pixelstore_attrib
*packing
,
160 struct gl_texture_object
*texObj
,
161 struct gl_texture_image
*texImage
)
163 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
165 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
168 viaSwapOutTexObj(VIA_CONTEXT(ctx
), t
);
170 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
171 height
, format
, type
, pixels
, packing
, texObj
,
175 vmesa
->shareCtx
->NewState
|= _NEW_TEXTURE
;
179 static void viaBindTexture(GLcontext
*ctx
, GLenum target
,
180 struct gl_texture_object
*texObj
)
182 if (VIA_DEBUG
) fprintf(stderr
, "viaBindTexture - in\n");
183 if (target
== GL_TEXTURE_2D
) {
184 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
188 t
= viaAllocTextureObject(texObj
);
190 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "viaBindTexture");
193 texObj
->DriverData
= t
;
196 if (VIA_DEBUG
) fprintf(stderr
, "viaBindTexture - out\n");
199 static void viaDeleteTexture(GLcontext
*ctx
, struct gl_texture_object
*texObj
)
201 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
202 if (VIA_DEBUG
) fprintf(stderr
, "viaDeleteTexture - in\n");
204 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
206 if (vmesa
->dma
) { /* imply vmesa is not under destroying */
207 VIA_FLUSH_DMA(vmesa
);
209 viaDestroyTexObj(vmesa
, t
);
211 texObj
->DriverData
= 0;
213 if (VIA_DEBUG
) fprintf(stderr
, "viaDeleteTexture - out\n");
215 /* Free mipmap images and the texture object itself */
216 _mesa_delete_texture_object(ctx
, texObj
);
219 static GLboolean
viaIsTextureResident(GLcontext
*ctx
,
220 struct gl_texture_object
*texObj
)
222 viaTextureObjectPtr t
= (viaTextureObjectPtr
)texObj
->DriverData
;
224 return t
&& t
->bufAddr
;
227 static const struct gl_texture_format
*
228 viaChooseTexFormat(GLcontext
*ctx
, GLint internalFormat
,
229 GLenum format
, GLenum type
)
231 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
234 if (VIA_DEBUG
) fprintf(stderr
, "%s in\n", __FUNCTION__
);
235 if (VIA_DEBUG
) fprintf(stderr
, "internalFormat:%d format:%d\n", internalFormat
, format
);
236 switch (internalFormat
) {
243 return &_mesa_texformat_l8
;
245 case GL_LUMINANCE_ALPHA
:
246 case GL_LUMINANCE4_ALPHA4
:
247 case GL_LUMINANCE6_ALPHA2
:
248 case GL_LUMINANCE8_ALPHA8
:
249 case GL_LUMINANCE12_ALPHA4
:
250 case GL_LUMINANCE12_ALPHA12
:
251 case GL_LUMINANCE16_ALPHA16
:
252 return &_mesa_texformat_al88
;
256 if (VIA_DEBUG
) fprintf(stderr
, "2 &_mesa_texformat_arg565\n");
257 return &_mesa_texformat_rgb565
;
264 if (vmesa
->viaScreen
->bitsPerPixel
== 0x20) {
265 if (VIA_DEBUG
) fprintf(stderr
,"3 argb8888\n");
266 return &_mesa_texformat_argb8888
;
269 if (VIA_DEBUG
) fprintf(stderr
,"3 rgb565\n");
270 return &_mesa_texformat_rgb565
;
273 if (vmesa
->viaScreen
->bitsPerPixel
== 0x20) {
274 if (VIA_DEBUG
) fprintf(stderr
, "4 &_mesa_texformat_argb8888\n");
275 return &_mesa_texformat_argb8888
;
278 if (VIA_DEBUG
) fprintf(stderr
, "4 &_mesa_texformat_argb4444\n");
279 return &_mesa_texformat_argb4444
;
283 if (VIA_DEBUG
) fprintf(stderr
, "GL_RGBA4 &_mesa_texformat_argb4444\n");
284 return &_mesa_texformat_argb4444
;
287 if (VIA_DEBUG
) fprintf(stderr
, "GL_RGB5_A1 &_mesa_texformat_argb1555\n");
288 return &_mesa_texformat_argb1555
;
294 if (VIA_DEBUG
) fprintf(stderr
, "GL_RGBA &_mesa_texformat_argb8888\n");
295 return &_mesa_texformat_argb8888
;
301 return &_mesa_texformat_a8
;
307 return &_mesa_texformat_i8
;
309 case GL_COLOR_INDEX1_EXT
:
310 case GL_COLOR_INDEX2_EXT
:
311 case GL_COLOR_INDEX4_EXT
:
312 case GL_COLOR_INDEX8_EXT
:
313 case GL_COLOR_INDEX12_EXT
:
314 case GL_COLOR_INDEX16_EXT
:
315 return &_mesa_texformat_ci8
;
317 _mesa_problem(ctx
, "unexpected format in viaChooseTextureFormat");
322 void viaInitTextureFuncs(struct dd_function_table
* functions
)
324 if (VIA_DEBUG
) fprintf(stderr
, "viaInitTextureFuncs - in\n");
325 functions
->ChooseTextureFormat
= viaChooseTexFormat
;
326 functions
->TexImage1D
= viaTexImage1D
;
327 functions
->TexImage2D
= viaTexImage2D
;
328 functions
->TexSubImage1D
= viaTexSubImage1D
;
329 functions
->TexSubImage2D
= viaTexSubImage2D
;
331 functions
->NewTextureObject
= _mesa_new_texture_object
;
332 functions
->BindTexture
= viaBindTexture
;
333 functions
->DeleteTexture
= viaDeleteTexture
;
334 functions
->UpdateTexturePalette
= 0;
335 functions
->IsTextureResident
= viaIsTextureResident
;
337 if (VIA_DEBUG
) fprintf(stderr
, "viaInitTextureFuncs - out\n");
340 void viaInitTextures(GLcontext
*ctx
)
342 GLuint tmp
= ctx
->Texture
.CurrentUnit
;
343 ctx
->Texture
.CurrentUnit
= 0;
344 viaBindTexture(ctx
, GL_TEXTURE_1D
, ctx
->Texture
.Unit
[0].Current1D
);
345 viaBindTexture(ctx
, GL_TEXTURE_2D
, ctx
->Texture
.Unit
[0].Current2D
);
346 ctx
->Texture
.CurrentUnit
= 1;
347 viaBindTexture(ctx
, GL_TEXTURE_1D
, ctx
->Texture
.Unit
[1].Current1D
);
348 viaBindTexture(ctx
, GL_TEXTURE_2D
, ctx
->Texture
.Unit
[1].Current2D
);
349 ctx
->Texture
.CurrentUnit
= tmp
;