2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 #include "texformat.h"
51 fxPrintTextureData(tfxTexInfo
* ti
)
53 fprintf(stderr
, "Texture Data:\n");
55 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
56 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
57 fprintf(stderr
, "\tSize: %d x %d\n",
58 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
59 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
62 fprintf(stderr
, "\tName: UNNAMED\n");
63 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
64 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
65 fprintf(stderr
, "\t%s\n", (ti
->isInTM
) ? "In TMU" : "Not in TMU");
67 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
68 (unsigned) ti
->tm
[0]->endAddr
);
70 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
71 (unsigned) ti
->tm
[1]->endAddr
);
72 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
73 fprintf(stderr
, "\tFilters: min %d min %d\n",
74 (int) ti
->minFilt
, (int) ti
->maxFilt
);
75 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
,
77 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
78 fprintf(stderr
, "\t%s\n",
79 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
80 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
84 /************************************************************************/
85 /*************************** Texture Mapping ****************************/
86 /************************************************************************/
89 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
91 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
94 ti
= fxTMGetTexInfo(tObj
);
96 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
98 ti
->validated
= GL_FALSE
;
99 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
103 fxAllocTexObjData(fxMesaContext fxMesa
)
107 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
108 fprintf(stderr
, "%s: ERROR: out of memory !\n", __FUNCTION__
);
113 ti
->validated
= GL_FALSE
;
114 ti
->isInTM
= GL_FALSE
;
116 ti
->whichTMU
= FX_TMU_NONE
;
118 ti
->tm
[FX_TMU0
] = NULL
;
119 ti
->tm
[FX_TMU1
] = NULL
;
121 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
122 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
124 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
125 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
127 ti
->mmMode
= GR_MIPMAP_NEAREST
;
128 ti
->LODblend
= FXFALSE
;
134 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
136 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
139 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
140 fprintf(stderr
, "%s(%d, %x)\n", __FUNCTION__
, tObj
->Name
,
141 (GLuint
) tObj
->DriverData
);
144 if (target
!= GL_TEXTURE_2D
)
147 if (!tObj
->DriverData
) {
148 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
151 ti
= fxTMGetTexInfo(tObj
);
153 fxMesa
->texBindNumber
++;
154 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
156 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
160 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
161 const GLfloat
* param
)
163 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
165 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
167 fprintf(stderr
, "%s(%x, %x)\n", __FUNCTION__
, pname
, (GLint
) (*param
));
169 fprintf(stderr
, "%s(%x)\n", __FUNCTION__
, pname
);
172 /* apply any lod biasing right now */
173 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
174 grTexLodBiasValue(GR_TMU0
, *param
);
176 if (fxMesa
->haveTwoTMUs
) {
177 grTexLodBiasValue(GR_TMU1
, *param
);
182 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
186 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
187 GLenum pname
, const GLfloat
* params
)
189 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
190 GLenum param
= (GLenum
) (GLint
) params
[0];
193 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
194 fprintf(stderr
, "fxDDTexParam(%d, %x, %s, %s)\n",
195 tObj
->Name
, (GLuint
) tObj
->DriverData
,
196 _mesa_lookup_enum_by_nr(pname
),
197 _mesa_lookup_enum_by_nr(param
));
200 if (target
!= GL_TEXTURE_2D
)
203 if (!tObj
->DriverData
)
204 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
206 ti
= fxTMGetTexInfo(tObj
);
210 case GL_TEXTURE_MIN_FILTER
:
213 ti
->mmMode
= GR_MIPMAP_DISABLE
;
214 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
215 ti
->LODblend
= FXFALSE
;
218 ti
->mmMode
= GR_MIPMAP_DISABLE
;
219 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
220 ti
->LODblend
= FXFALSE
;
222 case GL_NEAREST_MIPMAP_LINEAR
:
223 if (fxMesa
->haveTwoTMUs
) {
224 ti
->mmMode
= GR_MIPMAP_NEAREST
;
225 ti
->LODblend
= FXTRUE
;
228 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
229 ti
->LODblend
= FXFALSE
;
231 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
232 break; /* ZZZ: we may have to fall through here for V3 */
233 case GL_NEAREST_MIPMAP_NEAREST
:
234 ti
->mmMode
= GR_MIPMAP_NEAREST
;
235 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
236 ti
->LODblend
= FXFALSE
;
238 case GL_LINEAR_MIPMAP_LINEAR
:
239 /* ZZZ: HACK ALERT! trilinear is bugged! mipmap blending produce
240 incorrect filtered colors for the smallest mipmap levels. */
242 if (fxMesa
->haveTwoTMUs
) {
243 ti
->mmMode
= GR_MIPMAP_NEAREST
;
244 ti
->LODblend
= FXTRUE
;
247 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
248 ti
->LODblend
= FXFALSE
;
250 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
251 break; /* ZZZ: we may have to fall through here for V3 */
253 case GL_LINEAR_MIPMAP_NEAREST
:
254 ti
->mmMode
= GR_MIPMAP_NEAREST
;
255 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
256 ti
->LODblend
= FXFALSE
;
261 fxTexInvalidate(ctx
, tObj
);
264 case GL_TEXTURE_MAG_FILTER
:
267 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
270 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
275 fxTexInvalidate(ctx
, tObj
);
278 case GL_TEXTURE_WRAP_S
:
280 case GL_MIRRORED_REPEAT
:
281 ti
->sClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
283 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
285 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
288 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
293 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
296 case GL_TEXTURE_WRAP_T
:
298 case GL_MIRRORED_REPEAT
:
299 ti
->tClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
301 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
303 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
306 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
311 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
314 case GL_TEXTURE_BORDER_COLOR
:
318 case GL_TEXTURE_MIN_LOD
:
321 case GL_TEXTURE_MAX_LOD
:
324 case GL_TEXTURE_BASE_LEVEL
:
325 fxTexInvalidate(ctx
, tObj
);
327 case GL_TEXTURE_MAX_LEVEL
:
328 fxTexInvalidate(ctx
, tObj
);
337 fxDDTexDel(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
339 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
340 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
342 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
343 fprintf(stderr
, "%s(%d, %p)\n", __FUNCTION__
, tObj
->Name
, (void *) ti
);
349 fxTMFreeTexture(fxMesa
, tObj
);
352 tObj
->DriverData
= NULL
;
356 * Return true if texture is resident, false otherwise.
359 fxDDIsTextureResident(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
361 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
362 return (ti
&& ti
->isInTM
);
368 * Convert a gl_color_table texture palette to Glide's format.
371 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
373 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
374 GLint width
= table
->Size
;
378 ASSERT(!table
->FloatTable
);
380 switch (table
->Format
) {
382 for (i
= 0; i
< width
; i
++) {
387 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
391 for (i
= 0; i
< width
; i
++) {
396 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
400 for (i
= 0; i
< width
; i
++) {
403 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
406 case GL_LUMINANCE_ALPHA
:
407 for (i
= 0; i
< width
; i
++) {
408 r
= g
= b
= tableUB
[i
* 2 + 0];
409 a
= tableUB
[i
* 2 + 1];
410 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
414 for (i
= 0; i
< width
; i
++) {
415 r
= tableUB
[i
* 3 + 0];
416 g
= tableUB
[i
* 3 + 1];
417 b
= tableUB
[i
* 3 + 2];
419 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
423 for (i
= 0; i
< width
; i
++) {
424 r
= tableUB
[i
* 4 + 0];
425 g
= tableUB
[i
* 4 + 1];
426 b
= tableUB
[i
* 4 + 2];
427 a
= tableUB
[i
* 4 + 3];
428 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
436 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
438 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
441 /* per-texture palette */
443 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
444 fprintf(stderr
, "%s(%d, %x)\n", __FUNCTION__
,
445 tObj
->Name
, (GLuint
) tObj
->DriverData
);
447 if (!tObj
->DriverData
)
448 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
449 ti
= fxTMGetTexInfo(tObj
);
450 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
451 fxTexInvalidate(ctx
, tObj
);
454 /* global texture palette */
455 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
456 fprintf(stderr
, "%s(global)\n", __FUNCTION__
);
458 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
459 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
465 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
467 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
469 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
470 fprintf(stderr
, "%s(%d)\n", __FUNCTION__
, state
);
474 fxMesa
->haveGlobalPaletteTexture
= 1;
476 grTexDownloadTable(GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
479 fxMesa
->haveGlobalPaletteTexture
= 0;
481 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
482 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
483 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
485 if (!tObj
->DriverData
)
486 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
488 fxTexInvalidate(ctx
, tObj
);
518 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
519 float *sscale
, float *tscale
,
520 int *wscale
, int *hscale
)
522 static GrLOD_t lod
[12] = {
537 int logw
, logh
, ws
, hs
;
539 GrAspectRatio_t aspectratio
;
545 switch (logw
- logh
) {
547 aspectratio
= GR_ASPECT_LOG2_1x1
;
553 aspectratio
= GR_ASPECT_LOG2_2x1
;
561 aspectratio
= GR_ASPECT_LOG2_4x1
;
569 aspectratio
= GR_ASPECT_LOG2_8x1
;
577 aspectratio
= GR_ASPECT_LOG2_1x2
;
585 aspectratio
= GR_ASPECT_LOG2_1x4
;
593 aspectratio
= GR_ASPECT_LOG2_1x8
;
601 if ((logw
- logh
) > 3) {
602 aspectratio
= GR_ASPECT_LOG2_8x1
;
607 hs
= 1 << (logw
- logh
- 3);
608 } else /*if ((logw - logh) < -3)*/ {
609 aspectratio
= GR_ASPECT_LOG2_1x8
;
613 ws
= 1 << (logh
- logw
- 3);
641 fxIsTexSupported(GLenum target
, GLint internalFormat
,
642 const struct gl_texture_image
*image
)
644 if (target
!= GL_TEXTURE_2D
)
647 if (!fxTexGetInfo(image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
))
650 if (image
->Border
> 0)
657 /**********************************************************************/
658 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
659 /**********************************************************************/
661 /* Texel-fetch functions for software texturing and glGetTexImage().
662 * We should have been able to use some "standard" fetch functions (which
663 * may get defined in texutil.c) but we have to account for scaled texture
664 * images on tdfx hardware (the 8:1 aspect ratio limit).
665 * Hence, we need special functions here.
669 fetch_intensity8(const struct gl_texture_image
*texImage
,
670 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
672 GLchan
*rgba
= (GLchan
*) texelOut
;
673 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
674 const GLubyte
*texel
;
679 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
680 rgba
[RCOMP
] = *texel
;
681 rgba
[GCOMP
] = *texel
;
682 rgba
[BCOMP
] = *texel
;
683 rgba
[ACOMP
] = *texel
;
688 fetch_luminance8(const struct gl_texture_image
*texImage
,
689 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
691 GLchan
*rgba
= (GLchan
*) texelOut
;
692 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
693 const GLubyte
*texel
;
698 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
699 rgba
[RCOMP
] = *texel
;
700 rgba
[GCOMP
] = *texel
;
701 rgba
[BCOMP
] = *texel
;
707 fetch_alpha8(const struct gl_texture_image
*texImage
,
708 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
710 GLchan
*rgba
= (GLchan
*) texelOut
;
711 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
712 const GLubyte
*texel
;
716 /* [dBorca] why, oh... why? */
717 i
= i
* mml
->width
/ texImage
->Width
;
718 j
= j
* mml
->height
/ texImage
->Height
;
720 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
724 rgba
[ACOMP
] = *texel
;
729 fetch_index8(const struct gl_texture_image
*texImage
,
730 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
732 GLchan
*indexOut
= (GLchan
*) texelOut
;
733 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
734 const GLubyte
*texel
;
738 /* [dBorca] why, oh... why? */
739 i
= i
* mml
->width
/ texImage
->Width
;
740 j
= j
* mml
->height
/ texImage
->Height
;
742 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
748 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
749 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
751 GLchan
*rgba
= (GLchan
*) texelOut
;
752 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
753 const GLubyte
*texel
;
758 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
759 rgba
[RCOMP
] = texel
[0];
760 rgba
[GCOMP
] = texel
[0];
761 rgba
[BCOMP
] = texel
[0];
762 rgba
[ACOMP
] = texel
[1];
767 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
768 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
770 GLchan
*rgba
= (GLchan
*) texelOut
;
771 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
772 const GLushort
*texel
;
777 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
778 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
779 rgba
[GCOMP
] = FX_rgb_scale_6
[(*texel
>> 5) & 0x3F];
780 rgba
[BCOMP
] = FX_rgb_scale_5
[ *texel
& 0x1F];
786 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
787 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
789 GLchan
*rgba
= (GLchan
*) texelOut
;
790 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
791 const GLushort
*texel
;
796 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
797 rgba
[RCOMP
] = FX_rgb_scale_4
[(*texel
>> 12) & 0xF];
798 rgba
[GCOMP
] = FX_rgb_scale_4
[(*texel
>> 8) & 0xF];
799 rgba
[BCOMP
] = FX_rgb_scale_4
[(*texel
>> 4) & 0xF];
800 rgba
[ACOMP
] = FX_rgb_scale_4
[ *texel
& 0xF];
805 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
806 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
808 GLchan
*rgba
= (GLchan
*) texelOut
;
809 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
810 const GLushort
*texel
;
815 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
816 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
817 rgba
[GCOMP
] = FX_rgb_scale_5
[(*texel
>> 6) & 0x1F];
818 rgba
[BCOMP
] = FX_rgb_scale_5
[(*texel
>> 1) & 0x1F];
819 rgba
[ACOMP
] = ((*texel
) & 0x01) * 255;
824 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
825 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
827 GLchan
*rgba
= (GLchan
*) texelOut
;
828 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
834 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
835 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
836 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
837 rgba
[BCOMP
] = (((*texel
) ) & 0xff);
838 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
843 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
846 for (i
= 0; i
< h
; i
++) {
847 for (j
= 0; j
< w
; j
++) {
849 fprintf(stderr
, "%02x %02x ", data
[0], data
[1]);
851 fprintf(stderr
, "%02x %02x %02x ", data
[0], data
[1], data
[2]);
854 fprintf(stderr
, "\n");
859 const struct gl_texture_format
*
860 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
861 GLenum srcFormat
, GLenum srcType
)
863 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
864 GLboolean allow32bpt
= fxMesa
->HaveTexFmt
;
866 /* [dBorca] Hack alert:
867 * There is something wrong with this!!! Take an example:
868 * 1) start HW rendering
869 * 2) create a texture like this:
870 * glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
871 * GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
872 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
873 * 3) we get here with internalFormat==3 and return either
874 * _mesa_texformat_argb565 or _mesa_texformat_argb8888
875 * 4) at some point, we encounter total rasterization fallback
876 * 5) displaying a polygon with the above textures yield garbage on areas
877 * where pixel is larger than a texel, because our already set texel
878 * function doesn't match the real _mesa_texformat_argb888
881 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
882 fprintf(stderr
, "fxDDChooseTextureFormat(...)\n");
885 switch (internalFormat
) {
891 case GL_COMPRESSED_INTENSITY
:
892 return &_mesa_texformat_i8
;
899 case GL_COMPRESSED_LUMINANCE
:
900 return &_mesa_texformat_l8
;
906 case GL_COMPRESSED_ALPHA
:
907 return &_mesa_texformat_a8
;
909 case GL_COLOR_INDEX1_EXT
:
910 case GL_COLOR_INDEX2_EXT
:
911 case GL_COLOR_INDEX4_EXT
:
912 case GL_COLOR_INDEX8_EXT
:
913 case GL_COLOR_INDEX12_EXT
:
914 case GL_COLOR_INDEX16_EXT
:
915 return &_mesa_texformat_ci8
;
917 case GL_LUMINANCE_ALPHA
:
918 case GL_LUMINANCE4_ALPHA4
:
919 case GL_LUMINANCE6_ALPHA2
:
920 case GL_LUMINANCE8_ALPHA8
:
921 case GL_LUMINANCE12_ALPHA4
:
922 case GL_LUMINANCE12_ALPHA12
:
923 case GL_LUMINANCE16_ALPHA16
:
924 case GL_COMPRESSED_LUMINANCE_ALPHA
:
925 return &_mesa_texformat_al88
;
929 return &_mesa_texformat_rgb565
;
932 case GL_COMPRESSED_RGB
:
933 if ( srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
934 return &_mesa_texformat_rgb565
;
936 /* intentional fall through */
941 return (allow32bpt
) ? &_mesa_texformat_argb8888
942 : &_mesa_texformat_rgb565
;
945 return &_mesa_texformat_argb4444
;
948 case GL_COMPRESSED_RGBA
:
949 if ( srcFormat
== GL_BGRA
) {
950 if ( srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) {
951 return &_mesa_texformat_argb8888
;
953 else if ( srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
954 return &_mesa_texformat_argb4444
;
956 else if ( srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
957 return &_mesa_texformat_argb1555
;
960 /* intentional fall through */
965 return (allow32bpt
) ? &_mesa_texformat_argb8888
966 : &_mesa_texformat_argb4444
;
968 return &_mesa_texformat_argb1555
;
970 /* GL_EXT_texture_compression_s3tc */
971 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
972 return &_mesa_texformat_rgb_dxt1
;
973 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
974 return &_mesa_texformat_rgba_dxt1
;
975 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
976 return &_mesa_texformat_rgba_dxt3
;
977 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
978 return &_mesa_texformat_rgba_dxt5
;
979 /*case GL_COMPRESSED_RGB_FXT1_3DFX:
980 case GL_COMPRESSED_RGBA_FXT1_3DFX:
984 _mesa_problem(NULL
, "unexpected format in fxDDChooseTextureFormat");
990 static GrTextureFormat_t
991 fxGlideFormat(GLint mesaFormat
)
993 switch (mesaFormat
) {
995 return GR_TEXFMT_ALPHA_8
;
997 return GR_TEXFMT_ALPHA_8
;
999 return GR_TEXFMT_INTENSITY_8
;
1000 case MESA_FORMAT_CI8
:
1001 return GR_TEXFMT_P_8
;
1002 case MESA_FORMAT_AL88
:
1003 return GR_TEXFMT_ALPHA_INTENSITY_88
;
1004 case MESA_FORMAT_RGB565
:
1005 return GR_TEXFMT_RGB_565
;
1006 case MESA_FORMAT_ARGB4444
:
1007 return GR_TEXFMT_ARGB_4444
;
1008 case MESA_FORMAT_ARGB1555
:
1009 return GR_TEXFMT_ARGB_1555
;
1010 case MESA_FORMAT_ARGB8888
:
1011 return GR_TEXFMT_ARGB_8888
;
1013 case MESA_FORMAT_RGB_DXT1
:
1014 case MESA_FORMAT_RGBA_DXT1
:
1015 return GR_TEXFMT_ARGB_CMP_DXT1
;
1016 case MESA_FORMAT_RGBA_DXT3
:
1017 return GR_TEXFMT_ARGB_CMP_DXT3
;
1018 case MESA_FORMAT_RGBA_DXT5
:
1019 return GR_TEXFMT_ARGB_CMP_DXT5
;
1020 /*case MESA_FORMAT_ARGB_CMP_FXT1:
1021 return GR_TEXFMT_ARGB_CMP_FXT1;
1022 case MESA_FORMAT_RGB_CMP_FXT1:
1023 return GL_COMPRESSED_RGBA_FXT1_3DFX;*/
1026 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1032 static FetchTexelFunc
1033 fxFetchFunction(GLint mesaFormat
)
1035 switch (mesaFormat
) {
1036 case MESA_FORMAT_I8
:
1037 return fetch_intensity8
;
1038 case MESA_FORMAT_A8
:
1039 return fetch_alpha8
;
1040 case MESA_FORMAT_L8
:
1041 return fetch_luminance8
;
1042 case MESA_FORMAT_CI8
:
1043 return fetch_index8
;
1044 case MESA_FORMAT_AL88
:
1045 return fetch_luminance8_alpha8
;
1046 case MESA_FORMAT_RGB565
:
1047 return fetch_r5g6b5
;
1048 case MESA_FORMAT_ARGB4444
:
1049 return fetch_r4g4b4a4
;
1050 case MESA_FORMAT_ARGB1555
:
1051 return fetch_r5g5b5a1
;
1052 case MESA_FORMAT_ARGB8888
:
1053 return fetch_a8r8g8b8
;
1055 case MESA_FORMAT_RGB_DXT1
:
1056 case MESA_FORMAT_RGBA_DXT1
:
1057 case MESA_FORMAT_RGBA_DXT3
:
1058 case MESA_FORMAT_RGBA_DXT5
:
1059 return fetch_r4g4b4a4
;
1062 _mesa_problem(NULL
, "Unexpected format in fxFetchFunction");
1068 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1069 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1070 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1071 const struct gl_pixelstore_attrib
*packing
,
1072 struct gl_texture_object
*texObj
,
1073 struct gl_texture_image
*texImage
)
1075 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1077 tfxMipMapLevel
*mml
;
1080 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1081 fprintf(stderr
, "fxDDTexImage2D: id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1082 texObj
->Name
, texImage
->IntFormat
, format
, type
,
1083 texImage
->Width
, texImage
->Height
);
1086 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1087 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1091 if (!texObj
->DriverData
) {
1092 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1093 if (!texObj
->DriverData
) {
1094 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1098 ti
= fxTMGetTexInfo(texObj
);
1100 if (!texImage
->DriverData
) {
1101 texImage
->DriverData
= CALLOC(sizeof(tfxMipMapLevel
));
1102 if (!texImage
->DriverData
) {
1103 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1107 mml
= FX_MIPMAP_DATA(texImage
);
1109 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1110 &mml
->wScale
, &mml
->hScale
);
1112 mml
->width
= width
* mml
->wScale
;
1113 mml
->height
= height
* mml
->hScale
;
1116 /* choose the texture format */
1117 assert(ctx
->Driver
.ChooseTextureFormat
);
1118 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1119 internalFormat
, format
, type
);
1120 assert(texImage
->TexFormat
);
1121 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1122 /*if (!fxMesa->HaveTexFmt) assert(texelBytes == 1 || texelBytes == 2);*/
1124 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1125 /* rescale image to overcome 1:8 aspect limitation */
1127 tempImage
= MALLOC(width
* height
* texelBytes
);
1129 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1132 /* unpack image, apply transfer ops and store in tempImage */
1133 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1134 texImage
->TexFormat
,
1136 width
, height
, 1, 0, 0, 0,
1138 0, /* dstImageStride */
1139 format
, type
, pixels
, packing
);
1140 assert(!texImage
->Data
);
1141 texImage
->Data
= MESA_PBUFFER_ALLOC(mml
->width
* mml
->height
* texelBytes
);
1142 if (!texImage
->Data
) {
1143 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1147 _mesa_rescale_teximage2d(texelBytes
,
1148 mml
->width
* texelBytes
, /* dst stride */
1150 mml
->width
, mml
->height
,
1151 tempImage
/*src*/, texImage
->Data
/*dst*/ );
1155 /* no rescaling needed */
1156 assert(!texImage
->Data
);
1157 texImage
->Data
= MESA_PBUFFER_ALLOC(mml
->width
* mml
->height
* texelBytes
);
1158 if (!texImage
->Data
) {
1159 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1162 /* unpack image, apply transfer ops and store in texImage->Data */
1163 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1164 texImage
->TexFormat
, texImage
->Data
,
1165 width
, height
, 1, 0, 0, 0,
1166 texImage
->Width
* texelBytes
,
1167 0, /* dstImageStride */
1168 format
, type
, pixels
, packing
);
1171 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1172 ti
->info
.format
= mml
->glideFormat
;
1173 texImage
->FetchTexel
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1176 * Hack alert: unsure...
1178 if (!(fxMesa
->new_state
& FX_NEW_TEXTURING
) && ti
->validated
&& ti
->isInTM
) {
1179 /*fprintf(stderr, "reloadmipmaplevels\n"); */
1180 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1183 /*fprintf(stderr, "invalidate2\n"); */
1184 fxTexInvalidate(ctx
, texObj
);
1190 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1191 GLint xoffset
, GLint yoffset
,
1192 GLsizei width
, GLsizei height
,
1193 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1194 const struct gl_pixelstore_attrib
*packing
,
1195 struct gl_texture_object
*texObj
,
1196 struct gl_texture_image
*texImage
)
1198 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1200 tfxMipMapLevel
*mml
;
1203 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1204 fprintf(stderr
, "fxDDTexSubImage2D: id=%d\n", texObj
->Name
);
1207 if (!texObj
->DriverData
) {
1208 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1212 ti
= fxTMGetTexInfo(texObj
);
1214 mml
= FX_MIPMAP_DATA(texImage
);
1217 assert(texImage
->Data
); /* must have an existing texture image! */
1218 assert(texImage
->Format
);
1220 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1222 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1223 /* need to rescale subimage to match mipmap level's rescale factors */
1224 const GLint newWidth
= width
* mml
->wScale
;
1225 const GLint newHeight
= height
* mml
->hScale
;
1228 tempImage
= MALLOC(width
* height
* texelBytes
);
1230 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1234 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,/* Tex int format */
1235 texImage
->TexFormat
, /* dest format */
1236 (GLubyte
*) tempImage
, /* dest */
1237 width
, height
, 1, /* subimage size */
1238 0, 0, 0, /* subimage pos */
1239 width
* texelBytes
, /* dest row stride */
1240 0, /* dst image stride */
1241 format
, type
, pixels
, packing
);
1244 /* compute address of dest subimage within the overal tex image */
1245 destAddr
= (GLubyte
*) texImage
->Data
1246 + (yoffset
* mml
->hScale
* mml
->width
1247 + xoffset
* mml
->wScale
) * texelBytes
;
1249 _mesa_rescale_teximage2d(texelBytes
,
1250 mml
->width
* texelBytes
, /* dst stride */
1252 newWidth
, newHeight
,
1253 tempImage
, destAddr
);
1258 /* no rescaling needed */
1259 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, /* Tex int format */
1260 texImage
->TexFormat
, /* dest format */
1261 (GLubyte
*) texImage
->Data
,/* dest */
1262 width
, height
, 1, /* subimage size */
1263 xoffset
, yoffset
, 0, /* subimage pos */
1264 mml
->width
* texelBytes
, /* dest row stride */
1265 0, /* dst image stride */
1266 format
, type
, pixels
, packing
);
1270 * Hack alert: unsure...
1272 if (!(fxMesa
->new_state
& FX_NEW_TEXTURING
) && ti
->validated
&& ti
->isInTM
)
1273 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1275 fxTexInvalidate(ctx
, texObj
);
1282 * Need this to provide at least one external definition.
1285 extern int gl_fx_dummy_function_ddtex(void);
1287 gl_fx_dummy_function_ddtex(void)