1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 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.
27 * Original Mesa / 3Dfx device driver (C) 1999 David Bucciarelli, by the
30 * Thank you for your contribution, David!
32 * Please make note of the above copyright/license statement. If you
33 * contributed code or bug fixes to this code under the previous (GNU
34 * Library) license and object to the new license, your code will be
35 * removed at your request. Please see the Mesa docs/COPYRIGHT file
36 * for more information.
38 * Additional Mesa/3Dfx driver developers:
39 * Daryll Strauss <daryll@precisioninsight.com>
40 * Keith Whitwell <keith@precisioninsight.com>
42 * See fxapi.h for more revision/author details.
57 void fxPrintTextureData(tfxTexInfo
*ti
)
59 fprintf(stderr
, "Texture Data:\n");
61 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
62 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
63 fprintf(stderr
, "\tSize: %d x %d\n",
64 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
65 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
67 fprintf(stderr
, "\tName: UNNAMED\n");
68 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
69 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
70 fprintf(stderr
, "\t%s\n", (ti
->isInTM
)?"In TMU":"Not in TMU");
72 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
73 (unsigned) ti
->tm
[0]->endAddr
);
75 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
76 (unsigned) ti
->tm
[1]->endAddr
);
77 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
78 fprintf(stderr
, "\tFilters: min %d min %d\n",
79 (int) ti
->minFilt
, (int) ti
->maxFilt
);
80 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
, (int) ti
->tClamp
);
81 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
82 fprintf(stderr
, "\tInt Scales: s %d t %d\n",
83 ti
->int_sScale
/0x800000, ti
->int_tScale
/0x800000);
84 fprintf(stderr
, "\t%s\n", (ti
->fixedPalette
)?"Fixed palette":"Non fixed palette");
85 fprintf(stderr
, "\t%s\n", (ti
->validated
)?"Validated":"Not validated");
89 /************************************************************************/
90 /*************************** Texture Mapping ****************************/
91 /************************************************************************/
93 static void fxTexInvalidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
95 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
98 ti
=fxTMGetTexInfo(tObj
);
99 if (ti
->isInTM
) fxTMMoveOutTM(fxMesa
,tObj
); /* TO DO: SLOW but easy to write */
101 ti
->validated
=GL_FALSE
;
102 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
103 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
106 static tfxTexInfo
*fxAllocTexObjData(fxMesaContext fxMesa
)
111 if(!(ti
=CALLOC(sizeof(tfxTexInfo
)))) {
112 fprintf(stderr
,"fx Driver: out of memory !\n");
117 ti
->validated
=GL_FALSE
;
120 ti
->whichTMU
=FX_TMU_NONE
;
122 ti
->tm
[FX_TMU0
]=NULL
;
123 ti
->tm
[FX_TMU1
]=NULL
;
125 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
126 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
128 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
129 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
131 ti
->mmMode
=GR_MIPMAP_NEAREST
;
132 ti
->LODblend
=FXFALSE
;
134 for(i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
135 ti
->mipmapLevel
[i
].data
=NULL
;
141 void fxDDTexBind(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
)
143 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
146 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
147 fprintf(stderr
,"fxmesa: fxDDTexBind(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
150 if(target
!=GL_TEXTURE_2D
)
153 if (!tObj
->DriverData
) {
154 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
157 ti
=fxTMGetTexInfo(tObj
);
159 fxMesa
->texBindNumber
++;
160 ti
->lastTimeUsed
=fxMesa
->texBindNumber
;
162 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
163 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
166 void fxDDTexEnv(GLcontext
*ctx
, GLenum target
, GLenum pname
, const GLfloat
*param
)
168 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
170 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
172 fprintf(stderr
,"fxmesa: texenv(%x,%x)\n",pname
,(GLint
)(*param
));
174 fprintf(stderr
,"fxmesa: texenv(%x)\n",pname
);
177 /* apply any lod biasing right now */
178 if (pname
==GL_TEXTURE_LOD_BIAS_EXT
) {
179 FX_grTexLodBiasValue(GR_TMU0
,*param
);
181 if(fxMesa
->haveTwoTMUs
) {
182 FX_grTexLodBiasValue(GR_TMU1
,*param
);
187 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
188 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
191 void fxDDTexParam(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
,
192 GLenum pname
, const GLfloat
*params
)
194 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
195 GLenum param
=(GLenum
)(GLint
)params
[0];
198 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
199 fprintf(stderr
,"fxmesa: fxDDTexParam(%d,%x,%x,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
,pname
,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_NEAREST
:
225 ti
->mmMode
=GR_MIPMAP_NEAREST
;
226 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
227 ti
->LODblend
=FXFALSE
;
229 case GL_LINEAR_MIPMAP_NEAREST
:
230 ti
->mmMode
=GR_MIPMAP_NEAREST
;
231 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
232 ti
->LODblend
=FXFALSE
;
234 case GL_NEAREST_MIPMAP_LINEAR
:
235 if(fxMesa
->haveTwoTMUs
) {
236 ti
->mmMode
=GR_MIPMAP_NEAREST
;
239 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
240 ti
->LODblend
=FXFALSE
;
242 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
244 case GL_LINEAR_MIPMAP_LINEAR
:
245 if(fxMesa
->haveTwoTMUs
) {
246 ti
->mmMode
=GR_MIPMAP_NEAREST
;
249 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
250 ti
->LODblend
=FXFALSE
;
252 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
257 fxTexInvalidate(ctx
,tObj
);
260 case GL_TEXTURE_MAG_FILTER
:
263 ti
->maxFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
266 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
271 fxTexInvalidate(ctx
,tObj
);
274 case GL_TEXTURE_WRAP_S
:
277 ti
->sClamp
=GR_TEXTURECLAMP_CLAMP
;
280 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
285 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
286 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
289 case GL_TEXTURE_WRAP_T
:
292 ti
->tClamp
=GR_TEXTURECLAMP_CLAMP
;
295 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
300 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
301 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
304 case GL_TEXTURE_BORDER_COLOR
:
308 case GL_TEXTURE_MIN_LOD
:
311 case GL_TEXTURE_MAX_LOD
:
314 case GL_TEXTURE_BASE_LEVEL
:
315 fxTexInvalidate(ctx
,tObj
);
317 case GL_TEXTURE_MAX_LEVEL
:
318 fxTexInvalidate(ctx
,tObj
);
326 void fxDDTexDel(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
328 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
329 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
331 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
332 fprintf(stderr
, "fxmesa: fxDDTexDel(%d,%p)\n", tObj
->Name
, ti
);
338 fxTMFreeTexture(fxMesa
, tObj
);
341 tObj
->DriverData
= NULL
;
343 ctx
->NewState
|= NEW_TEXTURING
;
349 * Convert a gl_color_table texture palette to Glide's format.
352 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
354 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
355 GLint width
= table
->Size
;
359 ASSERT(!table
->FloatTable
);
361 switch (table
->Format
) {
363 for (i
= 0; i
< width
; i
++) {
368 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
372 for (i
= 0; i
< width
; i
++) {
377 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
381 for (i
= 0; i
< width
; i
++) {
384 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
387 case GL_LUMINANCE_ALPHA
:
388 for (i
= 0; i
< width
; i
++) {
389 r
= g
= b
= tableUB
[i
*2+0];
391 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
395 for (i
= 0; i
< width
; i
++) {
400 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
404 for (i
= 0; i
< width
; i
++) {
409 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
416 void fxDDTexPalette(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
418 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
421 /* per-texture palette */
423 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
424 fprintf(stderr
, "fxmesa: fxDDTexPalette(%d,%x)\n",
425 tObj
->Name
, (GLuint
) tObj
->DriverData
);
427 if (!tObj
->DriverData
)
428 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
429 ti
= fxTMGetTexInfo(tObj
);
430 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
431 fxTexInvalidate(ctx
, tObj
);
434 /* global texture palette */
435 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
436 fprintf(stderr
, "fxmesa: fxDDTexPalette(global)\n");
438 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
439 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
440 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
445 void fxDDTexUseGlbPalette(GLcontext
*ctx
, GLboolean state
)
447 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
449 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
450 fprintf(stderr
,"fxmesa: fxDDTexUseGlbPalette(%d)\n",state
);
454 fxMesa
->haveGlobalPaletteTexture
= 1;
456 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
457 if (fxMesa
->haveTwoTMUs
)
458 FX_grTexDownloadTable(GR_TMU1
, GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
461 fxMesa
->haveGlobalPaletteTexture
= 0;
463 if ((ctx
->Texture
.Unit
[0].Current
== ctx
->Texture
.Unit
[0].CurrentD
[2]) &&
464 (ctx
->Texture
.Unit
[0].Current
!= NULL
)) {
465 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0].Current
;
467 if (!tObj
->DriverData
)
468 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
470 fxTexInvalidate(ctx
, tObj
);
476 static int logbase2(int n
)
497 /* Need different versions for different cpus.
499 #define INT_TRICK(l2) (0x800000 * l2)
502 int fxTexGetInfo(int w
, int h
, GrLOD_t
*lodlevel
, GrAspectRatio_t
*ar
,
503 float *sscale
, float *tscale
,
504 int *i_sscale
, int *i_tscale
,
505 int *wscale
, int *hscale
)
508 static GrLOD_t lod
[9]={GR_LOD_256
,GR_LOD_128
,GR_LOD_64
,GR_LOD_32
,
509 GR_LOD_16
,GR_LOD_8
,GR_LOD_4
,GR_LOD_2
,GR_LOD_1
};
513 GrAspectRatio_t aspectratio
;
522 aspectratio
=GR_ASPECT_1x1
;
529 aspectratio
=GR_ASPECT_2x1
;
533 is
=INT_TRICK(8);it
=INT_TRICK(7);
538 aspectratio
=GR_ASPECT_4x1
;
542 is
=INT_TRICK(8);it
=INT_TRICK(6);
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_8x1
;
596 is
=INT_TRICK(8);it
=INT_TRICK(5);
601 aspectratio
=GR_ASPECT_1x2
;
605 is
=INT_TRICK(7);it
=INT_TRICK(8);
610 aspectratio
=GR_ASPECT_1x4
;
614 is
=INT_TRICK(6);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);
664 aspectratio
=GR_ASPECT_1x8
;
668 is
=INT_TRICK(5);it
=INT_TRICK(8);
706 * Given an OpenGL internal texture format, return the corresponding
707 * Glide internal texture format and base texture format.
709 void fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
*tfmt
, GLint
*ifmt
)
719 (*tfmt
)=GR_TEXFMT_INTENSITY_8
;
721 (*ifmt
)=GL_LUMINANCE
;
724 case GL_LUMINANCE_ALPHA
:
725 case GL_LUMINANCE4_ALPHA4
:
726 case GL_LUMINANCE6_ALPHA2
:
727 case GL_LUMINANCE8_ALPHA8
:
728 case GL_LUMINANCE12_ALPHA4
:
729 case GL_LUMINANCE12_ALPHA12
:
730 case GL_LUMINANCE16_ALPHA16
:
732 (*tfmt
)=GR_TEXFMT_ALPHA_INTENSITY_88
;
734 (*ifmt
)=GL_LUMINANCE_ALPHA
;
742 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
744 (*ifmt
)=GL_INTENSITY
;
752 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
766 (*tfmt
)=GR_TEXFMT_RGB_565
;
779 (*tfmt
)=GR_TEXFMT_ARGB_4444
;
785 (*tfmt
)=GR_TEXFMT_ARGB_1555
;
790 case GL_COLOR_INDEX1_EXT
:
791 case GL_COLOR_INDEX2_EXT
:
792 case GL_COLOR_INDEX4_EXT
:
793 case GL_COLOR_INDEX8_EXT
:
794 case GL_COLOR_INDEX12_EXT
:
795 case GL_COLOR_INDEX16_EXT
:
797 (*tfmt
)=GR_TEXFMT_P_8
;
799 (*ifmt
)=GL_RGBA
; /* XXX why is this RGBA? */
803 "fx Driver: unsupported internalFormat in fxTexGetFormat()\n");
810 static GLboolean
fxIsTexSupported(GLenum target
, GLint internalFormat
,
811 const struct gl_texture_image
*image
)
813 if(target
!= GL_TEXTURE_2D
)
816 if(!fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
820 if (image
->Border
> 0)
827 /**********************************************************************/
828 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
829 /**********************************************************************/
831 GLboolean
fxDDTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
832 GLenum format
, GLenum type
, const GLvoid
*pixels
,
833 const struct gl_pixelstore_attrib
*packing
,
834 struct gl_texture_object
*texObj
,
835 struct gl_texture_image
*texImage
,
836 GLboolean
*retainInternalCopy
)
838 fxMesaContext fxMesa
= (fxMesaContext
)ctx
->DriverCtx
;
840 if (target
!= GL_TEXTURE_2D
)
843 if (!texObj
->DriverData
)
844 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
846 if (fxIsTexSupported(target
, texImage
->IntFormat
, texImage
)) {
847 GrTextureFormat_t gldformat
;
848 tfxTexInfo
*ti
= fxTMGetTexInfo(texObj
);
849 tfxMipMapLevel
*mml
= &ti
->mipmapLevel
[level
];
850 GLint dstWidth
, dstHeight
, wScale
, hScale
, texelSize
, dstStride
;
851 MesaIntTexFormat intFormat
;
853 fxTexGetFormat(texImage
->IntFormat
, &gldformat
, NULL
);
855 fxTexGetInfo(texImage
->Width
, texImage
->Height
, NULL
,NULL
,NULL
,NULL
,
856 NULL
,NULL
, &wScale
, &hScale
);
858 dstWidth
= texImage
->Width
* wScale
;
859 dstHeight
= texImage
->Height
* hScale
;
861 switch (texImage
->IntFormat
) {
888 case GL_COLOR_INDEX1_EXT
:
889 case GL_COLOR_INDEX2_EXT
:
890 case GL_COLOR_INDEX4_EXT
:
891 case GL_COLOR_INDEX8_EXT
:
892 case GL_COLOR_INDEX12_EXT
:
893 case GL_COLOR_INDEX16_EXT
:
898 case GL_LUMINANCE_ALPHA
:
899 case GL_LUMINANCE4_ALPHA4
:
900 case GL_LUMINANCE6_ALPHA2
:
901 case GL_LUMINANCE8_ALPHA8
:
902 case GL_LUMINANCE12_ALPHA4
:
903 case GL_LUMINANCE12_ALPHA12
:
904 case GL_LUMINANCE16_ALPHA16
:
906 intFormat
= MESA_A8_L8
;
918 intFormat
= MESA_R5_G6_B5
;
929 intFormat
= MESA_A4_R4_G4_B4
;
933 intFormat
= MESA_A1_R5_G5_B5
;
936 gl_problem(NULL
, "tdfx driver: texbuildimagemap() bad format");
940 _mesa_set_teximage_component_sizes(intFormat
, texImage
);
942 /*printf("teximage:\n");*/
943 /* allocate new storage for texture image, if needed */
944 if (!mml
->data
|| mml
->glideFormat
!= gldformat
||
945 mml
->width
!= dstWidth
|| mml
->height
!= dstHeight
) {
948 mml
->data
= MALLOC(dstWidth
* dstHeight
* texelSize
);
951 mml
->glideFormat
= gldformat
;
952 mml
->width
= dstWidth
;
953 mml
->height
= dstHeight
;
954 fxTexInvalidate(ctx
, texObj
);
957 dstStride
= dstWidth
* texelSize
;
959 /* store the texture image */
960 if (!_mesa_convert_teximage(intFormat
, dstWidth
, dstHeight
, mml
->data
,
962 texImage
->Width
, texImage
->Height
,
963 format
, type
, pixels
, packing
)) {
967 if (ti
->validated
&& ti
->isInTM
) {
968 /*printf("reloadmipmaplevels\n");*/
969 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
972 /*printf("invalidate2\n");*/
973 fxTexInvalidate(ctx
,texObj
);
976 *retainInternalCopy
= GL_FALSE
;
980 gl_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
986 GLboolean
fxDDTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
987 GLint xoffset
, GLint yoffset
,
988 GLsizei width
, GLsizei height
,
989 GLenum format
, GLenum type
, const GLvoid
*pixels
,
990 const struct gl_pixelstore_attrib
*packing
,
991 struct gl_texture_object
*texObj
,
992 struct gl_texture_image
*texImage
)
994 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
996 GLint wscale
, hscale
, dstStride
;
1000 if (target
!= GL_TEXTURE_2D
)
1003 if (!texObj
->DriverData
)
1006 ti
= fxTMGetTexInfo(texObj
);
1007 mml
= &ti
->mipmapLevel
[level
];
1009 fxTexGetInfo( texImage
->Width
, texImage
->Height
, NULL
,NULL
,NULL
,NULL
,
1010 NULL
,NULL
, &wscale
, &hscale
);
1012 assert(mml
->data
); /* must have an existing texture image! */
1014 switch (mml
->glideFormat
) {
1015 case GR_TEXFMT_INTENSITY_8
:
1016 dstStride
= mml
->width
;
1017 result
= _mesa_convert_texsubimage(MESA_I8
, xoffset
, yoffset
,
1018 mml
->width
, mml
->height
, mml
->data
,
1019 dstStride
, width
, height
,
1020 texImage
->Width
, texImage
->Height
,
1021 format
, type
, pixels
, packing
);
1023 case GR_TEXFMT_ALPHA_8
:
1024 dstStride
= mml
->width
;
1025 result
= _mesa_convert_texsubimage(MESA_A8
, xoffset
, yoffset
,
1026 mml
->width
, mml
->height
, mml
->data
,
1027 dstStride
, width
, height
,
1028 texImage
->Width
, texImage
->Height
,
1029 format
, type
, pixels
, packing
);
1032 dstStride
= mml
->width
;
1033 result
= _mesa_convert_texsubimage(MESA_C8
, xoffset
, yoffset
,
1034 mml
->width
, mml
->height
, mml
->data
,
1035 dstStride
, width
, height
,
1036 texImage
->Width
, texImage
->Height
,
1037 format
, type
, pixels
, packing
);
1039 case GR_TEXFMT_ALPHA_INTENSITY_88
:
1040 dstStride
= mml
->width
* 2;
1041 result
= _mesa_convert_texsubimage(MESA_A8_L8
, xoffset
, yoffset
,
1042 mml
->width
, mml
->height
, mml
->data
,
1043 dstStride
, width
, height
,
1044 texImage
->Width
, texImage
->Height
,
1045 format
, type
, pixels
, packing
);
1047 case GR_TEXFMT_RGB_565
:
1048 dstStride
= mml
->width
* 2;
1049 result
= _mesa_convert_texsubimage(MESA_R5_G6_B5
, xoffset
, yoffset
,
1050 mml
->width
, mml
->height
, mml
->data
,
1051 dstStride
, width
, height
,
1052 texImage
->Width
, texImage
->Height
,
1053 format
, type
, pixels
, packing
);
1055 case GR_TEXFMT_ARGB_4444
:
1056 dstStride
= mml
->width
* 2;
1057 result
= _mesa_convert_texsubimage(MESA_A4_R4_G4_B4
, xoffset
, yoffset
,
1058 mml
->width
, mml
->height
, mml
->data
,
1059 dstStride
, width
, height
,
1060 texImage
->Width
, texImage
->Height
,
1061 format
, type
, pixels
, packing
);
1063 case GR_TEXFMT_ARGB_1555
:
1064 dstStride
= mml
->width
* 2;
1065 result
= _mesa_convert_texsubimage(MESA_A1_R5_G5_B5
, xoffset
, yoffset
,
1066 mml
->width
, mml
->height
, mml
->data
,
1067 dstStride
, width
, height
,
1068 texImage
->Width
, texImage
->Height
,
1069 format
, type
, pixels
, packing
);
1072 gl_problem(NULL
, "tdfx driver: fxTexBuildSubImageMap() bad format");
1080 if (ti
->validated
&& ti
->isInTM
)
1081 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1083 fxTexInvalidate(ctx
, texObj
);
1089 static void PrintTexture(int w
, int h
, int c
, const GLubyte
*data
)
1092 for (i
= 0; i
< h
; i
++) {
1093 for (j
= 0; j
< w
; j
++) {
1095 printf("%02x %02x ", data
[0], data
[1]);
1097 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
1105 GLvoid
*fxDDGetTexImage(GLcontext
*ctx
, GLenum target
, GLint level
,
1106 const struct gl_texture_object
*texObj
,
1107 GLenum
*formatOut
, GLenum
*typeOut
,
1108 GLboolean
*freeImageOut
)
1111 tfxMipMapLevel
*mml
;
1113 if (target
!= GL_TEXTURE_2D
)
1116 if (!texObj
->DriverData
)
1119 ti
= fxTMGetTexInfo(texObj
);
1120 mml
= &ti
->mipmapLevel
[level
];
1122 MesaIntTexFormat mesaFormat
;
1124 struct gl_texture_image
*texImage
= texObj
->Image
[level
];
1127 GLubyte
*data
= (GLubyte
*) MALLOC(texImage
->Width
* texImage
->Height
* 4);
1131 switch (mml
->glideFormat
) {
1132 case GR_TEXFMT_INTENSITY_8
:
1133 mesaFormat
= MESA_I8
;
1134 glFormat
= GL_INTENSITY
;
1135 srcStride
= mml
->width
;
1137 case GR_TEXFMT_ALPHA_INTENSITY_88
:
1138 mesaFormat
= MESA_A8_L8
;
1139 glFormat
= GL_LUMINANCE_ALPHA
;
1140 srcStride
= mml
->width
;
1142 case GR_TEXFMT_ALPHA_8
:
1143 mesaFormat
= MESA_A8
;
1144 glFormat
= GL_ALPHA
;
1145 srcStride
= mml
->width
;
1147 case GR_TEXFMT_RGB_565
:
1148 mesaFormat
= MESA_R5_G6_B5
;
1150 srcStride
= mml
->width
* 2;
1152 case GR_TEXFMT_ARGB_4444
:
1153 mesaFormat
= MESA_A4_R4_G4_B4
;
1155 srcStride
= mml
->width
* 2;
1157 case GR_TEXFMT_ARGB_1555
:
1158 mesaFormat
= MESA_A1_R5_G5_B5
;
1160 srcStride
= mml
->width
* 2;
1163 mesaFormat
= MESA_C8
;
1164 glFormat
= GL_COLOR_INDEX
;
1165 srcStride
= mml
->width
;
1168 gl_problem(NULL
, "Bad glideFormat in fxDDGetTexImage");
1171 _mesa_unconvert_teximage(mesaFormat
, mml
->width
, mml
->height
, mml
->data
,
1172 srcStride
, texImage
->Width
, texImage
->Height
,
1174 *formatOut
= glFormat
;
1175 *typeOut
= GL_UNSIGNED_BYTE
;
1176 *freeImageOut
= GL_TRUE
;
1189 * Need this to provide at least one external definition.
1192 int gl_fx_dummy_function_ddtex(void)