remove some dead texture code
[mesa.git] / src / mesa / drivers / dri / unichrome / via_tex.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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.
23 */
24
25
26 #include <stdlib.h>
27 #include <stdio.h>
28
29 #include "glheader.h"
30 #include "mtypes.h"
31 #include "simple_list.h"
32 #include "enums.h"
33 #include "teximage.h"
34 #include "texobj.h"
35 #include "texstore.h"
36 #include "texformat.h"
37 #include "swrast/swrast.h"
38 #include "context.h"
39 #include "via_context.h"
40 #include "via_tex.h"
41 #include "via_state.h"
42 #include "via_ioctl.h"
43
44
45 viaTextureObjectPtr viaAllocTextureObject(struct gl_texture_object *texObj)
46 {
47 viaTextureObjectPtr t;
48
49 t = (viaTextureObjectPtr)CALLOC_STRUCT(via_texture_object_t);
50 if (!t)
51 return NULL;
52
53 /* Initialize non-image-dependent parts of the state:
54 */
55 t->bufAddr = NULL;
56 t->dirtyImages = ~0;
57 t->actualLevel = 0;
58 t->globj = texObj;
59 make_empty_list(t);
60
61 return t;
62 }
63
64 static void viaTexImage1D(GLcontext *ctx, GLenum target, GLint level,
65 GLint internalFormat,
66 GLint width, GLint border,
67 GLenum format, GLenum type,
68 const GLvoid *pixels,
69 const struct gl_pixelstore_attrib *packing,
70 struct gl_texture_object *texObj,
71 struct gl_texture_image *texImage)
72 {
73 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
74 if (VIA_DEBUG) fprintf(stderr, "viaTexImage1D - in\n");
75 if (t) {
76 if (level == 0) {
77 viaSwapOutTexObj(VIA_CONTEXT(ctx), t);
78 t->actualLevel = 0;
79 }
80 else
81 t->actualLevel++;
82 }
83 else {
84 t = viaAllocTextureObject(texObj);
85 if (!t) {
86 _mesa_error(ctx, GL_OUT_OF_MEMORY, "viaTexImage1D");
87 return;
88 }
89 texObj->DriverData = t;
90 }
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");
95 }
96 static void viaTexSubImage1D(GLcontext *ctx,
97 GLenum target,
98 GLint level,
99 GLint xoffset,
100 GLsizei width,
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)
106
107 {
108 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
109
110 if (t) {
111 viaSwapOutTexObj(VIA_CONTEXT(ctx), t);
112 }
113 _mesa_store_texsubimage1d(ctx, target, level, xoffset, width,
114 format, type, pixels, packing, texObj,
115 texImage);
116
117 }
118
119
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)
127 {
128 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
129 if (VIA_DEBUG) fprintf(stderr, "viaTexImage2D - in\n");
130 if (t) {
131 if (level == 0) {
132 viaSwapOutTexObj(VIA_CONTEXT(ctx), t);
133 t->actualLevel = 0;
134 }
135 else
136 t->actualLevel++;
137 }
138 else {
139 t = viaAllocTextureObject(texObj);
140 if (!t) {
141 _mesa_error(ctx, GL_OUT_OF_MEMORY, "viaTexImage2D");
142 return;
143 }
144 texObj->DriverData = t;
145 }
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");
150 }
151
152 static void viaTexSubImage2D(GLcontext *ctx,
153 GLenum target,
154 GLint level,
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)
162 {
163 viaContextPtr vmesa = VIA_CONTEXT(ctx);
164
165 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
166
167 if (t) {
168 viaSwapOutTexObj(VIA_CONTEXT(ctx), t);
169 }
170 _mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
171 height, format, type, pixels, packing, texObj,
172 texImage);
173
174 if(vmesa->shareCtx)
175 vmesa->shareCtx->NewState |= _NEW_TEXTURE;
176
177 }
178
179 static void viaBindTexture(GLcontext *ctx, GLenum target,
180 struct gl_texture_object *texObj)
181 {
182 if (VIA_DEBUG) fprintf(stderr, "viaBindTexture - in\n");
183 if (target == GL_TEXTURE_2D) {
184 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
185
186 if (!t) {
187
188 t = viaAllocTextureObject(texObj);
189 if (!t) {
190 _mesa_error(ctx, GL_OUT_OF_MEMORY, "viaBindTexture");
191 return;
192 }
193 texObj->DriverData = t;
194 }
195 }
196 if (VIA_DEBUG) fprintf(stderr, "viaBindTexture - out\n");
197 }
198
199 static void viaDeleteTexture(GLcontext *ctx, struct gl_texture_object *texObj)
200 {
201 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
202 if (VIA_DEBUG) fprintf(stderr, "viaDeleteTexture - in\n");
203 if (t) {
204 viaContextPtr vmesa = VIA_CONTEXT(ctx);
205 if (vmesa) {
206 if (vmesa->dma) { /* imply vmesa is not under destroying */
207 VIA_FLUSH_DMA(vmesa);
208 }
209 viaDestroyTexObj(vmesa, t);
210 }
211 texObj->DriverData = 0;
212 }
213 if (VIA_DEBUG) fprintf(stderr, "viaDeleteTexture - out\n");
214
215 /* Free mipmap images and the texture object itself */
216 _mesa_delete_texture_object(ctx, texObj);
217 }
218
219 static GLboolean viaIsTextureResident(GLcontext *ctx,
220 struct gl_texture_object *texObj)
221 {
222 viaTextureObjectPtr t = (viaTextureObjectPtr)texObj->DriverData;
223
224 return t && t->bufAddr;
225 }
226
227 static const struct gl_texture_format *
228 viaChooseTexFormat(GLcontext *ctx, GLint internalFormat,
229 GLenum format, GLenum type)
230 {
231 viaContextPtr vmesa = VIA_CONTEXT(ctx);
232 (void)format;
233 (void)type;
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) {
237 case 1:
238 case GL_LUMINANCE:
239 case GL_LUMINANCE4:
240 case GL_LUMINANCE8:
241 case GL_LUMINANCE12:
242 case GL_LUMINANCE16:
243 return &_mesa_texformat_l8;
244 case 2:
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;
253 case GL_R3_G3_B2:
254 case GL_RGB4:
255 case GL_RGB5:
256 if (VIA_DEBUG) fprintf(stderr, "2 &_mesa_texformat_arg565\n");
257 return &_mesa_texformat_rgb565;
258 case 3:
259 case GL_RGB:
260 case GL_RGB8:
261 case GL_RGB10:
262 case GL_RGB12:
263 case GL_RGB16:
264 if (vmesa->viaScreen->bitsPerPixel == 0x20) {
265 if (VIA_DEBUG) fprintf(stderr,"3 argb8888\n");
266 return &_mesa_texformat_argb8888;
267 }
268 else {
269 if (VIA_DEBUG) fprintf(stderr,"3 rgb565\n");
270 return &_mesa_texformat_rgb565;
271 }
272 case 4:
273 if (vmesa->viaScreen->bitsPerPixel == 0x20) {
274 if (VIA_DEBUG) fprintf(stderr, "4 &_mesa_texformat_argb8888\n");
275 return &_mesa_texformat_argb8888;
276 }
277 else {
278 if (VIA_DEBUG) fprintf(stderr, "4 &_mesa_texformat_argb4444\n");
279 return &_mesa_texformat_argb4444;
280 }
281 case GL_RGBA2:
282 case GL_RGBA4:
283 if (VIA_DEBUG) fprintf(stderr, "GL_RGBA4 &_mesa_texformat_argb4444\n");
284 return &_mesa_texformat_argb4444;
285
286 case GL_RGB5_A1:
287 if (VIA_DEBUG) fprintf(stderr, "GL_RGB5_A1 &_mesa_texformat_argb1555\n");
288 return &_mesa_texformat_argb1555;
289 case GL_RGBA:
290 case GL_RGBA8:
291 case GL_RGBA12:
292 case GL_RGBA16:
293 case GL_RGB10_A2:
294 if (VIA_DEBUG) fprintf(stderr, "GL_RGBA &_mesa_texformat_argb8888\n");
295 return &_mesa_texformat_argb8888;
296 case GL_ALPHA:
297 case GL_ALPHA4:
298 case GL_ALPHA8:
299 case GL_ALPHA12:
300 case GL_ALPHA16:
301 return &_mesa_texformat_a8;
302 case GL_INTENSITY:
303 case GL_INTENSITY4:
304 case GL_INTENSITY8:
305 case GL_INTENSITY12:
306 case GL_INTENSITY16:
307 return &_mesa_texformat_i8;
308 case GL_COLOR_INDEX:
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;
316 default:
317 _mesa_problem(ctx, "unexpected format in viaChooseTextureFormat");
318 return NULL;
319 }
320 }
321
322 void viaInitTextureFuncs(struct dd_function_table * functions)
323 {
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;
330
331 functions->NewTextureObject = _mesa_new_texture_object;
332 functions->BindTexture = viaBindTexture;
333 functions->DeleteTexture = viaDeleteTexture;
334 functions->UpdateTexturePalette = 0;
335 functions->IsTextureResident = viaIsTextureResident;
336
337 if (VIA_DEBUG) fprintf(stderr, "viaInitTextureFuncs - out\n");
338 }
339
340 void viaInitTextures(GLcontext *ctx)
341 {
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;
350 }