1 /* $Id: fxddtex.c,v 1.50 2003/10/13 11:14:58 dborca Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47 #include "texformat.h"
53 fxPrintTextureData(tfxTexInfo
* ti
)
55 fprintf(stderr
, "Texture Data:\n");
57 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
58 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
59 fprintf(stderr
, "\tSize: %d x %d\n",
60 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
61 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
64 fprintf(stderr
, "\tName: UNNAMED\n");
65 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
66 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
67 fprintf(stderr
, "\t%s\n", (ti
->isInTM
) ? "In TMU" : "Not in TMU");
69 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
70 (unsigned) ti
->tm
[0]->endAddr
);
72 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
73 (unsigned) ti
->tm
[1]->endAddr
);
74 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
75 fprintf(stderr
, "\tFilters: min %d min %d\n",
76 (int) ti
->minFilt
, (int) ti
->maxFilt
);
77 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
,
79 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
80 fprintf(stderr
, "\t%s\n",
81 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
82 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
86 /************************************************************************/
87 /*************************** Texture Mapping ****************************/
88 /************************************************************************/
91 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
93 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
96 ti
= fxTMGetTexInfo(tObj
);
98 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
100 ti
->validated
= GL_FALSE
;
101 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
105 fxAllocTexObjData(fxMesaContext fxMesa
)
109 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
110 fprintf(stderr
, "%s: ERROR: out of memory !\n", __FUNCTION__
);
115 ti
->validated
= GL_FALSE
;
116 ti
->isInTM
= GL_FALSE
;
118 ti
->whichTMU
= FX_TMU_NONE
;
120 ti
->tm
[FX_TMU0
] = NULL
;
121 ti
->tm
[FX_TMU1
] = NULL
;
123 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
124 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
126 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
127 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
129 ti
->mmMode
= GR_MIPMAP_NEAREST
;
130 ti
->LODblend
= FXFALSE
;
136 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
138 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
141 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
142 fprintf(stderr
, "%s(%d, %x)\n", __FUNCTION__
, tObj
->Name
,
143 (GLuint
) tObj
->DriverData
);
146 if (target
!= GL_TEXTURE_2D
)
149 if (!tObj
->DriverData
) {
150 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
153 ti
= fxTMGetTexInfo(tObj
);
155 fxMesa
->texBindNumber
++;
156 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
158 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
162 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
163 const GLfloat
* param
)
165 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
167 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
169 fprintf(stderr
, "%s(%x, %x)\n", __FUNCTION__
, pname
, (GLint
) (*param
));
171 fprintf(stderr
, "%s(%x)\n", __FUNCTION__
, pname
);
174 /* apply any lod biasing right now */
175 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
176 grTexLodBiasValue(GR_TMU0
, *param
);
178 if (fxMesa
->haveTwoTMUs
) {
179 grTexLodBiasValue(GR_TMU1
, *param
);
184 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
188 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
189 GLenum pname
, const GLfloat
* params
)
191 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
192 GLenum param
= (GLenum
) (GLint
) params
[0];
195 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
196 fprintf(stderr
, "fxDDTexParam(%d, %x, %s, %s)\n",
197 tObj
->Name
, (GLuint
) tObj
->DriverData
,
198 _mesa_lookup_enum_by_nr(pname
),
199 _mesa_lookup_enum_by_nr(param
));
202 if (target
!= GL_TEXTURE_2D
)
205 if (!tObj
->DriverData
)
206 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
208 ti
= fxTMGetTexInfo(tObj
);
212 case GL_TEXTURE_MIN_FILTER
:
215 ti
->mmMode
= GR_MIPMAP_DISABLE
;
216 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
217 ti
->LODblend
= FXFALSE
;
220 ti
->mmMode
= GR_MIPMAP_DISABLE
;
221 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
222 ti
->LODblend
= FXFALSE
;
224 case GL_NEAREST_MIPMAP_LINEAR
:
225 if (fxMesa
->haveTwoTMUs
) {
226 ti
->mmMode
= GR_MIPMAP_NEAREST
;
227 ti
->LODblend
= FXTRUE
;
230 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
231 ti
->LODblend
= FXFALSE
;
233 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
234 break; /* ZZZ: we may have to fall through here for V3 */
235 case GL_NEAREST_MIPMAP_NEAREST
:
236 ti
->mmMode
= GR_MIPMAP_NEAREST
;
237 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
238 ti
->LODblend
= FXFALSE
;
240 case GL_LINEAR_MIPMAP_LINEAR
:
241 /* ZZZ: HACK ALERT! trilinear is bugged! mipmap blending produce
242 incorrect filtered colors for the smallest mipmap levels. */
244 if (fxMesa
->haveTwoTMUs
) {
245 ti
->mmMode
= GR_MIPMAP_NEAREST
;
246 ti
->LODblend
= FXTRUE
;
249 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
250 ti
->LODblend
= FXFALSE
;
252 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
253 break; /* ZZZ: we may have to fall through here for V3 */
255 case GL_LINEAR_MIPMAP_NEAREST
:
256 ti
->mmMode
= GR_MIPMAP_NEAREST
;
257 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
258 ti
->LODblend
= FXFALSE
;
263 fxTexInvalidate(ctx
, tObj
);
266 case GL_TEXTURE_MAG_FILTER
:
269 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
272 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
277 fxTexInvalidate(ctx
, tObj
);
280 case GL_TEXTURE_WRAP_S
:
282 case GL_MIRRORED_REPEAT
:
283 ti
->sClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
285 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
287 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
290 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
295 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
298 case GL_TEXTURE_WRAP_T
:
300 case GL_MIRRORED_REPEAT
:
301 ti
->tClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
303 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
305 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
308 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
313 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
316 case GL_TEXTURE_BORDER_COLOR
:
320 case GL_TEXTURE_MIN_LOD
:
323 case GL_TEXTURE_MAX_LOD
:
326 case GL_TEXTURE_BASE_LEVEL
:
327 fxTexInvalidate(ctx
, tObj
);
329 case GL_TEXTURE_MAX_LEVEL
:
330 fxTexInvalidate(ctx
, tObj
);
339 fxDDTexDel(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
341 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
342 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
344 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
345 fprintf(stderr
, "%s(%d, %p)\n", __FUNCTION__
, tObj
->Name
, (void *) ti
);
351 fxTMFreeTexture(fxMesa
, tObj
);
354 tObj
->DriverData
= NULL
;
360 * Convert a gl_color_table texture palette to Glide's format.
363 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
365 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
366 GLint width
= table
->Size
;
370 ASSERT(!table
->FloatTable
);
372 switch (table
->Format
) {
374 for (i
= 0; i
< width
; i
++) {
379 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
383 for (i
= 0; i
< width
; i
++) {
388 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
392 for (i
= 0; i
< width
; i
++) {
395 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
398 case GL_LUMINANCE_ALPHA
:
399 for (i
= 0; i
< width
; i
++) {
400 r
= g
= b
= tableUB
[i
* 2 + 0];
401 a
= tableUB
[i
* 2 + 1];
402 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
406 for (i
= 0; i
< width
; i
++) {
407 r
= tableUB
[i
* 3 + 0];
408 g
= tableUB
[i
* 3 + 1];
409 b
= tableUB
[i
* 3 + 2];
411 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
415 for (i
= 0; i
< width
; i
++) {
416 r
= tableUB
[i
* 4 + 0];
417 g
= tableUB
[i
* 4 + 1];
418 b
= tableUB
[i
* 4 + 2];
419 a
= tableUB
[i
* 4 + 3];
420 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
428 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
430 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
433 /* per-texture palette */
435 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
436 fprintf(stderr
, "%s(%d, %x)\n", __FUNCTION__
,
437 tObj
->Name
, (GLuint
) tObj
->DriverData
);
439 if (!tObj
->DriverData
)
440 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
441 ti
= fxTMGetTexInfo(tObj
);
442 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
443 fxTexInvalidate(ctx
, tObj
);
446 /* global texture palette */
447 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
448 fprintf(stderr
, "%s(global)\n", __FUNCTION__
);
450 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
451 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
457 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
459 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
461 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
462 fprintf(stderr
, "%s(%d)\n", __FUNCTION__
, state
);
466 fxMesa
->haveGlobalPaletteTexture
= 1;
468 grTexDownloadTable(GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
471 fxMesa
->haveGlobalPaletteTexture
= 0;
473 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
474 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
475 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
477 if (!tObj
->DriverData
)
478 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
480 fxTexInvalidate(ctx
, tObj
);
510 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
511 float *sscale
, float *tscale
,
512 int *wscale
, int *hscale
)
514 static GrLOD_t lod
[12] = {
529 int logw
, logh
, ws
, hs
;
531 GrAspectRatio_t aspectratio
;
537 switch (logw
- logh
) {
539 aspectratio
= GR_ASPECT_LOG2_1x1
;
545 aspectratio
= GR_ASPECT_LOG2_2x1
;
553 aspectratio
= GR_ASPECT_LOG2_4x1
;
561 aspectratio
= GR_ASPECT_LOG2_8x1
;
569 aspectratio
= GR_ASPECT_LOG2_1x2
;
577 aspectratio
= GR_ASPECT_LOG2_1x4
;
585 aspectratio
= GR_ASPECT_LOG2_1x8
;
593 if ((logw
- logh
) > 3) {
594 aspectratio
= GR_ASPECT_LOG2_8x1
;
599 hs
= 1 << (logw
- logh
- 3);
600 } else /*if ((logw - logh) < -3)*/ {
601 aspectratio
= GR_ASPECT_LOG2_1x8
;
605 ws
= 1 << (logh
- logw
- 3);
633 fxIsTexSupported(GLenum target
, GLint internalFormat
,
634 const struct gl_texture_image
*image
)
636 if (target
!= GL_TEXTURE_2D
)
639 if (!fxTexGetInfo(image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
))
642 if (image
->Border
> 0)
649 /**********************************************************************/
650 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
651 /**********************************************************************/
653 /* Texel-fetch functions for software texturing and glGetTexImage().
654 * We should have been able to use some "standard" fetch functions (which
655 * may get defined in texutil.c) but we have to account for scaled texture
656 * images on tdfx hardware (the 8:1 aspect ratio limit).
657 * Hence, we need special functions here.
661 fetch_intensity8(const struct gl_texture_image
*texImage
,
662 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
664 GLchan
*rgba
= (GLchan
*) texelOut
;
665 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
666 const GLubyte
*texel
;
671 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
672 rgba
[RCOMP
] = *texel
;
673 rgba
[GCOMP
] = *texel
;
674 rgba
[BCOMP
] = *texel
;
675 rgba
[ACOMP
] = *texel
;
680 fetch_luminance8(const struct gl_texture_image
*texImage
,
681 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
683 GLchan
*rgba
= (GLchan
*) texelOut
;
684 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
685 const GLubyte
*texel
;
690 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
691 rgba
[RCOMP
] = *texel
;
692 rgba
[GCOMP
] = *texel
;
693 rgba
[BCOMP
] = *texel
;
699 fetch_alpha8(const struct gl_texture_image
*texImage
,
700 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
702 GLchan
*rgba
= (GLchan
*) texelOut
;
703 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
704 const GLubyte
*texel
;
708 i
= i
* mml
->width
/ texImage
->Width
;
709 j
= j
* mml
->height
/ texImage
->Height
;
711 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
715 rgba
[ACOMP
] = *texel
;
720 fetch_index8(const struct gl_texture_image
*texImage
,
721 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
723 GLchan
*indexOut
= (GLchan
*) texelOut
;
724 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
725 const GLubyte
*texel
;
729 i
= i
* mml
->width
/ texImage
->Width
;
730 j
= j
* mml
->height
/ texImage
->Height
;
732 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
738 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
739 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
741 GLchan
*rgba
= (GLchan
*) texelOut
;
742 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
743 const GLubyte
*texel
;
748 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
749 rgba
[RCOMP
] = texel
[0];
750 rgba
[GCOMP
] = texel
[0];
751 rgba
[BCOMP
] = texel
[0];
752 rgba
[ACOMP
] = texel
[1];
757 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
758 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
760 GLchan
*rgba
= (GLchan
*) texelOut
;
761 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
762 const GLushort
*texel
;
767 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
768 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
769 rgba
[GCOMP
] = FX_rgb_scale_6
[(*texel
>> 5) & 0x3F];
770 rgba
[BCOMP
] = FX_rgb_scale_5
[ *texel
& 0x1F];
776 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
777 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
779 GLchan
*rgba
= (GLchan
*) texelOut
;
780 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
781 const GLushort
*texel
;
786 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
787 rgba
[RCOMP
] = FX_rgb_scale_4
[(*texel
>> 12) & 0xF];
788 rgba
[GCOMP
] = FX_rgb_scale_4
[(*texel
>> 8) & 0xF];
789 rgba
[BCOMP
] = FX_rgb_scale_4
[(*texel
>> 4) & 0xF];
790 rgba
[ACOMP
] = FX_rgb_scale_4
[ *texel
& 0xF];
795 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
796 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
798 GLchan
*rgba
= (GLchan
*) texelOut
;
799 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
800 const GLushort
*texel
;
805 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
806 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
807 rgba
[GCOMP
] = FX_rgb_scale_5
[(*texel
>> 6) & 0x1F];
808 rgba
[BCOMP
] = FX_rgb_scale_5
[(*texel
>> 1) & 0x1F];
809 rgba
[ACOMP
] = ((*texel
) & 0x01) * 255;
814 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
815 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
817 GLchan
*rgba
= (GLchan
*) texelOut
;
818 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
824 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
825 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
826 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
827 rgba
[BCOMP
] = (((*texel
) ) & 0xff);
828 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
833 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
836 for (i
= 0; i
< h
; i
++) {
837 for (j
= 0; j
< w
; j
++) {
839 fprintf(stderr
, "%02x %02x ", data
[0], data
[1]);
841 fprintf(stderr
, "%02x %02x %02x ", data
[0], data
[1], data
[2]);
844 fprintf(stderr
, "\n");
849 const struct gl_texture_format
*
850 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
851 GLenum srcFormat
, GLenum srcType
)
853 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
854 GLboolean allow32bpt
= fxMesa
->HaveTexFmt
;
856 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
857 fprintf(stderr
, "fxDDChooseTextureFormat(...)\n");
860 switch (internalFormat
) {
866 case GL_COMPRESSED_INTENSITY
:
867 return &_mesa_texformat_i8
;
874 case GL_COMPRESSED_LUMINANCE
:
875 return &_mesa_texformat_l8
;
881 case GL_COMPRESSED_ALPHA
:
882 return &_mesa_texformat_a8
;
884 case GL_COLOR_INDEX1_EXT
:
885 case GL_COLOR_INDEX2_EXT
:
886 case GL_COLOR_INDEX4_EXT
:
887 case GL_COLOR_INDEX8_EXT
:
888 case GL_COLOR_INDEX12_EXT
:
889 case GL_COLOR_INDEX16_EXT
:
890 return &_mesa_texformat_ci8
;
892 case GL_LUMINANCE_ALPHA
:
893 case GL_LUMINANCE4_ALPHA4
:
894 case GL_LUMINANCE6_ALPHA2
:
895 case GL_LUMINANCE8_ALPHA8
:
896 case GL_LUMINANCE12_ALPHA4
:
897 case GL_LUMINANCE12_ALPHA12
:
898 case GL_LUMINANCE16_ALPHA16
:
899 case GL_COMPRESSED_LUMINANCE_ALPHA
:
900 return &_mesa_texformat_al88
;
904 return &_mesa_texformat_rgb565
;
907 case GL_COMPRESSED_RGB
:
908 if ( srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
909 return &_mesa_texformat_rgb565
;
911 /* intentional fall through */
916 return (allow32bpt
) ? &_mesa_texformat_argb8888
917 : &_mesa_texformat_rgb565
;
920 return &_mesa_texformat_argb4444
;
923 case GL_COMPRESSED_RGBA
:
924 if ( srcFormat
== GL_BGRA
) {
925 if ( srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) {
926 return &_mesa_texformat_argb8888
;
928 else if ( srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
929 return &_mesa_texformat_argb4444
;
931 else if ( srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
932 return &_mesa_texformat_argb1555
;
935 /* intentional fall through */
940 return (allow32bpt
) ? &_mesa_texformat_argb8888
941 : &_mesa_texformat_argb4444
;
943 return &_mesa_texformat_argb1555
;
945 /* GL_EXT_texture_compression_s3tc */
946 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
947 return &_mesa_texformat_rgb_dxt1
;
948 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
949 return &_mesa_texformat_rgba_dxt1
;
950 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
951 return &_mesa_texformat_rgba_dxt3
;
952 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
953 return &_mesa_texformat_rgba_dxt5
;
954 /*case GL_COMPRESSED_RGB_FXT1_3DFX:
955 case GL_COMPRESSED_RGBA_FXT1_3DFX:
959 _mesa_problem(NULL
, "unexpected format in fxDDChooseTextureFormat");
965 static GrTextureFormat_t
966 fxGlideFormat(GLint mesaFormat
)
968 switch (mesaFormat
) {
970 return GR_TEXFMT_ALPHA_8
;
972 return GR_TEXFMT_ALPHA_8
;
974 return GR_TEXFMT_INTENSITY_8
;
975 case MESA_FORMAT_CI8
:
976 return GR_TEXFMT_P_8
;
977 case MESA_FORMAT_AL88
:
978 return GR_TEXFMT_ALPHA_INTENSITY_88
;
979 case MESA_FORMAT_RGB565
:
980 return GR_TEXFMT_RGB_565
;
981 case MESA_FORMAT_ARGB4444
:
982 return GR_TEXFMT_ARGB_4444
;
983 case MESA_FORMAT_ARGB1555
:
984 return GR_TEXFMT_ARGB_1555
;
985 case MESA_FORMAT_ARGB8888
:
986 return GR_TEXFMT_ARGB_8888
;
988 case MESA_FORMAT_RGB_DXT1
:
989 case MESA_FORMAT_RGBA_DXT1
:
990 return GR_TEXFMT_ARGB_CMP_DXT1
;
991 case MESA_FORMAT_RGBA_DXT3
:
992 return GR_TEXFMT_ARGB_CMP_DXT3
;
993 case MESA_FORMAT_RGBA_DXT5
:
994 return GR_TEXFMT_ARGB_CMP_DXT5
;
995 /*case MESA_FORMAT_ARGB_CMP_FXT1:
996 return GR_TEXFMT_ARGB_CMP_FXT1;
997 case MESA_FORMAT_RGB_CMP_FXT1:
998 return GL_COMPRESSED_RGBA_FXT1_3DFX;*/
1001 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1007 static FetchTexelFunc
1008 fxFetchFunction(GLint mesaFormat
)
1010 switch (mesaFormat
) {
1011 case MESA_FORMAT_I8
:
1012 return fetch_intensity8
;
1013 case MESA_FORMAT_A8
:
1014 return fetch_alpha8
;
1015 case MESA_FORMAT_L8
:
1016 return fetch_luminance8
;
1017 case MESA_FORMAT_CI8
:
1018 return fetch_index8
;
1019 case MESA_FORMAT_AL88
:
1020 return fetch_luminance8_alpha8
;
1021 case MESA_FORMAT_RGB565
:
1022 return fetch_r5g6b5
;
1023 case MESA_FORMAT_ARGB4444
:
1024 return fetch_r4g4b4a4
;
1025 case MESA_FORMAT_ARGB1555
:
1026 return fetch_r5g5b5a1
;
1027 case MESA_FORMAT_ARGB8888
:
1028 return fetch_a8r8g8b8
;
1030 case MESA_FORMAT_RGB_DXT1
:
1031 case MESA_FORMAT_RGBA_DXT1
:
1032 case MESA_FORMAT_RGBA_DXT3
:
1033 case MESA_FORMAT_RGBA_DXT5
:
1034 return fetch_r4g4b4a4
;
1037 _mesa_problem(NULL
, "Unexpected format in fxFetchFunction");
1043 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1044 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1045 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1046 const struct gl_pixelstore_attrib
*packing
,
1047 struct gl_texture_object
*texObj
,
1048 struct gl_texture_image
*texImage
)
1050 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1052 tfxMipMapLevel
*mml
;
1055 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1056 fprintf(stderr
, "fxDDTexImage2D: id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1057 texObj
->Name
, texImage
->IntFormat
, format
, type
,
1058 texImage
->Width
, texImage
->Height
);
1061 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1062 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1066 if (!texObj
->DriverData
) {
1067 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1068 if (!texObj
->DriverData
) {
1069 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1073 ti
= fxTMGetTexInfo(texObj
);
1075 if (!texImage
->DriverData
) {
1076 texImage
->DriverData
= CALLOC(sizeof(tfxMipMapLevel
));
1077 if (!texImage
->DriverData
) {
1078 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1082 mml
= FX_MIPMAP_DATA(texImage
);
1084 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1085 &mml
->wScale
, &mml
->hScale
);
1087 mml
->width
= width
* mml
->wScale
;
1088 mml
->height
= height
* mml
->hScale
;
1091 /* choose the texture format */
1092 assert(ctx
->Driver
.ChooseTextureFormat
);
1093 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1094 internalFormat
, format
, type
);
1095 assert(texImage
->TexFormat
);
1096 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1097 /*if (!fxMesa->HaveTexFmt) assert(texelBytes == 1 || texelBytes == 2);*/
1099 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1100 /* rescale image to overcome 1:8 aspect limitation */
1102 tempImage
= MALLOC(width
* height
* texelBytes
);
1104 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1107 /* unpack image, apply transfer ops and store in tempImage */
1108 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1109 texImage
->TexFormat
,
1111 width
, height
, 1, 0, 0, 0,
1113 0, /* dstImageStride */
1114 format
, type
, pixels
, packing
);
1115 assert(!texImage
->Data
);
1116 texImage
->Data
= MESA_PBUFFER_ALLOC(mml
->width
* mml
->height
* texelBytes
);
1117 if (!texImage
->Data
) {
1118 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1122 _mesa_rescale_teximage2d(texelBytes
,
1123 mml
->width
* texelBytes
, /* dst stride */
1125 mml
->width
, mml
->height
,
1126 tempImage
/*src*/, texImage
->Data
/*dst*/ );
1130 /* no rescaling needed */
1131 assert(!texImage
->Data
);
1132 texImage
->Data
= MESA_PBUFFER_ALLOC(mml
->width
* mml
->height
* texelBytes
);
1133 if (!texImage
->Data
) {
1134 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1137 /* unpack image, apply transfer ops and store in texImage->Data */
1138 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1139 texImage
->TexFormat
, texImage
->Data
,
1140 width
, height
, 1, 0, 0, 0,
1141 texImage
->Width
* texelBytes
,
1142 0, /* dstImageStride */
1143 format
, type
, pixels
, packing
);
1146 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1147 ti
->info
.format
= mml
->glideFormat
;
1148 texImage
->FetchTexel
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1151 * Hack alert: unsure...
1153 if (!(fxMesa
->new_state
& FX_NEW_TEXTURING
) && ti
->validated
&& ti
->isInTM
) {
1154 /*fprintf(stderr, "reloadmipmaplevels\n"); */
1155 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1158 /*fprintf(stderr, "invalidate2\n"); */
1159 fxTexInvalidate(ctx
, texObj
);
1165 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1166 GLint xoffset
, GLint yoffset
,
1167 GLsizei width
, GLsizei height
,
1168 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1169 const struct gl_pixelstore_attrib
*packing
,
1170 struct gl_texture_object
*texObj
,
1171 struct gl_texture_image
*texImage
)
1173 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1175 tfxMipMapLevel
*mml
;
1178 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1179 fprintf(stderr
, "fxDDTexSubImage2D: id=%d\n", texObj
->Name
);
1182 if (!texObj
->DriverData
) {
1183 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1187 ti
= fxTMGetTexInfo(texObj
);
1189 mml
= FX_MIPMAP_DATA(texImage
);
1192 assert(texImage
->Data
); /* must have an existing texture image! */
1193 assert(texImage
->Format
);
1195 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1197 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1198 /* need to rescale subimage to match mipmap level's rescale factors */
1199 const GLint newWidth
= width
* mml
->wScale
;
1200 const GLint newHeight
= height
* mml
->hScale
;
1203 tempImage
= MALLOC(width
* height
* texelBytes
);
1205 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1209 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,/* Tex int format */
1210 texImage
->TexFormat
, /* dest format */
1211 (GLubyte
*) tempImage
, /* dest */
1212 width
, height
, 1, /* subimage size */
1213 0, 0, 0, /* subimage pos */
1214 width
* texelBytes
, /* dest row stride */
1215 0, /* dst image stride */
1216 format
, type
, pixels
, packing
);
1219 /* compute address of dest subimage within the overal tex image */
1220 destAddr
= (GLubyte
*) texImage
->Data
1221 + (yoffset
* mml
->hScale
* mml
->width
1222 + xoffset
* mml
->wScale
) * texelBytes
;
1224 _mesa_rescale_teximage2d(texelBytes
,
1225 mml
->width
* texelBytes
, /* dst stride */
1227 newWidth
, newHeight
,
1228 tempImage
, destAddr
);
1233 /* no rescaling needed */
1234 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, /* Tex int format */
1235 texImage
->TexFormat
, /* dest format */
1236 (GLubyte
*) texImage
->Data
,/* dest */
1237 width
, height
, 1, /* subimage size */
1238 xoffset
, yoffset
, 0, /* subimage pos */
1239 mml
->width
* texelBytes
, /* dest row stride */
1240 0, /* dst image stride */
1241 format
, type
, pixels
, packing
);
1245 * Hack alert: unsure...
1247 if (!(fxMesa
->new_state
& FX_NEW_TEXTURING
) && ti
->validated
&& ti
->isInTM
)
1248 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1250 fxTexInvalidate(ctx
, texObj
);
1257 * Need this to provide at least one external definition.
1260 extern int gl_fx_dummy_function_ddtex(void);
1262 gl_fx_dummy_function_ddtex(void)