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