1 /* $Id: fxddtex.c,v 1.47 2003/08/19 15:52:53 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
46 #include "texformat.h"
52 fxPrintTextureData(tfxTexInfo
* ti
)
54 fprintf(stderr
, "Texture Data:\n");
56 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
57 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
58 fprintf(stderr
, "\tSize: %d x %d\n",
59 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
60 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
63 fprintf(stderr
, "\tName: UNNAMED\n");
64 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
65 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
66 fprintf(stderr
, "\t%s\n", (ti
->isInTM
) ? "In TMU" : "Not in TMU");
68 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
69 (unsigned) ti
->tm
[0]->endAddr
);
71 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
72 (unsigned) ti
->tm
[1]->endAddr
);
73 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
74 fprintf(stderr
, "\tFilters: min %d min %d\n",
75 (int) ti
->minFilt
, (int) ti
->maxFilt
);
76 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
,
78 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
79 fprintf(stderr
, "\tInt Scales: s %d t %d\n",
80 ti
->int_sScale
/ 0x800000, ti
->int_tScale
/ 0x800000);
81 fprintf(stderr
, "\t%s\n",
82 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
83 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
87 /************************************************************************/
88 /*************************** Texture Mapping ****************************/
89 /************************************************************************/
92 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
94 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
97 ti
= fxTMGetTexInfo(tObj
);
99 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
101 ti
->validated
= GL_FALSE
;
102 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
106 fxAllocTexObjData(fxMesaContext fxMesa
)
110 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
111 fprintf(stderr
, "fx Driver: out of memory !\n");
116 ti
->validated
= GL_FALSE
;
117 ti
->isInTM
= 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
;
137 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
139 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
142 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
143 fprintf(stderr
, "fxmesa: fxDDTexBind(%d,%x)\n", tObj
->Name
,
144 (GLuint
) tObj
->DriverData
);
147 if (target
!= GL_TEXTURE_2D
)
150 if (!tObj
->DriverData
) {
151 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
154 ti
= fxTMGetTexInfo(tObj
);
156 fxMesa
->texBindNumber
++;
157 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
159 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
163 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
164 const GLfloat
* param
)
166 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
168 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
170 fprintf(stderr
, "fxmesa: texenv(%x,%x)\n", pname
, (GLint
) (*param
));
172 fprintf(stderr
, "fxmesa: texenv(%x)\n", pname
);
175 /* apply any lod biasing right now */
176 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
177 grTexLodBiasValue(GR_TMU0
, *param
);
179 if (fxMesa
->haveTwoTMUs
) {
180 grTexLodBiasValue(GR_TMU1
, *param
);
185 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
189 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
190 GLenum pname
, const GLfloat
* params
)
192 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
193 GLenum param
= (GLenum
) (GLint
) params
[0];
196 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
197 fprintf(stderr
, "fxmesa: fxDDTexParam(%d,%x,%x,%x)\n", tObj
->Name
,
198 (GLuint
) tObj
->DriverData
, pname
, param
);
201 if (target
!= GL_TEXTURE_2D
)
204 if (!tObj
->DriverData
)
205 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
207 ti
= fxTMGetTexInfo(tObj
);
211 case GL_TEXTURE_MIN_FILTER
:
214 ti
->mmMode
= GR_MIPMAP_DISABLE
;
215 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
216 ti
->LODblend
= FXFALSE
;
219 ti
->mmMode
= GR_MIPMAP_DISABLE
;
220 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
221 ti
->LODblend
= FXFALSE
;
223 case GL_NEAREST_MIPMAP_NEAREST
:
224 ti
->mmMode
= GR_MIPMAP_NEAREST
;
225 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
226 ti
->LODblend
= FXFALSE
;
228 case GL_LINEAR_MIPMAP_NEAREST
:
229 ti
->mmMode
= GR_MIPMAP_NEAREST
;
230 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
231 ti
->LODblend
= FXFALSE
;
233 case GL_NEAREST_MIPMAP_LINEAR
:
234 if (fxMesa
->haveTwoTMUs
) {
235 ti
->mmMode
= GR_MIPMAP_NEAREST
;
236 ti
->LODblend
= FXTRUE
;
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
;
247 ti
->LODblend
= FXTRUE
;
250 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
251 ti
->LODblend
= FXFALSE
;
253 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
258 fxTexInvalidate(ctx
, tObj
);
261 case GL_TEXTURE_MAG_FILTER
:
264 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
267 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
272 fxTexInvalidate(ctx
, tObj
);
275 case GL_TEXTURE_WRAP_S
:
278 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
281 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
286 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
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
;
303 case GL_TEXTURE_BORDER_COLOR
:
307 case GL_TEXTURE_MIN_LOD
:
310 case GL_TEXTURE_MAX_LOD
:
313 case GL_TEXTURE_BASE_LEVEL
:
314 fxTexInvalidate(ctx
, tObj
);
316 case GL_TEXTURE_MAX_LEVEL
:
317 fxTexInvalidate(ctx
, tObj
);
326 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
, (void *) ti
);
338 fxTMFreeTexture(fxMesa
, tObj
);
341 tObj
->DriverData
= NULL
;
347 * Convert a gl_color_table texture palette to Glide's format.
350 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
352 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
353 GLint width
= table
->Size
;
357 ASSERT(!table
->FloatTable
);
359 switch (table
->Format
) {
361 for (i
= 0; i
< width
; i
++) {
366 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
370 for (i
= 0; i
< width
; i
++) {
375 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
379 for (i
= 0; i
< width
; i
++) {
382 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
385 case GL_LUMINANCE_ALPHA
:
386 for (i
= 0; i
< width
; i
++) {
387 r
= g
= b
= tableUB
[i
* 2 + 0];
388 a
= tableUB
[i
* 2 + 1];
389 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
393 for (i
= 0; i
< width
; i
++) {
394 r
= tableUB
[i
* 3 + 0];
395 g
= tableUB
[i
* 3 + 1];
396 b
= tableUB
[i
* 3 + 2];
398 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
402 for (i
= 0; i
< width
; i
++) {
403 r
= tableUB
[i
* 4 + 0];
404 g
= tableUB
[i
* 4 + 1];
405 b
= tableUB
[i
* 4 + 2];
406 a
= tableUB
[i
* 4 + 3];
407 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
415 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
417 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
420 /* per-texture palette */
422 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
423 fprintf(stderr
, "fxmesa: fxDDTexPalette(%d,%x)\n",
424 tObj
->Name
, (GLuint
) tObj
->DriverData
);
426 if (!tObj
->DriverData
)
427 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
428 ti
= fxTMGetTexInfo(tObj
);
429 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
430 fxTexInvalidate(ctx
, tObj
);
433 /* global texture palette */
434 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
435 fprintf(stderr
, "fxmesa: fxDDTexPalette(global)\n");
437 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
438 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
444 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
446 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
448 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
449 fprintf(stderr
, "fxmesa: fxDDTexUseGlbPalette(%d)\n", state
);
453 fxMesa
->haveGlobalPaletteTexture
= 1;
455 grTexDownloadTable(GR_TEXTABLE_PALETTE
, &(fxMesa
->glbPalette
));
458 fxMesa
->haveGlobalPaletteTexture
= 0;
460 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
461 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
462 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
464 if (!tObj
->DriverData
)
465 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
467 fxTexInvalidate(ctx
, tObj
);
495 /* Need different versions for different cpus.
497 #define INT_TRICK(l2) (0x800000 * l2)
501 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
502 float *sscale
, float *tscale
,
503 int *i_sscale
, int *i_tscale
, int *wscale
, int *hscale
)
506 static GrLOD_t lod
[12] = { GR_LOD_2048
, GR_LOD_1024
, GR_LOD_512
, GR_LOD_256
, GR_LOD_128
, GR_LOD_64
, GR_LOD_32
,
507 GR_LOD_16
, GR_LOD_8
, GR_LOD_4
, GR_LOD_2
, GR_LOD_1
510 int logw
, logh
, ws
, hs
;
512 GrAspectRatio_t aspectratio
;
519 switch (logw
- logh
) {
521 aspectratio
= GR_ASPECT_1x1
;
524 is
= it
= INT_TRICK(8);
528 aspectratio
= GR_ASPECT_2x1
;
538 aspectratio
= GR_ASPECT_4x1
;
548 aspectratio
= GR_ASPECT_8x1
;
558 aspectratio
= GR_ASPECT_8x1
;
568 aspectratio
= GR_ASPECT_8x1
;
578 aspectratio
= GR_ASPECT_8x1
;
588 aspectratio
= GR_ASPECT_8x1
;
598 aspectratio
= GR_ASPECT_8x1
;
608 aspectratio
= GR_ASPECT_8x1
;
618 aspectratio
= GR_ASPECT_8x1
;
628 aspectratio
= GR_ASPECT_8x1
;
638 aspectratio
= GR_ASPECT_1x2
;
648 aspectratio
= GR_ASPECT_1x4
;
658 aspectratio
= GR_ASPECT_1x8
;
668 aspectratio
= GR_ASPECT_1x8
;
678 aspectratio
= GR_ASPECT_1x8
;
688 aspectratio
= GR_ASPECT_1x8
;
698 aspectratio
= GR_ASPECT_1x8
;
708 aspectratio
= GR_ASPECT_1x8
;
718 aspectratio
= GR_ASPECT_1x8
;
728 aspectratio
= GR_ASPECT_1x8
;
738 aspectratio
= GR_ASPECT_1x8
;
781 * Given an OpenGL internal texture format, return the corresponding
782 * Glide internal texture format and base texture format.
785 fxTexGetFormat(GLcontext
*ctx
, GLenum glformat
, GrTextureFormat_t
* tfmt
, GLint
* ifmt
) /* [koolsmoky] */
787 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
797 (*tfmt
) = GR_TEXFMT_INTENSITY_8
;
799 (*ifmt
) = GL_LUMINANCE
;
802 case GL_LUMINANCE_ALPHA
:
803 case GL_LUMINANCE4_ALPHA4
:
804 case GL_LUMINANCE6_ALPHA2
:
805 case GL_LUMINANCE8_ALPHA8
:
806 case GL_LUMINANCE12_ALPHA4
:
807 case GL_LUMINANCE12_ALPHA12
:
808 case GL_LUMINANCE16_ALPHA16
:
810 (*tfmt
) = GR_TEXFMT_ALPHA_INTENSITY_88
;
812 (*ifmt
) = GL_LUMINANCE_ALPHA
;
820 (*tfmt
) = GR_TEXFMT_ALPHA_8
;
822 (*ifmt
) = GL_INTENSITY
;
830 (*tfmt
) = GR_TEXFMT_ALPHA_8
;
838 (*tfmt
) = GR_TEXFMT_RGB_565
;
848 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
849 if (fxMesa
->colDepth
== 32) {
850 if (tfmt
) (*tfmt
) = GR_TEXFMT_ARGB_8888
;
852 if (tfmt
) (*tfmt
) = GR_TEXFMT_RGB_565
;
854 if (ifmt
) (*ifmt
) = GL_RGB
;
857 (*tfmt
) = GR_TEXFMT_RGB_565
;
865 (*tfmt
) = GR_TEXFMT_ARGB_4444
;
875 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
876 if (fxMesa
->colDepth
== 32) {
877 if (tfmt
) (*tfmt
) = GR_TEXFMT_ARGB_8888
;
879 if (tfmt
) (*tfmt
) = GR_TEXFMT_ARGB_4444
;
881 if (ifmt
) (*ifmt
) = GL_RGBA
;
884 (*tfmt
) = GR_TEXFMT_ARGB_4444
;
891 (*tfmt
) = GR_TEXFMT_ARGB_1555
;
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
:
903 (*tfmt
) = GR_TEXFMT_P_8
;
905 (*ifmt
) = GL_RGBA
; /* XXX why is this RGBA? */
909 "fx Driver: unsupported internalFormat (0x%x) in fxTexGetFormat()\n",
918 fxIsTexSupported(GLenum target
, GLint internalFormat
,
919 const struct gl_texture_image
*image
)
921 if (target
!= GL_TEXTURE_2D
)
925 (image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
926 NULL
)) return GL_FALSE
;
928 if (image
->Border
> 0)
935 /**********************************************************************/
936 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
937 /**********************************************************************/
939 /* Texel-fetch functions for software texturing and glGetTexImage().
940 * We should have been able to use some "standard" fetch functions (which
941 * may get defined in texutil.c) but we have to account for scaled texture
942 * images on tdfx hardware (the 8:1 aspect ratio limit).
943 * Hence, we need special functions here.
947 fetch_intensity8(const struct gl_texture_image
*texImage
,
948 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
950 GLchan
*rgba
= (GLchan
*) texelOut
;
951 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
952 const GLubyte
*texel
;
957 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
958 rgba
[RCOMP
] = *texel
;
959 rgba
[GCOMP
] = *texel
;
960 rgba
[BCOMP
] = *texel
;
961 rgba
[ACOMP
] = *texel
;
966 fetch_luminance8(const struct gl_texture_image
*texImage
,
967 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
969 GLchan
*rgba
= (GLchan
*) texelOut
;
970 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
971 const GLubyte
*texel
;
976 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
977 rgba
[RCOMP
] = *texel
;
978 rgba
[GCOMP
] = *texel
;
979 rgba
[BCOMP
] = *texel
;
985 fetch_alpha8(const struct gl_texture_image
*texImage
,
986 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
988 GLchan
*rgba
= (GLchan
*) texelOut
;
989 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
990 const GLubyte
*texel
;
994 i
= i
* mml
->width
/ texImage
->Width
;
995 j
= j
* mml
->height
/ texImage
->Height
;
997 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
1001 rgba
[ACOMP
] = *texel
;
1006 fetch_index8(const struct gl_texture_image
*texImage
,
1007 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1009 GLchan
*indexOut
= (GLchan
*) texelOut
;
1010 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1011 const GLubyte
*texel
;
1013 i
= i
* mml
->wScale
;
1014 j
= j
* mml
->hScale
;
1015 i
= i
* mml
->width
/ texImage
->Width
;
1016 j
= j
* mml
->height
/ texImage
->Height
;
1018 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
1024 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
1025 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1027 GLchan
*rgba
= (GLchan
*) texelOut
;
1028 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1029 const GLubyte
*texel
;
1031 i
= i
* mml
->wScale
;
1032 j
= j
* mml
->hScale
;
1034 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
1035 rgba
[RCOMP
] = texel
[0];
1036 rgba
[GCOMP
] = texel
[0];
1037 rgba
[BCOMP
] = texel
[0];
1038 rgba
[ACOMP
] = texel
[1];
1043 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
1044 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1046 GLchan
*rgba
= (GLchan
*) texelOut
;
1047 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1048 const GLushort
*texel
;
1050 i
= i
* mml
->wScale
;
1051 j
= j
* mml
->hScale
;
1053 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1054 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1055 rgba
[GCOMP
] = (((*texel
) >> 5) & 0x3f) * 255 / 63;
1056 rgba
[BCOMP
] = (((*texel
) >> 0) & 0x1f) * 255 / 31;
1062 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
1063 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1065 GLchan
*rgba
= (GLchan
*) texelOut
;
1066 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1067 const GLushort
*texel
;
1069 i
= i
* mml
->wScale
;
1070 j
= j
* mml
->hScale
;
1072 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1073 rgba
[RCOMP
] = (((*texel
) >> 12) & 0xf) * 255 / 15;
1074 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xf) * 255 / 15;
1075 rgba
[BCOMP
] = (((*texel
) >> 4) & 0xf) * 255 / 15;
1076 rgba
[ACOMP
] = (((*texel
) >> 0) & 0xf) * 255 / 15;
1081 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
1082 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1084 GLchan
*rgba
= (GLchan
*) texelOut
;
1085 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1086 const GLushort
*texel
;
1088 i
= i
* mml
->wScale
;
1089 j
= j
* mml
->hScale
;
1091 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1092 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1093 rgba
[GCOMP
] = (((*texel
) >> 6) & 0x1f) * 255 / 31;
1094 rgba
[BCOMP
] = (((*texel
) >> 1) & 0x1f) * 255 / 31;
1095 rgba
[ACOMP
] = (((*texel
) >> 0) & 0x01) * 255;
1099 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
1101 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
1102 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1104 GLchan
*rgba
= (GLchan
*) texelOut
;
1105 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1106 const GLuint
*texel
;
1108 i
= i
* mml
->wScale
;
1109 j
= j
* mml
->hScale
;
1111 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
1112 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
1113 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
1114 rgba
[BCOMP
] = (((*texel
)) & 0xff);
1115 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
1121 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
1124 for (i
= 0; i
< h
; i
++) {
1125 for (j
= 0; j
< w
; j
++) {
1127 printf("%02x %02x ", data
[0], data
[1]);
1129 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
1137 const struct gl_texture_format
*
1138 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
1139 GLenum srcFormat
, GLenum srcType
)
1141 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1143 switch (internalFormat
) {
1147 case GL_INTENSITY12
:
1148 case GL_INTENSITY16
:
1149 return &_mesa_texformat_i8
;
1154 case GL_LUMINANCE12
:
1155 case GL_LUMINANCE16
:
1156 return &_mesa_texformat_l8
;
1162 return &_mesa_texformat_a8
;
1163 case GL_COLOR_INDEX
:
1164 case GL_COLOR_INDEX1_EXT
:
1165 case GL_COLOR_INDEX2_EXT
:
1166 case GL_COLOR_INDEX4_EXT
:
1167 case GL_COLOR_INDEX8_EXT
:
1168 case GL_COLOR_INDEX12_EXT
:
1169 case GL_COLOR_INDEX16_EXT
:
1170 return &_mesa_texformat_ci8
;
1172 case GL_LUMINANCE_ALPHA
:
1173 case GL_LUMINANCE4_ALPHA4
:
1174 case GL_LUMINANCE6_ALPHA2
:
1175 case GL_LUMINANCE8_ALPHA8
:
1176 case GL_LUMINANCE12_ALPHA4
:
1177 case GL_LUMINANCE12_ALPHA12
:
1178 case GL_LUMINANCE16_ALPHA16
:
1179 return &_mesa_texformat_al88
;
1183 return &_mesa_texformat_rgb565
;
1190 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
1191 return (fxMesa
->colDepth
== 32) ? &_mesa_texformat_argb8888
1192 : &_mesa_texformat_rgb565
;
1194 return &_mesa_texformat_rgb565
;
1198 return &_mesa_texformat_argb4444
;
1205 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
1206 return (fxMesa
->colDepth
== 32) ? &_mesa_texformat_argb8888
1207 : &_mesa_texformat_argb4444
;
1209 return &_mesa_texformat_argb4444
;
1212 return &_mesa_texformat_argb1555
;
1214 _mesa_problem(NULL
, "unexpected format in fxDDChooseTextureFormat");
1220 static GrTextureFormat_t
1221 fxGlideFormat(GLint mesaFormat
)
1223 switch (mesaFormat
) {
1224 case MESA_FORMAT_I8
:
1225 return GR_TEXFMT_ALPHA_8
;
1226 case MESA_FORMAT_A8
:
1227 return GR_TEXFMT_ALPHA_8
;
1228 case MESA_FORMAT_L8
:
1229 return GR_TEXFMT_INTENSITY_8
;
1230 case MESA_FORMAT_CI8
:
1231 return GR_TEXFMT_P_8
;
1232 case MESA_FORMAT_AL88
:
1233 return GR_TEXFMT_ALPHA_INTENSITY_88
;
1234 case MESA_FORMAT_RGB565
:
1235 return GR_TEXFMT_RGB_565
;
1236 case MESA_FORMAT_ARGB4444
:
1237 return GR_TEXFMT_ARGB_4444
;
1238 case MESA_FORMAT_ARGB1555
:
1239 return GR_TEXFMT_ARGB_1555
;
1240 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
1241 case MESA_FORMAT_ARGB8888
:
1242 return GR_TEXFMT_ARGB_8888
;
1245 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1251 static FetchTexelFunc
1252 fxFetchFunction(GLint mesaFormat
)
1254 switch (mesaFormat
) {
1255 case MESA_FORMAT_I8
:
1256 return fetch_intensity8
;
1257 case MESA_FORMAT_A8
:
1258 return fetch_alpha8
;
1259 case MESA_FORMAT_L8
:
1260 return fetch_luminance8
;
1261 case MESA_FORMAT_CI8
:
1262 return fetch_index8
;
1263 case MESA_FORMAT_AL88
:
1264 return fetch_luminance8_alpha8
;
1265 case MESA_FORMAT_RGB565
:
1266 return fetch_r5g6b5
;
1267 case MESA_FORMAT_ARGB4444
:
1268 return fetch_r4g4b4a4
;
1269 case MESA_FORMAT_ARGB1555
:
1270 return fetch_r5g5b5a1
;
1271 #if 0 /* [koolsmoky] getting ready for 32bpp textures */
1272 case MESA_FORMAT_ARGB8888
:
1273 return fetch_a8r8g8b8
;
1276 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1282 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1283 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1284 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1285 const struct gl_pixelstore_attrib
*packing
,
1286 struct gl_texture_object
*texObj
,
1287 struct gl_texture_image
*texImage
)
1289 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1291 tfxMipMapLevel
*mml
;
1294 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1295 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1299 if (!texObj
->DriverData
) {
1300 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1301 if (!texObj
->DriverData
) {
1302 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1306 ti
= fxTMGetTexInfo(texObj
);
1308 if (!texImage
->DriverData
) {
1309 texImage
->DriverData
= MALLOC(sizeof(tfxMipMapLevel
));
1310 if (!texImage
->DriverData
) {
1311 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1315 mml
= FX_MIPMAP_DATA(texImage
);
1317 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1318 NULL
, NULL
, &mml
->wScale
, &mml
->hScale
);
1320 mml
->width
= width
* mml
->wScale
;
1321 mml
->height
= height
* mml
->hScale
;
1324 /* choose the texture format */
1325 assert(ctx
->Driver
.ChooseTextureFormat
);
1326 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1327 internalFormat
, format
, type
);
1328 assert(texImage
->TexFormat
);
1329 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1330 assert(texelBytes
== 1 || texelBytes
== 2);
1332 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1333 /* rescale image to overcome 1:8 aspect limitation */
1335 tempImage
= MALLOC(width
* height
* texelBytes
);
1337 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1340 /* unpack image, apply transfer ops and store in tempImage */
1341 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1342 texImage
->TexFormat
,
1344 width
, height
, 1, 0, 0, 0,
1346 0, /* dstImageStride */
1347 format
, type
, pixels
, packing
);
1348 assert(!texImage
->Data
);
1349 texImage
->Data
= MALLOC(mml
->width
* mml
->height
* texelBytes
);
1350 if (!texImage
->Data
) {
1351 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1355 _mesa_rescale_teximage2d(texelBytes
,
1356 mml
->width
* texelBytes
, /* dst stride */
1358 mml
->width
, mml
->height
,
1359 tempImage
/*src*/, texImage
->Data
/*dst*/ );
1363 /* no rescaling needed */
1364 assert(!texImage
->Data
);
1365 texImage
->Data
= MALLOC(mml
->width
* mml
->height
* texelBytes
);
1366 if (!texImage
->Data
) {
1367 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1370 /* unpack image, apply transfer ops and store in texImage->Data */
1371 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1372 texImage
->TexFormat
, texImage
->Data
,
1373 width
, height
, 1, 0, 0, 0,
1374 texImage
->Width
* texelBytes
,
1375 0, /* dstImageStride */
1376 format
, type
, pixels
, packing
);
1379 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1380 texImage
->FetchTexel
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1382 fxTexInvalidate(ctx
, texObj
);
1384 if (ti
->validated
&& ti
->isInTM
) {
1385 /*printf("reloadmipmaplevels\n"); */
1386 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1389 /*printf("invalidate2\n"); */
1390 fxTexInvalidate(ctx
, texObj
);
1396 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1397 GLint xoffset
, GLint yoffset
,
1398 GLsizei width
, GLsizei height
,
1399 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1400 const struct gl_pixelstore_attrib
*packing
,
1401 struct gl_texture_object
*texObj
,
1402 struct gl_texture_image
*texImage
)
1404 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1406 tfxMipMapLevel
*mml
;
1409 if (!texObj
->DriverData
) {
1410 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1414 ti
= fxTMGetTexInfo(texObj
);
1416 mml
= FX_MIPMAP_DATA(texImage
);
1419 assert(texImage
->Data
); /* must have an existing texture image! */
1420 assert(texImage
->Format
);
1422 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1424 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1425 /* need to rescale subimage to match mipmap level's rescale factors */
1426 const GLint newWidth
= width
* mml
->wScale
;
1427 const GLint newHeight
= height
* mml
->hScale
;
1428 GLvoid
*scaledImage
, *tempImage
;
1430 tempImage
= MALLOC(width
* height
* texelBytes
);
1432 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1436 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,/* Tex int format */
1437 texImage
->TexFormat
, /* dest format */
1438 (GLubyte
*) tempImage
, /* dest */
1439 width
, height
, 1, /* subimage size */
1440 0, 0, 0, /* subimage pos */
1441 width
* texelBytes
, /* dest row stride */
1442 0, /* dst image stride */
1443 format
, type
, pixels
, packing
);
1446 scaledImage
= MALLOC(newWidth
* newHeight
* texelBytes
);
1448 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1453 /* compute address of dest subimage within the overal tex image */
1454 destAddr
= (GLubyte
*) texImage
->Data
1455 + (yoffset
* mml
->hScale
* mml
->width
1456 + xoffset
* mml
->wScale
) * texelBytes
;
1458 _mesa_rescale_teximage2d(texelBytes
,
1459 mml
->width
* texelBytes
, /* dst stride */
1461 newWidth
, newHeight
,
1462 tempImage
, destAddr
);
1468 /* no rescaling needed */
1469 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, /* Tex int format */
1470 texImage
->TexFormat
, /* dest format */
1471 (GLubyte
*) texImage
->Data
,/* dest */
1472 width
, height
, 1, /* subimage size */
1473 xoffset
, yoffset
, 0, /* subimage pos */
1474 mml
->width
* texelBytes
, /* dest row stride */
1475 0, /* dst image stride */
1476 format
, type
, pixels
, packing
);
1479 if (ti
->validated
&& ti
->isInTM
)
1480 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1482 fxTexInvalidate(ctx
, texObj
);
1489 * Need this to provide at least one external definition.
1492 extern int gl_fx_dummy_function_ddtex(void);
1494 gl_fx_dummy_function_ddtex(void)