Bug #5754: Allocate texture memory correctly. (Richard Drummond)
[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 "texcompress.h"
45 #include "texformat.h"
46 #include "teximage.h"
47 #include "texstore.h"
48 #include "texobj.h"
49 #include "tdfx_context.h"
50 #include "tdfx_tex.h"
51 #include "tdfx_texman.h"
52
53
54 /* no borders! can't halve 1x1! (stride > width * comp) not allowed */
55 void
56 _mesa_halve2x2_teximage2d ( GLcontext *ctx,
57 struct gl_texture_image *texImage,
58 GLuint bytesPerPixel,
59 GLint srcWidth, GLint srcHeight,
60 const GLvoid *srcImage, GLvoid *dstImage )
61 {
62 GLint i, j, k;
63 GLint dstWidth = srcWidth / 2;
64 GLint dstHeight = srcHeight / 2;
65 GLint srcRowStride = srcWidth * bytesPerPixel;
66 GLubyte *src = (GLubyte *)srcImage;
67 GLubyte *dst = dstImage;
68
69 GLuint bpt = 0;
70 GLubyte *_s = NULL;
71 GLubyte *_d = NULL;
72 GLenum _t = 0;
73
74 if (texImage->TexFormat->MesaFormat == MESA_FORMAT_RGB565) {
75 _t = GL_UNSIGNED_SHORT_5_6_5_REV;
76 bpt = bytesPerPixel;
77 } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB4444) {
78 _t = GL_UNSIGNED_SHORT_4_4_4_4_REV;
79 bpt = bytesPerPixel;
80 } else if (texImage->TexFormat->MesaFormat == MESA_FORMAT_ARGB1555) {
81 _t = GL_UNSIGNED_SHORT_1_5_5_5_REV;
82 bpt = bytesPerPixel;
83 }
84 if (bpt) {
85 bytesPerPixel = 4;
86 srcRowStride = srcWidth * bytesPerPixel;
87 if (dstWidth == 0) {
88 dstWidth = 1;
89 }
90 if (dstHeight == 0) {
91 dstHeight = 1;
92 }
93 _s = src = MALLOC(srcRowStride * srcHeight);
94 _d = dst = MALLOC(dstWidth * bytesPerPixel * dstHeight);
95 _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
96 &_mesa_texformat_rgba8888_rev, src,
97 0, 0, 0, /* dstX/Y/Zoffset */
98 srcRowStride, /* dstRowStride */
99 0, /* dstImageStride */
100 srcWidth, srcHeight, 1,
101 texImage->_BaseFormat, _t, srcImage, &ctx->DefaultPacking);
102 }
103
104 if (srcHeight == 1) {
105 for (i = 0; i < dstWidth; i++) {
106 for (k = 0; k < bytesPerPixel; k++) {
107 dst[0] = (src[0] + src[bytesPerPixel] + 1) / 2;
108 src++;
109 dst++;
110 }
111 src += bytesPerPixel;
112 }
113 } else if (srcWidth == 1) {
114 for (j = 0; j < dstHeight; j++) {
115 for (k = 0; k < bytesPerPixel; k++) {
116 dst[0] = (src[0] + src[srcRowStride] + 1) / 2;
117 src++;
118 dst++;
119 }
120 src += srcRowStride;
121 }
122 } else {
123 for (j = 0; j < dstHeight; j++) {
124 for (i = 0; i < dstWidth; i++) {
125 for (k = 0; k < bytesPerPixel; k++) {
126 dst[0] = (src[0] +
127 src[bytesPerPixel] +
128 src[srcRowStride] +
129 src[srcRowStride + bytesPerPixel] + 2) / 4;
130 src++;
131 dst++;
132 }
133 src += bytesPerPixel;
134 }
135 src += srcRowStride;
136 }
137 }
138
139 if (bpt) {
140 src = _s;
141 dst = _d;
142 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
143 texImage->TexFormat, dstImage,
144 0, 0, 0, /* dstX/Y/Zoffset */
145 dstWidth * bpt,
146 0, /* dstImageStride */
147 dstWidth, dstHeight, 1,
148 GL_BGRA, CHAN_TYPE, dst, &ctx->DefaultPacking);
149 FREE(dst);
150 FREE(src);
151 }
152 }
153
154
155 static int
156 logbase2(int n)
157 {
158 GLint i = 1;
159 GLint log2 = 0;
160
161 if (n < 0) {
162 return -1;
163 }
164
165 while (n > i) {
166 i *= 2;
167 log2++;
168 }
169 if (i != n) {
170 return -1;
171 }
172 else {
173 return log2;
174 }
175 }
176
177
178 /*
179 * Compute various texture image parameters.
180 * Input: w, h - source texture width and height
181 * Output: lodlevel - Glide lod level token for the larger texture dimension
182 * aspectratio - Glide aspect ratio token
183 * sscale - S scale factor used during triangle setup
184 * tscale - T scale factor used during triangle setup
185 * wscale - OpenGL -> Glide image width scale factor
186 * hscale - OpenGL -> Glide image height scale factor
187 *
188 * Sample results:
189 * w h lodlevel aspectRatio
190 * 128 128 GR_LOD_LOG2_128 (=7) GR_ASPECT_LOG2_1x1 (=0)
191 * 64 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x1 (=0)
192 * 64 32 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_2x1 (=1)
193 * 32 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x2 (=-1)
194 * 32 32 GR_LOD_LOG2_32 (=5) GR_ASPECT_LOG2_1x1 (=0)
195 */
196 static void
197 tdfxTexGetInfo(const GLcontext *ctx, int w, int h,
198 GrLOD_t *lodlevel, GrAspectRatio_t *aspectratio,
199 float *sscale, float *tscale,
200 int *wscale, int *hscale)
201 {
202 int logw, logh, ar, lod, ws, hs;
203 float s, t;
204
205 ASSERT(w >= 1);
206 ASSERT(h >= 1);
207
208 logw = logbase2(w);
209 logh = logbase2(h);
210 ar = logw - logh; /* aspect ratio = difference in log dimensions */
211 s = t = 256.0;
212 ws = hs = 1;
213
214 /* Hardware only allows a maximum aspect ratio of 8x1, so handle
215 |ar| > 3 by scaling the image and using an 8x1 aspect ratio */
216 if (ar >= 0) {
217 ASSERT(w >= h);
218 lod = logw;
219 if (ar <= GR_ASPECT_LOG2_8x1) {
220 t = 256 >> ar;
221 }
222 else {
223 /* have to stretch image height */
224 t = 32.0;
225 hs = 1 << (ar - 3);
226 ar = GR_ASPECT_LOG2_8x1;
227 }
228 }
229 else {
230 ASSERT(w < h);
231 lod = logh;
232 if (ar >= GR_ASPECT_LOG2_1x8) {
233 s = 256 >> -ar;
234 }
235 else {
236 /* have to stretch image width */
237 s = 32.0;
238 ws = 1 << (-ar - 3);
239 ar = GR_ASPECT_LOG2_1x8;
240 }
241 }
242
243 if (lodlevel)
244 *lodlevel = (GrLOD_t) lod;
245 if (aspectratio)
246 *aspectratio = (GrAspectRatio_t) ar;
247 if (sscale)
248 *sscale = s;
249 if (tscale)
250 *tscale = t;
251 if (wscale)
252 *wscale = ws;
253 if (hscale)
254 *hscale = hs;
255 }
256
257
258 /*
259 * We need to call this when a texture object's minification filter
260 * or texture image sizes change.
261 */
262 static void RevalidateTexture(GLcontext *ctx, struct gl_texture_object *tObj)
263 {
264 tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj);
265 GLint minl, maxl;
266
267 if (!ti)
268 return;
269
270 minl = maxl = tObj->BaseLevel;
271
272 if (tObj->Image[0][minl]) {
273 maxl = MIN2(tObj->MaxLevel, tObj->Image[0][minl]->MaxLog2);
274
275 /* compute largeLodLog2, aspect ratio and texcoord scale factors */
276 tdfxTexGetInfo(ctx, tObj->Image[0][minl]->Width, tObj->Image[0][minl]->Height,
277 &ti->info.largeLodLog2,
278 &ti->info.aspectRatioLog2,
279 &(ti->sScale), &(ti->tScale), NULL, NULL);
280 }
281
282 if (tObj->Image[0][maxl] && (tObj->MinFilter != GL_NEAREST) && (tObj->MinFilter != GL_LINEAR)) {
283 /* mipmapping: need to compute smallLodLog2 */
284 tdfxTexGetInfo(ctx, tObj->Image[0][maxl]->Width,
285 tObj->Image[0][maxl]->Height,
286 &ti->info.smallLodLog2, NULL,
287 NULL, NULL, NULL, NULL);
288 }
289 else {
290 /* not mipmapping: smallLodLog2 = largeLodLog2 */
291 ti->info.smallLodLog2 = ti->info.largeLodLog2;
292 maxl = minl;
293 }
294
295 ti->minLevel = minl;
296 ti->maxLevel = maxl;
297 ti->info.data = NULL;
298
299 /* this is necessary because of fxDDCompressedTexImage2D */
300 if (ti->padded) {
301 struct gl_texture_image *texImage = tObj->Image[0][minl];
302 tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
303 if (mml->wScale != 1 || mml->hScale != 1) {
304 ti->sScale /= mml->wScale;
305 ti->tScale /= mml->hScale;
306 }
307 }
308 }
309
310
311 static tdfxTexInfo *
312 fxAllocTexObjData(tdfxContextPtr fxMesa)
313 {
314 tdfxTexInfo *ti;
315
316 if (!(ti = CALLOC(sizeof(tdfxTexInfo)))) {
317 _mesa_problem(NULL, "tdfx driver: out of memory");
318 return NULL;
319 }
320
321 ti->isInTM = GL_FALSE;
322
323 ti->whichTMU = TDFX_TMU_NONE;
324
325 ti->tm[TDFX_TMU0] = NULL;
326 ti->tm[TDFX_TMU1] = NULL;
327
328 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
329 ti->magFilt = GR_TEXTUREFILTER_BILINEAR;
330
331 ti->sClamp = GR_TEXTURECLAMP_WRAP;
332 ti->tClamp = GR_TEXTURECLAMP_WRAP;
333
334 ti->mmMode = GR_MIPMAP_NEAREST;
335 ti->LODblend = FXFALSE;
336
337 return ti;
338 }
339
340
341 /*
342 * Called via glBindTexture.
343 */
344 static void
345 tdfxBindTexture(GLcontext * ctx, GLenum target,
346 struct gl_texture_object *tObj)
347 {
348 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
349 tdfxTexInfo *ti;
350
351 if (MESA_VERBOSE & VERBOSE_DRIVER) {
352 fprintf(stderr, "fxmesa: fxDDTexBind(%d,%p)\n", tObj->Name,
353 tObj->DriverData);
354 }
355
356 if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))
357 return;
358
359 if (!tObj->DriverData) {
360 tObj->DriverData = fxAllocTexObjData(fxMesa);
361 }
362
363 ti = TDFX_TEXTURE_DATA(tObj);
364 ti->lastTimeUsed = fxMesa->texBindNumber++;
365
366 fxMesa->new_state |= TDFX_NEW_TEXTURE;
367 }
368
369
370 /*
371 * Called via glTexEnv.
372 */
373 static void
374 tdfxTexEnv(GLcontext * ctx, GLenum target, GLenum pname,
375 const GLfloat * param)
376 {
377 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
378
379 if ( TDFX_DEBUG & DEBUG_VERBOSE_API ) {
380 if (param)
381 fprintf(stderr, "fxmesa: texenv(%x,%x)\n", pname,
382 (GLint) (*param));
383 else
384 fprintf(stderr, "fxmesa: texenv(%x)\n", pname);
385 }
386
387 /* XXX this is a bit of a hack to force the Glide texture
388 * state to be updated.
389 */
390 fxMesa->TexState.EnvMode[ctx->Texture.CurrentUnit] = 0;
391
392 fxMesa->new_state |= TDFX_NEW_TEXTURE;
393 }
394
395
396 /*
397 * Called via glTexParameter.
398 */
399 static void
400 tdfxTexParameter(GLcontext * ctx, GLenum target,
401 struct gl_texture_object *tObj,
402 GLenum pname, const GLfloat * params)
403 {
404 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
405 GLenum param = (GLenum) (GLint) params[0];
406 tdfxTexInfo *ti;
407
408 if (MESA_VERBOSE & VERBOSE_DRIVER) {
409 fprintf(stderr, "fxmesa: fxDDTexParam(%d,%p,%x,%x)\n", tObj->Name,
410 tObj->DriverData, pname, param);
411 }
412
413 if ((target != GL_TEXTURE_1D) && (target != GL_TEXTURE_2D))
414 return;
415
416 if (!tObj->DriverData)
417 tObj->DriverData = fxAllocTexObjData(fxMesa);
418
419 ti = TDFX_TEXTURE_DATA(tObj);
420
421 switch (pname) {
422 case GL_TEXTURE_MIN_FILTER:
423 switch (param) {
424 case GL_NEAREST:
425 ti->mmMode = GR_MIPMAP_DISABLE;
426 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
427 ti->LODblend = FXFALSE;
428 break;
429 case GL_LINEAR:
430 ti->mmMode = GR_MIPMAP_DISABLE;
431 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;
432 ti->LODblend = FXFALSE;
433 break;
434 case GL_NEAREST_MIPMAP_LINEAR:
435 if (!fxMesa->Glide.HaveCombineExt) {
436 if (fxMesa->haveTwoTMUs) {
437 ti->mmMode = GR_MIPMAP_NEAREST;
438 ti->LODblend = FXTRUE;
439 }
440 else {
441 ti->mmMode = GR_MIPMAP_NEAREST_DITHER;
442 ti->LODblend = FXFALSE;
443 }
444 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
445 break;
446 }
447 /* XXX Voodoo3/Banshee mipmap blending seems to produce
448 * incorrectly filtered colors for the smallest mipmap levels.
449 * To work-around we fall-through here and use a different filter.
450 */
451 case GL_NEAREST_MIPMAP_NEAREST:
452 ti->mmMode = GR_MIPMAP_NEAREST;
453 ti->minFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
454 ti->LODblend = FXFALSE;
455 break;
456 case GL_LINEAR_MIPMAP_LINEAR:
457 if (!fxMesa->Glide.HaveCombineExt) {
458 if (fxMesa->haveTwoTMUs) {
459 ti->mmMode = GR_MIPMAP_NEAREST;
460 ti->LODblend = FXTRUE;
461 }
462 else {
463 ti->mmMode = GR_MIPMAP_NEAREST_DITHER;
464 ti->LODblend = FXFALSE;
465 }
466 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;
467 break;
468 }
469 /* XXX Voodoo3/Banshee mipmap blending seems to produce
470 * incorrectly filtered colors for the smallest mipmap levels.
471 * To work-around we fall-through here and use a different filter.
472 */
473 case GL_LINEAR_MIPMAP_NEAREST:
474 ti->mmMode = GR_MIPMAP_NEAREST;
475 ti->minFilt = GR_TEXTUREFILTER_BILINEAR;
476 ti->LODblend = FXFALSE;
477 break;
478 default:
479 break;
480 }
481 ti->reloadImages = GL_TRUE;
482 RevalidateTexture(ctx, tObj);
483 fxMesa->new_state |= TDFX_NEW_TEXTURE;
484 break;
485
486 case GL_TEXTURE_MAG_FILTER:
487 switch (param) {
488 case GL_NEAREST:
489 ti->magFilt = GR_TEXTUREFILTER_POINT_SAMPLED;
490 break;
491 case GL_LINEAR:
492 ti->magFilt = GR_TEXTUREFILTER_BILINEAR;
493 break;
494 default:
495 break;
496 }
497 fxMesa->new_state |= TDFX_NEW_TEXTURE;
498 break;
499
500 case GL_TEXTURE_WRAP_S:
501 switch (param) {
502 case GL_CLAMP_TO_BORDER:
503 case GL_CLAMP_TO_EDGE:
504 case GL_CLAMP:
505 ti->sClamp = GR_TEXTURECLAMP_CLAMP;
506 break;
507 case GL_REPEAT:
508 ti->sClamp = GR_TEXTURECLAMP_WRAP;
509 break;
510 case GL_MIRRORED_REPEAT:
511 ti->sClamp = GR_TEXTURECLAMP_MIRROR_EXT;
512 break;
513 default:
514 break;
515 }
516 fxMesa->new_state |= TDFX_NEW_TEXTURE;
517 break;
518
519 case GL_TEXTURE_WRAP_T:
520 switch (param) {
521 case GL_CLAMP_TO_BORDER:
522 case GL_CLAMP_TO_EDGE:
523 case GL_CLAMP:
524 ti->tClamp = GR_TEXTURECLAMP_CLAMP;
525 break;
526 case GL_REPEAT:
527 ti->tClamp = GR_TEXTURECLAMP_WRAP;
528 break;
529 case GL_MIRRORED_REPEAT:
530 ti->tClamp = GR_TEXTURECLAMP_MIRROR_EXT;
531 break;
532 default:
533 break;
534 }
535 fxMesa->new_state |= TDFX_NEW_TEXTURE;
536 break;
537
538 case GL_TEXTURE_BORDER_COLOR:
539 /* TO DO */
540 break;
541 case GL_TEXTURE_MIN_LOD:
542 /* TO DO */
543 break;
544 case GL_TEXTURE_MAX_LOD:
545 /* TO DO */
546 break;
547 case GL_TEXTURE_BASE_LEVEL:
548 RevalidateTexture(ctx, tObj);
549 break;
550 case GL_TEXTURE_MAX_LEVEL:
551 RevalidateTexture(ctx, tObj);
552 break;
553
554 default:
555 break;
556 }
557 }
558
559
560 /*
561 * Called via glDeleteTextures to delete a texture object.
562 * Here, we delete the Glide data associated with the texture.
563 */
564 static void
565 tdfxDeleteTexture(GLcontext * ctx, struct gl_texture_object *tObj)
566 {
567 if (ctx && ctx->DriverCtx) {
568 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
569 tdfxTMFreeTexture(fxMesa, tObj);
570 fxMesa->new_state |= TDFX_NEW_TEXTURE;
571 /* Free mipmap images and the texture object itself */
572 _mesa_delete_texture_object(ctx, tObj);
573 }
574 }
575
576
577 /*
578 * Return true if texture is resident, false otherwise.
579 */
580 static GLboolean
581 tdfxIsTextureResident(GLcontext *ctx, struct gl_texture_object *tObj)
582 {
583 tdfxTexInfo *ti = TDFX_TEXTURE_DATA(tObj);
584 return (GLboolean) (ti && ti->isInTM);
585 }
586
587
588
589 /*
590 * Convert a gl_color_table texture palette to Glide's format.
591 */
592 static GrTexTable_t
593 convertPalette(FxU32 data[256], const struct gl_color_table *table)
594 {
595 const GLubyte *tableUB = (const GLubyte *) table->Table;
596 GLint width = table->Size;
597 FxU32 r, g, b, a;
598 GLint i;
599
600 ASSERT(table->Type == GL_UNSIGNED_BYTE);
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
1181 if (!texImage->IsCompressed) {
1182 GLubyte *destAddr;
1183 tempImage = MALLOC(width * height * texelBytes);
1184 if (!tempImage) {
1185 return GL_FALSE;
1186 }
1187
1188 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1189 texImage->TexFormat, tempImage,
1190 0, 0, 0, /* dstX/Y/Zoffset */
1191 width * texelBytes, /* dstRowStride */
1192 0, /* dstImageStride */
1193 width, height, 1,
1194 format, type, pixels, packing);
1195
1196 /* now rescale */
1197 /* compute address of dest subimage within the overal tex image */
1198 destAddr = (GLubyte *) texImage->Data
1199 + (yoffset * mml->hScale * mml->width
1200 + xoffset * mml->wScale) * texelBytes;
1201
1202 _mesa_rescale_teximage2d(texelBytes,
1203 width,
1204 dstRowStride, /* dst stride */
1205 width, height,
1206 newWidth, newHeight,
1207 tempImage, destAddr);
1208 } else {
1209 const GLint rawBytes = 4;
1210 GLvoid *rawImage = MALLOC(width * height * rawBytes);
1211 if (!rawImage) {
1212 return GL_FALSE;
1213 }
1214 tempImage = MALLOC(newWidth * newHeight * rawBytes);
1215 if (!tempImage) {
1216 FREE(rawImage);
1217 return GL_FALSE;
1218 }
1219 /* unpack image, apply transfer ops and store in rawImage */
1220 _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
1221 &_mesa_texformat_rgba8888_rev, rawImage,
1222 0, 0, 0, /* dstX/Y/Zoffset */
1223 width * rawBytes, /* dstRowStride */
1224 0, /* dstImageStride */
1225 width, height, 1,
1226 format, type, pixels, packing);
1227 _mesa_rescale_teximage2d(rawBytes,
1228 width,
1229 newWidth * rawBytes, /* dst stride */
1230 width, height, /* src */
1231 newWidth, newHeight, /* dst */
1232 rawImage /*src*/, tempImage /*dst*/ );
1233 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1234 texImage->TexFormat, texImage->Data,
1235 xoffset * mml->wScale, yoffset * mml->hScale, 0, /* dstX/Y/Zoffset */
1236 dstRowStride,
1237 0, /* dstImageStride */
1238 newWidth, newHeight, 1,
1239 GL_RGBA, CHAN_TYPE, tempImage, &ctx->DefaultPacking);
1240 FREE(rawImage);
1241 }
1242
1243 FREE(tempImage);
1244
1245 return GL_TRUE;
1246 }
1247
1248
1249 static void
1250 tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
1251 GLint internalFormat, GLint width, GLint height, GLint border,
1252 GLenum format, GLenum type, const GLvoid *pixels,
1253 const struct gl_pixelstore_attrib *packing,
1254 struct gl_texture_object *texObj,
1255 struct gl_texture_image *texImage)
1256 {
1257 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1258 tdfxTexInfo *ti;
1259 tdfxMipMapLevel *mml;
1260 GLint texelBytes, dstRowStride;
1261
1262 /*
1263 printf("TexImage id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1264 texObj->Name, texImage->InternalFormat, format, type,
1265 texImage->Width, texImage->Height);
1266 */
1267
1268 ti = TDFX_TEXTURE_DATA(texObj);
1269 if (!ti) {
1270 texObj->DriverData = fxAllocTexObjData(fxMesa);
1271 if (!texObj->DriverData) {
1272 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1273 return;
1274 }
1275 ti = TDFX_TEXTURE_DATA(texObj);
1276 }
1277 assert(ti);
1278
1279 mml = TDFX_TEXIMAGE_DATA(texImage);
1280 if (!mml) {
1281 texImage->DriverData = CALLOC(sizeof(tdfxMipMapLevel));
1282 if (!texImage->DriverData) {
1283 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1284 return;
1285 }
1286 mml = TDFX_TEXIMAGE_DATA(texImage);
1287 }
1288
1289 /* Determine width and height scale factors for texture.
1290 * Remember, Glide is limited to 8:1 aspect ratios.
1291 */
1292 tdfxTexGetInfo(ctx,
1293 texImage->Width, texImage->Height,
1294 NULL, /* lod level */
1295 NULL, /* aspect ratio */
1296 NULL, NULL, /* sscale, tscale */
1297 &mml->wScale, &mml->hScale);
1298
1299 /* rescaled size: */
1300 mml->width = width * mml->wScale;
1301 mml->height = height * mml->hScale;
1302
1303 #if FX_COMPRESS_S3TC_AS_FXT1_HACK
1304 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1305 /* [dBorca] we should update texture's attribute, then,
1306 * because if the application asks us to decompress, we
1307 * have to know the REAL format! Also, DXT3/5 might not
1308 * be correct, since it would mess with "compressedSize".
1309 * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3.
1310 */
1311 if (texImage->IsCompressed) {
1312 switch (internalFormat) {
1313 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1314 case GL_RGB_S3TC:
1315 case GL_RGB4_S3TC:
1316 internalFormat = GL_COMPRESSED_RGB_FXT1_3DFX;
1317 break;
1318 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1319 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1320 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1321 case GL_RGBA_S3TC:
1322 case GL_RGBA4_S3TC:
1323 internalFormat = GL_COMPRESSED_RGBA_FXT1_3DFX;
1324 }
1325 texImage->InternalFormat = internalFormat;
1326 }
1327 #endif
1328 #if FX_TC_NAPALM
1329 if (fxMesa->type >= GR_SSTTYPE_Voodoo4) {
1330 GLenum texNapalm = 0;
1331 if (internalFormat == GL_COMPRESSED_RGB) {
1332 texNapalm = GL_COMPRESSED_RGB_FXT1_3DFX;
1333 } else if (internalFormat == GL_COMPRESSED_RGBA) {
1334 texNapalm = GL_COMPRESSED_RGBA_FXT1_3DFX;
1335 }
1336 if (texNapalm) {
1337 texImage->InternalFormat = internalFormat = texNapalm;
1338 texImage->IsCompressed = GL_TRUE;
1339 }
1340 }
1341 #endif
1342
1343 /* choose the texture format */
1344 assert(ctx->Driver.ChooseTextureFormat);
1345 texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
1346 internalFormat, format, type);
1347 assert(texImage->TexFormat);
1348 mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
1349 ti->info.format = mml->glideFormat;
1350 texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat);
1351 texelBytes = texImage->TexFormat->TexelBytes;
1352
1353 if (texImage->IsCompressed) {
1354 texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
1355 mml->width,
1356 mml->height,
1357 1,
1358 internalFormat);
1359 dstRowStride = _mesa_compressed_row_stride(internalFormat, mml->width);
1360 texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
1361 } else {
1362 dstRowStride = mml->width * texelBytes;
1363 texImage->Data = _mesa_alloc_texmemory(mml->width * mml->height *
1364 texelBytes);
1365 }
1366 if (!texImage->Data) {
1367 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1368 return;
1369 }
1370
1371 if (pixels != NULL) {
1372 if (mml->wScale != 1 || mml->hScale != 1) {
1373 /* rescale image to overcome 1:8 aspect limitation */
1374 if (!adjust2DRatio(ctx,
1375 0, 0,
1376 width, height,
1377 format, type, pixels,
1378 packing,
1379 mml,
1380 texImage,
1381 texelBytes,
1382 dstRowStride)
1383 ) {
1384 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1385 return;
1386 }
1387 }
1388 else {
1389 /* no rescaling needed */
1390 /* unpack image, apply transfer ops and store in texImage->Data */
1391 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1392 texImage->TexFormat, texImage->Data,
1393 0, 0, 0, /* dstX/Y/Zoffset */
1394 dstRowStride,
1395 0, /* dstImageStride */
1396 width, height, 1,
1397 format, type, pixels, packing);
1398 }
1399
1400 /* GL_SGIS_generate_mipmap */
1401 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1402 GLint mipWidth, mipHeight;
1403 tdfxMipMapLevel *mip;
1404 struct gl_texture_image *mipImage;
1405 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1406 const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
1407
1408 assert(!texImage->IsCompressed);
1409
1410 while (level < texObj->MaxLevel && level < maxLevels - 1) {
1411 mipWidth = width / 2;
1412 if (!mipWidth) {
1413 mipWidth = 1;
1414 }
1415 mipHeight = height / 2;
1416 if (!mipHeight) {
1417 mipHeight = 1;
1418 }
1419 if ((mipWidth == width) && (mipHeight == height)) {
1420 break;
1421 }
1422 _mesa_TexImage2D(target, ++level, internalFormat,
1423 mipWidth, mipHeight, border,
1424 format, type,
1425 NULL);
1426 mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1427 mip = TDFX_TEXIMAGE_DATA(mipImage);
1428 _mesa_halve2x2_teximage2d(ctx,
1429 texImage,
1430 texelBytes,
1431 mml->width, mml->height,
1432 texImage->Data, mipImage->Data);
1433 texImage = mipImage;
1434 mml = mip;
1435 width = mipWidth;
1436 height = mipHeight;
1437 }
1438 }
1439 }
1440
1441 RevalidateTexture(ctx, texObj);
1442
1443 ti->reloadImages = GL_TRUE;
1444 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1445 }
1446
1447
1448 static void
1449 tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1450 GLint xoffset, GLint yoffset,
1451 GLsizei width, GLsizei height,
1452 GLenum format, GLenum type,
1453 const GLvoid *pixels,
1454 const struct gl_pixelstore_attrib *packing,
1455 struct gl_texture_object *texObj,
1456 struct gl_texture_image *texImage )
1457 {
1458 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1459 tdfxTexInfo *ti;
1460 tdfxMipMapLevel *mml;
1461 GLint texelBytes, dstRowStride;
1462
1463 if (!texObj->DriverData) {
1464 _mesa_problem(ctx, "problem in fxDDTexSubImage2D");
1465 return;
1466 }
1467
1468 ti = TDFX_TEXTURE_DATA(texObj);
1469 assert(ti);
1470 mml = TDFX_TEXIMAGE_DATA(texImage);
1471 assert(mml);
1472
1473 assert(texImage->Data); /* must have an existing texture image! */
1474 assert(texImage->_BaseFormat);
1475
1476 texelBytes = texImage->TexFormat->TexelBytes;
1477 if (texImage->IsCompressed) {
1478 dstRowStride = _mesa_compressed_row_stride(texImage->InternalFormat, mml->width);
1479 } else {
1480 dstRowStride = mml->width * texelBytes;
1481 }
1482
1483 if (mml->wScale != 1 || mml->hScale != 1) {
1484 /* need to rescale subimage to match mipmap level's rescale factors */
1485 if (!adjust2DRatio(ctx,
1486 xoffset, yoffset,
1487 width, height,
1488 format, type, pixels,
1489 packing,
1490 mml,
1491 texImage,
1492 texelBytes,
1493 dstRowStride)
1494 ) {
1495 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
1496 return;
1497 }
1498 }
1499 else {
1500 /* no rescaling needed */
1501 texImage->TexFormat->StoreImage(ctx, 2, texImage->_BaseFormat,
1502 texImage->TexFormat, texImage->Data,
1503 xoffset, yoffset, 0,
1504 dstRowStride,
1505 0, /* dstImageStride */
1506 width, height, 1,
1507 format, type, pixels, packing);
1508 }
1509
1510 /* GL_SGIS_generate_mipmap */
1511 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1512 GLint mipWidth, mipHeight;
1513 tdfxMipMapLevel *mip;
1514 struct gl_texture_image *mipImage;
1515 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1516 const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
1517
1518 assert(!texImage->IsCompressed);
1519
1520 width = texImage->Width;
1521 height = texImage->Height;
1522 while (level < texObj->MaxLevel && level < maxLevels - 1) {
1523 mipWidth = width / 2;
1524 if (!mipWidth) {
1525 mipWidth = 1;
1526 }
1527 mipHeight = height / 2;
1528 if (!mipHeight) {
1529 mipHeight = 1;
1530 }
1531 if ((mipWidth == width) && (mipHeight == height)) {
1532 break;
1533 }
1534 ++level;
1535 mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1536 mip = TDFX_TEXIMAGE_DATA(mipImage);
1537 _mesa_halve2x2_teximage2d(ctx,
1538 texImage,
1539 texelBytes,
1540 mml->width, mml->height,
1541 texImage->Data, mipImage->Data);
1542 texImage = mipImage;
1543 mml = mip;
1544 width = mipWidth;
1545 height = mipHeight;
1546 }
1547 }
1548
1549 ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */
1550 fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX this might be a bit much */
1551 }
1552
1553
1554 static void
1555 tdfxTexImage1D(GLcontext *ctx, GLenum target, GLint level,
1556 GLint internalFormat, GLint width, GLint border,
1557 GLenum format, GLenum type, const GLvoid *pixels,
1558 const struct gl_pixelstore_attrib *packing,
1559 struct gl_texture_object *texObj,
1560 struct gl_texture_image *texImage)
1561 {
1562 tdfxTexImage2D(ctx, target, level,
1563 internalFormat, width, 1, border,
1564 format, type, pixels,
1565 packing,
1566 texObj,
1567 texImage);
1568 }
1569
1570 static void
1571 tdfxTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1572 GLint xoffset,
1573 GLsizei width,
1574 GLenum format, GLenum type,
1575 const GLvoid *pixels,
1576 const struct gl_pixelstore_attrib *packing,
1577 struct gl_texture_object *texObj,
1578 struct gl_texture_image *texImage )
1579 {
1580 tdfxTexSubImage2D(ctx, target, level,
1581 xoffset, 0,
1582 width, 1,
1583 format, type,
1584 pixels,
1585 packing,
1586 texObj,
1587 texImage);
1588 }
1589
1590 /**********************************************************************/
1591 /**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/
1592 /**********************************************************************/
1593
1594 static void
1595 tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
1596 GLint level, GLint internalFormat,
1597 GLsizei width, GLsizei height, GLint border,
1598 GLsizei imageSize, const GLvoid *data,
1599 struct gl_texture_object *texObj,
1600 struct gl_texture_image *texImage)
1601 {
1602 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1603 tdfxTexInfo *ti;
1604 tdfxMipMapLevel *mml;
1605
1606 if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
1607 fprintf(stderr, "tdfxCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1608 texObj->Name, internalFormat,
1609 width, height);
1610 }
1611
1612 if ((target != GL_TEXTURE_1D && target != GL_TEXTURE_2D) || texImage->Border > 0) {
1613 _mesa_problem(NULL, "tdfx: unsupported texture in tdfxCompressedTexImg()\n");
1614 return;
1615 }
1616
1617 assert(texImage->IsCompressed);
1618
1619 ti = TDFX_TEXTURE_DATA(texObj);
1620 if (!ti) {
1621 texObj->DriverData = fxAllocTexObjData(fxMesa);
1622 if (!texObj->DriverData) {
1623 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1624 return;
1625 }
1626 ti = TDFX_TEXTURE_DATA(texObj);
1627 }
1628 assert(ti);
1629
1630 mml = TDFX_TEXIMAGE_DATA(texImage);
1631 if (!mml) {
1632 texImage->DriverData = CALLOC(sizeof(tdfxMipMapLevel));
1633 if (!texImage->DriverData) {
1634 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1635 return;
1636 }
1637 mml = TDFX_TEXIMAGE_DATA(texImage);
1638 }
1639
1640 tdfxTexGetInfo(ctx, width, height, NULL, NULL, NULL, NULL,
1641 &mml->wScale, &mml->hScale);
1642
1643 mml->width = width * mml->wScale;
1644 mml->height = height * mml->hScale;
1645
1646
1647 /* choose the texture format */
1648 assert(ctx->Driver.ChooseTextureFormat);
1649 texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
1650 internalFormat, -1/*format*/, -1/*type*/);
1651 assert(texImage->TexFormat);
1652
1653 /* Determine the appropriate Glide texel format,
1654 * given the user's internal texture format hint.
1655 */
1656 mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
1657 ti->info.format = mml->glideFormat;
1658 texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat);
1659
1660 /* allocate new storage for texture image, if needed */
1661 if (!texImage->Data) {
1662 texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
1663 mml->width,
1664 mml->height,
1665 1,
1666 internalFormat);
1667 texImage->Data = _mesa_alloc_texmemory(texImage->CompressedSize);
1668 if (!texImage->Data) {
1669 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1670 return;
1671 }
1672 }
1673
1674 /* save the texture data */
1675 if (mml->wScale != 1 || mml->hScale != 1) {
1676 /* [dBorca] Hack alert:
1677 * now we're screwed. We can't decompress,
1678 * unless we do it in HW (via textureBuffer).
1679 * We still have some chances:
1680 * 1) we got FXT1 textures - we CAN decompress, rescale for
1681 * aspectratio, then compress back.
1682 * 2) there is a chance that MIN("s", "t") won't be overflowed.
1683 * Thus, we don't care about textureclamp and we could lower
1684 * MIN("uscale", "vscale") below 32. We still have to have
1685 * our data aligned inside a 8:1 rectangle.
1686 * 3) just in case if MIN("s", "t") gets overflowed with GL_REPEAT,
1687 * we replicate the data over the padded area.
1688 * For now, we take 2) + 3) but texelfetchers will be wrong!
1689 */
1690 GLuint srcRowStride = _mesa_compressed_row_stride(internalFormat, width);
1691
1692 GLuint destRowStride = _mesa_compressed_row_stride(internalFormat,
1693 mml->width);
1694
1695 _mesa_upscale_teximage2d(srcRowStride, (height+3) / 4,
1696 destRowStride, (mml->height+3) / 4,
1697 1, data, srcRowStride,
1698 texImage->Data);
1699 ti->padded = GL_TRUE;
1700 } else {
1701 MEMCPY(texImage->Data, data, texImage->CompressedSize);
1702 }
1703
1704 /* GL_SGIS_generate_mipmap */
1705 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1706 assert(!texImage->IsCompressed);
1707 }
1708
1709 RevalidateTexture(ctx, texObj);
1710
1711 ti->reloadImages = GL_TRUE;
1712 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1713 }
1714
1715
1716 static void
1717 tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
1718 GLint level, GLint xoffset,
1719 GLint yoffset, GLsizei width,
1720 GLint height, GLenum format,
1721 GLsizei imageSize, const GLvoid *data,
1722 struct gl_texture_object *texObj,
1723 struct gl_texture_image *texImage )
1724 {
1725 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1726 tdfxTexInfo *ti;
1727 tdfxMipMapLevel *mml;
1728 GLint destRowStride, srcRowStride;
1729 GLint i, rows;
1730 GLubyte *dest;
1731
1732 if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
1733 fprintf(stderr, "tdfxCompressedTexSubImage2D: id=%d\n", texObj->Name);
1734 }
1735
1736 ti = TDFX_TEXTURE_DATA(texObj);
1737 assert(ti);
1738 mml = TDFX_TEXIMAGE_DATA(texImage);
1739 assert(mml);
1740
1741 srcRowStride = _mesa_compressed_row_stride(texImage->InternalFormat, width);
1742
1743 destRowStride = _mesa_compressed_row_stride(texImage->InternalFormat,
1744 mml->width);
1745 dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
1746 texImage->InternalFormat,
1747 mml->width,
1748 (GLubyte*) texImage->Data);
1749
1750 rows = height / 4; /* [dBorca] hardcoded 4, but works for FXT1/DXTC */
1751
1752 for (i = 0; i < rows; i++) {
1753 MEMCPY(dest, data, srcRowStride);
1754 dest += destRowStride;
1755 data = (GLvoid *)((GLuint)data + (GLuint)srcRowStride);
1756 }
1757
1758 /* [dBorca] Hack alert:
1759 * see fxDDCompressedTexImage2D for caveats
1760 */
1761 if (mml->wScale != 1 || mml->hScale != 1) {
1762 srcRowStride = _mesa_compressed_row_stride(texImage->InternalFormat, texImage->Width);
1763
1764 destRowStride = _mesa_compressed_row_stride(texImage->InternalFormat,
1765 mml->width);
1766 _mesa_upscale_teximage2d(srcRowStride, texImage->Height / 4,
1767 destRowStride, mml->height / 4,
1768 1, texImage->Data, destRowStride,
1769 texImage->Data);
1770 }
1771
1772 /* GL_SGIS_generate_mipmap */
1773 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1774 assert(!texImage->IsCompressed);
1775 }
1776
1777 RevalidateTexture(ctx, texObj);
1778
1779 ti->reloadImages = GL_TRUE;
1780 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1781 }
1782
1783
1784 #if 0
1785 static void
1786 PrintTexture(int w, int h, int c, const GLubyte * data)
1787 {
1788 int i, j;
1789 for (i = 0; i < h; i++) {
1790 for (j = 0; j < w; j++) {
1791 if (c == 2)
1792 printf("%02x %02x ", data[0], data[1]);
1793 else if (c == 3)
1794 printf("%02x %02x %02x ", data[0], data[1], data[2]);
1795 data += c;
1796 }
1797 printf("\n");
1798 }
1799 }
1800 #endif
1801
1802
1803 GLboolean
1804 tdfxTestProxyTexImage(GLcontext *ctx, GLenum target,
1805 GLint level, GLint internalFormat,
1806 GLenum format, GLenum type,
1807 GLint width, GLint height,
1808 GLint depth, GLint border)
1809 {
1810 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1811 struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared;
1812 struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData;
1813
1814 switch (target) {
1815 case GL_PROXY_TEXTURE_1D:
1816 /*JJJ wrong*/
1817 case GL_PROXY_TEXTURE_2D:
1818 {
1819 struct gl_texture_object *tObj;
1820 tdfxTexInfo *ti;
1821 int memNeeded;
1822
1823 tObj = ctx->Texture.Proxy2D;
1824 if (!tObj->DriverData)
1825 tObj->DriverData = fxAllocTexObjData(fxMesa);
1826 ti = TDFX_TEXTURE_DATA(tObj);
1827 assert(ti);
1828
1829 /* assign the parameters to test against */
1830 tObj->Image[0][level]->Width = width;
1831 tObj->Image[0][level]->Height = height;
1832 tObj->Image[0][level]->Border = border;
1833 #if 0
1834 tObj->Image[0][level]->InternalFormat = internalFormat;
1835 #endif
1836 if (level == 0) {
1837 /* don't use mipmap levels > 0 */
1838 tObj->MinFilter = tObj->MagFilter = GL_NEAREST;
1839 }
1840 else {
1841 /* test with all mipmap levels */
1842 tObj->MinFilter = GL_LINEAR_MIPMAP_LINEAR;
1843 tObj->MagFilter = GL_NEAREST;
1844 }
1845 RevalidateTexture(ctx, tObj);
1846
1847 /*
1848 printf("small lodlog2 0x%x\n", ti->info.smallLodLog2);
1849 printf("large lodlog2 0x%x\n", ti->info.largeLodLog2);
1850 printf("aspect ratio 0x%x\n", ti->info.aspectRatioLog2);
1851 printf("glide format 0x%x\n", ti->info.format);
1852 printf("data %p\n", ti->info.data);
1853 printf("lodblend %d\n", (int) ti->LODblend);
1854 */
1855
1856 /* determine where texture will reside */
1857 if (ti->LODblend && !shared->umaTexMemory) {
1858 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1859 memNeeded = fxMesa->Glide.grTexTextureMemRequired(
1860 GR_MIPMAPLEVELMASK_BOTH, &(ti->info));
1861 }
1862 else {
1863 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1864 memNeeded = fxMesa->Glide.grTexTextureMemRequired(
1865 GR_MIPMAPLEVELMASK_BOTH, &(ti->info));
1866 }
1867 /*
1868 printf("Proxy test %d > %d\n", memNeeded, shared->totalTexMem[0]);
1869 */
1870 if (memNeeded > shared->totalTexMem[0])
1871 return GL_FALSE;
1872 else
1873 return GL_TRUE;
1874 }
1875 case GL_PROXY_TEXTURE_3D:
1876 return GL_TRUE; /* software rendering */
1877 default:
1878 return GL_TRUE; /* never happens, silence compiler */
1879 }
1880 }
1881
1882
1883 /**
1884 * Allocate a new texture object.
1885 * Called via ctx->Driver.NewTextureObject.
1886 * Note: this function will be called during context creation to
1887 * allocate the default texture objects.
1888 * Note: we could use containment here to 'derive' the driver-specific
1889 * texture object from the core mesa gl_texture_object. Not done at this time.
1890 */
1891 static struct gl_texture_object *
1892 tdfxNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
1893 {
1894 struct gl_texture_object *obj;
1895 obj = _mesa_new_texture_object(ctx, name, target);
1896 return obj;
1897 }
1898
1899
1900 void tdfxInitTextureFuncs( struct dd_function_table *functions )
1901 {
1902 functions->BindTexture = tdfxBindTexture;
1903 functions->NewTextureObject = tdfxNewTextureObject;
1904 functions->DeleteTexture = tdfxDeleteTexture;
1905 functions->TexEnv = tdfxTexEnv;
1906 functions->TexParameter = tdfxTexParameter;
1907 functions->ChooseTextureFormat = tdfxChooseTextureFormat;
1908 functions->TexImage1D = tdfxTexImage1D;
1909 functions->TexSubImage1D = tdfxTexSubImage1D;
1910 functions->TexImage2D = tdfxTexImage2D;
1911 functions->TexSubImage2D = tdfxTexSubImage2D;
1912 functions->IsTextureResident = tdfxIsTextureResident;
1913 functions->CompressedTexImage2D = tdfxCompressedTexImage2D;
1914 functions->CompressedTexSubImage2D = tdfxCompressedTexSubImage2D;
1915 functions->UpdateTexturePalette = tdfxUpdateTexturePalette;
1916 }