1 /* -*- mode: C; tab-width:8; -*-
3 fxddtex.c - 3Dfx VooDoo Texture mapping functions
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * See the file fxapi.c for more informations about authors
33 /************************************************************************/
34 /*************************** Texture Mapping ****************************/
35 /************************************************************************/
37 static void fxTexInvalidate(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
39 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
42 fxTMMoveOutTM(fxMesa
,tObj
); /* TO DO: SLOW but easy to write */
44 ti
=(tfxTexInfo
*)tObj
->DriverData
;
45 ti
->validated
=GL_FALSE
;
46 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
47 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
50 static tfxTexInfo
*fxAllocTexObjData(fxMesaContext fxMesa
)
55 if(!(ti
=malloc(sizeof(tfxTexInfo
)))) {
56 fprintf(stderr
,"fx Driver: out of memory !\n");
61 ti
->validated
=GL_FALSE
;
62 ti
->tmi
.isInTM
=GL_FALSE
;
64 ti
->tmi
.whichTMU
=FX_TMU_NONE
;
66 ti
->tmi
.tm
[FX_TMU0
]=NULL
;
67 ti
->tmi
.tm
[FX_TMU1
]=NULL
;
69 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
70 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
72 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
73 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
75 if(fxMesa
->haveTwoTMUs
) {
76 ti
->mmMode
=GR_MIPMAP_NEAREST
;
79 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
83 for(i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
84 ti
->tmi
.mipmapLevel
[i
].used
=GL_FALSE
;
85 ti
->tmi
.mipmapLevel
[i
].data
=NULL
;
91 void fxDDTexBind(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
)
93 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
96 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
97 fprintf(stderr
,"fxmesa: fxDDTexBind(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
100 if(target
!=GL_TEXTURE_2D
)
103 if(!tObj
->DriverData
)
104 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
106 ti
=(tfxTexInfo
*)tObj
->DriverData
;
108 fxMesa
->texBindNumber
++;
109 ti
->tmi
.lastTimeUsed
=fxMesa
->texBindNumber
;
111 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
112 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
115 void fxDDTexEnv(GLcontext
*ctx
, GLenum pname
, const GLfloat
*param
)
117 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
119 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
121 fprintf(stderr
,"fxmesa: texenv(%x,%x)\n",pname
,(GLint
)(*param
));
123 fprintf(stderr
,"fxmesa: texenv(%x)\n",pname
);
126 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
127 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
130 void fxDDTexParam(GLcontext
*ctx
, GLenum target
, struct gl_texture_object
*tObj
,
131 GLenum pname
, const GLfloat
*params
)
133 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
134 GLenum param
=(GLenum
)(GLint
)params
[0];
137 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
138 fprintf(stderr
,"fxmesa: fxDDTexParam(%d,%x,%x,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
,pname
,param
);
141 if(target
!=GL_TEXTURE_2D
)
144 if(!tObj
->DriverData
)
145 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
147 ti
=(tfxTexInfo
*)tObj
->DriverData
;
151 case GL_TEXTURE_MIN_FILTER
:
154 ti
->mmMode
=GR_MIPMAP_DISABLE
;
155 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
156 ti
->LODblend
=FXFALSE
;
159 ti
->mmMode
=GR_MIPMAP_DISABLE
;
160 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
161 ti
->LODblend
=FXFALSE
;
163 case GL_NEAREST_MIPMAP_NEAREST
:
164 ti
->mmMode
=GR_MIPMAP_NEAREST
;
165 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
166 ti
->LODblend
=FXFALSE
;
168 case GL_LINEAR_MIPMAP_NEAREST
:
169 ti
->mmMode
=GR_MIPMAP_NEAREST
;
170 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
171 ti
->LODblend
=FXFALSE
;
173 case GL_NEAREST_MIPMAP_LINEAR
:
174 if(fxMesa
->haveTwoTMUs
) {
175 ti
->mmMode
=GR_MIPMAP_NEAREST
;
178 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
179 ti
->LODblend
=FXFALSE
;
181 ti
->minFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
183 case GL_LINEAR_MIPMAP_LINEAR
:
184 if(fxMesa
->haveTwoTMUs
) {
185 ti
->mmMode
=GR_MIPMAP_NEAREST
;
188 ti
->mmMode
=GR_MIPMAP_NEAREST_DITHER
;
189 ti
->LODblend
=FXFALSE
;
191 ti
->minFilt
=GR_TEXTUREFILTER_BILINEAR
;
196 fxTexInvalidate(ctx
,tObj
);
199 case GL_TEXTURE_MAG_FILTER
:
202 ti
->maxFilt
=GR_TEXTUREFILTER_POINT_SAMPLED
;
205 ti
->maxFilt
=GR_TEXTUREFILTER_BILINEAR
;
210 fxTexInvalidate(ctx
,tObj
);
213 case GL_TEXTURE_WRAP_S
:
216 ti
->sClamp
=GR_TEXTURECLAMP_CLAMP
;
219 ti
->sClamp
=GR_TEXTURECLAMP_WRAP
;
224 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
225 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
228 case GL_TEXTURE_WRAP_T
:
231 ti
->tClamp
=GR_TEXTURECLAMP_CLAMP
;
234 ti
->tClamp
=GR_TEXTURECLAMP_WRAP
;
239 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
240 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
243 case GL_TEXTURE_BORDER_COLOR
:
247 case GL_TEXTURE_MIN_LOD
:
250 case GL_TEXTURE_MAX_LOD
:
253 case GL_TEXTURE_BASE_LEVEL
:
254 fxTexInvalidate(ctx
,tObj
);
256 case GL_TEXTURE_MAX_LEVEL
:
257 fxTexInvalidate(ctx
,tObj
);
265 void fxDDTexDel(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
267 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
268 tfxTexInfo
*ti
=(tfxTexInfo
*)tObj
->DriverData
;
270 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
271 fprintf(stderr
,"fxmesa: fxDDTexDel(%d,%x)\n",tObj
->Name
,(GLuint
)ti
);
277 fxTMFreeTexture(fxMesa
,tObj
);
280 tObj
->DriverData
=NULL
;
282 ctx
->NewState
|=NEW_TEXTURING
;
285 void fxDDTexPalette(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
287 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
293 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
294 fprintf(stderr
,"fxmesa: fxDDTexPalette(%d,%x)\n",tObj
->Name
,(GLuint
)tObj
->DriverData
);
297 if(tObj
->PaletteFormat
!=GL_RGBA
) {
299 fprintf(stderr
,"fx Driver: unsupported palette format in texpalette()\n");
304 if(tObj
->PaletteSize
>256) {
306 fprintf(stderr
,"fx Driver: unsupported palette size in texpalette()\n");
311 if(!tObj
->DriverData
)
312 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
314 ti
=(tfxTexInfo
*)tObj
->DriverData
;
316 for(i
=0;i
<tObj
->PaletteSize
;i
++) {
317 r
=tObj
->Palette
[i
*4];
318 g
=tObj
->Palette
[i
*4+1];
319 b
=tObj
->Palette
[i
*4+2];
320 a
=tObj
->Palette
[i
*4+3];
321 ti
->palette
.data
[i
]=(a
<<24)|(r
<<16)|(g
<<8)|b
;
324 fxTexInvalidate(ctx
,tObj
);
326 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
327 fprintf(stderr
,"fxmesa: fxDDTexPalette(global)\n");
329 if(ctx
->Texture
.PaletteFormat
!=GL_RGBA
) {
331 fprintf(stderr
,"fx Driver: unsupported palette format in texpalette()\n");
336 if(ctx
->Texture
.PaletteSize
>256) {
338 fprintf(stderr
,"fx Driver: unsupported palette size in texpalette()\n");
343 for(i
=0;i
<ctx
->Texture
.PaletteSize
;i
++) {
344 r
=ctx
->Texture
.Palette
[i
*4];
345 g
=ctx
->Texture
.Palette
[i
*4+1];
346 b
=ctx
->Texture
.Palette
[i
*4+2];
347 a
=ctx
->Texture
.Palette
[i
*4+3];
348 fxMesa
->glbPalette
.data
[i
]=(a
<<24)|(r
<<16)|(g
<<8)|b
;
351 fxMesa
->new_state
|=FX_NEW_TEXTURING
;
352 ctx
->Driver
.RenderStart
= fxSetupFXUnits
;
356 void fxDDTexUseGlbPalette(GLcontext
*ctx
, GLboolean state
)
358 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
360 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
361 fprintf(stderr
,"fxmesa: fxDDTexUseGlbPalette(%d)\n",state
);
365 fxMesa
->haveGlobalPaletteTexture
=1;
367 FX_grTexDownloadTable(GR_TMU0
,GR_TEXTABLE_PALETTE
,&(fxMesa
->glbPalette
));
368 if (fxMesa
->haveTwoTMUs
)
369 FX_grTexDownloadTable(GR_TMU1
,GR_TEXTABLE_PALETTE
,&(fxMesa
->glbPalette
));
371 fxMesa
->haveGlobalPaletteTexture
=0;
373 if((ctx
->Texture
.Unit
[0].Current
==ctx
->Texture
.Unit
[0].CurrentD
[2]) &&
374 (ctx
->Texture
.Unit
[0].Current
!=NULL
)) {
375 struct gl_texture_object
*tObj
=ctx
->Texture
.Unit
[0].Current
;
378 if(!tObj
->DriverData
)
379 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
381 ti
=(tfxTexInfo
*)tObj
->DriverData
;
383 fxTexInvalidate(ctx
,tObj
);
388 static int logbase2(int n
)
409 /* Need different versions for different cpus.
411 #define INT_TRICK(l2) (0x800000 * l2)
414 int fxTexGetInfo(int w
, int h
, GrLOD_t
*lodlevel
, GrAspectRatio_t
*ar
,
415 float *sscale
, float *tscale
,
416 int *i_sscale
, int *i_tscale
,
417 int *wscale
, int *hscale
)
420 static GrLOD_t lod
[9]={GR_LOD_256
,GR_LOD_128
,GR_LOD_64
,GR_LOD_32
,
421 GR_LOD_16
,GR_LOD_8
,GR_LOD_4
,GR_LOD_2
,GR_LOD_1
};
425 GrAspectRatio_t aspectratio
;
434 aspectratio
=GR_ASPECT_1x1
;
441 aspectratio
=GR_ASPECT_2x1
;
445 is
=INT_TRICK(8);it
=INT_TRICK(7);
450 aspectratio
=GR_ASPECT_4x1
;
454 is
=INT_TRICK(8);it
=INT_TRICK(6);
459 aspectratio
=GR_ASPECT_8x1
;
463 is
=INT_TRICK(8);it
=INT_TRICK(5);
468 aspectratio
=GR_ASPECT_8x1
;
472 is
=INT_TRICK(8);it
=INT_TRICK(5);
477 aspectratio
=GR_ASPECT_8x1
;
481 is
=INT_TRICK(8);it
=INT_TRICK(5);
486 aspectratio
=GR_ASPECT_8x1
;
490 is
=INT_TRICK(8);it
=INT_TRICK(5);
495 aspectratio
=GR_ASPECT_8x1
;
499 is
=INT_TRICK(8);it
=INT_TRICK(5);
504 aspectratio
=GR_ASPECT_8x1
;
508 is
=INT_TRICK(8);it
=INT_TRICK(5);
513 aspectratio
=GR_ASPECT_1x2
;
517 is
=INT_TRICK(7);it
=INT_TRICK(8);
522 aspectratio
=GR_ASPECT_1x4
;
526 is
=INT_TRICK(6);it
=INT_TRICK(8);
531 aspectratio
=GR_ASPECT_1x8
;
535 is
=INT_TRICK(5);it
=INT_TRICK(8);
540 aspectratio
=GR_ASPECT_1x8
;
544 is
=INT_TRICK(5);it
=INT_TRICK(8);
549 aspectratio
=GR_ASPECT_1x8
;
553 is
=INT_TRICK(5);it
=INT_TRICK(8);
558 aspectratio
=GR_ASPECT_1x8
;
562 is
=INT_TRICK(5);it
=INT_TRICK(8);
567 aspectratio
=GR_ASPECT_1x8
;
571 is
=INT_TRICK(5);it
=INT_TRICK(8);
576 aspectratio
=GR_ASPECT_1x8
;
580 is
=INT_TRICK(5);it
=INT_TRICK(8);
617 void fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
*tfmt
, GLint
*ifmt
)
627 (*tfmt
)=GR_TEXFMT_INTENSITY_8
;
629 (*ifmt
)=GL_LUMINANCE
;
632 case GL_LUMINANCE_ALPHA
:
633 case GL_LUMINANCE4_ALPHA4
:
634 case GL_LUMINANCE6_ALPHA2
:
635 case GL_LUMINANCE8_ALPHA8
:
636 case GL_LUMINANCE12_ALPHA4
:
637 case GL_LUMINANCE12_ALPHA12
:
638 case GL_LUMINANCE16_ALPHA16
:
640 (*tfmt
)=GR_TEXFMT_ALPHA_INTENSITY_88
;
642 (*ifmt
)=GL_LUMINANCE_ALPHA
;
650 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
652 (*ifmt
)=GL_INTENSITY
;
660 (*tfmt
)=GR_TEXFMT_ALPHA_8
;
674 (*tfmt
)=GR_TEXFMT_RGB_565
;
688 (*tfmt
)=GR_TEXFMT_ARGB_4444
;
693 case GL_COLOR_INDEX1_EXT
:
694 case GL_COLOR_INDEX2_EXT
:
695 case GL_COLOR_INDEX4_EXT
:
696 case GL_COLOR_INDEX8_EXT
:
697 case GL_COLOR_INDEX12_EXT
:
698 case GL_COLOR_INDEX16_EXT
:
700 (*tfmt
)=GR_TEXFMT_P_8
;
705 fprintf(stderr
,"fx Driver: unsupported internalFormat in fxTexGetFormat()\n");
712 static int fxIsTexSupported(GLenum target
, GLint internalFormat
,
713 const struct gl_texture_image
*image
)
715 if(target
!=GL_TEXTURE_2D
)
718 switch(internalFormat
) {
731 case GL_LUMINANCE_ALPHA
:
732 case GL_LUMINANCE4_ALPHA4
:
733 case GL_LUMINANCE6_ALPHA2
:
734 case GL_LUMINANCE8_ALPHA8
:
735 case GL_LUMINANCE12_ALPHA4
:
736 case GL_LUMINANCE12_ALPHA12
:
737 case GL_LUMINANCE16_ALPHA16
:
762 case GL_COLOR_INDEX1_EXT
:
763 case GL_COLOR_INDEX2_EXT
:
764 case GL_COLOR_INDEX4_EXT
:
765 case GL_COLOR_INDEX8_EXT
:
766 case GL_COLOR_INDEX12_EXT
:
767 case GL_COLOR_INDEX16_EXT
:
776 if(image
->Height
>256)
779 if(!fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
786 static void fxTexBuildImageMap(const struct gl_texture_image
*image
,
787 GLint internalFormat
, unsigned short **dest
,
788 GLboolean
*istranslate
)
792 int x
,y
,w
,h
,wscale
,hscale
,idx
;
794 fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
796 w
=image
->Width
*wscale
;
797 h
=image
->Height
*hscale
;
800 switch(internalFormat
) {
818 case GL_COLOR_INDEX1_EXT
:
819 case GL_COLOR_INDEX2_EXT
:
820 case GL_COLOR_INDEX4_EXT
:
821 case GL_COLOR_INDEX8_EXT
:
822 case GL_COLOR_INDEX12_EXT
:
823 case GL_COLOR_INDEX16_EXT
:
824 /* Optimized for GLQuake */
826 if(wscale
==hscale
==1) {
827 (*istranslate
)=GL_FALSE
;
829 (*dest
)=(unsigned short *)data
;
833 (*istranslate
)=GL_TRUE
;
836 if(!((*dest
)=src
=(unsigned short *)malloc(sizeof(unsigned char)*w
*h
))) {
837 fprintf(stderr
,"fx Driver: out of memory !\n");
844 srcb
=(unsigned char *)src
;
848 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
));
849 srcb
[x
+y
*w
]=data
[idx
];
854 case GL_LUMINANCE_ALPHA
:
855 case GL_LUMINANCE4_ALPHA4
:
856 case GL_LUMINANCE6_ALPHA2
:
857 case GL_LUMINANCE8_ALPHA8
:
858 case GL_LUMINANCE12_ALPHA4
:
859 case GL_LUMINANCE12_ALPHA12
:
860 case GL_LUMINANCE16_ALPHA16
:
861 (*istranslate
)=GL_TRUE
;
864 if(!((*dest
)=src
=(unsigned short *)malloc(sizeof(unsigned short)*w
*h
))) {
865 fprintf(stderr
,"fx Driver: out of memory !\n");
872 if(wscale
==hscale
==1) {
888 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
))*2;
892 src
[x
+y
*w
]=(a
<< 8) | l
;
905 (*istranslate
)=GL_TRUE
;
908 if(!((*dest
)=src
=(unsigned short *)malloc(sizeof(unsigned short)*w
*h
))) {
909 fprintf(stderr
,"fx Driver: out of memory !\n");
916 if(wscale
==hscale
==1) {
919 unsigned short r
,g
,b
;
926 *src
++=((0xf8 & r
) << (11-3)) |
927 ((0xfc & g
) << (5-3+1)) |
931 unsigned short r
,g
,b
;
935 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
))*3;
940 src
[x
+y
*w
]=((0xf8 & r
) << (11-3)) |
941 ((0xfc & g
) << (5-3+1)) |
955 (*istranslate
)=GL_TRUE
;
958 if(!((*dest
)=src
=(unsigned short *)malloc(sizeof(unsigned short)*w
*h
))) {
959 fprintf(stderr
,"fx Driver: out of memory !\n");
966 if(wscale
==hscale
==1) {
969 unsigned short r
,g
,b
,a
;
977 *src
++=((0xf0 & a
) << 8) |
983 unsigned short r
,g
,b
,a
;
987 idx
=(x
/wscale
+(y
/hscale
)*(w
/wscale
))*4;
993 src
[x
+y
*w
]=((0xf0 & a
) << 8) |
1001 fprintf(stderr
,"fx Driver: wrong internalFormat in texbuildimagemap()\n");
1008 void fxDDTexImg(GLcontext
*ctx
, GLenum target
,
1009 struct gl_texture_object
*tObj
, GLint level
, GLint internalFormat
,
1010 const struct gl_texture_image
*image
)
1012 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1015 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1016 fprintf(stderr
,"fxmesa: (%d) fxDDTexImg(...,%d,%x,%d,%d...)\n",tObj
->Name
,
1017 target
,internalFormat
,image
->Width
,image
->Height
);
1020 if(target
!=GL_TEXTURE_2D
)
1023 if(!tObj
->DriverData
)
1024 tObj
->DriverData
=fxAllocTexObjData(fxMesa
);
1026 ti
=(tfxTexInfo
*)tObj
->DriverData
;
1028 if(fxIsTexSupported(target
,internalFormat
,image
)) {
1029 GrTextureFormat_t gldformat
;
1030 tfxMipMapLevel
*mml
=&ti
->tmi
.mipmapLevel
[level
];
1032 fxTexGetFormat(internalFormat
,&gldformat
,NULL
);
1035 if((mml
->glideFormat
==gldformat
) &&
1036 (mml
->width
==image
->Width
) &&
1037 (mml
->height
==image
->Height
)) {
1038 fxTexBuildImageMap(image
,internalFormat
,&(mml
->data
),
1039 &(mml
->translated
));
1041 if(ti
->validated
&& ti
->tmi
.isInTM
)
1042 fxTMReloadMipMapLevel(fxMesa
,tObj
,level
);
1044 fxTexInvalidate(ctx
,tObj
);
1054 mml
->glideFormat
=gldformat
;
1055 mml
->width
=image
->Width
;
1056 mml
->height
=image
->Height
;
1059 fxTexBuildImageMap(image
,internalFormat
,&(mml
->data
),
1060 &(mml
->translated
));
1062 fxTexInvalidate(ctx
,tObj
);
1066 fprintf(stderr
,"fx Driver: unsupported texture in fxDDTexImg()\n");
1070 static void fxTexBuildSubImageMap(const struct gl_texture_image
*image
,
1071 GLint internalFormat
,
1072 GLint xoffset
, GLint yoffset
, GLint width
, GLint height
,
1073 unsigned short *destimg
)
1075 fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,
1078 switch(internalFormat
) {
1082 case GL_INTENSITY12
:
1083 case GL_INTENSITY16
:
1088 case GL_LUMINANCE12
:
1089 case GL_LUMINANCE16
:
1095 case GL_COLOR_INDEX
:
1096 case GL_COLOR_INDEX1_EXT
:
1097 case GL_COLOR_INDEX2_EXT
:
1098 case GL_COLOR_INDEX4_EXT
:
1099 case GL_COLOR_INDEX8_EXT
:
1100 case GL_COLOR_INDEX12_EXT
:
1101 case GL_COLOR_INDEX16_EXT
:
1105 unsigned char *bsrc
,*bdst
;
1107 bsrc
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
));
1108 bdst
=((unsigned char *)destimg
)+(yoffset
*image
->Width
+xoffset
);
1110 for(y
=0;y
<height
;y
++) {
1111 MEMCPY(bdst
,bsrc
,width
);
1112 bsrc
+= image
->Width
;
1113 bdst
+= image
->Width
;
1118 case GL_LUMINANCE_ALPHA
:
1119 case GL_LUMINANCE4_ALPHA4
:
1120 case GL_LUMINANCE6_ALPHA2
:
1121 case GL_LUMINANCE8_ALPHA8
:
1122 case GL_LUMINANCE12_ALPHA4
:
1123 case GL_LUMINANCE12_ALPHA12
:
1124 case GL_LUMINANCE16_ALPHA16
:
1128 unsigned short *dst
,a
,l
;
1131 src
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
)*2);
1132 dst
=destimg
+(yoffset
*image
->Width
+xoffset
);
1134 simgw
=(image
->Width
-width
)*2;
1135 dimgw
=image
->Width
-width
;
1136 for(y
=0;y
<height
;y
++) {
1137 for(x
=0;x
<width
;x
++) {
1140 *dst
++=(a
<< 8) | l
;
1160 unsigned short *dst
,r
,g
,b
;
1163 src
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
)*3);
1164 dst
=destimg
+(yoffset
*image
->Width
+xoffset
);
1166 simgw
=(image
->Width
-width
)*3;
1167 dimgw
=image
->Width
-width
;
1168 for(y
=0;y
<height
;y
++) {
1169 for(x
=0;x
<width
;x
++) {
1173 *dst
++=((0xf8 & r
) << (11-3)) |
1174 ((0xfc & g
) << (5-3+1)) |
1195 unsigned short *dst
,r
,g
,b
,a
;
1198 src
=(unsigned char *)(image
->Data
+(yoffset
*image
->Width
+xoffset
)*4);
1199 dst
=destimg
+(yoffset
*image
->Width
+xoffset
);
1201 simgw
=(image
->Width
-width
)*4;
1202 dimgw
=image
->Width
-width
;
1203 for(y
=0;y
<height
;y
++) {
1204 for(x
=0;x
<width
;x
++) {
1209 *dst
++=((0xf0 & a
) << 8) |
1221 fprintf(stderr
,"fx Driver: wrong internalFormat in fxTexBuildSubImageMap()\n");
1229 void fxDDTexSubImg(GLcontext
*ctx
, GLenum target
,
1230 struct gl_texture_object
*tObj
, GLint level
,
1231 GLint xoffset
, GLint yoffset
, GLint width
, GLint height
,
1232 GLint internalFormat
, const struct gl_texture_image
*image
)
1234 fxMesaContext fxMesa
=(fxMesaContext
)ctx
->DriverCtx
;
1236 GrTextureFormat_t gldformat
;
1238 tfxMipMapLevel
*mml
;
1240 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1241 fprintf(stderr
,"fxmesa: (%d) fxDDTexSubImg(...,%d,%x,%d,%d...)\n",tObj
->Name
,
1242 target
,internalFormat
,image
->Width
,image
->Height
);
1245 if(target
!=GL_TEXTURE_2D
)
1248 if(!tObj
->DriverData
)
1251 ti
=(tfxTexInfo
*)tObj
->DriverData
;
1252 mml
=&ti
->tmi
.mipmapLevel
[level
];
1254 fxTexGetFormat(internalFormat
,&gldformat
,NULL
);
1256 if(mml
->glideFormat
!=gldformat
) {
1257 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1258 fprintf(stderr
,"fxmesa: ti->info.format!=format in fxDDTexSubImg()\n");
1260 fxDDTexImg(ctx
,target
,tObj
,level
,internalFormat
,image
);
1265 fxTexGetInfo(image
->Width
,image
->Height
,NULL
,NULL
,NULL
,NULL
,NULL
,NULL
,&wscale
,&hscale
);
1267 if((wscale
!=1) || (hscale
!=1)) {
1268 if (MESA_VERBOSE
&VERBOSE_DRIVER
) {
1269 fprintf(stderr
,"fxmesa: (wscale!=1) || (hscale!=1) in fxDDTexSubImg()\n");
1271 fxDDTexImg(ctx
,target
,tObj
,level
,internalFormat
,image
);
1277 fxTexBuildSubImageMap(image
,internalFormat
,xoffset
,yoffset
,
1278 width
,height
,mml
->data
);
1280 if(ti
->validated
&& ti
->tmi
.isInTM
)
1281 fxTMReloadSubMipMapLevel(fxMesa
,tObj
,level
,yoffset
,height
);
1283 fxTexInvalidate(ctx
,tObj
);
1291 * Need this to provide at least one external definition.
1294 int gl_fx_dummy_function_ddtex(void)