fixed automatic mipmap generation
[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 }
653
654
655
656 static void
657 tdfxUpdateTexturePalette(GLcontext * ctx, struct gl_texture_object *tObj)
658 {
659 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
660
661 if (tObj) {
662 /* per-texture palette */
663 tdfxTexInfo *ti;
664
665 /* This might be a proxy texture. */
666 if (!tObj->Palette.Table)
667 return;
668
669 if (!tObj->DriverData)
670 tObj->DriverData = fxAllocTexObjData(fxMesa);
671 ti = TDFX_TEXTURE_DATA(tObj);
672 assert(ti);
673 ti->paltype = convertPalette(ti->palette.data, &tObj->Palette);
674 /*tdfxTexInvalidate(ctx, tObj);*/
675 }
676 else {
677 /* global texture palette */
678 fxMesa->TexPalette.Type = convertPalette(fxMesa->glbPalette.data, &ctx->Texture.Palette);
679 fxMesa->TexPalette.Data = &(fxMesa->glbPalette.data);
680 fxMesa->dirty |= TDFX_UPLOAD_TEXTURE_PALETTE;
681 }
682 fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX too heavy-handed */
683 }
684
685
686 /**********************************************************************/
687 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
688 /**********************************************************************/
689
690 #if 000
691 static FxBool TexusFatalError = FXFALSE;
692 static FxBool TexusError = FXFALSE;
693
694 #define TX_DITHER_NONE 0x00000000
695
696 static void
697 fxTexusError(const char *string, FxBool fatal)
698 {
699 _mesa_problem(NULL, string);
700 /*
701 * Just propagate the fatal value up.
702 */
703 TexusError = FXTRUE;
704 TexusFatalError = fatal;
705 }
706 #endif
707
708
709 static const struct gl_texture_format *
710 tdfxChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
711 GLenum srcFormat, GLenum srcType )
712 {
713 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
714 const GLboolean allow32bpt = TDFX_IS_NAPALM(fxMesa);
715
716 switch (internalFormat) {
717 case GL_ALPHA:
718 case GL_ALPHA4:
719 case GL_ALPHA8:
720 case GL_ALPHA12:
721 case GL_ALPHA16:
722 case GL_COMPRESSED_ALPHA:
723 return &_mesa_texformat_a8;
724 case 1:
725 case GL_LUMINANCE:
726 case GL_LUMINANCE4:
727 case GL_LUMINANCE8:
728 case GL_LUMINANCE12:
729 case GL_LUMINANCE16:
730 case GL_COMPRESSED_LUMINANCE:
731 return &_mesa_texformat_l8;
732 case 2:
733 case GL_LUMINANCE_ALPHA:
734 case GL_LUMINANCE4_ALPHA4:
735 case GL_LUMINANCE6_ALPHA2:
736 case GL_LUMINANCE8_ALPHA8:
737 case GL_LUMINANCE12_ALPHA4:
738 case GL_LUMINANCE12_ALPHA12:
739 case GL_LUMINANCE16_ALPHA16:
740 case GL_COMPRESSED_LUMINANCE_ALPHA:
741 return &_mesa_texformat_al88;
742 case GL_INTENSITY:
743 case GL_INTENSITY4:
744 case GL_INTENSITY8:
745 case GL_INTENSITY12:
746 case GL_INTENSITY16:
747 case GL_COMPRESSED_INTENSITY:
748 return &_mesa_texformat_i8;
749 case GL_R3_G3_B2:
750 case GL_RGB4:
751 case GL_RGB5:
752 return &_mesa_texformat_rgb565;
753 case GL_COMPRESSED_RGB:
754 /* intentional fall-through */
755 case 3:
756 case GL_RGB:
757 if ( srcFormat == GL_RGB && srcType == GL_UNSIGNED_SHORT_5_6_5 ) {
758 return &_mesa_texformat_rgb565;
759 }
760 /* intentional fall through */
761 case GL_RGB8:
762 case GL_RGB10:
763 case GL_RGB12:
764 case GL_RGB16:
765 return (allow32bpt) ? &_mesa_texformat_argb8888
766 : &_mesa_texformat_rgb565;
767 case GL_RGBA2:
768 case GL_RGBA4:
769 return &_mesa_texformat_argb4444;
770 case GL_COMPRESSED_RGBA:
771 /* intentional fall-through */
772 case 4:
773 case GL_RGBA:
774 if ( srcFormat == GL_BGRA ) {
775 if ( srcType == GL_UNSIGNED_INT_8_8_8_8_REV ) {
776 return &_mesa_texformat_argb8888;
777 }
778 else if ( srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV ) {
779 return &_mesa_texformat_argb4444;
780 }
781 else if ( srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV ) {
782 return &_mesa_texformat_argb1555;
783 }
784 }
785 /* intentional fall through */
786 case GL_RGBA8:
787 case GL_RGB10_A2:
788 case GL_RGBA12:
789 case GL_RGBA16:
790 return allow32bpt ? &_mesa_texformat_argb8888
791 : &_mesa_texformat_argb4444;
792 case GL_RGB5_A1:
793 return &_mesa_texformat_argb1555;
794 case GL_COLOR_INDEX:
795 case GL_COLOR_INDEX1_EXT:
796 case GL_COLOR_INDEX2_EXT:
797 case GL_COLOR_INDEX4_EXT:
798 case GL_COLOR_INDEX8_EXT:
799 case GL_COLOR_INDEX12_EXT:
800 case GL_COLOR_INDEX16_EXT:
801 return &_mesa_texformat_ci8;
802 /* GL_EXT_texture_compression_s3tc */
803 /* GL_S3_s3tc */
804 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
805 case GL_RGB_S3TC:
806 case GL_RGB4_S3TC:
807 return &_mesa_texformat_rgb_dxt1;
808 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
809 return &_mesa_texformat_rgba_dxt1;
810 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
811 case GL_RGBA_S3TC:
812 case GL_RGBA4_S3TC:
813 return &_mesa_texformat_rgba_dxt3;
814 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
815 return &_mesa_texformat_rgba_dxt5;
816 /* GL_3DFX_texture_compression_FXT1 */
817 case GL_COMPRESSED_RGB_FXT1_3DFX:
818 return &_mesa_texformat_rgb_fxt1;
819 case GL_COMPRESSED_RGBA_FXT1_3DFX:
820 return &_mesa_texformat_rgba_fxt1;
821 default:
822 _mesa_problem(ctx, "unexpected format in tdfxChooseTextureFormat");
823 return NULL;
824 }
825 }
826
827
828 /*
829 * Return the Glide format for the given mesa texture format.
830 */
831 static GrTextureFormat_t
832 fxGlideFormat(GLint mesaFormat)
833 {
834 switch (mesaFormat) {
835 case MESA_FORMAT_I8:
836 return GR_TEXFMT_ALPHA_8;
837 case MESA_FORMAT_A8:
838 return GR_TEXFMT_ALPHA_8;
839 case MESA_FORMAT_L8:
840 return GR_TEXFMT_INTENSITY_8;
841 case MESA_FORMAT_CI8:
842 return GR_TEXFMT_P_8;
843 case MESA_FORMAT_AL88:
844 return GR_TEXFMT_ALPHA_INTENSITY_88;
845 case MESA_FORMAT_RGB565:
846 return GR_TEXFMT_RGB_565;
847 case MESA_FORMAT_ARGB4444:
848 return GR_TEXFMT_ARGB_4444;
849 case MESA_FORMAT_ARGB1555:
850 return GR_TEXFMT_ARGB_1555;
851 case MESA_FORMAT_ARGB8888:
852 return GR_TEXFMT_ARGB_8888;
853 case MESA_FORMAT_RGB_FXT1:
854 case MESA_FORMAT_RGBA_FXT1:
855 return GR_TEXFMT_ARGB_CMP_FXT1;
856 case MESA_FORMAT_RGB_DXT1:
857 case MESA_FORMAT_RGBA_DXT1:
858 return GR_TEXFMT_ARGB_CMP_DXT1;
859 case MESA_FORMAT_RGBA_DXT3:
860 return GR_TEXFMT_ARGB_CMP_DXT3;
861 case MESA_FORMAT_RGBA_DXT5:
862 return GR_TEXFMT_ARGB_CMP_DXT5;
863 default:
864 _mesa_problem(NULL, "Unexpected format in fxGlideFormat");
865 return 0;
866 }
867 }
868
869
870 /* Texel-fetch functions for software texturing and glGetTexImage().
871 * We should have been able to use some "standard" fetch functions (which
872 * may get defined in texutil.c) but we have to account for scaled texture
873 * images on tdfx hardware (the 8:1 aspect ratio limit).
874 * Hence, we need special functions here.
875 */
876 extern void
877 fxt1_decode_1 (const void *texture, int width,
878 int i, int j, unsigned char *rgba);
879
880 static void
881 fetch_intensity8(const struct gl_texture_image *texImage,
882 GLint i, GLint j, GLint k, GLchan * rgba)
883 {
884 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
885 const GLubyte *texel;
886
887 i = i * mml->wScale;
888 j = j * mml->hScale;
889
890 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
891 rgba[RCOMP] = *texel;
892 rgba[GCOMP] = *texel;
893 rgba[BCOMP] = *texel;
894 rgba[ACOMP] = *texel;
895 }
896
897
898 static void
899 fetch_luminance8(const struct gl_texture_image *texImage,
900 GLint i, GLint j, GLint k, GLchan * rgba)
901 {
902 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
903 const GLubyte *texel;
904
905 i = i * mml->wScale;
906 j = j * mml->hScale;
907
908 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
909 rgba[RCOMP] = *texel;
910 rgba[GCOMP] = *texel;
911 rgba[BCOMP] = *texel;
912 rgba[ACOMP] = 255;
913 }
914
915
916 static void
917 fetch_alpha8(const struct gl_texture_image *texImage,
918 GLint i, GLint j, GLint k, GLchan * rgba)
919 {
920 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
921 const GLubyte *texel;
922
923 i = i * mml->wScale;
924 j = j * mml->hScale;
925
926 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
927 rgba[RCOMP] = 255;
928 rgba[GCOMP] = 255;
929 rgba[BCOMP] = 255;
930 rgba[ACOMP] = *texel;
931 }
932
933
934 static void
935 fetch_index8(const struct gl_texture_image *texImage,
936 GLint i, GLint j, GLint k, GLchan * indexOut)
937 {
938 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
939 const GLubyte *texel;
940
941 i = i * mml->wScale;
942 j = j * mml->hScale;
943
944 texel = ((GLubyte *) texImage->Data) + j * mml->width + i;
945 *indexOut = *texel;
946 }
947
948
949 static void
950 fetch_luminance8_alpha8(const struct gl_texture_image *texImage,
951 GLint i, GLint j, GLint k, GLchan * rgba)
952 {
953 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
954 const GLubyte *texel;
955
956 i = i * mml->wScale;
957 j = j * mml->hScale;
958
959 texel = ((GLubyte *) texImage->Data) + (j * mml->width + i) * 2;
960 rgba[RCOMP] = texel[0];
961 rgba[GCOMP] = texel[0];
962 rgba[BCOMP] = texel[0];
963 rgba[ACOMP] = texel[1];
964 }
965
966
967 static void
968 fetch_r5g6b5(const struct gl_texture_image *texImage,
969 GLint i, GLint j, GLint k, GLchan * rgba)
970 {
971 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
972 const GLushort *texel;
973
974 i = i * mml->wScale;
975 j = j * mml->hScale;
976
977 texel = ((GLushort *) texImage->Data) + j * mml->width + i;
978 rgba[RCOMP] = (((*texel) >> 11) & 0x1f) * 255 / 31;
979 rgba[GCOMP] = (((*texel) >> 5) & 0x3f) * 255 / 63;
980 rgba[BCOMP] = (((*texel) >> 0) & 0x1f) * 255 / 31;
981 rgba[ACOMP] = 255;
982 }
983
984
985 static void
986 fetch_r4g4b4a4(const struct gl_texture_image *texImage,
987 GLint i, GLint j, GLint k, GLchan * rgba)
988 {
989 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
990 const GLushort *texel;
991
992 i = i * mml->wScale;
993 j = j * mml->hScale;
994
995 texel = ((GLushort *) texImage->Data) + j * mml->width + i;
996 rgba[RCOMP] = (((*texel) >> 12) & 0xf) * 255 / 15;
997 rgba[GCOMP] = (((*texel) >> 8) & 0xf) * 255 / 15;
998 rgba[BCOMP] = (((*texel) >> 4) & 0xf) * 255 / 15;
999 rgba[ACOMP] = (((*texel) >> 0) & 0xf) * 255 / 15;
1000 }
1001
1002
1003 static void
1004 fetch_r5g5b5a1(const struct gl_texture_image *texImage,
1005 GLint i, GLint j, GLint k, GLchan * rgba)
1006 {
1007 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1008 const GLushort *texel;
1009
1010 i = i * mml->wScale;
1011 j = j * mml->hScale;
1012
1013 texel = ((GLushort *) texImage->Data) + j * mml->width + i;
1014 rgba[RCOMP] = (((*texel) >> 11) & 0x1f) * 255 / 31;
1015 rgba[GCOMP] = (((*texel) >> 6) & 0x1f) * 255 / 31;
1016 rgba[BCOMP] = (((*texel) >> 1) & 0x1f) * 255 / 31;
1017 rgba[ACOMP] = (((*texel) >> 0) & 0x01) * 255;
1018 }
1019
1020
1021 static void
1022 fetch_a8r8g8b8(const struct gl_texture_image *texImage,
1023 GLint i, GLint j, GLint k, GLchan * rgba)
1024 {
1025 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1026 const GLuint *texel;
1027
1028 i = i * mml->wScale;
1029 j = j * mml->hScale;
1030
1031 texel = ((GLuint *) texImage->Data) + j * mml->width + i;
1032 rgba[RCOMP] = (((*texel) >> 16) & 0xff);
1033 rgba[GCOMP] = (((*texel) >> 8) & 0xff);
1034 rgba[BCOMP] = (((*texel) ) & 0xff);
1035 rgba[ACOMP] = (((*texel) >> 24) & 0xff);
1036 }
1037
1038
1039 static void
1040 fetch_rgb_fxt1(const struct gl_texture_image *texImage,
1041 GLint i, GLint j, GLint k, GLchan *rgba)
1042 {
1043 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1044
1045 i = i * mml->wScale;
1046 j = j * mml->hScale;
1047
1048 fxt1_decode_1(texImage->Data, mml->width, i, j, rgba);
1049 rgba[ACOMP] = 255;
1050 }
1051
1052
1053 static void
1054 fetch_rgba_fxt1(const struct gl_texture_image *texImage,
1055 GLint i, GLint j, GLint k, GLchan *rgba)
1056 {
1057 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1058
1059 i = i * mml->wScale;
1060 j = j * mml->hScale;
1061
1062 fxt1_decode_1(texImage->Data, mml->width, i, j, rgba);
1063 }
1064
1065
1066 static void
1067 fetch_rgb_dxt1(const struct gl_texture_image *texImage,
1068 GLint i, GLint j, GLint k, GLchan *rgba)
1069 {
1070 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1071
1072 i = i * mml->wScale;
1073 j = j * mml->hScale;
1074
1075 _mesa_texformat_rgb_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
1076 }
1077
1078
1079 static void
1080 fetch_rgba_dxt1(const struct gl_texture_image *texImage,
1081 GLint i, GLint j, GLint k, GLchan *rgba)
1082 {
1083 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1084
1085 i = i * mml->wScale;
1086 j = j * mml->hScale;
1087
1088 _mesa_texformat_rgba_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
1089 }
1090
1091
1092 static void
1093 fetch_rgba_dxt3(const struct gl_texture_image *texImage,
1094 GLint i, GLint j, GLint k, GLchan *rgba)
1095 {
1096 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1097
1098 i = i * mml->wScale;
1099 j = j * mml->hScale;
1100
1101 _mesa_texformat_rgba_dxt3.FetchTexel2D(texImage, i, j, k, rgba);
1102 }
1103
1104
1105 static void
1106 fetch_rgba_dxt5(const struct gl_texture_image *texImage,
1107 GLint i, GLint j, GLint k, GLchan *rgba)
1108 {
1109 const tdfxMipMapLevel *mml = TDFX_TEXIMAGE_DATA(texImage);
1110
1111 i = i * mml->wScale;
1112 j = j * mml->hScale;
1113
1114 _mesa_texformat_rgba_dxt5.FetchTexel2D(texImage, i, j, k, rgba);
1115 }
1116
1117
1118 static FetchTexelFuncC
1119 fxFetchFunction(GLint mesaFormat)
1120 {
1121 switch (mesaFormat) {
1122 case MESA_FORMAT_I8:
1123 return &fetch_intensity8;
1124 case MESA_FORMAT_A8:
1125 return &fetch_alpha8;
1126 case MESA_FORMAT_L8:
1127 return &fetch_luminance8;
1128 case MESA_FORMAT_CI8:
1129 return &fetch_index8;
1130 case MESA_FORMAT_AL88:
1131 return &fetch_luminance8_alpha8;
1132 case MESA_FORMAT_RGB565:
1133 return &fetch_r5g6b5;
1134 case MESA_FORMAT_ARGB4444:
1135 return &fetch_r4g4b4a4;
1136 case MESA_FORMAT_ARGB1555:
1137 return &fetch_r5g5b5a1;
1138 case MESA_FORMAT_ARGB8888:
1139 return &fetch_a8r8g8b8;
1140 case MESA_FORMAT_RGB_FXT1:
1141 return &fetch_rgb_fxt1;
1142 case MESA_FORMAT_RGBA_FXT1:
1143 return &fetch_rgba_fxt1;
1144 case MESA_FORMAT_RGB_DXT1:
1145 return &fetch_rgb_dxt1;
1146 case MESA_FORMAT_RGBA_DXT1:
1147 return &fetch_rgba_dxt1;
1148 case MESA_FORMAT_RGBA_DXT3:
1149 return &fetch_rgba_dxt3;
1150 case MESA_FORMAT_RGBA_DXT5:
1151 return &fetch_rgba_dxt5;
1152 default:
1153 _mesa_problem(NULL, "Unexpected format in fxFetchFunction");
1154 return NULL;
1155 }
1156 }
1157
1158
1159 static GLboolean
1160 adjust2DRatio (GLcontext *ctx,
1161 GLint xoffset, GLint yoffset,
1162 GLint width, GLint height,
1163 GLenum format, GLenum type, const GLvoid *pixels,
1164 const struct gl_pixelstore_attrib *packing,
1165 tdfxMipMapLevel *mml,
1166 struct gl_texture_image *texImage,
1167 GLint texelBytes,
1168 GLint dstRowStride)
1169 {
1170 const GLint newWidth = width * mml->wScale;
1171 const GLint newHeight = height * mml->hScale;
1172 GLvoid *tempImage;
1173
1174 if (!texImage->IsCompressed) {
1175 GLubyte *destAddr;
1176 tempImage = MALLOC(width * height * texelBytes);
1177 if (!tempImage) {
1178 return GL_FALSE;
1179 }
1180
1181 texImage->TexFormat->StoreImage(ctx, 2, texImage->Format,
1182 texImage->TexFormat, tempImage,
1183 0, 0, 0, /* dstX/Y/Zoffset */
1184 width * texelBytes, /* dstRowStride */
1185 0, /* dstImageStride */
1186 width, height, 1,
1187 format, type, pixels, packing);
1188
1189 /* now rescale */
1190 /* compute address of dest subimage within the overal tex image */
1191 destAddr = (GLubyte *) texImage->Data
1192 + (yoffset * mml->hScale * mml->width
1193 + xoffset * mml->wScale) * texelBytes;
1194
1195 _mesa_rescale_teximage2d(texelBytes,
1196 dstRowStride, /* dst stride */
1197 width, height,
1198 newWidth, newHeight,
1199 tempImage, destAddr);
1200 } else {
1201 const GLint rawBytes = 4;
1202 GLvoid *rawImage = MALLOC(width * height * rawBytes);
1203 if (!rawImage) {
1204 return GL_FALSE;
1205 }
1206 tempImage = MALLOC(newWidth * newHeight * rawBytes);
1207 if (!tempImage) {
1208 return GL_FALSE;
1209 }
1210 /* unpack image, apply transfer ops and store in rawImage */
1211 _mesa_texstore_rgba8888(ctx, 2, GL_RGBA,
1212 &_mesa_texformat_rgba8888_rev, rawImage,
1213 0, 0, 0, /* dstX/Y/Zoffset */
1214 width * rawBytes, /* dstRowStride */
1215 0, /* dstImageStride */
1216 width, height, 1,
1217 format, type, pixels, packing);
1218 _mesa_rescale_teximage2d(rawBytes,
1219 newWidth * rawBytes, /* dst stride */
1220 width, height, /* src */
1221 newWidth, newHeight, /* dst */
1222 rawImage /*src*/, tempImage /*dst*/ );
1223 texImage->TexFormat->StoreImage(ctx, 2, texImage->Format,
1224 texImage->TexFormat, texImage->Data,
1225 xoffset * mml->wScale, yoffset * mml->hScale, 0, /* dstX/Y/Zoffset */
1226 dstRowStride,
1227 0, /* dstImageStride */
1228 newWidth, newHeight, 1,
1229 GL_RGBA, CHAN_TYPE, tempImage, &ctx->DefaultPacking);
1230 FREE(rawImage);
1231 }
1232
1233 FREE(tempImage);
1234
1235 return GL_TRUE;
1236 }
1237
1238
1239 static void
1240 tdfxTexImage2D(GLcontext *ctx, GLenum target, GLint level,
1241 GLint internalFormat, GLint width, GLint height, GLint border,
1242 GLenum format, GLenum type, const GLvoid *pixels,
1243 const struct gl_pixelstore_attrib *packing,
1244 struct gl_texture_object *texObj,
1245 struct gl_texture_image *texImage)
1246 {
1247 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1248 tdfxTexInfo *ti;
1249 tdfxMipMapLevel *mml;
1250 GLint texelBytes, dstRowStride;
1251
1252 /*
1253 printf("TexImage id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1254 texObj->Name, texImage->IntFormat, format, type,
1255 texImage->Width, texImage->Height);
1256 */
1257
1258 ti = TDFX_TEXTURE_DATA(texObj);
1259 if (!ti) {
1260 texObj->DriverData = fxAllocTexObjData(fxMesa);
1261 if (!texObj->DriverData) {
1262 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1263 return;
1264 }
1265 ti = TDFX_TEXTURE_DATA(texObj);
1266 }
1267 assert(ti);
1268
1269 mml = TDFX_TEXIMAGE_DATA(texImage);
1270 if (!mml) {
1271 texImage->DriverData = CALLOC(sizeof(tdfxMipMapLevel));
1272 if (!texImage->DriverData) {
1273 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1274 return;
1275 }
1276 mml = TDFX_TEXIMAGE_DATA(texImage);
1277 }
1278
1279 /* Determine width and height scale factors for texture.
1280 * Remember, Glide is limited to 8:1 aspect ratios.
1281 */
1282 tdfxTexGetInfo(ctx,
1283 texImage->Width, texImage->Height,
1284 NULL, /* lod level */
1285 NULL, /* aspect ratio */
1286 NULL, NULL, /* sscale, tscale */
1287 &mml->wScale, &mml->hScale);
1288
1289 /* rescaled size: */
1290 mml->width = width * mml->wScale;
1291 mml->height = height * mml->hScale;
1292
1293 #if FX_COMPRESS_S3TC_AS_FXT1_HACK
1294 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1295 /* [dBorca] we should update texture's attribute, then,
1296 * because if the application asks us to decompress, we
1297 * have to know the REAL format! Also, DXT3/5 might not
1298 * be correct, since it would mess with "compressedSize".
1299 * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3.
1300 */
1301 if (texImage->IsCompressed) {
1302 switch (internalFormat) {
1303 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1304 case GL_RGB_S3TC:
1305 case GL_RGB4_S3TC:
1306 internalFormat = GL_COMPRESSED_RGB_FXT1_3DFX;
1307 break;
1308 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1309 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1310 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1311 case GL_RGBA_S3TC:
1312 case GL_RGBA4_S3TC:
1313 internalFormat = GL_COMPRESSED_RGBA_FXT1_3DFX;
1314 }
1315 texImage->IntFormat = internalFormat;
1316 }
1317 #endif
1318 #if FX_TC_NAPALM
1319 if (fxMesa->type >= GR_SSTTYPE_Voodoo4) {
1320 GLenum texNapalm = 0;
1321 if (internalFormat == GL_COMPRESSED_RGB) {
1322 texNapalm = GL_COMPRESSED_RGB_FXT1_3DFX;
1323 } else if (internalFormat == GL_COMPRESSED_RGBA) {
1324 texNapalm = GL_COMPRESSED_RGBA_FXT1_3DFX;
1325 }
1326 if (texNapalm) {
1327 texImage->IntFormat = internalFormat = texNapalm;
1328 texImage->IsCompressed = GL_TRUE;
1329 }
1330 }
1331 #endif
1332
1333 /* choose the texture format */
1334 assert(ctx->Driver.ChooseTextureFormat);
1335 texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
1336 internalFormat, format, type);
1337 assert(texImage->TexFormat);
1338 mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
1339 ti->info.format = mml->glideFormat;
1340 texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat);
1341 texelBytes = texImage->TexFormat->TexelBytes;
1342
1343 if (texImage->IsCompressed) {
1344 texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
1345 mml->width,
1346 mml->height,
1347 1,
1348 internalFormat);
1349 dstRowStride = _mesa_compressed_row_stride(internalFormat, mml->width);
1350 texImage->Data = MESA_PBUFFER_ALLOC(texImage->CompressedSize);
1351 } else {
1352 dstRowStride = mml->width * texelBytes;
1353 texImage->Data = MESA_PBUFFER_ALLOC(mml->width * mml->height * texelBytes);
1354 }
1355 if (!texImage->Data) {
1356 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1357 return;
1358 }
1359
1360 if (pixels != NULL) {
1361 if (mml->wScale != 1 || mml->hScale != 1) {
1362 /* rescale image to overcome 1:8 aspect limitation */
1363 if (!adjust2DRatio(ctx,
1364 0, 0,
1365 width, height,
1366 format, type, pixels,
1367 packing,
1368 mml,
1369 texImage,
1370 texelBytes,
1371 dstRowStride)
1372 ) {
1373 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
1374 return;
1375 }
1376 }
1377 else {
1378 /* no rescaling needed */
1379 /* unpack image, apply transfer ops and store in texImage->Data */
1380 texImage->TexFormat->StoreImage(ctx, 2, texImage->Format,
1381 texImage->TexFormat, texImage->Data,
1382 0, 0, 0, /* dstX/Y/Zoffset */
1383 dstRowStride,
1384 0, /* dstImageStride */
1385 width, height, 1,
1386 format, type, pixels, packing);
1387 }
1388
1389 /* GL_SGIS_generate_mipmap */
1390 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1391 GLint mipWidth, mipHeight;
1392 tdfxMipMapLevel *mip;
1393 struct gl_texture_image *mipImage;
1394 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1395 const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
1396
1397 assert(!texImage->IsCompressed);
1398
1399 while (level < texObj->MaxLevel && level < maxLevels - 1) {
1400 mipWidth = width / 2;
1401 if (!mipWidth) {
1402 mipWidth = 1;
1403 }
1404 mipHeight = height / 2;
1405 if (!mipHeight) {
1406 mipHeight = 1;
1407 }
1408 if ((mipWidth == width) && (mipHeight == height)) {
1409 break;
1410 }
1411 _mesa_TexImage2D(target, ++level, internalFormat,
1412 mipWidth, mipHeight, border,
1413 format, type,
1414 NULL);
1415 mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1416 mip = TDFX_TEXIMAGE_DATA(mipImage);
1417 _mesa_halve2x2_teximage2d(ctx,
1418 texImage,
1419 texelBytes,
1420 mml->width, mml->height,
1421 texImage->Data, mipImage->Data);
1422 texImage = mipImage;
1423 mml = mip;
1424 width = mipWidth;
1425 height = mipHeight;
1426 }
1427 }
1428 }
1429
1430 RevalidateTexture(ctx, texObj);
1431
1432 ti->reloadImages = GL_TRUE;
1433 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1434 }
1435
1436
1437 static void
1438 tdfxTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
1439 GLint xoffset, GLint yoffset,
1440 GLsizei width, GLsizei height,
1441 GLenum format, GLenum type,
1442 const GLvoid *pixels,
1443 const struct gl_pixelstore_attrib *packing,
1444 struct gl_texture_object *texObj,
1445 struct gl_texture_image *texImage )
1446 {
1447 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1448 tdfxTexInfo *ti;
1449 tdfxMipMapLevel *mml;
1450 GLint texelBytes, dstRowStride;
1451
1452 if (!texObj->DriverData) {
1453 _mesa_problem(ctx, "problem in fxDDTexSubImage2D");
1454 return;
1455 }
1456
1457 ti = TDFX_TEXTURE_DATA(texObj);
1458 assert(ti);
1459 mml = TDFX_TEXIMAGE_DATA(texImage);
1460 assert(mml);
1461
1462 assert(texImage->Data); /* must have an existing texture image! */
1463 assert(texImage->Format);
1464
1465 texelBytes = texImage->TexFormat->TexelBytes;
1466 if (texImage->IsCompressed) {
1467 dstRowStride = _mesa_compressed_row_stride(texImage->IntFormat, mml->width);
1468 } else {
1469 dstRowStride = mml->width * texelBytes;
1470 }
1471
1472 if (mml->wScale != 1 || mml->hScale != 1) {
1473 /* need to rescale subimage to match mipmap level's rescale factors */
1474 if (!adjust2DRatio(ctx,
1475 xoffset, yoffset,
1476 width, height,
1477 format, type, pixels,
1478 packing,
1479 mml,
1480 texImage,
1481 texelBytes,
1482 dstRowStride)
1483 ) {
1484 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
1485 return;
1486 }
1487 }
1488 else {
1489 /* no rescaling needed */
1490 texImage->TexFormat->StoreImage(ctx, 2, texImage->Format,
1491 texImage->TexFormat, texImage->Data,
1492 xoffset, yoffset, 0,
1493 dstRowStride,
1494 0, /* dstImageStride */
1495 width, height, 1,
1496 format, type, pixels, packing);
1497 }
1498
1499 /* GL_SGIS_generate_mipmap */
1500 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1501 GLint mipWidth, mipHeight;
1502 tdfxMipMapLevel *mip;
1503 struct gl_texture_image *mipImage;
1504 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1505 const GLint maxLevels = _mesa_max_texture_levels(ctx, texObj->Target);
1506
1507 assert(!texImage->IsCompressed);
1508
1509 width = texImage->Width;
1510 height = texImage->Height;
1511 while (level < texObj->MaxLevel && level < maxLevels - 1) {
1512 mipWidth = width / 2;
1513 if (!mipWidth) {
1514 mipWidth = 1;
1515 }
1516 mipHeight = height / 2;
1517 if (!mipHeight) {
1518 mipHeight = 1;
1519 }
1520 if ((mipWidth == width) && (mipHeight == height)) {
1521 break;
1522 }
1523 ++level;
1524 mipImage = _mesa_select_tex_image(ctx, texUnit, target, level);
1525 mip = TDFX_TEXIMAGE_DATA(mipImage);
1526 _mesa_halve2x2_teximage2d(ctx,
1527 texImage,
1528 texelBytes,
1529 mml->width, mml->height,
1530 texImage->Data, mipImage->Data);
1531 texImage = mipImage;
1532 mml = mip;
1533 width = mipWidth;
1534 height = mipHeight;
1535 }
1536 }
1537
1538 ti->reloadImages = GL_TRUE; /* signal the image needs to be reloaded */
1539 fxMesa->new_state |= TDFX_NEW_TEXTURE; /* XXX this might be a bit much */
1540 }
1541
1542
1543 static void
1544 tdfxTexImage1D(GLcontext *ctx, GLenum target, GLint level,
1545 GLint internalFormat, GLint width, GLint border,
1546 GLenum format, GLenum type, const GLvoid *pixels,
1547 const struct gl_pixelstore_attrib *packing,
1548 struct gl_texture_object *texObj,
1549 struct gl_texture_image *texImage)
1550 {
1551 tdfxTexImage2D(ctx, target, level,
1552 internalFormat, width, 1, border,
1553 format, type, pixels,
1554 packing,
1555 texObj,
1556 texImage);
1557 }
1558
1559 static void
1560 tdfxTexSubImage1D(GLcontext *ctx, GLenum target, GLint level,
1561 GLint xoffset,
1562 GLsizei width,
1563 GLenum format, GLenum type,
1564 const GLvoid *pixels,
1565 const struct gl_pixelstore_attrib *packing,
1566 struct gl_texture_object *texObj,
1567 struct gl_texture_image *texImage )
1568 {
1569 tdfxTexSubImage2D(ctx, target, level,
1570 xoffset, 0,
1571 width, 1,
1572 format, type,
1573 pixels,
1574 packing,
1575 texObj,
1576 texImage);
1577 }
1578
1579 /**********************************************************************/
1580 /**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/
1581 /**********************************************************************/
1582
1583 static void
1584 tdfxCompressedTexImage2D (GLcontext *ctx, GLenum target,
1585 GLint level, GLint internalFormat,
1586 GLsizei width, GLsizei height, GLint border,
1587 GLsizei imageSize, const GLvoid *data,
1588 struct gl_texture_object *texObj,
1589 struct gl_texture_image *texImage)
1590 {
1591 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1592 tdfxTexInfo *ti;
1593 tdfxMipMapLevel *mml;
1594
1595 if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
1596 fprintf(stderr, "tdfxCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1597 texObj->Name, internalFormat,
1598 width, height);
1599 }
1600
1601 if ((target != GL_TEXTURE_1D && target != GL_TEXTURE_2D) || texImage->Border > 0) {
1602 _mesa_problem(NULL, "tdfx: unsupported texture in tdfxCompressedTexImg()\n");
1603 return;
1604 }
1605
1606 assert(texImage->IsCompressed);
1607
1608 ti = TDFX_TEXTURE_DATA(texObj);
1609 if (!ti) {
1610 texObj->DriverData = fxAllocTexObjData(fxMesa);
1611 if (!texObj->DriverData) {
1612 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1613 return;
1614 }
1615 ti = TDFX_TEXTURE_DATA(texObj);
1616 }
1617 assert(ti);
1618
1619 mml = TDFX_TEXIMAGE_DATA(texImage);
1620 if (!mml) {
1621 texImage->DriverData = CALLOC(sizeof(tdfxMipMapLevel));
1622 if (!texImage->DriverData) {
1623 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1624 return;
1625 }
1626 mml = TDFX_TEXIMAGE_DATA(texImage);
1627 }
1628
1629 tdfxTexGetInfo(ctx, width, height, NULL, NULL, NULL, NULL,
1630 &mml->wScale, &mml->hScale);
1631
1632 mml->width = width * mml->wScale;
1633 mml->height = height * mml->hScale;
1634
1635
1636 /* choose the texture format */
1637 assert(ctx->Driver.ChooseTextureFormat);
1638 texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
1639 internalFormat, -1/*format*/, -1/*type*/);
1640 assert(texImage->TexFormat);
1641
1642 /* Determine the appropriate Glide texel format,
1643 * given the user's internal texture format hint.
1644 */
1645 mml->glideFormat = fxGlideFormat(texImage->TexFormat->MesaFormat);
1646 ti->info.format = mml->glideFormat;
1647 texImage->FetchTexelc = fxFetchFunction(texImage->TexFormat->MesaFormat);
1648
1649 /* allocate new storage for texture image, if needed */
1650 if (!texImage->Data) {
1651 texImage->CompressedSize = _mesa_compressed_texture_size(ctx,
1652 mml->width,
1653 mml->height,
1654 1,
1655 internalFormat);
1656 texImage->Data = MESA_PBUFFER_ALLOC(texImage->CompressedSize);
1657 if (!texImage->Data) {
1658 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
1659 return;
1660 }
1661 }
1662
1663 /* save the texture data */
1664 if (mml->wScale != 1 || mml->hScale != 1) {
1665 /* [dBorca] Hack alert:
1666 * now we're screwed. We can't decompress,
1667 * unless we do it in HW (via textureBuffer).
1668 * We still have some chances:
1669 * 1) we got FXT1 textures - we CAN decompress, rescale for
1670 * aspectratio, then compress back.
1671 * 2) there is a chance that MIN("s", "t") won't be overflowed.
1672 * Thus, we don't care about textureclamp and we could lower
1673 * MIN("uscale", "vscale") below 32. We still have to have
1674 * our data aligned inside a 8:1 rectangle.
1675 * 3) just in case if MIN("s", "t") gets overflowed with GL_REPEAT,
1676 * we replicate the data over the padded area.
1677 * For now, we take 2) + 3) but texelfetchers will be wrong!
1678 */
1679 GLuint srcRowStride = _mesa_compressed_row_stride(internalFormat, width);
1680
1681 GLuint destRowStride = _mesa_compressed_row_stride(internalFormat,
1682 mml->width);
1683
1684 _mesa_upscale_teximage2d(srcRowStride, (height+3) / 4,
1685 destRowStride, (mml->height+3) / 4,
1686 1, data, srcRowStride,
1687 texImage->Data);
1688 ti->padded = GL_TRUE;
1689 } else {
1690 MEMCPY(texImage->Data, data, texImage->CompressedSize);
1691 }
1692
1693 /* GL_SGIS_generate_mipmap */
1694 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1695 assert(!texImage->IsCompressed);
1696 }
1697
1698 RevalidateTexture(ctx, texObj);
1699
1700 ti->reloadImages = GL_TRUE;
1701 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1702 }
1703
1704
1705 static void
1706 tdfxCompressedTexSubImage2D( GLcontext *ctx, GLenum target,
1707 GLint level, GLint xoffset,
1708 GLint yoffset, GLsizei width,
1709 GLint height, GLenum format,
1710 GLsizei imageSize, const GLvoid *data,
1711 struct gl_texture_object *texObj,
1712 struct gl_texture_image *texImage )
1713 {
1714 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1715 tdfxTexInfo *ti;
1716 tdfxMipMapLevel *mml;
1717 GLint destRowStride, srcRowStride;
1718 GLint i, rows;
1719 GLubyte *dest;
1720
1721 if (TDFX_DEBUG & DEBUG_VERBOSE_DRI) {
1722 fprintf(stderr, "tdfxCompressedTexSubImage2D: id=%d\n", texObj->Name);
1723 }
1724
1725 ti = TDFX_TEXTURE_DATA(texObj);
1726 assert(ti);
1727 mml = TDFX_TEXIMAGE_DATA(texImage);
1728 assert(mml);
1729
1730 srcRowStride = _mesa_compressed_row_stride(texImage->IntFormat, width);
1731
1732 destRowStride = _mesa_compressed_row_stride(texImage->IntFormat,
1733 mml->width);
1734 dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
1735 texImage->IntFormat,
1736 mml->width,
1737 (GLubyte*) texImage->Data);
1738
1739 rows = height / 4; /* [dBorca] hardcoded 4, but works for FXT1/DXTC */
1740
1741 for (i = 0; i < rows; i++) {
1742 MEMCPY(dest, data, srcRowStride);
1743 dest += destRowStride;
1744 data = (GLvoid *)((GLuint)data + (GLuint)srcRowStride);
1745 }
1746
1747 /* [dBorca] Hack alert:
1748 * see fxDDCompressedTexImage2D for caveats
1749 */
1750 if (mml->wScale != 1 || mml->hScale != 1) {
1751 srcRowStride = _mesa_compressed_row_stride(texImage->IntFormat, texImage->Width);
1752
1753 destRowStride = _mesa_compressed_row_stride(texImage->IntFormat,
1754 mml->width);
1755 _mesa_upscale_teximage2d(srcRowStride, texImage->Height / 4,
1756 destRowStride, mml->height / 4,
1757 1, texImage->Data, destRowStride,
1758 texImage->Data);
1759 }
1760
1761 /* GL_SGIS_generate_mipmap */
1762 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
1763 assert(!texImage->IsCompressed);
1764 }
1765
1766 RevalidateTexture(ctx, texObj);
1767
1768 ti->reloadImages = GL_TRUE;
1769 fxMesa->new_state |= TDFX_NEW_TEXTURE;
1770 }
1771
1772
1773 #if 0
1774 static void
1775 PrintTexture(int w, int h, int c, const GLubyte * data)
1776 {
1777 int i, j;
1778 for (i = 0; i < h; i++) {
1779 for (j = 0; j < w; j++) {
1780 if (c == 2)
1781 printf("%02x %02x ", data[0], data[1]);
1782 else if (c == 3)
1783 printf("%02x %02x %02x ", data[0], data[1], data[2]);
1784 data += c;
1785 }
1786 printf("\n");
1787 }
1788 }
1789 #endif
1790
1791
1792 GLboolean
1793 tdfxTestProxyTexImage(GLcontext *ctx, GLenum target,
1794 GLint level, GLint internalFormat,
1795 GLenum format, GLenum type,
1796 GLint width, GLint height,
1797 GLint depth, GLint border)
1798 {
1799 tdfxContextPtr fxMesa = TDFX_CONTEXT(ctx);
1800 struct gl_shared_state *mesaShared = fxMesa->glCtx->Shared;
1801 struct tdfxSharedState *shared = (struct tdfxSharedState *) mesaShared->DriverData;
1802
1803 switch (target) {
1804 case GL_PROXY_TEXTURE_1D:
1805 /*JJJ wrong*/
1806 case GL_PROXY_TEXTURE_2D:
1807 {
1808 struct gl_texture_object *tObj;
1809 tdfxTexInfo *ti;
1810 int memNeeded;
1811
1812 tObj = ctx->Texture.Proxy2D;
1813 if (!tObj->DriverData)
1814 tObj->DriverData = fxAllocTexObjData(fxMesa);
1815 ti = TDFX_TEXTURE_DATA(tObj);
1816 assert(ti);
1817
1818 /* assign the parameters to test against */
1819 tObj->Image[0][level]->Width = width;
1820 tObj->Image[0][level]->Height = height;
1821 tObj->Image[0][level]->Border = border;
1822 #if 0
1823 tObj->Image[0][level]->IntFormat = internalFormat;
1824 #endif
1825 if (level == 0) {
1826 /* don't use mipmap levels > 0 */
1827 tObj->MinFilter = tObj->MagFilter = GL_NEAREST;
1828 }
1829 else {
1830 /* test with all mipmap levels */
1831 tObj->MinFilter = GL_LINEAR_MIPMAP_LINEAR;
1832 tObj->MagFilter = GL_NEAREST;
1833 }
1834 RevalidateTexture(ctx, tObj);
1835
1836 /*
1837 printf("small lodlog2 0x%x\n", ti->info.smallLodLog2);
1838 printf("large lodlog2 0x%x\n", ti->info.largeLodLog2);
1839 printf("aspect ratio 0x%x\n", ti->info.aspectRatioLog2);
1840 printf("glide format 0x%x\n", ti->info.format);
1841 printf("data %p\n", ti->info.data);
1842 printf("lodblend %d\n", (int) ti->LODblend);
1843 */
1844
1845 /* determine where texture will reside */
1846 if (ti->LODblend && !shared->umaTexMemory) {
1847 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1848 memNeeded = fxMesa->Glide.grTexTextureMemRequired(
1849 GR_MIPMAPLEVELMASK_BOTH, &(ti->info));
1850 }
1851 else {
1852 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1853 memNeeded = fxMesa->Glide.grTexTextureMemRequired(
1854 GR_MIPMAPLEVELMASK_BOTH, &(ti->info));
1855 }
1856 /*
1857 printf("Proxy test %d > %d\n", memNeeded, shared->totalTexMem[0]);
1858 */
1859 if (memNeeded > shared->totalTexMem[0])
1860 return GL_FALSE;
1861 else
1862 return GL_TRUE;
1863 }
1864 case GL_PROXY_TEXTURE_3D:
1865 return GL_TRUE; /* software rendering */
1866 default:
1867 return GL_TRUE; /* never happens, silence compiler */
1868 }
1869 }
1870
1871
1872 /**
1873 * Allocate a new texture object.
1874 * Called via ctx->Driver.NewTextureObject.
1875 * Note: this function will be called during context creation to
1876 * allocate the default texture objects.
1877 * Note: we could use containment here to 'derive' the driver-specific
1878 * texture object from the core mesa gl_texture_object. Not done at this time.
1879 */
1880 static struct gl_texture_object *
1881 tdfxNewTextureObject( GLcontext *ctx, GLuint name, GLenum target )
1882 {
1883 struct gl_texture_object *obj;
1884 obj = _mesa_new_texture_object(ctx, name, target);
1885 return obj;
1886 }
1887
1888
1889 void tdfxInitTextureFuncs( struct dd_function_table *functions )
1890 {
1891 functions->BindTexture = tdfxBindTexture;
1892 functions->NewTextureObject = tdfxNewTextureObject;
1893 functions->DeleteTexture = tdfxDeleteTexture;
1894 functions->TexEnv = tdfxTexEnv;
1895 functions->TexParameter = tdfxTexParameter;
1896 functions->ChooseTextureFormat = tdfxChooseTextureFormat;
1897 functions->TexImage1D = tdfxTexImage1D;
1898 functions->TexSubImage1D = tdfxTexSubImage1D;
1899 functions->TexImage2D = tdfxTexImage2D;
1900 functions->TexSubImage2D = tdfxTexSubImage2D;
1901 functions->IsTextureResident = tdfxIsTextureResident;
1902 functions->CompressedTexImage2D = tdfxCompressedTexImage2D;
1903 functions->CompressedTexSubImage2D = tdfxCompressedTexSubImage2D;
1904 functions->UpdateTexturePalette = tdfxUpdateTexturePalette;
1905 }