1 /* -*- mode: C; tab-width:8; c-basic-offset:2 -*- */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 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.
46 /* fxddtex.c - 3Dfx VooDoo Texture mapping functions */
57 /************************************************************************/
58 /*************************** Texture Mapping ****************************/
59 /************************************************************************/
61 void fxTexInvalidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
63 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
66 fxTMMoveOutTM(fxMesa
,tObj
); /* TO DO: SLOW but easy to write */
68 ti
=(tfxTexInfo
*)tObj
->DriverData
;
69 ti
->validated
=GL_FALSE
;
70 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
71 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
74 static tfxTexInfo
*fxAllocTexObjData(fxMesaContext fxMesa
)
79 if(!(ti
=CALLOC(sizeof(tfxTexInfo
)))) {
80 fprintf(stderr
,"fx Driver: out of memory !\n");
85 ti
->validated
=GL_FALSE
;
86 ti
->tmi
.isInTM
=GL_FALSE
;
88 ti
->tmi
.whichTMU
=FX_TMU_NONE
;
90 ti
->tmi
.tm
[FX_TMU0
]=NULL
;
91 ti
->tmi
.tm
[FX_TMU1
]=NULL
;
93 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
94 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
96 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
97 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
99 if(fxMesa
->haveTwoTMUs
) {
100 ti
->mmMode
=GR_MIPMAP_NEAREST
;
103 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
104 ti
->LODblend
=FXFALSE
;
107 for(i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
108 ti
->tmi
.mipmapLevel
[i
].used
=GL_FALSE
;
109 ti
->tmi
.mipmapLevel
[i
].data
=NULL
;
115 void fxDDTexBind(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
)
117 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
120 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
121 fprintf(stderr
,"fxmesa: fxDDTexBind(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
124 if(target
!=GL_TEXTURE_2D
)
127 if(!tObj
->DriverData
)
128 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
130 ti
=(tfxTexInfo
*)tObj
->DriverData
;
132 fxMesa
->texBindNumber
++;
133 ti
->tmi
.lastTimeUsed
=fxMesa
->texBindNumber
;
135 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
136 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
139 void fxDDTexEnv(GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
141 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
143 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
145 fprintf(stderr
,"fxmesa: texenv(%x,%x)\n",pname
,(GLint
)(*param
));
147 fprintf(stderr
,"fxmesa: texenv(%x)\n",pname
);
150 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
151 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
154 void fxDDTexParam(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
,
155 GLenum pname
, const GLfloat
*params
)
157 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
158 GLenum param
=(GLenum
)(GLint
)params
[0];
161 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
162 fprintf(stderr
,"fxmesa: fxDDTexParam(%d,%x,%x,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
,pname
,param
);
165 if(target
!=GL_TEXTURE_2D
)
168 if(!tObj
->DriverData
)
169 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
171 ti
=(tfxTexInfo
*)tObj
->DriverData
;
175 case GL_TEXTURE_MIN_FILTER
:
178 ti
->mmMode
=GR_MIPMAP_DISABLE
;
179 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
180 ti
->LODblend
=FXFALSE
;
183 ti
->mmMode
=GR_MIPMAP_DISABLE
;
184 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
185 ti
->LODblend
=FXFALSE
;
187 case GL_NEAREST_MIPMAP_NEAREST
:
188 ti
->mmMode
=GR_MIPMAP_NEAREST
;
189 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
190 ti
->LODblend
=FXFALSE
;
192 case GL_LINEAR_MIPMAP_NEAREST
:
193 ti
->mmMode
=GR_MIPMAP_NEAREST
;
194 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
195 ti
->LODblend
=FXFALSE
;
197 case GL_NEAREST_MIPMAP_LINEAR
:
198 if(fxMesa
->haveTwoTMUs
) {
199 ti
->mmMode
=GR_MIPMAP_NEAREST
;
202 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
203 ti
->LODblend
=FXFALSE
;
205 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
207 case GL_LINEAR_MIPMAP_LINEAR
:
208 if(fxMesa
->haveTwoTMUs
) {
209 ti
->mmMode
=GR_MIPMAP_NEAREST
;
212 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
213 ti
->LODblend
=FXFALSE
;
215 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
220 fxTexInvalidate(ctx
,tObj
);
223 case GL_TEXTURE_MAG_FILTER
:
226 ti
->maxFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
229 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
234 fxTexInvalidate(ctx
,tObj
);
237 case GL_TEXTURE_WRAP_S
:
240 ti
->sClamp
=GR_TEXTURECLAMP_CLAMP
;
243 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
248 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
249 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
252 case GL_TEXTURE_WRAP_T
:
255 ti
->tClamp
=GR_TEXTURECLAMP_CLAMP
;
258 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
263 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
264 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
267 case GL_TEXTURE_BORDER_COLOR
:
271 case GL_TEXTURE_MIN_LOD
:
274 case GL_TEXTURE_MAX_LOD
:
277 case GL_TEXTURE_BASE_LEVEL
:
278 fxTexInvalidate(ctx
,tObj
);
280 case GL_TEXTURE_MAX_LEVEL
:
281 fxTexInvalidate(ctx
,tObj
);
289 void fxDDTexDel(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
291 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
292 tfxTexInfo
*ti
=(tfxTexInfo
*)tObj
->DriverData
;
294 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
295 fprintf(stderr
,"fxmesa: fxDDTexDel(%d,%x)\n",tObj
->Name
,(GLuint
)ti
);
301 fxTMFreeTexture(fxMesa
,tObj
);
304 tObj
->DriverData
=NULL
;
306 ctx
->NewState
|=NEW_TEXTURING
;
309 void fxDDTexPalette(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
311 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
317 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
318 fprintf(stderr
,"fxmesa: fxDDTexPalette(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
321 if(tObj
->Palette
.Format
!=GL_RGBA
) {
323 fprintf(stderr
,"fx Driver: unsupported palette format in texpalette()\n");
328 if(tObj
->Palette
.Size
>256) {
330 fprintf(stderr
,"fx Driver: unsupported palette size in texpalette()\n");
335 if(!tObj
->DriverData
)
336 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
338 ti
=(tfxTexInfo
*)tObj
->DriverData
;
340 for(i
=0;i
<tObj
->Palette
.Size
;i
++) {
341 r
=tObj
->Palette
.Table
[i
*4];
342 g
=tObj
->Palette
.Table
[i
*4+1];
343 b
=tObj
->Palette
.Table
[i
*4+2];
344 a
=tObj
->Palette
.Table
[i
*4+3];
345 ti
->palette
.data
[i
]=(a
<<24)|(r
<<16)|(g
<<8)|b
;
348 fxTexInvalidate(ctx
,tObj
);
350 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
351 fprintf(stderr
,"fxmesa: fxDDTexPalette(global)\n");
353 if(ctx
->Texture
.Palette
.Format
!=GL_RGBA
) {
355 fprintf(stderr
,"fx Driver: unsupported palette format in texpalette()\n");
360 if(ctx
->Texture
.Palette
.Size
>256) {
362 fprintf(stderr
,"fx Driver: unsupported palette size in texpalette()\n");
367 for(i
=0;i
<ctx
->Texture
.Palette
.Size
;i
++) {
368 r
=ctx
->Texture
.Palette
.Table
[i
*4];
369 g
=ctx
->Texture
.Palette
.Table
[i
*4+1];
370 b
=ctx
->Texture
.Palette
.Table
[i
*4+2];
371 a
=ctx
->Texture
.Palette
.Table
[i
*4+3];
372 fxMesa
->glbPalette
.data
[i
]=(a
<<24)|(r
<<16)|(g
<<8)|b
;
375 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
376 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
380 void fxDDTexUseGlbPalette(GLcontext
*ctx
, GLboolean state
)
382 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
384 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
385 fprintf(stderr
,"fxmesa: fxDDTexUseGlbPalette(%d)\n",state
);
389 fxMesa
->haveGlobalPaletteTexture
=1;
391 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
,&(fxMesa
->glbPalette
));
392 if (fxMesa
->haveTwoTMUs
)
393 FX_grTexDownloadTable(GR_TMU1
,GR_TEXTABLE_PALETTE
,&(fxMesa
->glbPalette
));
395 fxMesa
->haveGlobalPaletteTexture
=0;
397 if((ctx
->Texture
.Unit
[0].Current
==ctx
->Texture
.Unit
[0].CurrentD
[2]) &&
398 (ctx
->Texture
.Unit
[0].Current
!=NULL
)) {
399 struct gl_texture_object
*tObj
=ctx
->Texture
.Unit
[0].Current
;
402 if(!tObj
->DriverData
)
403 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
405 ti
=(tfxTexInfo
*)tObj
->DriverData
;
407 fxTexInvalidate(ctx
,tObj
);
412 static int logbase2(int n
)
433 /* Need different versions for different cpus.
435 #define INT_TRICK(l2) (0x800000 * l2)
438 int fxTexGetInfo(int w
, int h
, GrLOD_t
*lodlevel
, GrAspectRatio_t
*ar
,
439 float *sscale
, float *tscale
,
440 int *i_sscale
, int *i_tscale
,
441 int *wscale
, int *hscale
)
444 static GrLOD_t lod
[9]={GR_LOD_256
,GR_LOD_128
,GR_LOD_64
,GR_LOD_32
,
445 GR_LOD_16
,GR_LOD_8
,GR_LOD_4
,GR_LOD_2
,GR_LOD_1
};
449 GrAspectRatio_t aspectratio
;
458 aspectratio
=GR_ASPECT_1x1
;
465 aspectratio
=GR_ASPECT_2x1
;
469 is
=INT_TRICK(8);it
=INT_TRICK(7);
474 aspectratio
=GR_ASPECT_4x1
;
478 is
=INT_TRICK(8);it
=INT_TRICK(6);
483 aspectratio
=GR_ASPECT_8x1
;
487 is
=INT_TRICK(8);it
=INT_TRICK(5);
492 aspectratio
=GR_ASPECT_8x1
;
496 is
=INT_TRICK(8);it
=INT_TRICK(5);
501 aspectratio
=GR_ASPECT_8x1
;
505 is
=INT_TRICK(8);it
=INT_TRICK(5);
510 aspectratio
=GR_ASPECT_8x1
;
514 is
=INT_TRICK(8);it
=INT_TRICK(5);
519 aspectratio
=GR_ASPECT_8x1
;
523 is
=INT_TRICK(8);it
=INT_TRICK(5);
528 aspectratio
=GR_ASPECT_8x1
;
532 is
=INT_TRICK(8);it
=INT_TRICK(5);
537 aspectratio
=GR_ASPECT_1x2
;
541 is
=INT_TRICK(7);it
=INT_TRICK(8);
546 aspectratio
=GR_ASPECT_1x4
;
550 is
=INT_TRICK(6);it
=INT_TRICK(8);
555 aspectratio
=GR_ASPECT_1x8
;
559 is
=INT_TRICK(5);it
=INT_TRICK(8);
564 aspectratio
=GR_ASPECT_1x8
;
568 is
=INT_TRICK(5);it
=INT_TRICK(8);
573 aspectratio
=GR_ASPECT_1x8
;
577 is
=INT_TRICK(5);it
=INT_TRICK(8);
582 aspectratio
=GR_ASPECT_1x8
;
586 is
=INT_TRICK(5);it
=INT_TRICK(8);
591 aspectratio
=GR_ASPECT_1x8
;
595 is
=INT_TRICK(5);it
=INT_TRICK(8);
600 aspectratio
=GR_ASPECT_1x8
;
604 is
=INT_TRICK(5);it
=INT_TRICK(8);
641 void fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
*tfmt
, GLint
*ifmt
)
651 (*tfmt
)=GR_TEXFMT_INTENSITY_8
;
653 (*ifmt
)=GL_LUMINANCE
;
656 case GL_LUMINANCE_ALPHA
:
657 case GL_LUMINANCE4_ALPHA4
:
658 case GL_LUMINANCE6_ALPHA2
:
659 case GL_LUMINANCE8_ALPHA8
:
660 case GL_LUMINANCE12_ALPHA4
:
661 case GL_LUMINANCE12_ALPHA12
:
662 case GL_LUMINANCE16_ALPHA16
:
664 (*tfmt
)=GR_TEXFMT_ALPHA_INTENSITY_88
;
666 (*ifmt
)=GL_LUMINANCE_ALPHA
;
674 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
676 (*ifmt
)=GL_INTENSITY
;
684 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
698 (*tfmt
)=GR_TEXFMT_RGB_565
;
712 (*tfmt
)=GR_TEXFMT_ARGB_4444
;
717 case GL_COLOR_INDEX1_EXT
:
718 case GL_COLOR_INDEX2_EXT
:
719 case GL_COLOR_INDEX4_EXT
:
720 case GL_COLOR_INDEX8_EXT
:
721 case GL_COLOR_INDEX12_EXT
:
722 case GL_COLOR_INDEX16_EXT
:
724 (*tfmt
)=GR_TEXFMT_P_8
;
729 fprintf(stderr
,"fx Driver: unsupported internalFormat in fxTexGetFormat()\n");
736 static int fxIsTexSupported(GLenum target
, GLint internalFormat
,
737 const struct gl_texture_image
*image
)
739 if(target
!=GL_TEXTURE_2D
)
742 switch(internalFormat
) {
755 case GL_LUMINANCE_ALPHA
:
756 case GL_LUMINANCE4_ALPHA4
:
757 case GL_LUMINANCE6_ALPHA2
:
758 case GL_LUMINANCE8_ALPHA8
:
759 case GL_LUMINANCE12_ALPHA4
:
760 case GL_LUMINANCE12_ALPHA12
:
761 case GL_LUMINANCE16_ALPHA16
:
786 case GL_COLOR_INDEX1_EXT
:
787 case GL_COLOR_INDEX2_EXT
:
788 case GL_COLOR_INDEX4_EXT
:
789 case GL_COLOR_INDEX8_EXT
:
790 case GL_COLOR_INDEX12_EXT
:
791 case GL_COLOR_INDEX16_EXT
:
800 if(image
->Height
>256)
803 if(!fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
810 static void fxTexBuildImageMap(const struct gl_texture_image
*image
,
811 GLint internalFormat
, unsigned short **dest
,
812 GLboolean
*istranslate
)
816 int x
,y
,w
,h
,wscale
,hscale
,idx
;
818 fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
820 w
=image
->Width
*wscale
;
821 h
=image
->Height
*hscale
;
824 switch(internalFormat
) {
842 case GL_COLOR_INDEX1_EXT
:
843 case GL_COLOR_INDEX2_EXT
:
844 case GL_COLOR_INDEX4_EXT
:
845 case GL_COLOR_INDEX8_EXT
:
846 case GL_COLOR_INDEX12_EXT
:
847 case GL_COLOR_INDEX16_EXT
:
848 /* Optimized for GLQuake */
850 if(wscale
==hscale
==1) {
851 (*istranslate
)=GL_FALSE
;
853 (*dest
)=(unsigned short *)data
;
857 (*istranslate
)=GL_TRUE
;
860 if(!((*dest
)=src
=(unsigned short *)MALLOC(sizeof(unsigned char)*w
*h
))) {
861 fprintf(stderr
,"fx Driver: out of memory !\n");
868 srcb
=(unsigned char *)src
;
872 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
));
873 srcb
[x
+y
*w
]=data
[idx
];
878 case GL_LUMINANCE_ALPHA
:
879 case GL_LUMINANCE4_ALPHA4
:
880 case GL_LUMINANCE6_ALPHA2
:
881 case GL_LUMINANCE8_ALPHA8
:
882 case GL_LUMINANCE12_ALPHA4
:
883 case GL_LUMINANCE12_ALPHA12
:
884 case GL_LUMINANCE16_ALPHA16
:
885 (*istranslate
)=GL_TRUE
;
888 if(!((*dest
)=src
=(unsigned short *)MALLOC(sizeof(unsigned short)*w
*h
))) {
889 fprintf(stderr
,"fx Driver: out of memory !\n");
896 if(wscale
==hscale
==1) {
912 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
))*2;
916 src
[x
+y
*w
]=(a
<< 8) | l
;
929 (*istranslate
)=GL_TRUE
;
932 if(!((*dest
)=src
=(unsigned short *)MALLOC(sizeof(unsigned short)*w
*h
))) {
933 fprintf(stderr
,"fx Driver: out of memory !\n");
940 if(wscale
==hscale
==1) {
943 unsigned short r
,g
,b
;
950 *src
++=((0xf8 & r
) << (11-3)) |
951 ((0xfc & g
) << (5-3+1)) |
955 unsigned short r
,g
,b
;
959 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
))*3;
964 src
[x
+y
*w
]=((0xf8 & r
) << (11-3)) |
965 ((0xfc & g
) << (5-3+1)) |
979 (*istranslate
)=GL_TRUE
;
982 if(!((*dest
)=src
=(unsigned short *)MALLOC(sizeof(unsigned short)*w
*h
))) {
983 fprintf(stderr
,"fx Driver: out of memory !\n");
990 if(wscale
==hscale
==1) {
993 unsigned short r
,g
,b
,a
;
1001 *src
++=((0xf0 & a
) << 8) |
1007 unsigned short r
,g
,b
,a
;
1011 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
))*4;
1017 src
[x
+y
*w
]=((0xf0 & a
) << 8) |
1025 fprintf(stderr
,"fx Driver: wrong internalFormat in texbuildimagemap()\n");
1032 void fxDDTexImg(GLcontext
*ctx
, GLenum target
,
1033 struct gl_texture_object
*tObj
, GLint level
, GLint internalFormat
,
1034 const struct gl_texture_image
*image
)
1036 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1039 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1040 fprintf(stderr
,"fxmesa: (%d) fxDDTexImg(...,%d,%x,%d,%d...)\n",tObj
->Name
,
1041 target
,internalFormat
,image
->Width
,image
->Height
);
1044 if(target
!=GL_TEXTURE_2D
)
1047 if(!tObj
->DriverData
)
1048 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
1050 ti
=(tfxTexInfo
*)tObj
->DriverData
;
1052 if(fxIsTexSupported(target
,internalFormat
,image
)) {
1053 GrTextureFormat_t gldformat
;
1054 tfxMipMapLevel
*mml
=&ti
->tmi
.mipmapLevel
[level
];
1056 fxTexGetFormat(internalFormat
,&gldformat
,NULL
);
1059 if((mml
->glideFormat
==gldformat
) &&
1060 (mml
->width
==image
->Width
) &&
1061 (mml
->height
==image
->Height
)) {
1062 fxTexBuildImageMap(image
,internalFormat
,&(mml
->data
),
1063 &(mml
->translated
));
1065 if(ti
->validated
&& ti
->tmi
.isInTM
)
1066 fxTMReloadMipMapLevel(fxMesa
,tObj
,level
);
1068 fxTexInvalidate(ctx
,tObj
);
1078 mml
->glideFormat
=gldformat
;
1079 mml
->width
=image
->Width
;
1080 mml
->height
=image
->Height
;
1083 fxTexBuildImageMap(image
,internalFormat
,&(mml
->data
),
1084 &(mml
->translated
));
1086 fxTexInvalidate(ctx
,tObj
);
1090 fprintf(stderr
,"fx Driver: unsupported texture in fxDDTexImg()\n");
1094 static void fxTexBuildSubImageMap(const struct gl_texture_image
*image
,
1095 GLint internalFormat
,
1096 GLint xoffset
, GLint yoffset
, GLint width
, GLint height
,
1097 unsigned short *destimg
)
1099 fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
1102 switch(internalFormat
) {
1106 case GL_INTENSITY12
:
1107 case GL_INTENSITY16
:
1112 case GL_LUMINANCE12
:
1113 case GL_LUMINANCE16
:
1119 case GL_COLOR_INDEX
:
1120 case GL_COLOR_INDEX1_EXT
:
1121 case GL_COLOR_INDEX2_EXT
:
1122 case GL_COLOR_INDEX4_EXT
:
1123 case GL_COLOR_INDEX8_EXT
:
1124 case GL_COLOR_INDEX12_EXT
:
1125 case GL_COLOR_INDEX16_EXT
:
1129 unsigned char *bsrc
,*bdst
;
1131 bsrc
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
));
1132 bdst
=((unsigned char *)destimg
)+(yoffset
*image
->Width
+xoffset
);
1134 for(y
=0;y
<height
;y
++) {
1135 MEMCPY(bdst
,bsrc
,width
);
1136 bsrc
+= image
->Width
;
1137 bdst
+= image
->Width
;
1142 case GL_LUMINANCE_ALPHA
:
1143 case GL_LUMINANCE4_ALPHA4
:
1144 case GL_LUMINANCE6_ALPHA2
:
1145 case GL_LUMINANCE8_ALPHA8
:
1146 case GL_LUMINANCE12_ALPHA4
:
1147 case GL_LUMINANCE12_ALPHA12
:
1148 case GL_LUMINANCE16_ALPHA16
:
1152 unsigned short *dst
,a
,l
;
1155 src
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
)*2);
1156 dst
=destimg
+(yoffset
*image
->Width
+xoffset
);
1158 simgw
=(image
->Width
-width
)*2;
1159 dimgw
=image
->Width
-width
;
1160 for(y
=0;y
<height
;y
++) {
1161 for(x
=0;x
<width
;x
++) {
1164 *dst
++=(a
<< 8) | l
;
1184 unsigned short *dst
,r
,g
,b
;
1187 src
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
)*3);
1188 dst
=destimg
+(yoffset
*image
->Width
+xoffset
);
1190 simgw
=(image
->Width
-width
)*3;
1191 dimgw
=image
->Width
-width
;
1192 for(y
=0;y
<height
;y
++) {
1193 for(x
=0;x
<width
;x
++) {
1197 *dst
++=((0xf8 & r
) << (11-3)) |
1198 ((0xfc & g
) << (5-3+1)) |
1219 unsigned short *dst
,r
,g
,b
,a
;
1222 src
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
)*4);
1223 dst
=destimg
+(yoffset
*image
->Width
+xoffset
);
1225 simgw
=(image
->Width
-width
)*4;
1226 dimgw
=image
->Width
-width
;
1227 for(y
=0;y
<height
;y
++) {
1228 for(x
=0;x
<width
;x
++) {
1233 *dst
++=((0xf0 & a
) << 8) |
1245 fprintf(stderr
,"fx Driver: wrong internalFormat in fxTexBuildSubImageMap()\n");
1253 void fxDDTexSubImg(GLcontext
*ctx
, GLenum target
,
1254 struct gl_texture_object
*tObj
, GLint level
,
1255 GLint xoffset
, GLint yoffset
, GLint width
, GLint height
,
1256 GLint internalFormat
, const struct gl_texture_image
*image
)
1258 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1260 GrTextureFormat_t gldformat
;
1262 tfxMipMapLevel
*mml
;
1264 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1265 fprintf(stderr
,"fxmesa: (%d) fxDDTexSubImg(...,%d,%x,%d,%d...)\n",tObj
->Name
,
1266 target
,internalFormat
,image
->Width
,image
->Height
);
1269 if(target
!=GL_TEXTURE_2D
)
1272 if(!tObj
->DriverData
)
1275 ti
=(tfxTexInfo
*)tObj
->DriverData
;
1276 mml
=&ti
->tmi
.mipmapLevel
[level
];
1278 fxTexGetFormat(internalFormat
,&gldformat
,NULL
);
1280 if(mml
->glideFormat
!=gldformat
) {
1281 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1282 fprintf(stderr
,"fxmesa: ti->info.format!=format in fxDDTexSubImg()\n");
1284 fxDDTexImg(ctx
,target
,tObj
,level
,internalFormat
,image
);
1289 fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,&wscale
,&hscale
);
1291 if((wscale
!=1) || (hscale
!=1)) {
1292 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1293 fprintf(stderr
,"fxmesa: (wscale!=1) || (hscale!=1) in fxDDTexSubImg()\n");
1295 fxDDTexImg(ctx
,target
,tObj
,level
,internalFormat
,image
);
1301 fxTexBuildSubImageMap(image
,internalFormat
,xoffset
,yoffset
,
1302 width
,height
,mml
->data
);
1304 if(ti
->validated
&& ti
->tmi
.isInTM
)
1305 fxTMReloadSubMipMapLevel(fxMesa
,tObj
,level
,yoffset
,height
);
1307 fxTexInvalidate(ctx
,tObj
);
1315 * Need this to provide at least one external definition.
1318 int gl_fx_dummy_function_ddtex(void)