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