Revamp color table code.
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_tex.c
1 /* -*- mode: c; c-basic-offset: 3 -*-
2 *
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26 /* $XFree86: xc/lib/GL/mesa/src/drv/tdfx/tdfx_tex.c,v 1.7 2002/11/05 17:46:10 tsi Exp $ */
27
28 /*
29 * New fixes:
30 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
31 *
32 * Original rewrite:
33 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
34 *
35 * Authors:
36 * Gareth Hughes <gareth@valinux.com>
37 * Brian Paul <brianp@valinux.com>
38 *
39 */
40
41
42 #include "enums.h"
43 #include "image.h"
44 #include "mipmap.h"
45 #include "texcompress.h"
46 #include "texformat.h"
47 #include "teximage.h"
48 #include "texstore.h"
49 #include "texobj.h"
50 #include "tdfx_context.h"
51 #include "tdfx_tex.h"
52 #include "tdfx_texman.h"
53
54
55 /* no borders! can't halve 1x1! (stride > width * comp) not allowed */
56 static void
57 _mesa_halve2x2_teximage2d ( GLcontext *ctx,
58 struct gl_texture_image *texImage,
59 GLuint bytesPerPixel,
60 GLint srcWidth, GLint srcHeight,
61 const GLvoid *srcImage, GLvoid *dstImage )
62 {
63 GLint i, j, k;
64 GLint dstWidth = srcWidth / 2;
65 GLint dstHeight = srcHeight / 2;
66 GLint srcRowStride = srcWidth * bytesPerPixel;
67 GLubyte *src = (GLubyte *)srcImage;
68 GLubyte *dst = dstImage;
69 GLuint dstImageOffsets = 0;
70
71 GLuint bpt = 0;
72 GLubyte *_s = NULL;
73 GLubyte *_d = NULL;
74 GLenum _t = 0;
75
76 if (texImage->TexFormat->MesaFormat == MESA_FORMAT_RGB565) {
77 _t = GL_UNSIGNED_SHORT_5_6_5_REV;
78 bpt = bytesPerPixel;
79 } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB4444) {
80 _t = GL_UNSIGNED_SHORT_4_4_4_4_REV;
81 bpt = bytesPerPixel;
82 } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB1555) {
83 _t = GL_UNSIGNED_SHORT_1_5_5_5_REV;
84 bpt = bytesPerPixel;
85 }
86 if (bpt) {
87 bytesPerPixel = 4;
88 srcRowStride = srcWidth * bytesPerPixel;
89 if (dstWidth == 0) {
90 dstWidth = 1;
91 }
92 if (dstHeight == 0) {
93 dstHeight = 1;
94 }
95 _s = src = MALLOC(srcRowStride * srcHeight);
96 _d = dst = MALLOC(dstWidth * bytesPerPixel * dstHeight);
97 _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
98 &_mesa_texformat_rgba8888_rev, src,
99 0, 0, 0, /* dstX/Y/Zoffset */
100 srcRowStride, /* dstRowStride */
101 &dstImageOffsets,
102 srcWidth, srcHeight, 1,
103 texImage->_BaseFormat, _t, srcImage, &ctx->DefaultPacking);
104 }
105
106 if (srcHeight == 1) {
107 for (i = 0; i < dstWidth; i++) {
108 for (k = 0; k < bytesPerPixel; k++) {
109 dst[0] = (src[0] + src[bytesPerPixel] + 1) / 2;
110 src++;
111 dst++;
112 }
113 src += bytesPerPixel;
114 }
115 } else if (srcWidth == 1) {
116 for (j = 0; j < dstHeight; j++) {
117 for (k = 0; k < bytesPerPixel; k++) {
118 dst[0] = (src[0] + src[srcRowStride] + 1) / 2;
119 src++;
120 dst++;
121 }
122 src += srcRowStride;
123 }
124 } else {
125 for (j = 0; j < dstHeight; j++) {
126 for (i = 0; i < dstWidth; i++) {
127 for (k = 0; k < bytesPerPixel; k++) {
128 dst[0] = (src[0] +
129 src[bytesPerPixel] +
130 src[srcRowStride] +
131 src[srcRowStride + bytesPerPixel] + 2) / 4;
132 src++;
133 dst++;
134 }
135 src += bytesPerPixel;
136 }
137 src += srcRowStride;
138 }
139 }
140
141 if (bpt) {
142 src = _s;
143 dst = _d;
144 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
145 texImage->TexFormat, dstImage,
146 0, 0, 0, /* dstX/Y/Zoffset */
147 dstWidth * bpt,
148 &dstImageOffsets,
149 dstWidth, dstHeight, 1,
150 GL_BGRA, CHAN_TYPE, dst, &ctx->DefaultPacking);
151 FREE(dst);
152 FREE(src);
153 }
154 }
155
156
157 static int
158 logbase2(int n)
159 {
160 GLint i = 1;
161 GLint log2 = 0;
162
163 if (n < 0) {
164 return -1;
165 }
166
167 while (n > i) {
168 i *= 2;
169 log2++;
170 }
171 if (i != n) {
172 return -1;
173 }
174 else {
175 return log2;
176 }
177 }
178
179
180 /*
181 * Compute various texture image parameters.
182 * Input: w, h - source texture width and height
183 * Output: lodlevel - Glide lod level token for the larger texture dimension
184 * aspectratio - Glide aspect ratio token
185 * sscale - S scale factor used during triangle setup
186 * tscale - T scale factor used during triangle setup
187 * wscale - OpenGL -> Glide image width scale factor
188 * hscale - OpenGL -> Glide image height scale factor
189 *
190 * Sample results:
191 * w h lodlevel aspectRatio
192 * 128 128 GR_LOD_LOG2_128 (=7) GR_ASPECT_LOG2_1x1 (=0)
193 * 64 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x1 (=0)
194 * 64 32 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_2x1 (=1)
195 * 32 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x2 (=-1)
196 * 32 32 GR_LOD_LOG2_32 (=5) GR_ASPECT_LOG2_1x1 (=0)
197 */
198 static void
199 tdfxTexGetInfo(const GLcontext *ctx, int w, int h,
200 GrLOD_t *lodlevel, GrAspectRatio_t *aspectratio,
201 float *sscale, float *tscale,
202 int *wscale, int *hscale)
203 {
204 int logw, logh, ar, lod, ws, hs;
205 float s, t;
206
207 ASSERT(w >= 1);
208 ASSERT(h >= 1);
209
210 logw = logbase2(w);
211 logh = logbase2(h);
212 ar = logw - logh; /* aspect ratio = difference in log dimensions */
213 s = t = 256.0;
214 ws = hs = 1;
215
216 /* Hardware only allows a maximum aspect ratio of 8x1, so handle
217 |ar| > 3 by scaling the image and using an 8x1 aspect ratio */
218 if (ar >= 0) {
219 ASSERT(w >= h);
220 lod = logw;
221 if (ar <= GR_ASPECT_LOG2_8x1) {
222 t = 256 >> ar;
223 }
224 else {
225 /* have to stretch image height */
226 t = 32.0;
227 hs = 1 << (ar - 3);
228 ar = GR_ASPECT_LOG2_8x1;
229 }
230 }
231 else {
232 ASSERT(w < h);
233 lod = logh;
234 if (ar >= GR_ASPECT_LOG2_1x8) {
235 s = 256 >> -ar;
236 }
237 else {
238 /* have to stretch image width */
239 s = 32.0;
240 ws = 1 << (-ar - 3);
241 ar = GR_ASPECT_LOG2_1x8;
242 }
243 }
244
245 if (lodlevel)
246 *lodlevel = (GrLOD_t) lod;
247 if (aspectratio)
248 *aspectratio = (GrAspectRatio_t) ar;
249 if (sscale)
250 *sscale = s;
251 if (tscale)
252 *tscale = t;
253 if (wscale)
254 *wscale = ws;
255 if (hscale)
256 *hscale = hs;
257 }
258
259
260 /*
261 * We need to call this when a texture object's minification filter
262 * or texture image sizes change.
263 */
264 static void RevalidateTexture(GLcontext *ctx, struct gl_texture_object *tObj)
265 {
266 tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj);
267 GLint minl, maxl;
268
269 if (!ti)
270 return;
271
272 minl = maxl = tObj->BaseLevel;
273
274 if (tObj->Image[0][minl]) {
275 maxl = MIN2(tObj->MaxLevel, tObj->Image[0][minl]->MaxLog2);
276
277 /* compute largeLodLog2, aspect ratio and texcoord scale factors */
278 tdfxTexGetInfo(ctx, tObj->Image[0][minl]->Width, tObj->Image[0][minl]->Height,
279 &ti->info.largeLodLog2,
280 &ti->info.aspectRatioLog2,
281 &(ti->sScale), &(ti->tScale), NULL, NULL);
282 }
283
284 if (tObj->Image[0][maxl] && (tObj->MinFilter != GL_NEAREST) && (tObj->MinFilter != GL_LINEAR)) {
285 /* mipmapping: need to compute smallLodLog2 */
286 tdfxTexGetInfo(ctx, tObj->Image[0][maxl]->Width,
287 tObj->Image[0][maxl]->Height,
288 &ti->info.smallLodLog2, NULL,
289 NULL, NULL, NULL, NULL);
290 }
291 else {
292 /* not mipmapping: smallLodLog2 = largeLodLog2 */
293 ti->info.smallLodLog2 = ti->info.largeLodLog2;
294 maxl = minl;
295 }
296
297 ti->minLevel = minl;
298 ti->maxLevel = maxl;
299 ti->info.data = NULL;
300
301 /* this is necessary because of fxDDCompressedTexImage2D */
302 if (ti->padded) {
303 struct gl_texture_image *texImage = tObj->Image[0][minl];
304 tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
305 if (mml->wScale != 1 || mml->hScale != 1) {
306 ti->sScale /= mml->wScale;
307 ti->tScale /= mml->hScale;
308 }
309 }
310 }
311
312
313 static tdfxTexInfo *
314 fxAllocTexObjData(tdfxContextPtr fxMesa)
315 {
316 tdfxTexInfo *ti;
317
318 if (!(ti = CALLOC(sizeof(tdfxTexInfo)))) {
319 _mesa_problem(NULL, "tdfx driver: out of memory");
320 return NULL;
321 }
322
323 ti->isInTM = GL_FALSE;
324
325 ti->whichTMU = TDFX_TMU_NONE;
326
327 ti->tm[TDFX_TMU0] = NULL;
328 ti->tm[TDFX_TMU1] = NULL;
329
330 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
331 ti->magFilt = GR_TEXTUREFILTER_BILINEAR;
332
333 ti->sClamp = GR_TEXTURECLAMP_WRAP;
334 ti->tClamp = GR_TEXTURECLAMP_WRAP;
335
336 ti->mmMode = GR_MIPMAP_NEAREST;
337 ti->LODblend = FXFALSE;
338
339 return ti;
340 }
341
342
343 /*
344 * Called via glBindTexture.
345 */
346 static void
347 tdfxBindTexture(GLcontext * ctx, GLenum target,
348 struct gl_texture_object *tObj)
349 {
350 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
351 tdfxTexInfo *ti;
352
353 if (MESA_VERBOSE & VERBOSE_DRIVER) {
354 fprintf(stderr, "fxmesa: fxDDTexBind(%d,%p)\n", tObj->Name,
355 tObj->DriverData);
356 }
357
358 if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))
359 return;
360
361 if (!tObj->DriverData) {
362 tObj->DriverData = fxAllocTexObjData(fxMesa);
363 }
364
365 ti = TDFX_TEXTURE_DATA(tObj);
366 ti->lastTimeUsed = fxMesa->texBindNumber++;
367
368 fxMesa->new_state |= TDFX_NEW_TEXTURE;
369 }
370
371
372 /*
373 * Called via glTexEnv.
374 */
375 static void
376 tdfxTexEnv(GLcontext * ctx, GLenum target, GLenum pname,
377 const GLfloat * param)
378 {
379 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
380
381 if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) {
382 if (param)
383 fprintf(stderr, "fxmesa: texenv(%x,%x)\n", pname,
384 (GLint) (*param));
385 else
386 fprintf(stderr, "fxmesa: texenv(%x)\n", pname);
387 }
388
389 /* XXX this is a bit of a hack to force the Glide texture
390 * state to be updated.
391 */
392 fxMesa->TexState.EnvMode[ctx->Texture.CurrentUnit] = 0;
393
394 fxMesa->new_state |= TDFX_NEW_TEXTURE;
395 }
396
397
398 /*
399 * Called via glTexParameter.
400 */
401 static void
402 tdfxTexParameter(GLcontext * ctx, GLenum target,
403 struct gl_texture_object *tObj,
404 GLenum pname, const GLfloat * params)
405 {
406 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
407 GLenum param = (GLenum) (GLint) params[0];
408 tdfxTexInfo *ti;
409
410 if (MESA_VERBOSE & VERBOSE_DRIVER) {
411 fprintf(stderr, "fxmesa: fxDDTexParam(%d,%p,%x,%x)\n", tObj->Name,
412 tObj->DriverData, pname, param);
413 }
414
415 if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))
416 return;
417
418 if (!tObj->DriverData)
419 tObj->DriverData = fxAllocTexObjData(fxMesa);
420
421 ti = TDFX_TEXTURE_DATA(tObj);
422
423 switch (pname) {
424 case GL_TEXTURE_MIN_FILTER:
425 switch (param) {
426 case GL_NEAREST:
427 ti->mmMode = GR_MIPMAP_DISABLE;
428 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
429 ti->LODblend = FXFALSE;
430 break;
431 case GL_LINEAR:
432 ti->mmMode = GR_MIPMAP_DISABLE;
433 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;
434 ti->LODblend = FXFALSE;
435 break;
436 case GL_NEAREST_MIPMAP_LINEAR:
437 if (!fxMesa->Glide.HaveCombineExt) {
438 if (fxMesa->haveTwoTMUs) {
439 ti->mmMode = GR_MIPMAP_NEAREST;
440 ti->LODblend = FXTRUE;
441 }
442 else {
443 ti->mmMode = GR_MIPMAP_NEAREST_DITHER;
444 ti->LODblend = FXFALSE;
445 }
446 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
447 break;
448 }
449 /* XXX Voodoo3/Banshee mipmap blending seems to produce
450 * incorrectly filtered colors for the smallest mipmap levels.
451 * To work-around we fall-through here and use a different filter.
452 */
453 case GL_NEAREST_MIPMAP_NEAREST:
454 ti->mmMode = GR_MIPMAP_NEAREST;
455 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
456 ti->LODblend = FXFALSE;
457 break;
458 case GL_LINEAR_MIPMAP_LINEAR:
459 if (!fxMesa->Glide.HaveCombineExt) {
460 if (fxMesa->haveTwoTMUs) {
461 ti->mmMode = GR_MIPMAP_NEAREST;
462 ti->LODblend = FXTRUE;
463 }
464 else {
465 ti->mmMode = GR_MIPMAP_NEAREST_DITHER;
466 ti->LODblend = FXFALSE;
467 }
468 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;
469 break;
470 }
471 /* XXX Voodoo3/Banshee mipmap blending seems to produce
472 * incorrectly filtered colors for the smallest mipmap levels.
473 * To work-around we fall-through here and use a different filter.
474 */
475 case GL_LINEAR_MIPMAP_NEAREST:
476 ti->mmMode = GR_MIPMAP_NEAREST;
477 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;
478 ti->LODblend = FXFALSE;
479 break;
480 default:
481 break;
482 }
483 ti->reloadImages = GL_TRUE;
484 RevalidateTexture(ctx, tObj);
485 fxMesa->new_state |= TDFX_NEW_TEXTURE;
486 break;
487
488 case GL_TEXTURE_MAG_FILTER:
489 switch (param) {
490 case GL_NEAREST:
491 ti->magFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
492 break;
493 case GL_LINEAR:
494 ti->magFilt = GR_TEXTUREFILTER_BILINEAR;
495 break;
496 default:
497 break;
498 }
499 fxMesa->new_state |= TDFX_NEW_TEXTURE;
500 break;
501
502 case GL_TEXTURE_WRAP_S:
503 switch (param) {
504 case GL_CLAMP_TO_BORDER:
505 case GL_CLAMP_TO_EDGE:
506 case GL_CLAMP:
507 ti->sClamp = GR_TEXTURECLAMP_CLAMP;
508 break;
509 case GL_REPEAT:
510 ti->sClamp = GR_TEXTURECLAMP_WRAP;
511 break;
512 case GL_MIRRORED_REPEAT:
513 ti->sClamp = GR_TEXTURECLAMP_MIRROR_EXT;
514 break;
515 default:
516 break;
517 }
518 fxMesa->new_state |= TDFX_NEW_TEXTURE;
519 break;
520
521 case GL_TEXTURE_WRAP_T:
522 switch (param) {
523 case GL_CLAMP_TO_BORDER:
524 case GL_CLAMP_TO_EDGE:
525 case GL_CLAMP:
526 ti->tClamp = GR_TEXTURECLAMP_CLAMP;
527 break;
528 case GL_REPEAT:
529 ti->tClamp = GR_TEXTURECLAMP_WRAP;
530 break;
531 case GL_MIRRORED_REPEAT:
532 ti->tClamp = GR_TEXTURECLAMP_MIRROR_EXT;
533 break;
534 default:
535 break;
536 }
537 fxMesa->new_state |= TDFX_NEW_TEXTURE;
538 break;
539
540 case GL_TEXTURE_BORDER_COLOR:
541 /* TO DO */
542 break;
543 case GL_TEXTURE_MIN_LOD:
544 /* TO DO */
545 break;
546 case GL_TEXTURE_MAX_LOD:
547 /* TO DO */
548 break;
549 case GL_TEXTURE_BASE_LEVEL:
550 RevalidateTexture(ctx, tObj);
551 break;
552 case GL_TEXTURE_MAX_LEVEL:
553 RevalidateTexture(ctx, tObj);
554 break;
555
556 default:
557 break;
558 }
559 }
560
561
562 /*
563 * Called via glDeleteTextures to delete a texture object.
564 * Here, we delete the Glide data associated with the texture.
565 */
566 static void
567 tdfxDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj)
568 {
569 if (ctx && ctx->DriverCtx) {
570 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
571 tdfxTMFreeTexture(fxMesa, tObj);
572 fxMesa->new_state |= TDFX_NEW_TEXTURE;
573 /* Free mipmap images and the texture object itself */
574 _mesa_delete_texture_object(ctx, tObj);
575 }
576 }
577
578
579 /*
580 * Return true if texture is resident, false otherwise.
581 */
582 static GLboolean
583 tdfxIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj)
584 {
585 tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj);
586 return (GLboolean) (ti && ti->isInTM);
587 }
588
589
590
591 /*
592 * Convert a gl_color_table texture palette to Glide's format.
593 */
594 static GrTexTable_t
595 convertPalette(FxU32 data[256], const struct gl_color_table *table)
596 {
597 const GLubyte *tableUB = table->TableUB;
598 GLint width = table->Size;
599 FxU32 r, g, b, a;
600 GLint i;
601
602 switch (table->_BaseFormat) {
603 case GL_INTENSITY:
604 for (i = 0; i < width; i++) {
605 r = tableUB[i];
606 g = tableUB[i];
607 b = tableUB[i];
608 a = tableUB[i];
609 data[i] = (a << 24) | (r << 16) | (g << 8) | b;
610 }
611 return GR_TEXTABLE_PALETTE_6666_EXT;
612 case GL_LUMINANCE:
613 for (i = 0; i < width; i++) {
614 r = tableUB[i];
615 g = tableUB[i];
616 b = tableUB[i];
617 a = 255;
618 data[i] = (a << 24) | (r << 16) | (g << 8) | b;
619 }
620 return GR_TEXTABLE_PALETTE;
621 case GL_ALPHA:
622 for (i = 0; i < width; i++) {
623 r = g = b = 255;
624 a = tableUB[i];
625 data[i] = (a << 24) | (r << 16) | (g << 8) | b;
626 }
627 return GR_TEXTABLE_PALETTE_6666_EXT;
628 case GL_LUMINANCE_ALPHA:
629 for (i = 0; i < width; i++) {
630 r = g = b = tableUB[i * 2 + 0];
631 a = tableUB[i * 2 + 1];
632 data[i] = (a << 24) | (r << 16) | (g << 8) | b;
633 }
634 return GR_TEXTABLE_PALETTE_6666_EXT;
635 case GL_RGB:
636 for (i = 0; i < width; i++) {
637 r = tableUB[i * 3 + 0];
638 g = tableUB[i * 3 + 1];
639 b = tableUB[i * 3 + 2];
640 a = 255;
641 data[i] = (a << 24) | (r << 16) | (g << 8) | b;
642 }
643 return GR_TEXTABLE_PALETTE;
644 case GL_RGBA:
645 for (i = 0; i < width; i++) {
646 r = tableUB[i * 4 + 0];
647 g = tableUB[i * 4 + 1];
648 b = tableUB[i * 4 + 2];
649 a = tableUB[i * 4 + 3];
650 data[i] = (a << 24) | (r << 16) | (g << 8) | b;
651 }
652 return GR_TEXTABLE_PALETTE_6666_EXT;
653 default:
654 /* XXX fixme: how can this happen? */
655 _mesa_error(NULL, GL_INVALID_ENUM, "convertPalette: table->Format == %s",
656 _mesa_lookup_enum_by_nr(table->Format));
657 return GR_TEXTABLE_PALETTE;
658 }
659 }
660
661
662
663 static void
664 tdfxUpdateTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj)
665 {
666 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
667
668 if (tObj) {
669 /* per-texture palette */
670 tdfxTexInfo *ti;
671
672 /* This might be a proxy texture. */
673 if (!tObj->Palette.Table)
674 return;
675
676 if (!tObj->DriverData)
677 tObj->DriverData = fxAllocTexObjData(fxMesa);
678 ti = TDFX_TEXTURE_DATA(tObj);
679 assert(ti);
680 ti->paltype = convertPalette(ti->palette.data, &tObj->Palette);
681 /*tdfxTexInvalidate(ctx, tObj);*/
682 }
683 else {
684 /* global texture palette */
685 fxMesa->TexPalette.Type = convertPalette(fxMesa->glbPalette.data, &ctx->Texture.Palette);
686 fxMesa->TexPalette.Data = &(fxMesa->glbPalette.data);
687 fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE;
688 }
689 fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX too heavy-handed */
690 }
691
692
693 /**********************************************************************/
694 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
695 /**********************************************************************/
696
697 #if 000
698 static FxBool TexusFatalError = FXFALSE;
699 static FxBool TexusError = FXFALSE;
700
701 #define TX_DITHER_NONE 0x00000000
702
703 static void
704 fxTexusError(const char *string, FxBool fatal)
705 {
706 _mesa_problem(NULL, string);
707 /*
708 * Just propagate the fatal value up.
709 */
710 TexusError = FXTRUE;
711 TexusFatalError = fatal;
712 }
713 #endif
714
715
716 static const struct gl_texture_format *
717 tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
718 GLenum srcFormat, GLenum srcType )
719 {
720 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
721 const GLboolean allow32bpt = TDFX_IS_NAPALM(fxMesa);
722
723 switch (internalFormat) {
724 case GL_ALPHA:
725 case GL_ALPHA4:
726 case GL_ALPHA8:
727 case GL_ALPHA12:
728 case GL_ALPHA16:
729 case GL_COMPRESSED_ALPHA:
730 return &_mesa_texformat_a8;
731 case 1:
732 case GL_LUMINANCE:
733 case GL_LUMINANCE4:
734 case GL_LUMINANCE8:
735 case GL_LUMINANCE12:
736 case GL_LUMINANCE16:
737 case GL_COMPRESSED_LUMINANCE:
738 return &_mesa_texformat_l8;
739 case 2:
740 case GL_LUMINANCE_ALPHA:
741 case GL_LUMINANCE4_ALPHA4:
742 case GL_LUMINANCE6_ALPHA2:
743 case GL_LUMINANCE8_ALPHA8:
744 case GL_LUMINANCE12_ALPHA4:
745 case GL_LUMINANCE12_ALPHA12:
746 case GL_LUMINANCE16_ALPHA16:
747 case GL_COMPRESSED_LUMINANCE_ALPHA:
748 return &_mesa_texformat_al88;
749 case GL_INTENSITY:
750 case GL_INTENSITY4:
751 case GL_INTENSITY8:
752 case GL_INTENSITY12:
753 case GL_INTENSITY16:
754 case GL_COMPRESSED_INTENSITY:
755 return &_mesa_texformat_i8;
756 case GL_R3_G3_B2:
757 case GL_RGB4:
758 case GL_RGB5:
759 return &_mesa_texformat_rgb565;
760 case GL_COMPRESSED_RGB:
761 /* intentional fall-through */
762 case 3:
763 case GL_RGB:
764 if ( srcFormat == GL_RGB && srcType == GL_UNSIGNED_SHORT_5_6_5 ) {
765 return &_mesa_texformat_rgb565;
766 }
767 /* intentional fall through */
768 case GL_RGB8:
769 case GL_RGB10:
770 case GL_RGB12:
771 case GL_RGB16:
772 return (allow32bpt) ? &_mesa_texformat_argb8888
773 : &_mesa_texformat_rgb565;
774 case GL_RGBA2:
775 case GL_RGBA4:
776 return &_mesa_texformat_argb4444;
777 case GL_COMPRESSED_RGBA:
778 /* intentional fall-through */
779 case 4:
780 case GL_RGBA:
781 if ( srcFormat == GL_BGRA ) {
782 if ( srcType == GL_UNSIGNED_INT_8_8_8_8_REV ) {
783 return &_mesa_texformat_argb8888;
784 }
785 else if ( srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ) {
786 return &_mesa_texformat_argb4444;
787 }
788 else if ( srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ) {
789 return &_mesa_texformat_argb1555;
790 }
791 }
792 /* intentional fall through */
793 case GL_RGBA8:
794 case GL_RGB10_A2:
795 case GL_RGBA12:
796 case GL_RGBA16:
797 return allow32bpt ? &_mesa_texformat_argb8888
798 : &_mesa_texformat_argb4444;
799 case GL_RGB5_A1:
800 return &_mesa_texformat_argb1555;
801 case GL_COLOR_INDEX:
802 case GL_COLOR_INDEX1_EXT:
803 case GL_COLOR_INDEX2_EXT:
804 case GL_COLOR_INDEX4_EXT:
805 case GL_COLOR_INDEX8_EXT:
806 case GL_COLOR_INDEX12_EXT:
807 case GL_COLOR_INDEX16_EXT:
808 return &_mesa_texformat_ci8;
809 /* GL_EXT_texture_compression_s3tc */
810 /* GL_S3_s3tc */
811 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
812 case GL_RGB_S3TC:
813 case GL_RGB4_S3TC:
814 return &_mesa_texformat_rgb_dxt1;
815 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
816 return &_mesa_texformat_rgba_dxt1;
817 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
818 case GL_RGBA_S3TC:
819 case GL_RGBA4_S3TC:
820 return &_mesa_texformat_rgba_dxt3;
821 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
822 return &_mesa_texformat_rgba_dxt5;
823 /* GL_3DFX_texture_compression_FXT1 */
824 case GL_COMPRESSED_RGB_FXT1_3DFX:
825 return &_mesa_texformat_rgb_fxt1;
826 case GL_COMPRESSED_RGBA_FXT1_3DFX:
827 return &_mesa_texformat_rgba_fxt1;
828 default:
829 _mesa_problem(ctx, "unexpected format in tdfxChooseTextureFormat");
830 return NULL;
831 }
832 }
833
834
835 /*
836 * Return the Glide format for the given mesa texture format.
837 */
838 static GrTextureFormat_t
839 fxGlideFormat(GLint mesaFormat)
840 {
841 switch (mesaFormat) {
842 case MESA_FORMAT_I8:
843 return GR_TEXFMT_ALPHA_8;
844 case MESA_FORMAT_A8:
845 return GR_TEXFMT_ALPHA_8;
846 case MESA_FORMAT_L8:
847 return GR_TEXFMT_INTENSITY_8;
848 case MESA_FORMAT_CI8:
849 return GR_TEXFMT_P_8;
850 case MESA_FORMAT_AL88:
851 return GR_TEXFMT_ALPHA_INTENSITY_88;
852 case MESA_FORMAT_RGB565:
853 return GR_TEXFMT_RGB_565;
854 case MESA_FORMAT_ARGB4444:
855 return GR_TEXFMT_ARGB_4444;
856 case MESA_FORMAT_ARGB1555:
857 return GR_TEXFMT_ARGB_1555;
858 case MESA_FORMAT_ARGB8888:
859 return GR_TEXFMT_ARGB_8888;
860 case MESA_FORMAT_RGB_FXT1:
861 case MESA_FORMAT_RGBA_FXT1:
862 return GR_TEXFMT_ARGB_CMP_FXT1;
863 case MESA_FORMAT_RGB_DXT1:
864 case MESA_FORMAT_RGBA_DXT1:
865 return GR_TEXFMT_ARGB_CMP_DXT1;
866 case MESA_FORMAT_RGBA_DXT3:
867 return GR_TEXFMT_ARGB_CMP_DXT3;
868 case MESA_FORMAT_RGBA_DXT5:
869 return GR_TEXFMT_ARGB_CMP_DXT5;
870 default:
871 _mesa_problem(NULL, "Unexpected format in fxGlideFormat");
872 return 0;
873 }
874 }
875
876
877 /* Texel-fetch functions for software texturing and glGetTexImage().
878 * We should have been able to use some "standard" fetch functions (which
879 * may get defined in texutil.c) but we have to account for scaled texture
880 * images on tdfx hardware (the 8:1 aspect ratio limit).
881 * Hence, we need special functions here.
882 */
883 extern void
884 fxt1_decode_1 (const void *texture, int width,
885 int i, int j, unsigned char *rgba);
886
887 static void
888 fetch_intensity8(const struct gl_texture_image *texImage,
889 GLint i, GLint j, GLint k, GLchan * rgba)
890 {
891 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
892 const GLubyte *texel;
893
894 i = i * mml->wScale;
895 j = j * mml->hScale;
896
897 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
898 rgba[RCOMP] = *texel;
899 rgba[GCOMP] = *texel;
900 rgba[BCOMP] = *texel;
901 rgba[ACOMP] = *texel;
902 }
903
904
905 static void
906 fetch_luminance8(const struct gl_texture_image *texImage,
907 GLint i, GLint j, GLint k, GLchan * rgba)
908 {
909 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
910 const GLubyte *texel;
911
912 i = i * mml->wScale;
913 j = j * mml->hScale;
914
915 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
916 rgba[RCOMP] = *texel;
917 rgba[GCOMP] = *texel;
918 rgba[BCOMP] = *texel;
919 rgba[ACOMP] = 255;
920 }
921
922
923 static void
924 fetch_alpha8(const struct gl_texture_image *texImage,
925 GLint i, GLint j, GLint k, GLchan * rgba)
926 {
927 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
928 const GLubyte *texel;
929
930 i = i * mml->wScale;
931 j = j * mml->hScale;
932
933 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
934 rgba[RCOMP] = 255;
935 rgba[GCOMP] = 255;
936 rgba[BCOMP] = 255;
937 rgba[ACOMP] = *texel;
938 }
939
940
941 static void
942 fetch_index8(const struct gl_texture_image *texImage,
943 GLint i, GLint j, GLint k, GLchan * indexOut)
944 {
945 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
946 const GLubyte *texel;
947
948 i = i * mml->wScale;
949 j = j * mml->hScale;
950
951 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
952 *indexOut = *texel;
953 }
954
955
956 static void
957 fetch_luminance8_alpha8(const struct gl_texture_image *texImage,
958 GLint i, GLint j, GLint k, GLchan * rgba)
959 {
960 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
961 const GLubyte *texel;
962
963 i = i * mml->wScale;
964 j = j * mml->hScale;
965
966 texel = ((GLubyte *) texImage->Data) + (j * mml->width + i) * 2;
967 rgba[RCOMP] = texel[0];
968 rgba[GCOMP] = texel[0];
969 rgba[BCOMP] = texel[0];
970 rgba[ACOMP] = texel[1];
971 }
972
973
974 static void
975 fetch_r5g6b5(const struct gl_texture_image *texImage,
976 GLint i, GLint j, GLint k, GLchan * rgba)
977 {
978 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
979 const GLushort *texel;
980
981 i = i * mml->wScale;
982 j = j * mml->hScale;
983
984 texel = ((GLushort *) texImage->Data) + j * mml->width + i;
985 rgba[RCOMP] = (((*texel) >> 11) & 0x1f) * 255 / 31;
986 rgba[GCOMP] = (((*texel) >> 5) & 0x3f) * 255 / 63;
987 rgba[BCOMP] = (((*texel) >> 0) & 0x1f) * 255 / 31;
988 rgba[ACOMP] = 255;
989 }
990
991
992 static void
993 fetch_r4g4b4a4(const struct gl_texture_image *texImage,
994 GLint i, GLint j, GLint k, GLchan * rgba)
995 {
996 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
997 const GLushort *texel;
998
999 i = i * mml->wScale;
1000 j = j * mml->hScale;
1001
1002 texel = ((GLushort *) texImage->Data) + j * mml->width + i;
1003 rgba[RCOMP] = (((*texel) >> 12) & 0xf) * 255 / 15;
1004 rgba[GCOMP] = (((*texel) >> 8) & 0xf) * 255 / 15;
1005 rgba[BCOMP] = (((*texel) >> 4) & 0xf) * 255 / 15;
1006 rgba[ACOMP] = (((*texel) >> 0) & 0xf) * 255 / 15;
1007 }
1008
1009
1010 static void
1011 fetch_r5g5b5a1(const struct gl_texture_image *texImage,
1012 GLint i, GLint j, GLint k, GLchan * rgba)
1013 {
1014 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1015 const GLushort *texel;
1016
1017 i = i * mml->wScale;
1018 j = j * mml->hScale;
1019
1020 texel = ((GLushort *) texImage->Data) + j * mml->width + i;
1021 rgba[RCOMP] = (((*texel) >> 11) & 0x1f) * 255 / 31;
1022 rgba[GCOMP] = (((*texel) >> 6) & 0x1f) * 255 / 31;
1023 rgba[BCOMP] = (((*texel) >> 1) & 0x1f) * 255 / 31;
1024 rgba[ACOMP] = (((*texel) >> 0) & 0x01) * 255;
1025 }
1026
1027
1028 static void
1029 fetch_a8r8g8b8(const struct gl_texture_image *texImage,
1030 GLint i, GLint j, GLint k, GLchan * rgba)
1031 {
1032 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1033 const GLuint *texel;
1034
1035 i = i * mml->wScale;
1036 j = j * mml->hScale;
1037
1038 texel = ((GLuint *) texImage->Data) + j * mml->width + i;
1039 rgba[RCOMP] = (((*texel) >> 16) & 0xff);
1040 rgba[GCOMP] = (((*texel) >> 8) & 0xff);
1041 rgba[BCOMP] = (((*texel) ) & 0xff);
1042 rgba[ACOMP] = (((*texel) >> 24) & 0xff);
1043 }
1044
1045
1046 static void
1047 fetch_rgb_fxt1(const struct gl_texture_image *texImage,
1048 GLint i, GLint j, GLint k, GLchan *rgba)
1049 {
1050 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1051
1052 i = i * mml->wScale;
1053 j = j * mml->hScale;
1054
1055 fxt1_decode_1(texImage->Data, mml->width, i, j, rgba);
1056 rgba[ACOMP] = 255;
1057 }
1058
1059
1060 static void
1061 fetch_rgba_fxt1(const struct gl_texture_image *texImage,
1062 GLint i, GLint j, GLint k, GLchan *rgba)
1063 {
1064 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1065
1066 i = i * mml->wScale;
1067 j = j * mml->hScale;
1068
1069 fxt1_decode_1(texImage->Data, mml->width, i, j, rgba);
1070 }
1071
1072
1073 static void
1074 fetch_rgb_dxt1(const struct gl_texture_image *texImage,
1075 GLint i, GLint j, GLint k, GLchan *rgba)
1076 {
1077 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1078
1079 i = i * mml->wScale;
1080 j = j * mml->hScale;
1081
1082 _mesa_texformat_rgb_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
1083 }
1084
1085
1086 static void
1087 fetch_rgba_dxt1(const struct gl_texture_image *texImage,
1088 GLint i, GLint j, GLint k, GLchan *rgba)
1089 {
1090 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1091
1092 i = i * mml->wScale;
1093 j = j * mml->hScale;
1094
1095 _mesa_texformat_rgba_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
1096 }
1097
1098
1099 static void
1100 fetch_rgba_dxt3(const struct gl_texture_image *texImage,
1101 GLint i, GLint j, GLint k, GLchan *rgba)
1102 {
1103 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1104
1105 i = i * mml->wScale;
1106 j = j * mml->hScale;
1107
1108 _mesa_texformat_rgba_dxt3.FetchTexel2D(texImage, i, j, k, rgba);
1109 }
1110
1111
1112 static void
1113 fetch_rgba_dxt5(const struct gl_texture_image *texImage,
1114 GLint i, GLint j, GLint k, GLchan *rgba)
1115 {
1116 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1117
1118 i = i * mml->wScale;
1119 j = j * mml->hScale;
1120
1121 _mesa_texformat_rgba_dxt5.FetchTexel2D(texImage, i, j, k, rgba);
1122 }
1123
1124
1125 static FetchTexelFuncC
1126 fxFetchFunction(GLint mesaFormat)
1127 {
1128 switch (mesaFormat) {
1129 case MESA_FORMAT_I8:
1130 return &fetch_intensity8;
1131 case MESA_FORMAT_A8:
1132 return &fetch_alpha8;
1133 case MESA_FORMAT_L8:
1134 return &fetch_luminance8;
1135 case MESA_FORMAT_CI8:
1136 return &fetch_index8;
1137 case MESA_FORMAT_AL88:
1138 return &fetch_luminance8_alpha8;
1139 case MESA_FORMAT_RGB565:
1140 return &fetch_r5g6b5;
1141 case MESA_FORMAT_ARGB4444:
1142 return &fetch_r4g4b4a4;
1143 case MESA_FORMAT_ARGB1555:
1144 return &fetch_r5g5b5a1;
1145 case MESA_FORMAT_ARGB8888:
1146 return &fetch_a8r8g8b8;
1147 case MESA_FORMAT_RGB_FXT1:
1148 return &fetch_rgb_fxt1;
1149 case MESA_FORMAT_RGBA_FXT1:
1150 return &fetch_rgba_fxt1;
1151 case MESA_FORMAT_RGB_DXT1:
1152 return &fetch_rgb_dxt1;
1153 case MESA_FORMAT_RGBA_DXT1:
1154 return &fetch_rgba_dxt1;
1155 case MESA_FORMAT_RGBA_DXT3:
1156 return &fetch_rgba_dxt3;
1157 case MESA_FORMAT_RGBA_DXT5:
1158 return &fetch_rgba_dxt5;
1159 default:
1160 _mesa_problem(NULL, "Unexpected format in fxFetchFunction");
1161 return NULL;
1162 }
1163 }
1164
1165
1166 static GLboolean
1167 adjust2DRatio (GLcontext *ctx,
1168 GLint xoffset, GLint yoffset,
1169 GLint width, GLint height,
1170 GLenum format, GLenum type, const GLvoid *pixels,
1171 const struct gl_pixelstore_attrib *packing,
1172 tdfxMipMapLevel *mml,
1173 struct gl_texture_image *texImage,
1174 GLint texelBytes,
1175 GLint dstRowStride)
1176 {
1177 const GLint newWidth = width * mml->wScale;
1178 const GLint newHeight = height * mml->hScale;
1179 GLvoid *tempImage;
1180 GLuint dstImageOffsets = 0;
1181
1182 if (!texImage->IsCompressed) {
1183 GLubyte *destAddr;
1184 tempImage = MALLOC(width * height * texelBytes);
1185 if (!tempImage) {
1186 return GL_FALSE;
1187 }
1188
1189 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1190 texImage->TexFormat, tempImage,
1191 0, 0, 0, /* dstX/Y/Zoffset */
1192 width * texelBytes, /* dstRowStride */
1193 &dstImageOffsets,
1194 width, height, 1,
1195 format, type, pixels, packing);
1196
1197 /* now rescale */
1198 /* compute address of dest subimage within the overal tex image */
1199 destAddr = (GLubyte *) texImage->Data
1200 + (yoffset * mml->hScale * mml->width
1201 + xoffset * mml->wScale) * texelBytes;
1202
1203 _mesa_rescale_teximage2d(texelBytes,
1204 width,
1205 dstRowStride, /* dst stride */
1206 width, height,
1207 newWidth, newHeight,
1208 tempImage, destAddr);
1209 } else {
1210 const GLint rawBytes = 4;
1211 GLvoid *rawImage = MALLOC(width * height * rawBytes);
1212 if (!rawImage) {
1213 return GL_FALSE;
1214 }
1215 tempImage = MALLOC(newWidth * newHeight * rawBytes);
1216 if (!tempImage) {
1217 FREE(rawImage);
1218 return GL_FALSE;
1219 }
1220 /* unpack image, apply transfer ops and store in rawImage */
1221 _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
1222 &_mesa_texformat_rgba8888_rev, rawImage,
1223 0, 0, 0, /* dstX/Y/Zoffset */
1224 width * rawBytes, /* dstRowStride */
1225 &dstImageOffsets,
1226 width, height, 1,
1227 format, type, pixels, packing);
1228 _mesa_rescale_teximage2d(rawBytes,
1229 width,
1230 newWidth * rawBytes, /* dst stride */
1231 width, height, /* src */
1232 newWidth, newHeight, /* dst */
1233 rawImage /*src*/, tempImage /*dst*/ );
1234 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1235 texImage->TexFormat, texImage->Data,
1236 xoffset * mml->wScale, yoffset * mml->hScale, 0, /* dstX/Y/Zoffset */
1237 dstRowStride,
1238 &dstImageOffsets,
1239 newWidth, newHeight, 1,
1240 GL_RGBA, CHAN_TYPE, tempImage, &ctx->DefaultPacking);
1241 FREE(rawImage);
1242 }
1243
1244 FREE(tempImage);
1245
1246 return GL_TRUE;
1247 }
1248
1249
1250 static void
1251 tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
1252 GLint internalFormat, GLint width, GLint height, GLint border,
1253 GLenum format, GLenum type, const GLvoid *pixels,
1254 const struct gl_pixelstore_attrib *packing,
1255 struct gl_texture_object *texObj,
1256 struct gl_texture_image *texImage)
1257 {
1258 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1259 tdfxTexInfo *ti;
1260 tdfxMipMapLevel *mml;
1261 GLint texelBytes, dstRowStride;
1262 GLuint mesaFormat;
1263
1264 /*
1265 printf("TexImage id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1266 texObj->Name, texImage->InternalFormat, format, type,
1267 texImage->Width, texImage->Height);
1268 */
1269
1270 ti = TDFX_TEXTURE_DATA(texObj);
1271 if (!ti) {
1272 texObj->DriverData = fxAllocTexObjData(fxMesa);
1273 if (!texObj->DriverData) {
1274 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1275 return;
1276 }
1277 ti = TDFX_TEXTURE_DATA(texObj);
1278 }
1279 assert(ti);
1280
1281 mml = TDFX_TEXIMAGE_DATA(texImage);
1282 if (!mml) {
1283 texImage->DriverData = CALLOC(sizeof(tdfxMipMapLevel));
1284 if (!texImage->DriverData) {
1285 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1286 return;
1287 }
1288 mml = TDFX_TEXIMAGE_DATA(texImage);
1289 }
1290
1291 /* Determine width and height scale factors for texture.
1292 * Remember, Glide is limited to 8:1 aspect ratios.
1293 */
1294 tdfxTexGetInfo(ctx,
1295 texImage->Width, texImage->Height,
1296 NULL, /* lod level */
1297 NULL, /* aspect ratio */
1298 NULL, NULL, /* sscale, tscale */
1299 &mml->wScale, &mml->hScale);
1300
1301 /* rescaled size: */
1302 mml->width = width * mml->wScale;
1303 mml->height = height * mml->hScale;
1304
1305 #if FX_COMPRESS_S3TC_AS_FXT1_HACK
1306 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1307 /* [dBorca] we should update texture's attribute, then,
1308 * because if the application asks us to decompress, we
1309 * have to know the REAL format! Also, DXT3/5 might not
1310 * be correct, since it would mess with "compressedSize".
1311 * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3.
1312 */
1313 if (texImage->IsCompressed) {
1314 switch (internalFormat) {
1315 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1316 case GL_RGB_S3TC:
1317 case GL_RGB4_S3TC:
1318 internalFormat = GL_COMPRESSED_RGB_FXT1_3DFX;
1319 break;
1320 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1321 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1322 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1323 case GL_RGBA_S3TC:
1324 case GL_RGBA4_S3TC:
1325 internalFormat = GL_COMPRESSED_RGBA_FXT1_3DFX;
1326 }
1327 texImage->InternalFormat = internalFormat;
1328 }
1329 #endif
1330 #if FX_TC_NAPALM
1331 if (fxMesa->type >= GR_SSTTYPE_Voodoo4) {
1332 GLenum texNapalm = 0;
1333 if (internalFormat == GL_COMPRESSED_RGB) {
1334 texNapalm = GL_COMPRESSED_RGB_FXT1_3DFX;
1335 } else if (internalFormat == GL_COMPRESSED_RGBA) {
1336 texNapalm = GL_COMPRESSED_RGBA_FXT1_3DFX;
1337 }
1338 if (texNapalm) {
1339 texImage->InternalFormat = internalFormat = texNapalm;
1340 texImage->IsCompressed = GL_TRUE;
1341 }
1342 }
1343 #endif
1344
1345 /* choose the texture format */
1346 assert(ctx->Driver.ChooseTextureFormat);
1347 texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
1348 internalFormat, format, type);
1349 assert(texImage->TexFormat);
1350 mesaFormat = texImage->TexFormat->MesaFormat;
1351 mml->glideFormat = fxGlideFormat(mesaFormat);
1352 ti->info.format = mml->glideFormat;
1353 texImage->FetchTexelc = fxFetchFunction(mesaFormat);
1354 texelBytes = texImage->TexFormat->TexelBytes;
1355
1356 if (texImage->IsCompressed) {
1357 texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
1358 mml->width,
1359 mml->height,
1360 1,
1361 mesaFormat);
1362 dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, mml->width);
1363 texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
1364 } else {
1365 dstRowStride = mml->width * texelBytes;
1366 texImage->Data = _mesa_alloc_texmemory(mml->width * mml->height * texelBytes);
1367 }
1368 if (!texImage->Data) {
1369 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1370 return;
1371 }
1372
1373 if (pixels != NULL) {
1374 if (mml->wScale != 1 || mml->hScale != 1) {
1375 /* rescale image to overcome 1:8 aspect limitation */
1376 if (!adjust2DRatio(ctx,
1377 0, 0,
1378 width, height,
1379 format, type, pixels,
1380 packing,
1381 mml,
1382 texImage,
1383 texelBytes,
1384 dstRowStride)
1385 ) {
1386 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1387 return;
1388 }
1389 }
1390 else {
1391 /* no rescaling needed */
1392 /* unpack image, apply transfer ops and store in texImage->Data */
1393 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1394 texImage->TexFormat, texImage->Data,
1395 0, 0, 0, /* dstX/Y/Zoffset */
1396 dstRowStride,
1397 texImage->ImageOffsets,
1398 width, height, 1,
1399 format, type, pixels, packing);
1400 }
1401
1402 /* GL_SGIS_generate_mipmap */
1403 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1404 GLint mipWidth, mipHeight;
1405 tdfxMipMapLevel *mip;
1406 struct gl_texture_image *mipImage;
1407 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1408 const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
1409
1410 assert(!texImage->IsCompressed);
1411
1412 while (level < texObj->MaxLevel && level < maxLevels - 1) {
1413 mipWidth = width / 2;
1414 if (!mipWidth) {
1415 mipWidth = 1;
1416 }
1417 mipHeight = height / 2;
1418 if (!mipHeight) {
1419 mipHeight = 1;
1420 }
1421 if ((mipWidth == width) && (mipHeight == height)) {
1422 break;
1423 }
1424 _mesa_TexImage2D(target, ++level, internalFormat,
1425 mipWidth, mipHeight, border,
1426 format, type,
1427 NULL);
1428 mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1429 mip = TDFX_TEXIMAGE_DATA(mipImage);
1430 _mesa_halve2x2_teximage2d(ctx,
1431 texImage,
1432 texelBytes,
1433 mml->width, mml->height,
1434 texImage->Data, mipImage->Data);
1435 texImage = mipImage;
1436 mml = mip;
1437 width = mipWidth;
1438 height = mipHeight;
1439 }
1440 }
1441 }
1442
1443 RevalidateTexture(ctx, texObj);
1444
1445 ti->reloadImages = GL_TRUE;
1446 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1447 }
1448
1449
1450 static void
1451 tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1452 GLint xoffset, GLint yoffset,
1453 GLsizei width, GLsizei height,
1454 GLenum format, GLenum type,
1455 const GLvoid *pixels,
1456 const struct gl_pixelstore_attrib *packing,
1457 struct gl_texture_object *texObj,
1458 struct gl_texture_image *texImage )
1459 {
1460 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1461 tdfxTexInfo *ti;
1462 tdfxMipMapLevel *mml;
1463 GLint texelBytes, dstRowStride;
1464
1465 if (!texObj->DriverData) {
1466 _mesa_problem(ctx, "problem in fxDDTexSubImage2D");
1467 return;
1468 }
1469
1470 ti = TDFX_TEXTURE_DATA(texObj);
1471 assert(ti);
1472 mml = TDFX_TEXIMAGE_DATA(texImage);
1473 assert(mml);
1474
1475 assert(texImage->Data); /* must have an existing texture image! */
1476 assert(texImage->_BaseFormat);
1477
1478 texelBytes = texImage->TexFormat->TexelBytes;
1479 if (texImage->IsCompressed) {
1480 dstRowStride = _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, mml->width);
1481 } else {
1482 dstRowStride = mml->width * texelBytes;
1483 }
1484
1485 if (mml->wScale != 1 || mml->hScale != 1) {
1486 /* need to rescale subimage to match mipmap level's rescale factors */
1487 if (!adjust2DRatio(ctx,
1488 xoffset, yoffset,
1489 width, height,
1490 format, type, pixels,
1491 packing,
1492 mml,
1493 texImage,
1494 texelBytes,
1495 dstRowStride)
1496 ) {
1497 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
1498 return;
1499 }
1500 }
1501 else {
1502 /* no rescaling needed */
1503 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1504 texImage->TexFormat, texImage->Data,
1505 xoffset, yoffset, 0,
1506 dstRowStride,
1507 texImage->ImageOffsets,
1508 width, height, 1,
1509 format, type, pixels, packing);
1510 }
1511
1512 /* GL_SGIS_generate_mipmap */
1513 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1514 GLint mipWidth, mipHeight;
1515 tdfxMipMapLevel *mip;
1516 struct gl_texture_image *mipImage;
1517 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1518 const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
1519
1520 assert(!texImage->IsCompressed);
1521
1522 width = texImage->Width;
1523 height = texImage->Height;
1524 while (level < texObj->MaxLevel && level < maxLevels - 1) {
1525 mipWidth = width / 2;
1526 if (!mipWidth) {
1527 mipWidth = 1;
1528 }
1529 mipHeight = height / 2;
1530 if (!mipHeight) {
1531 mipHeight = 1;
1532 }
1533 if ((mipWidth == width) && (mipHeight == height)) {
1534 break;
1535 }
1536 ++level;
1537 mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1538 mip = TDFX_TEXIMAGE_DATA(mipImage);
1539 _mesa_halve2x2_teximage2d(ctx,
1540 texImage,
1541 texelBytes,
1542 mml->width, mml->height,
1543 texImage->Data, mipImage->Data);
1544 texImage = mipImage;
1545 mml = mip;
1546 width = mipWidth;
1547 height = mipHeight;
1548 }
1549 }
1550
1551 ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */
1552 fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX this might be a bit much */
1553 }
1554
1555
1556 static void
1557 tdfxTexImage1D(GLcontext *ctx, GLenum target, GLint level,
1558 GLint internalFormat, GLint width, GLint border,
1559 GLenum format, GLenum type, const GLvoid *pixels,
1560 const struct gl_pixelstore_attrib *packing,
1561 struct gl_texture_object *texObj,
1562 struct gl_texture_image *texImage)
1563 {
1564 tdfxTexImage2D(ctx, target, level,
1565 internalFormat, width, 1, border,
1566 format, type, pixels,
1567 packing,
1568 texObj,
1569 texImage);
1570 }
1571
1572 static void
1573 tdfxTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1574 GLint xoffset,
1575 GLsizei width,
1576 GLenum format, GLenum type,
1577 const GLvoid *pixels,
1578 const struct gl_pixelstore_attrib *packing,
1579 struct gl_texture_object *texObj,
1580 struct gl_texture_image *texImage )
1581 {
1582 tdfxTexSubImage2D(ctx, target, level,
1583 xoffset, 0,
1584 width, 1,
1585 format, type,
1586 pixels,
1587 packing,
1588 texObj,
1589 texImage);
1590 }
1591
1592 /**********************************************************************/
1593 /**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/
1594 /**********************************************************************/
1595
1596 static void
1597 tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
1598 GLint level, GLint internalFormat,
1599 GLsizei width, GLsizei height, GLint border,
1600 GLsizei imageSize, const GLvoid *data,
1601 struct gl_texture_object *texObj,
1602 struct gl_texture_image *texImage)
1603 {
1604 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1605 tdfxTexInfo *ti;
1606 tdfxMipMapLevel *mml;
1607 GLuint mesaFormat;
1608
1609 if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
1610 fprintf(stderr, "tdfxCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1611 texObj->Name, internalFormat,
1612 width, height);
1613 }
1614
1615 if ((target != GL_TEXTURE_1D && target != GL_TEXTURE_2D) || texImage->Border > 0) {
1616 _mesa_problem(NULL, "tdfx: unsupported texture in tdfxCompressedTexImg()\n");
1617 return;
1618 }
1619
1620 assert(texImage->IsCompressed);
1621
1622 ti = TDFX_TEXTURE_DATA(texObj);
1623 if (!ti) {
1624 texObj->DriverData = fxAllocTexObjData(fxMesa);
1625 if (!texObj->DriverData) {
1626 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1627 return;
1628 }
1629 ti = TDFX_TEXTURE_DATA(texObj);
1630 }
1631 assert(ti);
1632
1633 mml = TDFX_TEXIMAGE_DATA(texImage);
1634 if (!mml) {
1635 texImage->DriverData = CALLOC(sizeof(tdfxMipMapLevel));
1636 if (!texImage->DriverData) {
1637 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1638 return;
1639 }
1640 mml = TDFX_TEXIMAGE_DATA(texImage);
1641 }
1642
1643 tdfxTexGetInfo(ctx, width, height, NULL, NULL, NULL, NULL,
1644 &mml->wScale, &mml->hScale);
1645
1646 mml->width = width * mml->wScale;
1647 mml->height = height * mml->hScale;
1648
1649
1650 /* choose the texture format */
1651 assert(ctx->Driver.ChooseTextureFormat);
1652 texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
1653 internalFormat, -1/*format*/, -1/*type*/);
1654 assert(texImage->TexFormat);
1655
1656 /* Determine the appropriate Glide texel format,
1657 * given the user's internal texture format hint.
1658 */
1659 mesaFormat = texImage->TexFormat->MesaFormat;
1660 mml->glideFormat = fxGlideFormat(mesaFormat);
1661 ti->info.format = mml->glideFormat;
1662 texImage->FetchTexelc = fxFetchFunction(mesaFormat);
1663
1664 /* allocate new storage for texture image, if needed */
1665 if (!texImage->Data) {
1666 texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
1667 mml->width,
1668 mml->height,
1669 1,
1670 mesaFormat);
1671 texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
1672 if (!texImage->Data) {
1673 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1674 return;
1675 }
1676 }
1677
1678 /* save the texture data */
1679 if (mml->wScale != 1 || mml->hScale != 1) {
1680 /* [dBorca] Hack alert:
1681 * now we're screwed. We can't decompress,
1682 * unless we do it in HW (via textureBuffer).
1683 * We still have some chances:
1684 * 1) we got FXT1 textures - we CAN decompress, rescale for
1685 * aspectratio, then compress back.
1686 * 2) there is a chance that MIN("s", "t") won't be overflowed.
1687 * Thus, we don't care about textureclamp and we could lower
1688 * MIN("uscale", "vscale") below 32. We still have to have
1689 * our data aligned inside a 8:1 rectangle.
1690 * 3) just in case if MIN("s", "t") gets overflowed with GL_REPEAT,
1691 * we replicate the data over the padded area.
1692 * For now, we take 2) + 3) but texelfetchers will be wrong!
1693 */
1694 const GLuint mesaFormat = texImage->TexFormat->MesaFormat;
1695 GLuint srcRowStride = _mesa_compressed_row_stride(mesaFormat, width);
1696
1697 GLuint destRowStride = _mesa_compressed_row_stride(mesaFormat,
1698 mml->width);
1699
1700 _mesa_upscale_teximage2d(srcRowStride, (height+3) / 4,
1701 destRowStride, (mml->height+3) / 4,
1702 1, data, srcRowStride,
1703 texImage->Data);
1704 ti->padded = GL_TRUE;
1705 } else {
1706 MEMCPY(texImage->Data, data, texImage->CompressedSize);
1707 }
1708
1709 /* GL_SGIS_generate_mipmap */
1710 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1711 assert(!texImage->IsCompressed);
1712 }
1713
1714 RevalidateTexture(ctx, texObj);
1715
1716 ti->reloadImages = GL_TRUE;
1717 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1718 }
1719
1720
1721 static void
1722 tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
1723 GLint level, GLint xoffset,
1724 GLint yoffset, GLsizei width,
1725 GLint height, GLenum format,
1726 GLsizei imageSize, const GLvoid *data,
1727 struct gl_texture_object *texObj,
1728 struct gl_texture_image *texImage )
1729 {
1730 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1731 tdfxTexInfo *ti;
1732 tdfxMipMapLevel *mml;
1733 GLint destRowStride, srcRowStride;
1734 GLint i, rows;
1735 GLubyte *dest;
1736 const GLuint mesaFormat = texImage->TexFormat->MesaFormat;
1737
1738 if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
1739 fprintf(stderr, "tdfxCompressedTexSubImage2D: id=%d\n", texObj->Name);
1740 }
1741
1742 ti = TDFX_TEXTURE_DATA(texObj);
1743 assert(ti);
1744 mml = TDFX_TEXIMAGE_DATA(texImage);
1745 assert(mml);
1746
1747 srcRowStride = _mesa_compressed_row_stride(mesaFormat, width);
1748
1749 destRowStride = _mesa_compressed_row_stride(mesaFormat, mml->width);
1750 dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
1751 mesaFormat,
1752 mml->width,
1753 (GLubyte*) texImage->Data);
1754
1755 rows = height / 4; /* [dBorca] hardcoded 4, but works for FXT1/DXTC */
1756
1757 for (i = 0; i < rows; i++) {
1758 MEMCPY(dest, data, srcRowStride);
1759 dest += destRowStride;
1760 data = (GLvoid *)((GLuint)data + (GLuint)srcRowStride);
1761 }
1762
1763 /* [dBorca] Hack alert:
1764 * see fxDDCompressedTexImage2D for caveats
1765 */
1766 if (mml->wScale != 1 || mml->hScale != 1) {
1767 srcRowStride = _mesa_compressed_row_stride(mesaFormat, texImage->Width);
1768
1769 destRowStride = _mesa_compressed_row_stride(mesaFormat, mml->width);
1770 _mesa_upscale_teximage2d(srcRowStride, texImage->Height / 4,
1771 destRowStride, mml->height / 4,
1772 1, texImage->Data, destRowStride,
1773 texImage->Data);
1774 }
1775
1776 /* GL_SGIS_generate_mipmap */
1777 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1778 assert(!texImage->IsCompressed);
1779 }
1780
1781 RevalidateTexture(ctx, texObj);
1782
1783 ti->reloadImages = GL_TRUE;
1784 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1785 }
1786
1787
1788 #if 0
1789 static void
1790 PrintTexture(int w, int h, int c, const GLubyte * data)
1791 {
1792 int i, j;
1793 for (i = 0; i < h; i++) {
1794 for (j = 0; j < w; j++) {
1795 if (c == 2)
1796 printf("%02x %02x ", data[0], data[1]);
1797 else if (c == 3)
1798 printf("%02x %02x %02x ", data[0], data[1], data[2]);
1799 data += c;
1800 }
1801 printf("\n");
1802 }
1803 }
1804 #endif
1805
1806
1807 GLboolean
1808 tdfxTestProxyTexImage(GLcontext *ctx, GLenum target,
1809 GLint level, GLint internalFormat,
1810 GLenum format, GLenum type,
1811 GLint width, GLint height,
1812 GLint depth, GLint border)
1813 {
1814 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1815 struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared;
1816 struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData;
1817
1818 switch (target) {
1819 case GL_PROXY_TEXTURE_1D:
1820 /*JJJ wrong*/
1821 case GL_PROXY_TEXTURE_2D:
1822 {
1823 struct gl_texture_object *tObj;
1824 tdfxTexInfo *ti;
1825 int memNeeded;
1826
1827 tObj = ctx->Texture.Proxy2D;
1828 if (!tObj->DriverData)
1829 tObj->DriverData = fxAllocTexObjData(fxMesa);
1830 ti = TDFX_TEXTURE_DATA(tObj);
1831 assert(ti);
1832
1833 /* assign the parameters to test against */
1834 tObj->Image[0][level]->Width = width;
1835 tObj->Image[0][level]->Height = height;
1836 tObj->Image[0][level]->Border = border;
1837 #if 0
1838 tObj->Image[0][level]->InternalFormat = internalFormat;
1839 #endif
1840 if (level == 0) {
1841 /* don't use mipmap levels > 0 */
1842 tObj->MinFilter = tObj->MagFilter = GL_NEAREST;
1843 }
1844 else {
1845 /* test with all mipmap levels */
1846 tObj->MinFilter = GL_LINEAR_MIPMAP_LINEAR;
1847 tObj->MagFilter = GL_NEAREST;
1848 }
1849 RevalidateTexture(ctx, tObj);
1850
1851 /*
1852 printf("small lodlog2 0x%x\n", ti->info.smallLodLog2);
1853 printf("large lodlog2 0x%x\n", ti->info.largeLodLog2);
1854 printf("aspect ratio 0x%x\n", ti->info.aspectRatioLog2);
1855 printf("glide format 0x%x\n", ti->info.format);
1856 printf("data %p\n", ti->info.data);
1857 printf("lodblend %d\n", (int) ti->LODblend);
1858 */
1859
1860 /* determine where texture will reside */
1861 if (ti->LODblend && !shared->umaTexMemory) {
1862 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1863 memNeeded = fxMesa->Glide.grTexTextureMemRequired(
1864 GR_MIPMAPLEVELMASK_BOTH, &(ti->info));
1865 }
1866 else {
1867 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1868 memNeeded = fxMesa->Glide.grTexTextureMemRequired(
1869 GR_MIPMAPLEVELMASK_BOTH, &(ti->info));
1870 }
1871 /*
1872 printf("Proxy test %d > %d\n", memNeeded, shared->totalTexMem[0]);
1873 */
1874 if (memNeeded > shared->totalTexMem[0])
1875 return GL_FALSE;
1876 else
1877 return GL_TRUE;
1878 }
1879 case GL_PROXY_TEXTURE_3D:
1880 return GL_TRUE; /* software rendering */
1881 default:
1882 return GL_TRUE; /* never happens, silence compiler */
1883 }
1884 }
1885
1886
1887 /**
1888 * Allocate a new texture object.
1889 * Called via ctx->Driver.NewTextureObject.
1890 * Note: this function will be called during context creation to
1891 * allocate the default texture objects.
1892 * Note: we could use containment here to 'derive' the driver-specific
1893 * texture object from the core mesa gl_texture_object. Not done at this time.
1894 */
1895 static struct gl_texture_object *
1896 tdfxNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
1897 {
1898 struct gl_texture_object *obj;
1899 obj = _mesa_new_texture_object(ctx, name, target);
1900 return obj;
1901 }
1902
1903
1904 void tdfxInitTextureFuncs( struct dd_function_table *functions )
1905 {
1906 functions->BindTexture = tdfxBindTexture;
1907 functions->NewTextureObject = tdfxNewTextureObject;
1908 functions->DeleteTexture = tdfxDeleteTexture;
1909 functions->TexEnv = tdfxTexEnv;
1910 functions->TexParameter = tdfxTexParameter;
1911 functions->ChooseTextureFormat = tdfxChooseTextureFormat;
1912 functions->TexImage1D = tdfxTexImage1D;
1913 functions->TexSubImage1D = tdfxTexSubImage1D;
1914 functions->TexImage2D = tdfxTexImage2D;
1915 functions->TexSubImage2D = tdfxTexSubImage2D;
1916 functions->IsTextureResident = tdfxIsTextureResident;
1917 functions->CompressedTexImage2D = tdfxCompressedTexImage2D;
1918 functions->CompressedTexSubImage2D = tdfxCompressedTexSubImage2D;
1919 functions->UpdateTexturePalette = tdfxUpdateTexturePalette;
1920 }