3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2000 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.
56 void fxPrintTextureData(tfxTexInfo
*ti
)
58 fprintf(stderr
, "Texture Data:\n");
60 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
61 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
62 fprintf(stderr
, "\tSize: %d x %d\n",
63 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
64 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
66 fprintf(stderr
, "\tName: UNNAMED\n");
67 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
68 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
69 fprintf(stderr
, "\t%s\n", (ti
->isInTM
)?"In TMU":"Not in TMU");
71 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
72 (unsigned) ti
->tm
[0]->endAddr
);
74 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
75 (unsigned) ti
->tm
[1]->endAddr
);
76 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
77 fprintf(stderr
, "\tFilters: min %d min %d\n",
78 (int) ti
->minFilt
, (int) ti
->maxFilt
);
79 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
, (int) ti
->tClamp
);
80 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
81 fprintf(stderr
, "\tInt Scales: s %d t %d\n",
82 ti
->int_sScale
/0x800000, ti
->int_tScale
/0x800000);
83 fprintf(stderr
, "\t%s\n", (ti
->fixedPalette
)?"Fixed palette":"Non fixed palette");
84 fprintf(stderr
, "\t%s\n", (ti
->validated
)?"Validated":"Not validated");
88 /************************************************************************/
89 /*************************** Texture Mapping ****************************/
90 /************************************************************************/
92 static void fxTexInvalidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
94 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
97 ti
=fxTMGetTexInfo(tObj
);
98 if (ti
->isInTM
) fxTMMoveOutTM(fxMesa
,tObj
); /* TO DO: SLOW but easy to write */
100 ti
->validated
=GL_FALSE
;
101 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
104 static tfxTexInfo
*fxAllocTexObjData(fxMesaContext fxMesa
)
109 if(!(ti
=CALLOC(sizeof(tfxTexInfo
)))) {
110 fprintf(stderr
,"fx Driver: out of memory !\n");
115 ti
->validated
=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
;
132 for(i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
133 ti
->mipmapLevel
[i
].data
=NULL
;
139 void fxDDTexBind(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
)
141 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
144 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
145 fprintf(stderr
,"fxmesa: fxDDTexBind(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
148 if(target
!=GL_TEXTURE_2D
)
151 if (!tObj
->DriverData
) {
152 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
155 ti
=fxTMGetTexInfo(tObj
);
157 fxMesa
->texBindNumber
++;
158 ti
->lastTimeUsed
=fxMesa
->texBindNumber
;
160 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
163 void fxDDTexEnv(GLcontext
*ctx
, GLenum target
, GLenum pname
, const GLfloat
*param
)
165 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
167 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
169 fprintf(stderr
,"fxmesa: texenv(%x,%x)\n",pname
,(GLint
)(*param
));
171 fprintf(stderr
,"fxmesa: texenv(%x)\n",pname
);
174 /* apply any lod biasing right now */
175 if (pname
==GL_TEXTURE_LOD_BIAS_EXT
) {
176 FX_grTexLodBiasValue(GR_TMU0
,*param
);
178 if(fxMesa
->haveTwoTMUs
) {
179 FX_grTexLodBiasValue(GR_TMU1
,*param
);
184 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
187 void fxDDTexParam(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
,
188 GLenum pname
, const GLfloat
*params
)
190 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
191 GLenum param
=(GLenum
)(GLint
)params
[0];
194 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
195 fprintf(stderr
,"fxmesa: fxDDTexParam(%d,%x,%x,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
,pname
,param
);
198 if(target
!=GL_TEXTURE_2D
)
201 if (!tObj
->DriverData
)
202 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
204 ti
=fxTMGetTexInfo(tObj
);
208 case GL_TEXTURE_MIN_FILTER
:
211 ti
->mmMode
=GR_MIPMAP_DISABLE
;
212 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
213 ti
->LODblend
=FXFALSE
;
216 ti
->mmMode
=GR_MIPMAP_DISABLE
;
217 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
218 ti
->LODblend
=FXFALSE
;
220 case GL_NEAREST_MIPMAP_NEAREST
:
221 ti
->mmMode
=GR_MIPMAP_NEAREST
;
222 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
223 ti
->LODblend
=FXFALSE
;
225 case GL_LINEAR_MIPMAP_NEAREST
:
226 ti
->mmMode
=GR_MIPMAP_NEAREST
;
227 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
228 ti
->LODblend
=FXFALSE
;
230 case GL_NEAREST_MIPMAP_LINEAR
:
231 if(fxMesa
->haveTwoTMUs
) {
232 ti
->mmMode
=GR_MIPMAP_NEAREST
;
235 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
236 ti
->LODblend
=FXFALSE
;
238 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
240 case GL_LINEAR_MIPMAP_LINEAR
:
241 if(fxMesa
->haveTwoTMUs
) {
242 ti
->mmMode
=GR_MIPMAP_NEAREST
;
245 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
246 ti
->LODblend
=FXFALSE
;
248 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
253 fxTexInvalidate(ctx
,tObj
);
256 case GL_TEXTURE_MAG_FILTER
:
259 ti
->maxFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
262 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
267 fxTexInvalidate(ctx
,tObj
);
270 case GL_TEXTURE_WRAP_S
:
273 ti
->sClamp
=GR_TEXTURECLAMP_CLAMP
;
276 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
281 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
284 case GL_TEXTURE_WRAP_T
:
287 ti
->tClamp
=GR_TEXTURECLAMP_CLAMP
;
290 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
295 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
298 case GL_TEXTURE_BORDER_COLOR
:
302 case GL_TEXTURE_MIN_LOD
:
305 case GL_TEXTURE_MAX_LOD
:
308 case GL_TEXTURE_BASE_LEVEL
:
309 fxTexInvalidate(ctx
,tObj
);
311 case GL_TEXTURE_MAX_LEVEL
:
312 fxTexInvalidate(ctx
,tObj
);
320 void fxDDTexDel(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
322 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
323 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
325 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
326 fprintf(stderr
, "fxmesa: fxDDTexDel(%d,%p)\n", tObj
->Name
, ti
);
332 fxTMFreeTexture(fxMesa
, tObj
);
335 tObj
->DriverData
= NULL
;
341 * Convert a gl_color_table texture palette to Glide's format.
344 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
346 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
347 GLint width
= table
->Size
;
351 ASSERT(!table
->FloatTable
);
353 switch (table
->Format
) {
355 for (i
= 0; i
< width
; i
++) {
360 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
364 for (i
= 0; i
< width
; i
++) {
369 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
373 for (i
= 0; i
< width
; i
++) {
376 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
379 case GL_LUMINANCE_ALPHA
:
380 for (i
= 0; i
< width
; i
++) {
381 r
= g
= b
= tableUB
[i
*2+0];
383 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
387 for (i
= 0; i
< width
; i
++) {
392 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
396 for (i
= 0; i
< width
; i
++) {
401 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
408 void fxDDTexPalette(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
410 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
413 /* per-texture palette */
415 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
416 fprintf(stderr
, "fxmesa: fxDDTexPalette(%d,%x)\n",
417 tObj
->Name
, (GLuint
) tObj
->DriverData
);
419 if (!tObj
->DriverData
)
420 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
421 ti
= fxTMGetTexInfo(tObj
);
422 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
423 fxTexInvalidate(ctx
, tObj
);
426 /* global texture palette */
427 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
428 fprintf(stderr
, "fxmesa: fxDDTexPalette(global)\n");
430 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
431 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
436 void fxDDTexUseGlbPalette(GLcontext
*ctx
, GLboolean state
)
438 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
440 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
441 fprintf(stderr
,"fxmesa: fxDDTexUseGlbPalette(%d)\n",state
);
445 fxMesa
->haveGlobalPaletteTexture
= 1;
447 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
448 if (fxMesa
->haveTwoTMUs
)
449 FX_grTexDownloadTable(GR_TMU1
, GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
452 fxMesa
->haveGlobalPaletteTexture
= 0;
454 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
455 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
456 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
458 if (!tObj
->DriverData
)
459 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
461 fxTexInvalidate(ctx
, tObj
);
467 static int logbase2(int n
)
488 /* Need different versions for different cpus.
490 #define INT_TRICK(l2) (0x800000 * l2)
493 int fxTexGetInfo(int w
, int h
, GrLOD_t
*lodlevel
, GrAspectRatio_t
*ar
,
494 float *sscale
, float *tscale
,
495 int *i_sscale
, int *i_tscale
,
496 int *wscale
, int *hscale
)
499 static GrLOD_t lod
[9]={GR_LOD_256
,GR_LOD_128
,GR_LOD_64
,GR_LOD_32
,
500 GR_LOD_16
,GR_LOD_8
,GR_LOD_4
,GR_LOD_2
,GR_LOD_1
};
504 GrAspectRatio_t aspectratio
;
513 aspectratio
=GR_ASPECT_1x1
;
520 aspectratio
=GR_ASPECT_2x1
;
524 is
=INT_TRICK(8);it
=INT_TRICK(7);
529 aspectratio
=GR_ASPECT_4x1
;
533 is
=INT_TRICK(8);it
=INT_TRICK(6);
538 aspectratio
=GR_ASPECT_8x1
;
542 is
=INT_TRICK(8);it
=INT_TRICK(5);
547 aspectratio
=GR_ASPECT_8x1
;
551 is
=INT_TRICK(8);it
=INT_TRICK(5);
556 aspectratio
=GR_ASPECT_8x1
;
560 is
=INT_TRICK(8);it
=INT_TRICK(5);
565 aspectratio
=GR_ASPECT_8x1
;
569 is
=INT_TRICK(8);it
=INT_TRICK(5);
574 aspectratio
=GR_ASPECT_8x1
;
578 is
=INT_TRICK(8);it
=INT_TRICK(5);
583 aspectratio
=GR_ASPECT_8x1
;
587 is
=INT_TRICK(8);it
=INT_TRICK(5);
592 aspectratio
=GR_ASPECT_1x2
;
596 is
=INT_TRICK(7);it
=INT_TRICK(8);
601 aspectratio
=GR_ASPECT_1x4
;
605 is
=INT_TRICK(6);it
=INT_TRICK(8);
610 aspectratio
=GR_ASPECT_1x8
;
614 is
=INT_TRICK(5);it
=INT_TRICK(8);
619 aspectratio
=GR_ASPECT_1x8
;
623 is
=INT_TRICK(5);it
=INT_TRICK(8);
628 aspectratio
=GR_ASPECT_1x8
;
632 is
=INT_TRICK(5);it
=INT_TRICK(8);
637 aspectratio
=GR_ASPECT_1x8
;
641 is
=INT_TRICK(5);it
=INT_TRICK(8);
646 aspectratio
=GR_ASPECT_1x8
;
650 is
=INT_TRICK(5);it
=INT_TRICK(8);
655 aspectratio
=GR_ASPECT_1x8
;
659 is
=INT_TRICK(5);it
=INT_TRICK(8);
697 * Given an OpenGL internal texture format, return the corresponding
698 * Glide internal texture format and base texture format.
700 void fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
*tfmt
, GLint
*ifmt
)
710 (*tfmt
)=GR_TEXFMT_INTENSITY_8
;
712 (*ifmt
)=GL_LUMINANCE
;
715 case GL_LUMINANCE_ALPHA
:
716 case GL_LUMINANCE4_ALPHA4
:
717 case GL_LUMINANCE6_ALPHA2
:
718 case GL_LUMINANCE8_ALPHA8
:
719 case GL_LUMINANCE12_ALPHA4
:
720 case GL_LUMINANCE12_ALPHA12
:
721 case GL_LUMINANCE16_ALPHA16
:
723 (*tfmt
)=GR_TEXFMT_ALPHA_INTENSITY_88
;
725 (*ifmt
)=GL_LUMINANCE_ALPHA
;
733 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
735 (*ifmt
)=GL_INTENSITY
;
743 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
757 (*tfmt
)=GR_TEXFMT_RGB_565
;
770 (*tfmt
)=GR_TEXFMT_ARGB_4444
;
776 (*tfmt
)=GR_TEXFMT_ARGB_1555
;
781 case GL_COLOR_INDEX1_EXT
:
782 case GL_COLOR_INDEX2_EXT
:
783 case GL_COLOR_INDEX4_EXT
:
784 case GL_COLOR_INDEX8_EXT
:
785 case GL_COLOR_INDEX12_EXT
:
786 case GL_COLOR_INDEX16_EXT
:
788 (*tfmt
)=GR_TEXFMT_P_8
;
790 (*ifmt
)=GL_RGBA
; /* XXX why is this RGBA? */
794 "fx Driver: unsupported internalFormat in fxTexGetFormat()\n");
801 static GLboolean
fxIsTexSupported(GLenum target
, GLint internalFormat
,
802 const struct gl_texture_image
*image
)
804 if(target
!= GL_TEXTURE_2D
)
807 if(!fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
811 if (image
->Border
> 0)
818 /**********************************************************************/
819 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
820 /**********************************************************************/
823 static void PrintTexture(int w
, int h
, int c
, const GLubyte
*data
)
826 for (i
= 0; i
< h
; i
++) {
827 for (j
= 0; j
< w
; j
++) {
829 printf("%02x %02x ", data
[0], data
[1]);
831 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
839 GLboolean
fxDDTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
840 GLenum format
, GLenum type
, const GLvoid
*pixels
,
841 const struct gl_pixelstore_attrib
*packing
,
842 struct gl_texture_object
*texObj
,
843 struct gl_texture_image
*texImage
,
844 GLboolean
*retainInternalCopy
)
846 fxMesaContext fxMesa
= (fxMesaContext
)ctx
->DriverCtx
;
848 if (target
!= GL_TEXTURE_2D
)
851 if (!texObj
->DriverData
)
852 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
854 if (fxIsTexSupported(target
, texImage
->IntFormat
, texImage
)) {
855 GrTextureFormat_t gldformat
;
856 tfxTexInfo
*ti
= fxTMGetTexInfo(texObj
);
857 tfxMipMapLevel
*mml
= &ti
->mipmapLevel
[level
];
858 GLint dstWidth
, dstHeight
, wScale
, hScale
, texelSize
, dstStride
;
859 MesaIntTexFormat intFormat
;
861 fxTexGetFormat(texImage
->IntFormat
, &gldformat
, NULL
);
863 fxTexGetInfo(texImage
->Width
, texImage
->Height
, NULL
,NULL
,NULL
,NULL
,
864 NULL
,NULL
, &wScale
, &hScale
);
866 dstWidth
= texImage
->Width
* wScale
;
867 dstHeight
= texImage
->Height
* hScale
;
869 switch (texImage
->IntFormat
) {
896 case GL_COLOR_INDEX1_EXT
:
897 case GL_COLOR_INDEX2_EXT
:
898 case GL_COLOR_INDEX4_EXT
:
899 case GL_COLOR_INDEX8_EXT
:
900 case GL_COLOR_INDEX12_EXT
:
901 case GL_COLOR_INDEX16_EXT
:
906 case GL_LUMINANCE_ALPHA
:
907 case GL_LUMINANCE4_ALPHA4
:
908 case GL_LUMINANCE6_ALPHA2
:
909 case GL_LUMINANCE8_ALPHA8
:
910 case GL_LUMINANCE12_ALPHA4
:
911 case GL_LUMINANCE12_ALPHA12
:
912 case GL_LUMINANCE16_ALPHA16
:
914 intFormat
= MESA_A8_L8
;
926 intFormat
= MESA_R5_G6_B5
;
937 intFormat
= MESA_A4_R4_G4_B4
;
941 intFormat
= MESA_A1_R5_G5_B5
;
944 gl_problem(NULL
, "tdfx driver: texbuildimagemap() bad format");
948 _mesa_set_teximage_component_sizes(intFormat
, texImage
);
950 /*printf("teximage:\n");*/
951 /* allocate new storage for texture image, if needed */
952 if (!mml
->data
|| mml
->glideFormat
!= gldformat
||
953 mml
->width
!= dstWidth
|| mml
->height
!= dstHeight
) {
956 mml
->data
= MALLOC(dstWidth
* dstHeight
* texelSize
);
959 mml
->glideFormat
= gldformat
;
960 mml
->width
= dstWidth
;
961 mml
->height
= dstHeight
;
962 fxTexInvalidate(ctx
, texObj
);
965 dstStride
= dstWidth
* texelSize
;
967 /* store the texture image */
968 if (!_mesa_convert_teximage(intFormat
, dstWidth
, dstHeight
, mml
->data
,
970 texImage
->Width
, texImage
->Height
,
971 format
, type
, pixels
, packing
)) {
976 if (ti
->validated
&& ti
->isInTM
) {
977 /*printf("reloadmipmaplevels\n");*/
978 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
981 /*printf("invalidate2\n");*/
982 fxTexInvalidate(ctx
,texObj
);
985 *retainInternalCopy
= GL_FALSE
;
989 gl_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
995 GLboolean
fxDDTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
996 GLint xoffset
, GLint yoffset
,
997 GLsizei width
, GLsizei height
,
998 GLenum format
, GLenum type
, const GLvoid
*pixels
,
999 const struct gl_pixelstore_attrib
*packing
,
1000 struct gl_texture_object
*texObj
,
1001 struct gl_texture_image
*texImage
)
1003 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1005 GLint wscale
, hscale
, dstStride
;
1006 tfxMipMapLevel
*mml
;
1009 if (target
!= GL_TEXTURE_2D
)
1012 if (!texObj
->DriverData
)
1015 ti
= fxTMGetTexInfo(texObj
);
1016 mml
= &ti
->mipmapLevel
[level
];
1018 fxTexGetInfo( texImage
->Width
, texImage
->Height
, NULL
,NULL
,NULL
,NULL
,
1019 NULL
,NULL
, &wscale
, &hscale
);
1021 assert(mml
->data
); /* must have an existing texture image! */
1023 switch (mml
->glideFormat
) {
1024 case GR_TEXFMT_INTENSITY_8
:
1025 dstStride
= mml
->width
;
1026 result
= _mesa_convert_texsubimage(MESA_I8
, xoffset
, yoffset
,
1027 mml
->width
, mml
->height
, mml
->data
,
1028 dstStride
, width
, height
,
1029 texImage
->Width
, texImage
->Height
,
1030 format
, type
, pixels
, packing
);
1032 case GR_TEXFMT_ALPHA_8
:
1033 dstStride
= mml
->width
;
1034 result
= _mesa_convert_texsubimage(MESA_A8
, xoffset
, yoffset
,
1035 mml
->width
, mml
->height
, mml
->data
,
1036 dstStride
, width
, height
,
1037 texImage
->Width
, texImage
->Height
,
1038 format
, type
, pixels
, packing
);
1041 dstStride
= mml
->width
;
1042 result
= _mesa_convert_texsubimage(MESA_C8
, xoffset
, yoffset
,
1043 mml
->width
, mml
->height
, mml
->data
,
1044 dstStride
, width
, height
,
1045 texImage
->Width
, texImage
->Height
,
1046 format
, type
, pixels
, packing
);
1048 case GR_TEXFMT_ALPHA_INTENSITY_88
:
1049 dstStride
= mml
->width
* 2;
1050 result
= _mesa_convert_texsubimage(MESA_A8_L8
, xoffset
, yoffset
,
1051 mml
->width
, mml
->height
, mml
->data
,
1052 dstStride
, width
, height
,
1053 texImage
->Width
, texImage
->Height
,
1054 format
, type
, pixels
, packing
);
1056 case GR_TEXFMT_RGB_565
:
1057 dstStride
= mml
->width
* 2;
1058 result
= _mesa_convert_texsubimage(MESA_R5_G6_B5
, xoffset
, yoffset
,
1059 mml
->width
, mml
->height
, mml
->data
,
1060 dstStride
, width
, height
,
1061 texImage
->Width
, texImage
->Height
,
1062 format
, type
, pixels
, packing
);
1064 case GR_TEXFMT_ARGB_4444
:
1065 dstStride
= mml
->width
* 2;
1066 result
= _mesa_convert_texsubimage(MESA_A4_R4_G4_B4
, xoffset
, yoffset
,
1067 mml
->width
, mml
->height
, mml
->data
,
1068 dstStride
, width
, height
,
1069 texImage
->Width
, texImage
->Height
,
1070 format
, type
, pixels
, packing
);
1072 case GR_TEXFMT_ARGB_1555
:
1073 dstStride
= mml
->width
* 2;
1074 result
= _mesa_convert_texsubimage(MESA_A1_R5_G5_B5
, xoffset
, yoffset
,
1075 mml
->width
, mml
->height
, mml
->data
,
1076 dstStride
, width
, height
,
1077 texImage
->Width
, texImage
->Height
,
1078 format
, type
, pixels
, packing
);
1081 gl_problem(NULL
, "tdfx driver: fxTexBuildSubImageMap() bad format");
1089 if (ti
->validated
&& ti
->isInTM
)
1090 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1092 fxTexInvalidate(ctx
, texObj
);
1099 GLvoid
*fxDDGetTexImage(GLcontext
*ctx
, GLenum target
, GLint level
,
1100 const struct gl_texture_object
*texObj
,
1101 GLenum
*formatOut
, GLenum
*typeOut
,
1102 GLboolean
*freeImageOut
)
1105 tfxMipMapLevel
*mml
;
1107 if (target
!= GL_TEXTURE_2D
)
1110 if (!texObj
->DriverData
)
1113 ti
= fxTMGetTexInfo(texObj
);
1114 mml
= &ti
->mipmapLevel
[level
];
1116 MesaIntTexFormat mesaFormat
;
1118 struct gl_texture_image
*texImage
= texObj
->Image
[level
];
1121 GLubyte
*data
= (GLubyte
*) MALLOC(texImage
->Width
* texImage
->Height
* 4);
1125 switch (mml
->glideFormat
) {
1126 case GR_TEXFMT_INTENSITY_8
:
1127 mesaFormat
= MESA_I8
;
1128 glFormat
= GL_INTENSITY
;
1129 srcStride
= mml
->width
;
1131 case GR_TEXFMT_ALPHA_INTENSITY_88
:
1132 mesaFormat
= MESA_A8_L8
;
1133 glFormat
= GL_LUMINANCE_ALPHA
;
1134 srcStride
= mml
->width
;
1136 case GR_TEXFMT_ALPHA_8
:
1137 mesaFormat
= MESA_A8
;
1138 glFormat
= GL_ALPHA
;
1139 srcStride
= mml
->width
;
1141 case GR_TEXFMT_RGB_565
:
1142 mesaFormat
= MESA_R5_G6_B5
;
1144 srcStride
= mml
->width
* 2;
1146 case GR_TEXFMT_ARGB_4444
:
1147 mesaFormat
= MESA_A4_R4_G4_B4
;
1149 srcStride
= mml
->width
* 2;
1151 case GR_TEXFMT_ARGB_1555
:
1152 mesaFormat
= MESA_A1_R5_G5_B5
;
1154 srcStride
= mml
->width
* 2;
1157 mesaFormat
= MESA_C8
;
1158 glFormat
= GL_COLOR_INDEX
;
1159 srcStride
= mml
->width
;
1162 gl_problem(NULL
, "Bad glideFormat in fxDDGetTexImage");
1165 _mesa_unconvert_teximage(mesaFormat
, mml
->width
, mml
->height
, mml
->data
,
1166 srcStride
, texImage
->Width
, texImage
->Height
,
1168 *formatOut
= glFormat
;
1169 *typeOut
= GL_UNSIGNED_BYTE
;
1170 *freeImageOut
= GL_TRUE
;
1183 * Need this to provide at least one external definition.
1186 extern int gl_fx_dummy_function_ddtex(void);
1187 int gl_fx_dummy_function_ddtex(void)