3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
29 * Thank you for your contribution, David!
31 * Please make note of the above copyright/license statement. If you
32 * contributed code or bug fixes to this code under the previous (GNU
33 * Library) license and object to the new license, your code will be
34 * removed at your request. Please see the Mesa docs/COPYRIGHT file
35 * for more information.
37 * Additional Mesa/3Dfx driver developers:
38 * Daryll Strauss <daryll@precisioninsight.com>
39 * Keith Whitwell <keith@precisioninsight.com>
41 * See fxapi.h for more revision/author details.
58 void fxPrintTextureData(tfxTexInfo
*ti
)
60 fprintf(stderr
, "Texture Data:\n");
62 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
63 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
64 fprintf(stderr
, "\tSize: %d x %d\n",
65 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
66 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
68 fprintf(stderr
, "\tName: UNNAMED\n");
69 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
70 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
71 fprintf(stderr
, "\t%s\n", (ti
->isInTM
)?"In TMU":"Not in TMU");
73 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
74 (unsigned) ti
->tm
[0]->endAddr
);
76 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
77 (unsigned) ti
->tm
[1]->endAddr
);
78 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
79 fprintf(stderr
, "\tFilters: min %d min %d\n",
80 (int) ti
->minFilt
, (int) ti
->maxFilt
);
81 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
, (int) ti
->tClamp
);
82 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
83 fprintf(stderr
, "\tInt Scales: s %d t %d\n",
84 ti
->int_sScale
/0x800000, ti
->int_tScale
/0x800000);
85 fprintf(stderr
, "\t%s\n", (ti
->fixedPalette
)?"Fixed palette":"Non fixed palette");
86 fprintf(stderr
, "\t%s\n", (ti
->validated
)?"Validated":"Not validated");
90 /************************************************************************/
91 /*************************** Texture Mapping ****************************/
92 /************************************************************************/
94 static void fxTexInvalidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
96 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
99 ti
=fxTMGetTexInfo(tObj
);
100 if (ti
->isInTM
) fxTMMoveOutTM(fxMesa
,tObj
); /* TO DO: SLOW but easy to write */
102 ti
->validated
=GL_FALSE
;
103 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
106 static tfxTexInfo
*fxAllocTexObjData(fxMesaContext fxMesa
)
110 if(!(ti
=CALLOC(sizeof(tfxTexInfo
)))) {
111 fprintf(stderr
,"fx Driver: out of memory !\n");
116 ti
->validated
=GL_FALSE
;
119 ti
->whichTMU
=FX_TMU_NONE
;
121 ti
->tm
[FX_TMU0
]=NULL
;
122 ti
->tm
[FX_TMU1
]=NULL
;
124 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
125 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
127 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
128 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
130 ti
->mmMode
=GR_MIPMAP_NEAREST
;
131 ti
->LODblend
=FXFALSE
;
136 void fxDDTexBind(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
)
138 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
141 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
142 fprintf(stderr
,"fxmesa: fxDDTexBind(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
145 if(target
!=GL_TEXTURE_2D
)
148 if (!tObj
->DriverData
) {
149 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
152 ti
=fxTMGetTexInfo(tObj
);
154 fxMesa
->texBindNumber
++;
155 ti
->lastTimeUsed
=fxMesa
->texBindNumber
;
157 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
160 void fxDDTexEnv(GLcontext
*ctx
, GLenum target
, GLenum pname
, const GLfloat
*param
)
162 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
164 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
166 fprintf(stderr
,"fxmesa: texenv(%x,%x)\n",pname
,(GLint
)(*param
));
168 fprintf(stderr
,"fxmesa: texenv(%x)\n",pname
);
171 /* apply any lod biasing right now */
172 if (pname
==GL_TEXTURE_LOD_BIAS_EXT
) {
173 FX_grTexLodBiasValue(GR_TMU0
,*param
);
175 if(fxMesa
->haveTwoTMUs
) {
176 FX_grTexLodBiasValue(GR_TMU1
,*param
);
181 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
184 void fxDDTexParam(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
,
185 GLenum pname
, const GLfloat
*params
)
187 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
188 GLenum param
=(GLenum
)(GLint
)params
[0];
191 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
192 fprintf(stderr
,"fxmesa: fxDDTexParam(%d,%x,%x,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
,pname
,param
);
195 if(target
!=GL_TEXTURE_2D
)
198 if (!tObj
->DriverData
)
199 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
201 ti
=fxTMGetTexInfo(tObj
);
205 case GL_TEXTURE_MIN_FILTER
:
208 ti
->mmMode
=GR_MIPMAP_DISABLE
;
209 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
210 ti
->LODblend
=FXFALSE
;
213 ti
->mmMode
=GR_MIPMAP_DISABLE
;
214 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
215 ti
->LODblend
=FXFALSE
;
217 case GL_NEAREST_MIPMAP_NEAREST
:
218 ti
->mmMode
=GR_MIPMAP_NEAREST
;
219 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
220 ti
->LODblend
=FXFALSE
;
222 case GL_LINEAR_MIPMAP_NEAREST
:
223 ti
->mmMode
=GR_MIPMAP_NEAREST
;
224 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
225 ti
->LODblend
=FXFALSE
;
227 case GL_NEAREST_MIPMAP_LINEAR
:
228 if(fxMesa
->haveTwoTMUs
) {
229 ti
->mmMode
=GR_MIPMAP_NEAREST
;
232 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
233 ti
->LODblend
=FXFALSE
;
235 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
237 case GL_LINEAR_MIPMAP_LINEAR
:
238 if(fxMesa
->haveTwoTMUs
) {
239 ti
->mmMode
=GR_MIPMAP_NEAREST
;
242 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
243 ti
->LODblend
=FXFALSE
;
245 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
250 fxTexInvalidate(ctx
,tObj
);
253 case GL_TEXTURE_MAG_FILTER
:
256 ti
->maxFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
259 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
264 fxTexInvalidate(ctx
,tObj
);
267 case GL_TEXTURE_WRAP_S
:
270 ti
->sClamp
=GR_TEXTURECLAMP_CLAMP
;
273 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
278 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
281 case GL_TEXTURE_WRAP_T
:
284 ti
->tClamp
=GR_TEXTURECLAMP_CLAMP
;
287 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
292 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
295 case GL_TEXTURE_BORDER_COLOR
:
299 case GL_TEXTURE_MIN_LOD
:
302 case GL_TEXTURE_MAX_LOD
:
305 case GL_TEXTURE_BASE_LEVEL
:
306 fxTexInvalidate(ctx
,tObj
);
308 case GL_TEXTURE_MAX_LEVEL
:
309 fxTexInvalidate(ctx
,tObj
);
317 void fxDDTexDel(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
319 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
320 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
322 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
323 fprintf(stderr
, "fxmesa: fxDDTexDel(%d,%p)\n", tObj
->Name
, ti
);
329 fxTMFreeTexture(fxMesa
, tObj
);
332 tObj
->DriverData
= NULL
;
338 * Convert a gl_color_table texture palette to Glide's format.
341 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
343 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
344 GLint width
= table
->Size
;
348 ASSERT(!table
->FloatTable
);
350 switch (table
->Format
) {
352 for (i
= 0; i
< width
; i
++) {
357 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
361 for (i
= 0; i
< width
; i
++) {
366 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
370 for (i
= 0; i
< width
; i
++) {
373 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
376 case GL_LUMINANCE_ALPHA
:
377 for (i
= 0; i
< width
; i
++) {
378 r
= g
= b
= tableUB
[i
*2+0];
380 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
384 for (i
= 0; i
< width
; i
++) {
389 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
393 for (i
= 0; i
< width
; i
++) {
398 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
405 void fxDDTexPalette(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
407 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
410 /* per-texture palette */
412 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
413 fprintf(stderr
, "fxmesa: fxDDTexPalette(%d,%x)\n",
414 tObj
->Name
, (GLuint
) tObj
->DriverData
);
416 if (!tObj
->DriverData
)
417 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
418 ti
= fxTMGetTexInfo(tObj
);
419 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
420 fxTexInvalidate(ctx
, tObj
);
423 /* global texture palette */
424 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
425 fprintf(stderr
, "fxmesa: fxDDTexPalette(global)\n");
427 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
428 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
433 void fxDDTexUseGlbPalette(GLcontext
*ctx
, GLboolean state
)
435 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
437 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
438 fprintf(stderr
,"fxmesa: fxDDTexUseGlbPalette(%d)\n",state
);
442 fxMesa
->haveGlobalPaletteTexture
= 1;
444 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
445 if (fxMesa
->haveTwoTMUs
)
446 FX_grTexDownloadTable(GR_TMU1
, GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
449 fxMesa
->haveGlobalPaletteTexture
= 0;
451 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
452 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
453 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
455 if (!tObj
->DriverData
)
456 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
458 fxTexInvalidate(ctx
, tObj
);
464 static int logbase2(int n
)
485 /* Need different versions for different cpus.
487 #define INT_TRICK(l2) (0x800000 * l2)
490 int fxTexGetInfo(int w
, int h
, GrLOD_t
*lodlevel
, GrAspectRatio_t
*ar
,
491 float *sscale
, float *tscale
,
492 int *i_sscale
, int *i_tscale
,
493 int *wscale
, int *hscale
)
496 static GrLOD_t lod
[9]={GR_LOD_256
,GR_LOD_128
,GR_LOD_64
,GR_LOD_32
,
497 GR_LOD_16
,GR_LOD_8
,GR_LOD_4
,GR_LOD_2
,GR_LOD_1
};
501 GrAspectRatio_t aspectratio
;
510 aspectratio
=GR_ASPECT_1x1
;
517 aspectratio
=GR_ASPECT_2x1
;
521 is
=INT_TRICK(8);it
=INT_TRICK(7);
526 aspectratio
=GR_ASPECT_4x1
;
530 is
=INT_TRICK(8);it
=INT_TRICK(6);
535 aspectratio
=GR_ASPECT_8x1
;
539 is
=INT_TRICK(8);it
=INT_TRICK(5);
544 aspectratio
=GR_ASPECT_8x1
;
548 is
=INT_TRICK(8);it
=INT_TRICK(5);
553 aspectratio
=GR_ASPECT_8x1
;
557 is
=INT_TRICK(8);it
=INT_TRICK(5);
562 aspectratio
=GR_ASPECT_8x1
;
566 is
=INT_TRICK(8);it
=INT_TRICK(5);
571 aspectratio
=GR_ASPECT_8x1
;
575 is
=INT_TRICK(8);it
=INT_TRICK(5);
580 aspectratio
=GR_ASPECT_8x1
;
584 is
=INT_TRICK(8);it
=INT_TRICK(5);
589 aspectratio
=GR_ASPECT_1x2
;
593 is
=INT_TRICK(7);it
=INT_TRICK(8);
598 aspectratio
=GR_ASPECT_1x4
;
602 is
=INT_TRICK(6);it
=INT_TRICK(8);
607 aspectratio
=GR_ASPECT_1x8
;
611 is
=INT_TRICK(5);it
=INT_TRICK(8);
616 aspectratio
=GR_ASPECT_1x8
;
620 is
=INT_TRICK(5);it
=INT_TRICK(8);
625 aspectratio
=GR_ASPECT_1x8
;
629 is
=INT_TRICK(5);it
=INT_TRICK(8);
634 aspectratio
=GR_ASPECT_1x8
;
638 is
=INT_TRICK(5);it
=INT_TRICK(8);
643 aspectratio
=GR_ASPECT_1x8
;
647 is
=INT_TRICK(5);it
=INT_TRICK(8);
652 aspectratio
=GR_ASPECT_1x8
;
656 is
=INT_TRICK(5);it
=INT_TRICK(8);
694 * Given an OpenGL internal texture format, return the corresponding
695 * Glide internal texture format and base texture format.
697 void fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
*tfmt
, GLint
*ifmt
)
707 (*tfmt
)=GR_TEXFMT_INTENSITY_8
;
709 (*ifmt
)=GL_LUMINANCE
;
712 case GL_LUMINANCE_ALPHA
:
713 case GL_LUMINANCE4_ALPHA4
:
714 case GL_LUMINANCE6_ALPHA2
:
715 case GL_LUMINANCE8_ALPHA8
:
716 case GL_LUMINANCE12_ALPHA4
:
717 case GL_LUMINANCE12_ALPHA12
:
718 case GL_LUMINANCE16_ALPHA16
:
720 (*tfmt
)=GR_TEXFMT_ALPHA_INTENSITY_88
;
722 (*ifmt
)=GL_LUMINANCE_ALPHA
;
730 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
732 (*ifmt
)=GL_INTENSITY
;
740 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
754 (*tfmt
)=GR_TEXFMT_RGB_565
;
767 (*tfmt
)=GR_TEXFMT_ARGB_4444
;
773 (*tfmt
)=GR_TEXFMT_ARGB_1555
;
778 case GL_COLOR_INDEX1_EXT
:
779 case GL_COLOR_INDEX2_EXT
:
780 case GL_COLOR_INDEX4_EXT
:
781 case GL_COLOR_INDEX8_EXT
:
782 case GL_COLOR_INDEX12_EXT
:
783 case GL_COLOR_INDEX16_EXT
:
785 (*tfmt
)=GR_TEXFMT_P_8
;
787 (*ifmt
)=GL_RGBA
; /* XXX why is this RGBA? */
791 "fx Driver: unsupported internalFormat in fxTexGetFormat()\n");
798 static GLboolean
fxIsTexSupported(GLenum target
, GLint internalFormat
,
799 const struct gl_texture_image
*image
)
801 if(target
!= GL_TEXTURE_2D
)
804 if(!fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
808 if (image
->Border
> 0)
815 /**********************************************************************/
816 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
817 /**********************************************************************/
819 /* Texel-fetch functions for software texturing and glGetTexImage().
820 * We should have been able to use some "standard" fetch functions (which
821 * may get defined in texutil.c) but we have to account for scaled texture
822 * images on tdfx hardware (the 8:1 aspect ratio limit).
823 * Hence, we need special functions here.
827 fetch_intensity8(GLcontext
*ctx
,
828 const struct gl_texture_object
*texObj
,
829 const struct gl_texture_image
*texImage
,
830 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
832 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
833 const GLubyte
*texel
;
838 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
839 rgba
[RCOMP
] = *texel
;
840 rgba
[GCOMP
] = *texel
;
841 rgba
[BCOMP
] = *texel
;
842 rgba
[ACOMP
] = *texel
;
847 fetch_luminance8(GLcontext
*ctx
,
848 const struct gl_texture_object
*texObj
,
849 const struct gl_texture_image
*texImage
,
850 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
852 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
853 const GLubyte
*texel
;
858 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
859 rgba
[RCOMP
] = *texel
;
860 rgba
[GCOMP
] = *texel
;
861 rgba
[BCOMP
] = *texel
;
868 fetch_alpha8(GLcontext
*ctx
,
869 const struct gl_texture_object
*texObj
,
870 const struct gl_texture_image
*texImage
,
871 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
873 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
874 const GLubyte
*texel
;
878 i
= i
* mml
->width
/ texImage
->Width
;
879 j
= j
* mml
->height
/ texImage
->Height
;
881 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
885 rgba
[ACOMP
] = *texel
;
890 fetch_index8(GLcontext
*ctx
,
891 const struct gl_texture_object
*texObj
,
892 const struct gl_texture_image
*texImage
,
893 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
900 fetch_luminance8_alpha8(GLcontext
*ctx
,
901 const struct gl_texture_object
*texObj
,
902 const struct gl_texture_image
*texImage
,
903 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
905 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
906 const GLubyte
*texel
;
911 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
912 rgba
[RCOMP
] = texel
[0];
913 rgba
[GCOMP
] = texel
[0];
914 rgba
[BCOMP
] = texel
[0];
915 rgba
[ACOMP
] = texel
[1];
919 fetch_r5g6b5(GLcontext
*ctx
,
920 const struct gl_texture_object
*texObj
,
921 const struct gl_texture_image
*texImage
,
922 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
924 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
925 const GLushort
*texel
;
930 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
931 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
932 rgba
[GCOMP
] = (((*texel
) >> 5) & 0x3f) * 255 / 63;
933 rgba
[BCOMP
] = (((*texel
) >> 0) & 0x1f) * 255 / 31;
939 fetch_r4g4b4a4(GLcontext
*ctx
,
940 const struct gl_texture_object
*texObj
,
941 const struct gl_texture_image
*texImage
,
942 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
944 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
945 const GLushort
*texel
;
950 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
951 rgba
[RCOMP
] = (((*texel
) >> 12) & 0xf) * 255 / 15;
952 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xf) * 255 / 15;
953 rgba
[BCOMP
] = (((*texel
) >> 4) & 0xf) * 255 / 15;
954 rgba
[ACOMP
] = (((*texel
) >> 0) & 0xf) * 255 / 15;
959 fetch_r5g5b5a1(GLcontext
*ctx
,
960 const struct gl_texture_object
*texObj
,
961 const struct gl_texture_image
*texImage
,
962 GLint i
, GLint j
, GLint k
, GLchan rgba
[4])
964 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
965 const GLushort
*texel
;
970 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
971 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
972 rgba
[GCOMP
] = (((*texel
) >> 6) & 0x1f) * 255 / 31;
973 rgba
[BCOMP
] = (((*texel
) >> 1) & 0x1f) * 255 / 31;
974 rgba
[ACOMP
] = (((*texel
) >> 0) & 0x01) * 255;
978 static void PrintTexture(int w
, int h
, int c
, const GLubyte
*data
)
981 for (i
= 0; i
< h
; i
++) {
982 for (j
= 0; j
< w
; j
++) {
984 printf("%02x %02x ", data
[0], data
[1]);
986 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
995 fxDDTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
996 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
997 GLenum format
, GLenum type
, const GLvoid
*pixels
,
998 const struct gl_pixelstore_attrib
*packing
,
999 struct gl_texture_object
*texObj
,
1000 struct gl_texture_image
*texImage
)
1002 fxMesaContext fxMesa
= (fxMesaContext
)ctx
->DriverCtx
;
1003 GrTextureFormat_t gldformat
;
1004 tfxTexInfo
*ti
= fxTMGetTexInfo(texObj
);
1005 tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1006 MesaIntTexFormat mesaFormat
;
1010 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1011 gl_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1015 if (!texObj
->DriverData
)
1016 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1019 texImage
->DriverData
= MALLOC(sizeof(tfxMipMapLevel
));
1020 mml
= FX_MIPMAP_DATA(texImage
);
1023 fxTexGetFormat(internalFormat
, &gldformat
, NULL
);
1025 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1026 NULL
, NULL
, &mml
->wScale
, &mml
->hScale
);
1028 mml
->width
= texImage
->Width
* mml
->wScale
;
1029 mml
->height
= texImage
->Height
* mml
->hScale
;
1031 switch (internalFormat
) {
1035 case GL_INTENSITY12
:
1036 case GL_INTENSITY16
:
1037 texImage
->FetchTexel
= fetch_intensity8
;
1039 mesaFormat
= MESA_I8
;
1045 case GL_LUMINANCE12
:
1046 case GL_LUMINANCE16
:
1047 texImage
->FetchTexel
= fetch_luminance8
;
1049 mesaFormat
= MESA_L8
;
1056 texImage
->FetchTexel
= fetch_alpha8
;
1058 mesaFormat
= MESA_A8
;
1060 case GL_COLOR_INDEX
:
1061 case GL_COLOR_INDEX1_EXT
:
1062 case GL_COLOR_INDEX2_EXT
:
1063 case GL_COLOR_INDEX4_EXT
:
1064 case GL_COLOR_INDEX8_EXT
:
1065 case GL_COLOR_INDEX12_EXT
:
1066 case GL_COLOR_INDEX16_EXT
:
1067 texImage
->FetchTexel
= fetch_index8
;
1069 mesaFormat
= MESA_C8
;
1072 case GL_LUMINANCE_ALPHA
:
1073 case GL_LUMINANCE4_ALPHA4
:
1074 case GL_LUMINANCE6_ALPHA2
:
1075 case GL_LUMINANCE8_ALPHA8
:
1076 case GL_LUMINANCE12_ALPHA4
:
1077 case GL_LUMINANCE12_ALPHA12
:
1078 case GL_LUMINANCE16_ALPHA16
:
1079 texImage
->FetchTexel
= fetch_luminance8_alpha8
;
1081 mesaFormat
= MESA_A8_L8
;
1092 texImage
->FetchTexel
= fetch_r5g6b5
;
1094 mesaFormat
= MESA_R5_G6_B5
;
1104 texImage
->FetchTexel
= fetch_r4g4b4a4
;
1106 mesaFormat
= MESA_A4_R4_G4_B4
;
1109 texImage
->FetchTexel
= fetch_r5g5b5a1
;
1111 mesaFormat
= MESA_A1_R5_G5_B5
;
1114 gl_problem(NULL
, "tdfx driver: texbuildimagemap() bad format");
1118 _mesa_set_teximage_component_sizes(mesaFormat
, texImage
);
1120 /* allocate new storage for texture image, if needed */
1121 texImage
->Data
= MALLOC(mml
->width
* mml
->height
* texelSize
);
1122 if (!texImage
->Data
)
1125 mml
->glideFormat
= gldformat
;
1126 fxTexInvalidate(ctx
, texObj
);
1128 /* store the texture image */
1129 if (ctx
->_ImageTransferState
) {
1133 success
= _mesa_convert_teximage(mesaFormat
, mml
->width
, mml
->height
,
1134 texImage
->Data
, mml
->width
* texelSize
,
1136 format
, type
, pixels
, packing
);
1140 /* First attempt at texture conversion failed. We may need to
1141 * do fancy pixel transfer ops or convert from an obscure texture
1144 GLenum simpleFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1145 GLint comps
= _mesa_components_in_format(simpleFormat
);
1148 tempImage
= MALLOC(width
* height
* comps
* sizeof(GLubyte
));
1150 /* Apply pixel transfer ops and convert image format to something
1151 * simple (format = simpleFormat, type = CHAN_TYPE).
1153 _mesa_transfer_teximage(ctx
, 2, /* dimensions */
1154 simpleFormat
, /* dest format */
1155 tempImage
, /* dest addr */
1156 width
, height
, 1, /* src size */
1157 0, 0, 0, /* dst offsets */
1158 width
* comps
, /* dstRowStride */
1159 0, /* dstImageStride */
1160 format
, type
, pixels
, packing
/* src info */);
1162 /* this conversion better work! */
1163 success
= _mesa_convert_teximage(mesaFormat
, mml
->width
, mml
->height
,
1164 texImage
->Data
, mml
->width
* texelSize
,
1166 simpleFormat
, CHAN_TYPE
, tempImage
,
1167 &_mesa_native_packing
);
1172 if (ti
->validated
&& ti
->isInTM
) {
1173 /*printf("reloadmipmaplevels\n");*/
1174 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1177 /*printf("invalidate2\n");*/
1178 fxTexInvalidate(ctx
,texObj
);
1184 fxDDTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
1185 GLint xoffset
, GLint yoffset
,
1186 GLsizei width
, GLsizei height
,
1187 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1188 const struct gl_pixelstore_attrib
*packing
,
1189 struct gl_texture_object
*texObj
,
1190 struct gl_texture_image
*texImage
)
1192 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1195 tfxMipMapLevel
*mml
;
1197 MesaIntTexFormat mesaFormat
;
1199 if (!texObj
->DriverData
) {
1200 gl_problem(ctx
, "problem in fxDDTexSubImage2D");
1204 ti
= fxTMGetTexInfo(texObj
);
1206 mml
= FX_MIPMAP_DATA(texImage
);
1209 assert(texImage
->Data
); /* must have an existing texture image! */
1211 switch (mml
->glideFormat
) {
1212 case GR_TEXFMT_INTENSITY_8
:
1214 mesaFormat
= MESA_I8
;
1216 case GR_TEXFMT_ALPHA_8
:
1218 mesaFormat
= MESA_A8
;
1222 mesaFormat
= MESA_C8
;
1224 case GR_TEXFMT_ALPHA_INTENSITY_88
:
1226 mesaFormat
= MESA_A8_L8
;
1228 case GR_TEXFMT_RGB_565
:
1230 mesaFormat
= MESA_R5_G6_B5
;
1232 case GR_TEXFMT_ARGB_4444
:
1234 mesaFormat
= MESA_A4_R4_G4_B4
;
1236 case GR_TEXFMT_ARGB_1555
:
1238 mesaFormat
= MESA_A1_R5_G5_B5
;
1241 gl_problem(NULL
, "tdfx driver: fxTexBuildSubImageMap() bad format");
1245 if (ctx
->_ImageTransferState
) {
1249 success
= _mesa_convert_texsubimage(mesaFormat
, xoffset
, yoffset
,
1250 mml
->width
, mml
->height
,
1252 mml
->width
* texelSize
,
1254 texImage
->Width
, texImage
->Height
,
1255 format
, type
, pixels
, packing
);
1259 /* Incoming image might need scale/bias or is in an uncommon format
1260 * that _mesa_convert_texsubimage() can't deal with. Convert it to
1261 * a simpler format now.
1264 GLenum simpleFormat
= _mesa_base_tex_format(ctx
, texImage
->IntFormat
);
1265 GLint comps
= _mesa_components_in_format(simpleFormat
);
1269 tempImage
= MALLOC(width
* height
* comps
* sizeof(GLubyte
));
1271 /* Apply pixel transfer ops and convert image format to something
1272 * simple (format = simpleFormat, type = CHAN_TYPE).
1274 _mesa_transfer_teximage(ctx
, 2, /* dimensions */
1275 simpleFormat
, /* dest format */
1276 tempImage
, /* dest addr */
1277 width
, height
, 1, /* src size */
1278 0, 0, 0, /* dst offsets */
1279 width
* comps
, /* dstRowStride */
1280 0, /* dstImageStride */
1281 format
, type
, pixels
, packing
/* src info */);
1283 /* this conversion better work! */
1284 success
= _mesa_convert_texsubimage(mesaFormat
, xoffset
, yoffset
,
1285 mml
->width
, mml
->height
,
1287 mml
->width
* texelSize
, /* dstRowStride */
1288 width
* mml
->wScale
,
1289 height
* mml
->hScale
,
1291 simpleFormat
, CHAN_TYPE
, tempImage
,
1292 &_mesa_native_packing
);
1297 if (ti
->validated
&& ti
->isInTM
)
1298 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1300 fxTexInvalidate(ctx
, texObj
);
1308 * Need this to provide at least one external definition.
1311 extern int gl_fx_dummy_function_ddtex(void);
1312 int gl_fx_dummy_function_ddtex(void)