3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 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.
54 #include "texformat.h"
60 fxPrintTextureData(tfxTexInfo
* ti
)
62 fprintf(stderr
, "Texture Data:\n");
64 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
65 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
66 fprintf(stderr
, "\tSize: %d x %d\n",
67 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
68 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
71 fprintf(stderr
, "\tName: UNNAMED\n");
72 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
73 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
74 fprintf(stderr
, "\t%s\n", (ti
->isInTM
) ? "In TMU" : "Not in TMU");
76 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
77 (unsigned) ti
->tm
[0]->endAddr
);
79 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
80 (unsigned) ti
->tm
[1]->endAddr
);
81 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
82 fprintf(stderr
, "\tFilters: min %d min %d\n",
83 (int) ti
->minFilt
, (int) ti
->maxFilt
);
84 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
,
86 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
87 fprintf(stderr
, "\tInt Scales: s %d t %d\n",
88 ti
->int_sScale
/ 0x800000, ti
->int_tScale
/ 0x800000);
89 fprintf(stderr
, "\t%s\n",
90 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
91 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
95 /************************************************************************/
96 /*************************** Texture Mapping ****************************/
97 /************************************************************************/
100 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
102 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
105 ti
= fxTMGetTexInfo(tObj
);
107 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
109 ti
->validated
= GL_FALSE
;
110 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
114 fxAllocTexObjData(fxMesaContext fxMesa
)
118 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
119 fprintf(stderr
, "fx Driver: out of memory !\n");
124 ti
->validated
= GL_FALSE
;
125 ti
->isInTM
= GL_FALSE
;
127 ti
->whichTMU
= FX_TMU_NONE
;
129 ti
->tm
[FX_TMU0
] = NULL
;
130 ti
->tm
[FX_TMU1
] = NULL
;
132 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
133 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
135 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
136 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
138 ti
->mmMode
= GR_MIPMAP_NEAREST
;
139 ti
->LODblend
= FXFALSE
;
145 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
147 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
150 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
151 fprintf(stderr
, "fxmesa: fxDDTexBind(%d,%x)\n", tObj
->Name
,
152 (GLuint
) tObj
->DriverData
);
155 if (target
!= GL_TEXTURE_2D
)
158 if (!tObj
->DriverData
) {
159 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
162 ti
= fxTMGetTexInfo(tObj
);
164 fxMesa
->texBindNumber
++;
165 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
167 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
171 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
172 const GLfloat
* param
)
174 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
176 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
178 fprintf(stderr
, "fxmesa: texenv(%x,%x)\n", pname
, (GLint
) (*param
));
180 fprintf(stderr
, "fxmesa: texenv(%x)\n", pname
);
183 /* apply any lod biasing right now */
184 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
185 FX_grTexLodBiasValue(GR_TMU0
, *param
);
187 if (fxMesa
->haveTwoTMUs
) {
188 FX_grTexLodBiasValue(GR_TMU1
, *param
);
193 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
197 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
198 GLenum pname
, const GLfloat
* params
)
200 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
201 GLenum param
= (GLenum
) (GLint
) params
[0];
204 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
205 fprintf(stderr
, "fxmesa: fxDDTexParam(%d,%x,%x,%x)\n", tObj
->Name
,
206 (GLuint
) tObj
->DriverData
, pname
, param
);
209 if (target
!= GL_TEXTURE_2D
)
212 if (!tObj
->DriverData
)
213 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
215 ti
= fxTMGetTexInfo(tObj
);
219 case GL_TEXTURE_MIN_FILTER
:
222 ti
->mmMode
= GR_MIPMAP_DISABLE
;
223 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
224 ti
->LODblend
= FXFALSE
;
227 ti
->mmMode
= GR_MIPMAP_DISABLE
;
228 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
229 ti
->LODblend
= FXFALSE
;
231 case GL_NEAREST_MIPMAP_NEAREST
:
232 ti
->mmMode
= GR_MIPMAP_NEAREST
;
233 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
234 ti
->LODblend
= FXFALSE
;
236 case GL_LINEAR_MIPMAP_NEAREST
:
237 ti
->mmMode
= GR_MIPMAP_NEAREST
;
238 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
239 ti
->LODblend
= FXFALSE
;
241 case GL_NEAREST_MIPMAP_LINEAR
:
242 if (fxMesa
->haveTwoTMUs
) {
243 ti
->mmMode
= GR_MIPMAP_NEAREST
;
244 ti
->LODblend
= FXTRUE
;
247 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
248 ti
->LODblend
= FXFALSE
;
250 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
252 case GL_LINEAR_MIPMAP_LINEAR
:
253 if (fxMesa
->haveTwoTMUs
) {
254 ti
->mmMode
= GR_MIPMAP_NEAREST
;
255 ti
->LODblend
= FXTRUE
;
258 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
259 ti
->LODblend
= FXFALSE
;
261 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
266 fxTexInvalidate(ctx
, tObj
);
269 case GL_TEXTURE_MAG_FILTER
:
272 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
275 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
280 fxTexInvalidate(ctx
, tObj
);
283 case GL_TEXTURE_WRAP_S
:
286 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
289 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
294 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
297 case GL_TEXTURE_WRAP_T
:
300 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
303 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
308 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
311 case GL_TEXTURE_BORDER_COLOR
:
315 case GL_TEXTURE_MIN_LOD
:
318 case GL_TEXTURE_MAX_LOD
:
321 case GL_TEXTURE_BASE_LEVEL
:
322 fxTexInvalidate(ctx
, tObj
);
324 case GL_TEXTURE_MAX_LEVEL
:
325 fxTexInvalidate(ctx
, tObj
);
334 fxDDTexDel(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
336 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
337 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
339 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
340 fprintf(stderr
, "fxmesa: fxDDTexDel(%d,%p)\n", tObj
->Name
, ti
);
346 fxTMFreeTexture(fxMesa
, tObj
);
349 tObj
->DriverData
= NULL
;
355 * Convert a gl_color_table texture palette to Glide's format.
358 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
360 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
361 GLint width
= table
->Size
;
365 ASSERT(!table
->FloatTable
);
367 switch (table
->Format
) {
369 for (i
= 0; i
< width
; i
++) {
374 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
378 for (i
= 0; i
< width
; i
++) {
383 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
387 for (i
= 0; i
< width
; i
++) {
390 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
393 case GL_LUMINANCE_ALPHA
:
394 for (i
= 0; i
< width
; i
++) {
395 r
= g
= b
= tableUB
[i
* 2 + 0];
396 a
= tableUB
[i
* 2 + 1];
397 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
401 for (i
= 0; i
< width
; i
++) {
402 r
= tableUB
[i
* 3 + 0];
403 g
= tableUB
[i
* 3 + 1];
404 b
= tableUB
[i
* 3 + 2];
406 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
410 for (i
= 0; i
< width
; i
++) {
411 r
= tableUB
[i
* 4 + 0];
412 g
= tableUB
[i
* 4 + 1];
413 b
= tableUB
[i
* 4 + 2];
414 a
= tableUB
[i
* 4 + 3];
415 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
423 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
425 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
428 /* per-texture palette */
430 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
431 fprintf(stderr
, "fxmesa: fxDDTexPalette(%d,%x)\n",
432 tObj
->Name
, (GLuint
) tObj
->DriverData
);
434 if (!tObj
->DriverData
)
435 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
436 ti
= fxTMGetTexInfo(tObj
);
437 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
438 fxTexInvalidate(ctx
, tObj
);
441 /* global texture palette */
442 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
443 fprintf(stderr
, "fxmesa: fxDDTexPalette(global)\n");
445 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
446 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
452 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
454 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
456 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
457 fprintf(stderr
, "fxmesa: fxDDTexUseGlbPalette(%d)\n", state
);
461 fxMesa
->haveGlobalPaletteTexture
= 1;
463 FX_grTexDownloadTable(GR_TMU0
, GR_TEXTABLE_PALETTE
,
464 &(fxMesa
->glbPalette
));
465 if (fxMesa
->haveTwoTMUs
)
466 FX_grTexDownloadTable(GR_TMU1
, GR_TEXTABLE_PALETTE
,
467 &(fxMesa
->glbPalette
));
470 fxMesa
->haveGlobalPaletteTexture
= 0;
472 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
473 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
474 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
476 if (!tObj
->DriverData
)
477 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
479 fxTexInvalidate(ctx
, tObj
);
507 /* Need different versions for different cpus.
509 #define INT_TRICK(l2) (0x800000 * l2)
513 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
514 float *sscale
, float *tscale
,
515 int *i_sscale
, int *i_tscale
, int *wscale
, int *hscale
)
518 static GrLOD_t lod
[9] = { GR_LOD_256
, GR_LOD_128
, GR_LOD_64
, GR_LOD_32
,
519 GR_LOD_16
, GR_LOD_8
, GR_LOD_4
, GR_LOD_2
, GR_LOD_1
522 int logw
, logh
, ws
, hs
;
524 GrAspectRatio_t aspectratio
;
531 switch (logw
- logh
) {
533 aspectratio
= GR_ASPECT_1x1
;
536 is
= it
= INT_TRICK(8);
540 aspectratio
= GR_ASPECT_2x1
;
550 aspectratio
= GR_ASPECT_4x1
;
560 aspectratio
= GR_ASPECT_8x1
;
570 aspectratio
= GR_ASPECT_8x1
;
580 aspectratio
= GR_ASPECT_8x1
;
590 aspectratio
= GR_ASPECT_8x1
;
600 aspectratio
= GR_ASPECT_8x1
;
610 aspectratio
= GR_ASPECT_8x1
;
620 aspectratio
= GR_ASPECT_1x2
;
630 aspectratio
= GR_ASPECT_1x4
;
640 aspectratio
= GR_ASPECT_1x8
;
650 aspectratio
= GR_ASPECT_1x8
;
660 aspectratio
= GR_ASPECT_1x8
;
670 aspectratio
= GR_ASPECT_1x8
;
680 aspectratio
= GR_ASPECT_1x8
;
690 aspectratio
= GR_ASPECT_1x8
;
733 * Given an OpenGL internal texture format, return the corresponding
734 * Glide internal texture format and base texture format.
737 fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
* tfmt
, GLint
* ifmt
)
747 (*tfmt
) = GR_TEXFMT_INTENSITY_8
;
749 (*ifmt
) = GL_LUMINANCE
;
752 case GL_LUMINANCE_ALPHA
:
753 case GL_LUMINANCE4_ALPHA4
:
754 case GL_LUMINANCE6_ALPHA2
:
755 case GL_LUMINANCE8_ALPHA8
:
756 case GL_LUMINANCE12_ALPHA4
:
757 case GL_LUMINANCE12_ALPHA12
:
758 case GL_LUMINANCE16_ALPHA16
:
760 (*tfmt
) = GR_TEXFMT_ALPHA_INTENSITY_88
;
762 (*ifmt
) = GL_LUMINANCE_ALPHA
;
770 (*tfmt
) = GR_TEXFMT_ALPHA_8
;
772 (*ifmt
) = GL_INTENSITY
;
780 (*tfmt
) = GR_TEXFMT_ALPHA_8
;
794 (*tfmt
) = GR_TEXFMT_RGB_565
;
807 (*tfmt
) = GR_TEXFMT_ARGB_4444
;
813 (*tfmt
) = GR_TEXFMT_ARGB_1555
;
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
:
825 (*tfmt
) = GR_TEXFMT_P_8
;
827 (*ifmt
) = GL_RGBA
; /* XXX why is this RGBA? */
831 "fx Driver: unsupported internalFormat (0x%x) in fxTexGetFormat()\n",
840 fxIsTexSupported(GLenum target
, GLint internalFormat
,
841 const struct gl_texture_image
*image
)
843 if (target
!= GL_TEXTURE_2D
)
847 (image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
848 NULL
)) return GL_FALSE
;
850 if (image
->Border
> 0)
857 /**********************************************************************/
858 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
859 /**********************************************************************/
861 /* Texel-fetch functions for software texturing and glGetTexImage().
862 * We should have been able to use some "standard" fetch functions (which
863 * may get defined in texutil.c) but we have to account for scaled texture
864 * images on tdfx hardware (the 8:1 aspect ratio limit).
865 * Hence, we need special functions here.
869 fetch_intensity8(const struct gl_texture_image
*texImage
,
870 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
872 GLchan
*rgba
= (GLchan
*) texelOut
;
873 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
874 const GLubyte
*texel
;
879 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
880 rgba
[RCOMP
] = *texel
;
881 rgba
[GCOMP
] = *texel
;
882 rgba
[BCOMP
] = *texel
;
883 rgba
[ACOMP
] = *texel
;
888 fetch_luminance8(const struct gl_texture_image
*texImage
,
889 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
891 GLchan
*rgba
= (GLchan
*) texelOut
;
892 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
893 const GLubyte
*texel
;
898 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
899 rgba
[RCOMP
] = *texel
;
900 rgba
[GCOMP
] = *texel
;
901 rgba
[BCOMP
] = *texel
;
907 fetch_alpha8(const struct gl_texture_image
*texImage
,
908 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
910 GLchan
*rgba
= (GLchan
*) texelOut
;
911 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
912 const GLubyte
*texel
;
916 i
= i
* mml
->width
/ texImage
->Width
;
917 j
= j
* mml
->height
/ texImage
->Height
;
919 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
923 rgba
[ACOMP
] = *texel
;
928 fetch_index8(const struct gl_texture_image
*texImage
,
929 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
931 GLchan
*indexOut
= (GLchan
*) texelOut
;
932 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
933 const GLubyte
*texel
;
937 i
= i
* mml
->width
/ texImage
->Width
;
938 j
= j
* mml
->height
/ texImage
->Height
;
940 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
946 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
947 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
949 GLchan
*rgba
= (GLchan
*) texelOut
;
950 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
951 const GLubyte
*texel
;
956 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
957 rgba
[RCOMP
] = texel
[0];
958 rgba
[GCOMP
] = texel
[0];
959 rgba
[BCOMP
] = texel
[0];
960 rgba
[ACOMP
] = texel
[1];
965 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
966 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
968 GLchan
*rgba
= (GLchan
*) texelOut
;
969 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
970 const GLushort
*texel
;
975 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
976 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
977 rgba
[GCOMP
] = (((*texel
) >> 5) & 0x3f) * 255 / 63;
978 rgba
[BCOMP
] = (((*texel
) >> 0) & 0x1f) * 255 / 31;
984 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
985 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
987 GLchan
*rgba
= (GLchan
*) texelOut
;
988 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
989 const GLushort
*texel
;
994 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
995 rgba
[RCOMP
] = (((*texel
) >> 12) & 0xf) * 255 / 15;
996 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xf) * 255 / 15;
997 rgba
[BCOMP
] = (((*texel
) >> 4) & 0xf) * 255 / 15;
998 rgba
[ACOMP
] = (((*texel
) >> 0) & 0xf) * 255 / 15;
1003 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
1004 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
1006 GLchan
*rgba
= (GLchan
*) texelOut
;
1007 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1008 const GLushort
*texel
;
1010 i
= i
* mml
->wScale
;
1011 j
= j
* mml
->hScale
;
1013 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1014 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1015 rgba
[GCOMP
] = (((*texel
) >> 6) & 0x1f) * 255 / 31;
1016 rgba
[BCOMP
] = (((*texel
) >> 1) & 0x1f) * 255 / 31;
1017 rgba
[ACOMP
] = (((*texel
) >> 0) & 0x01) * 255;
1022 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
1025 for (i
= 0; i
< h
; i
++) {
1026 for (j
= 0; j
< w
; j
++) {
1028 printf("%02x %02x ", data
[0], data
[1]);
1030 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
1038 const struct gl_texture_format
*
1039 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
1040 GLenum srcFormat
, GLenum srcType
)
1042 switch (internalFormat
) {
1046 case GL_INTENSITY12
:
1047 case GL_INTENSITY16
:
1048 return &_mesa_texformat_i8
;
1053 case GL_LUMINANCE12
:
1054 case GL_LUMINANCE16
:
1055 return &_mesa_texformat_l8
;
1061 return &_mesa_texformat_a8
;
1062 case GL_COLOR_INDEX
:
1063 case GL_COLOR_INDEX1_EXT
:
1064 case GL_COLOR_INDEX2_EXT
:
1065 case GL_COLOR_INDEX4_EXT
:
1066 case GL_COLOR_INDEX8_EXT
:
1067 case GL_COLOR_INDEX12_EXT
:
1068 case GL_COLOR_INDEX16_EXT
:
1069 return &_mesa_texformat_ci8
;
1071 case GL_LUMINANCE_ALPHA
:
1072 case GL_LUMINANCE4_ALPHA4
:
1073 case GL_LUMINANCE6_ALPHA2
:
1074 case GL_LUMINANCE8_ALPHA8
:
1075 case GL_LUMINANCE12_ALPHA4
:
1076 case GL_LUMINANCE12_ALPHA12
:
1077 case GL_LUMINANCE16_ALPHA16
:
1078 return &_mesa_texformat_al88
;
1088 return &_mesa_texformat_rgb565
;
1097 return &_mesa_texformat_argb4444
;
1099 return &_mesa_texformat_argb1555
;
1101 _mesa_problem(NULL
, "unexpected format in fxDDChooseTextureFormat");
1107 static GrTextureFormat_t
1108 fxGlideFormat(GLint mesaFormat
)
1110 switch (mesaFormat
) {
1111 case MESA_FORMAT_I8
:
1112 return GR_TEXFMT_ALPHA_8
;
1113 case MESA_FORMAT_A8
:
1114 return GR_TEXFMT_ALPHA_8
;
1115 case MESA_FORMAT_L8
:
1116 return GR_TEXFMT_INTENSITY_8
;
1117 case MESA_FORMAT_CI8
:
1118 return GR_TEXFMT_P_8
;
1119 case MESA_FORMAT_AL88
:
1120 return GR_TEXFMT_ALPHA_INTENSITY_88
;
1121 case MESA_FORMAT_RGB565
:
1122 return GR_TEXFMT_RGB_565
;
1123 case MESA_FORMAT_ARGB4444
:
1124 return GR_TEXFMT_ARGB_4444
;
1125 case MESA_FORMAT_ARGB1555
:
1126 return GR_TEXFMT_ARGB_1555
;
1128 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1134 static FetchTexelFunc
1135 fxFetchFunction(GLint mesaFormat
)
1137 switch (mesaFormat
) {
1138 case MESA_FORMAT_I8
:
1139 return fetch_intensity8
;
1140 case MESA_FORMAT_A8
:
1141 return fetch_alpha8
;
1142 case MESA_FORMAT_L8
:
1143 return fetch_luminance8
;
1144 case MESA_FORMAT_CI8
:
1145 return fetch_index8
;
1146 case MESA_FORMAT_AL88
:
1147 return fetch_luminance8_alpha8
;
1148 case MESA_FORMAT_RGB565
:
1149 return fetch_r5g6b5
;
1150 case MESA_FORMAT_ARGB4444
:
1151 return fetch_r4g4b4a4
;
1152 case MESA_FORMAT_ARGB1555
:
1153 return fetch_r5g5b5a1
;
1155 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1161 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1162 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1163 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1164 const struct gl_pixelstore_attrib
*packing
,
1165 struct gl_texture_object
*texObj
,
1166 struct gl_texture_image
*texImage
)
1168 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1169 GrTextureFormat_t gldformat
;
1171 tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1174 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1175 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1179 if (!texObj
->DriverData
)
1180 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1181 ti
= fxTMGetTexInfo(texObj
);
1184 texImage
->DriverData
= MALLOC(sizeof(tfxMipMapLevel
));
1185 mml
= FX_MIPMAP_DATA(texImage
);
1188 fxTexGetFormat(internalFormat
, &gldformat
, NULL
);
1190 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1191 NULL
, NULL
, &mml
->wScale
, &mml
->hScale
);
1193 mml
->width
= width
* mml
->wScale
;
1194 mml
->height
= height
* mml
->hScale
;
1197 /* choose the texture format */
1198 assert(ctx
->Driver
.ChooseTextureFormat
);
1199 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1200 internalFormat
, format
, type
);
1201 assert(texImage
->TexFormat
);
1203 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1204 assert(texelBytes
== 1 || texelBytes
== 2);
1206 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1207 /* rescale image to overcome 1:8 aspect limitation */
1209 tempImage
= MALLOC(width
* height
* texelBytes
);
1211 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1214 /* unpack image, apply transfer ops and store in tempImage */
1215 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1216 texImage
->TexFormat
,
1218 width
, height
, 1, 0, 0, 0,
1220 0, /* dstImageStride */
1221 format
, type
, pixels
, packing
);
1222 assert(!texImage
->Data
);
1223 texImage
->Data
= MALLOC(mml
->width
* mml
->height
* texelBytes
);
1224 if (!texImage
->Data
) {
1225 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1229 _mesa_rescale_teximage2d(texelBytes
,
1230 mml
->width
* texelBytes
, /* dst stride */
1232 mml
->width
, mml
->height
,
1233 tempImage
/*src*/, texImage
->Data
/*dst*/ );
1237 /* no rescaling needed */
1238 assert(!texImage
->Data
);
1239 texImage
->Data
= MALLOC(mml
->width
* mml
->height
* texelBytes
);
1240 if (!texImage
->Data
) {
1241 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1244 /* unpack image, apply transfer ops and store in texImage->Data */
1245 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1246 texImage
->TexFormat
, texImage
->Data
,
1247 width
, height
, 1, 0, 0, 0,
1248 texImage
->Width
* texelBytes
,
1249 0, /* dstImageStride */
1250 format
, type
, pixels
, packing
);
1253 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1254 texImage
->FetchTexel
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1256 fxTexInvalidate(ctx
, texObj
);
1258 if (ti
->validated
&& ti
->isInTM
) {
1259 /*printf("reloadmipmaplevels\n"); */
1260 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1263 /*printf("invalidate2\n"); */
1264 fxTexInvalidate(ctx
, texObj
);
1270 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1271 GLint xoffset
, GLint yoffset
,
1272 GLsizei width
, GLsizei height
,
1273 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1274 const struct gl_pixelstore_attrib
*packing
,
1275 struct gl_texture_object
*texObj
,
1276 struct gl_texture_image
*texImage
)
1278 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1280 tfxMipMapLevel
*mml
;
1283 if (!texObj
->DriverData
) {
1284 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1288 ti
= fxTMGetTexInfo(texObj
);
1290 mml
= FX_MIPMAP_DATA(texImage
);
1293 assert(texImage
->Data
); /* must have an existing texture image! */
1294 assert(texImage
->Format
);
1296 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1298 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1299 /* need to rescale subimage to match mipmap level's rescale factors */
1300 const GLint newWidth
= width
* mml
->wScale
;
1301 const GLint newHeight
= height
* mml
->hScale
;
1302 GLvoid
*scaledImage
, *tempImage
;
1304 tempImage
= MALLOC(width
* height
* texelBytes
);
1306 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1310 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,/* Tex int format */
1311 texImage
->TexFormat
, /* dest format */
1312 (GLubyte
*) tempImage
, /* dest */
1313 width
, height
, 1, /* subimage size */
1314 0, 0, 0, /* subimage pos */
1315 width
* texelBytes
, /* dest row stride */
1316 0, /* dst image stride */
1317 format
, type
, pixels
, packing
);
1320 scaledImage
= MALLOC(newWidth
* newHeight
* texelBytes
);
1322 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1327 /* compute address of dest subimage within the overal tex image */
1328 destAddr
= (GLubyte
*) texImage
->Data
1329 + (yoffset
* mml
->hScale
* mml
->width
1330 + xoffset
* mml
->wScale
) * texelBytes
;
1332 _mesa_rescale_teximage2d(texelBytes
,
1333 mml
->width
* texelBytes
, /* dst stride */
1335 newWidth
, newHeight
,
1336 tempImage
, destAddr
);
1342 /* no rescaling needed */
1343 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, /* Tex int format */
1344 texImage
->TexFormat
, /* dest format */
1345 (GLubyte
*) texImage
->Data
,/* dest */
1346 width
, height
, 1, /* subimage size */
1347 xoffset
, yoffset
, 0, /* subimage pos */
1348 mml
->width
* texelBytes
, /* dest row stride */
1349 0, /* dst image stride */
1350 format
, type
, pixels
, packing
);
1353 if (ti
->validated
&& ti
->isInTM
)
1354 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1356 fxTexInvalidate(ctx
, texObj
);
1363 * Need this to provide at least one external definition.
1366 extern int gl_fx_dummy_function_ddtex(void);
1368 gl_fx_dummy_function_ddtex(void)