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.
59 fxPrintTextureData(tfxTexInfo
* ti
)
61 fprintf(stderr
, "Texture Data:\n");
63 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
64 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
65 fprintf(stderr
, "\tSize: %d x %d\n",
66 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Width
,
67 ti
->tObj
->Image
[ti
->tObj
->BaseLevel
]->Height
);
70 fprintf(stderr
, "\tName: UNNAMED\n");
71 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
72 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
73 fprintf(stderr
, "\t%s\n", (ti
->isInTM
) ? "In TMU" : "Not in TMU");
75 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
76 (unsigned) ti
->tm
[0]->endAddr
);
78 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
79 (unsigned) ti
->tm
[1]->endAddr
);
80 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
81 fprintf(stderr
, "\tFilters: min %d min %d\n",
82 (int) ti
->minFilt
, (int) ti
->maxFilt
);
83 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
,
85 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
86 fprintf(stderr
, "\tInt Scales: s %d t %d\n",
87 ti
->int_sScale
/ 0x800000, ti
->int_tScale
/ 0x800000);
88 fprintf(stderr
, "\t%s\n",
89 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
90 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
94 /************************************************************************/
95 /*************************** Texture Mapping ****************************/
96 /************************************************************************/
99 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
101 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
104 ti
= fxTMGetTexInfo(tObj
);
106 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
108 ti
->validated
= GL_FALSE
;
109 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
113 fxAllocTexObjData(fxMesaContext fxMesa
)
117 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
118 fprintf(stderr
, "fx Driver: out of memory !\n");
123 ti
->validated
= GL_FALSE
;
124 ti
->isInTM
= GL_FALSE
;
126 ti
->whichTMU
= FX_TMU_NONE
;
128 ti
->tm
[FX_TMU0
] = NULL
;
129 ti
->tm
[FX_TMU1
] = NULL
;
131 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
132 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
134 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
135 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
137 ti
->mmMode
= GR_MIPMAP_NEAREST
;
138 ti
->LODblend
= FXFALSE
;
144 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
146 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
149 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
150 fprintf(stderr
, "fxmesa: fxDDTexBind(%d,%x)\n", tObj
->Name
,
151 (GLuint
) tObj
->DriverData
);
154 if (target
!= GL_TEXTURE_2D
)
157 if (!tObj
->DriverData
) {
158 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
161 ti
= fxTMGetTexInfo(tObj
);
163 fxMesa
->texBindNumber
++;
164 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
166 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
170 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
171 const GLfloat
* param
)
173 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
175 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
177 fprintf(stderr
, "fxmesa: texenv(%x,%x)\n", pname
, (GLint
) (*param
));
179 fprintf(stderr
, "fxmesa: texenv(%x)\n", pname
);
182 /* apply any lod biasing right now */
183 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
184 FX_grTexLodBiasValue(GR_TMU0
, *param
);
186 if (fxMesa
->haveTwoTMUs
) {
187 FX_grTexLodBiasValue(GR_TMU1
, *param
);
192 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
196 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
197 GLenum pname
, const GLfloat
* params
)
199 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
200 GLenum param
= (GLenum
) (GLint
) params
[0];
203 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
204 fprintf(stderr
, "fxmesa: fxDDTexParam(%d,%x,%x,%x)\n", tObj
->Name
,
205 (GLuint
) tObj
->DriverData
, pname
, param
);
208 if (target
!= GL_TEXTURE_2D
)
211 if (!tObj
->DriverData
)
212 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
214 ti
= fxTMGetTexInfo(tObj
);
218 case GL_TEXTURE_MIN_FILTER
:
221 ti
->mmMode
= GR_MIPMAP_DISABLE
;
222 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
223 ti
->LODblend
= FXFALSE
;
226 ti
->mmMode
= GR_MIPMAP_DISABLE
;
227 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
228 ti
->LODblend
= FXFALSE
;
230 case GL_NEAREST_MIPMAP_NEAREST
:
231 ti
->mmMode
= GR_MIPMAP_NEAREST
;
232 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
233 ti
->LODblend
= FXFALSE
;
235 case GL_LINEAR_MIPMAP_NEAREST
:
236 ti
->mmMode
= GR_MIPMAP_NEAREST
;
237 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
238 ti
->LODblend
= FXFALSE
;
240 case GL_NEAREST_MIPMAP_LINEAR
:
241 if (fxMesa
->haveTwoTMUs
) {
242 ti
->mmMode
= GR_MIPMAP_NEAREST
;
243 ti
->LODblend
= FXTRUE
;
246 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
247 ti
->LODblend
= FXFALSE
;
249 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
251 case GL_LINEAR_MIPMAP_LINEAR
:
252 if (fxMesa
->haveTwoTMUs
) {
253 ti
->mmMode
= GR_MIPMAP_NEAREST
;
254 ti
->LODblend
= FXTRUE
;
257 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
258 ti
->LODblend
= FXFALSE
;
260 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
265 fxTexInvalidate(ctx
, tObj
);
268 case GL_TEXTURE_MAG_FILTER
:
271 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
274 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
279 fxTexInvalidate(ctx
, tObj
);
282 case GL_TEXTURE_WRAP_S
:
285 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
288 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
293 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
296 case GL_TEXTURE_WRAP_T
:
299 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
302 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
307 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
310 case GL_TEXTURE_BORDER_COLOR
:
314 case GL_TEXTURE_MIN_LOD
:
317 case GL_TEXTURE_MAX_LOD
:
320 case GL_TEXTURE_BASE_LEVEL
:
321 fxTexInvalidate(ctx
, tObj
);
323 case GL_TEXTURE_MAX_LEVEL
:
324 fxTexInvalidate(ctx
, tObj
);
333 fxDDTexDel(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
335 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
336 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
338 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
339 fprintf(stderr
, "fxmesa: fxDDTexDel(%d,%p)\n", tObj
->Name
, ti
);
345 fxTMFreeTexture(fxMesa
, tObj
);
348 tObj
->DriverData
= NULL
;
354 * Convert a gl_color_table texture palette to Glide's format.
357 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
359 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
360 GLint width
= table
->Size
;
364 ASSERT(!table
->FloatTable
);
366 switch (table
->Format
) {
368 for (i
= 0; i
< width
; i
++) {
373 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
377 for (i
= 0; i
< width
; i
++) {
382 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
386 for (i
= 0; i
< width
; i
++) {
389 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
392 case GL_LUMINANCE_ALPHA
:
393 for (i
= 0; i
< width
; i
++) {
394 r
= g
= b
= tableUB
[i
* 2 + 0];
395 a
= tableUB
[i
* 2 + 1];
396 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
400 for (i
= 0; i
< width
; i
++) {
401 r
= tableUB
[i
* 3 + 0];
402 g
= tableUB
[i
* 3 + 1];
403 b
= tableUB
[i
* 3 + 2];
405 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
409 for (i
= 0; i
< width
; i
++) {
410 r
= tableUB
[i
* 4 + 0];
411 g
= tableUB
[i
* 4 + 1];
412 b
= tableUB
[i
* 4 + 2];
413 a
= tableUB
[i
* 4 + 3];
414 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
422 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
424 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
427 /* per-texture palette */
429 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
430 fprintf(stderr
, "fxmesa: fxDDTexPalette(%d,%x)\n",
431 tObj
->Name
, (GLuint
) tObj
->DriverData
);
433 if (!tObj
->DriverData
)
434 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
435 ti
= fxTMGetTexInfo(tObj
);
436 convertPalette(ti
->palette
.data
, &tObj
->Palette
);
437 fxTexInvalidate(ctx
, tObj
);
440 /* global texture palette */
441 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
442 fprintf(stderr
, "fxmesa: fxDDTexPalette(global)\n");
444 convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
445 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
451 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
453 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
455 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
456 fprintf(stderr
, "fxmesa: fxDDTexUseGlbPalette(%d)\n", state
);
460 fxMesa
->haveGlobalPaletteTexture
= 1;
462 FX_grTexDownloadTable(GR_TMU0
, GR_TEXTABLE_PALETTE
,
463 &(fxMesa
->glbPalette
));
464 if (fxMesa
->haveTwoTMUs
)
465 FX_grTexDownloadTable(GR_TMU1
, GR_TEXTABLE_PALETTE
,
466 &(fxMesa
->glbPalette
));
469 fxMesa
->haveGlobalPaletteTexture
= 0;
471 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
472 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
473 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
475 if (!tObj
->DriverData
)
476 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
478 fxTexInvalidate(ctx
, tObj
);
506 /* Need different versions for different cpus.
508 #define INT_TRICK(l2) (0x800000 * l2)
512 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
513 float *sscale
, float *tscale
,
514 int *i_sscale
, int *i_tscale
, int *wscale
, int *hscale
)
517 static GrLOD_t lod
[9] = { GR_LOD_256
, GR_LOD_128
, GR_LOD_64
, GR_LOD_32
,
518 GR_LOD_16
, GR_LOD_8
, GR_LOD_4
, GR_LOD_2
, GR_LOD_1
521 int logw
, logh
, ws
, hs
;
523 GrAspectRatio_t aspectratio
;
530 switch (logw
- logh
) {
532 aspectratio
= GR_ASPECT_1x1
;
535 is
= it
= INT_TRICK(8);
539 aspectratio
= GR_ASPECT_2x1
;
549 aspectratio
= GR_ASPECT_4x1
;
559 aspectratio
= GR_ASPECT_8x1
;
569 aspectratio
= GR_ASPECT_8x1
;
579 aspectratio
= GR_ASPECT_8x1
;
589 aspectratio
= GR_ASPECT_8x1
;
599 aspectratio
= GR_ASPECT_8x1
;
609 aspectratio
= GR_ASPECT_8x1
;
619 aspectratio
= GR_ASPECT_1x2
;
629 aspectratio
= GR_ASPECT_1x4
;
639 aspectratio
= GR_ASPECT_1x8
;
649 aspectratio
= GR_ASPECT_1x8
;
659 aspectratio
= GR_ASPECT_1x8
;
669 aspectratio
= GR_ASPECT_1x8
;
679 aspectratio
= GR_ASPECT_1x8
;
689 aspectratio
= GR_ASPECT_1x8
;
732 * Given an OpenGL internal texture format, return the corresponding
733 * Glide internal texture format and base texture format.
736 fxTexGetFormat(GLenum glformat
, GrTextureFormat_t
* tfmt
, GLint
* ifmt
)
746 (*tfmt
) = GR_TEXFMT_INTENSITY_8
;
748 (*ifmt
) = GL_LUMINANCE
;
751 case GL_LUMINANCE_ALPHA
:
752 case GL_LUMINANCE4_ALPHA4
:
753 case GL_LUMINANCE6_ALPHA2
:
754 case GL_LUMINANCE8_ALPHA8
:
755 case GL_LUMINANCE12_ALPHA4
:
756 case GL_LUMINANCE12_ALPHA12
:
757 case GL_LUMINANCE16_ALPHA16
:
759 (*tfmt
) = GR_TEXFMT_ALPHA_INTENSITY_88
;
761 (*ifmt
) = GL_LUMINANCE_ALPHA
;
769 (*tfmt
) = GR_TEXFMT_ALPHA_8
;
771 (*ifmt
) = GL_INTENSITY
;
779 (*tfmt
) = GR_TEXFMT_ALPHA_8
;
793 (*tfmt
) = GR_TEXFMT_RGB_565
;
806 (*tfmt
) = GR_TEXFMT_ARGB_4444
;
812 (*tfmt
) = GR_TEXFMT_ARGB_1555
;
817 case GL_COLOR_INDEX1_EXT
:
818 case GL_COLOR_INDEX2_EXT
:
819 case GL_COLOR_INDEX4_EXT
:
820 case GL_COLOR_INDEX8_EXT
:
821 case GL_COLOR_INDEX12_EXT
:
822 case GL_COLOR_INDEX16_EXT
:
824 (*tfmt
) = GR_TEXFMT_P_8
;
826 (*ifmt
) = GL_RGBA
; /* XXX why is this RGBA? */
830 "fx Driver: unsupported internalFormat (0x%x) in fxTexGetFormat()\n",
839 fxIsTexSupported(GLenum target
, GLint internalFormat
,
840 const struct gl_texture_image
*image
)
842 if (target
!= GL_TEXTURE_2D
)
846 (image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
847 NULL
)) return GL_FALSE
;
849 if (image
->Border
> 0)
856 /**********************************************************************/
857 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
858 /**********************************************************************/
860 /* Texel-fetch functions for software texturing and glGetTexImage().
861 * We should have been able to use some "standard" fetch functions (which
862 * may get defined in texutil.c) but we have to account for scaled texture
863 * images on tdfx hardware (the 8:1 aspect ratio limit).
864 * Hence, we need special functions here.
868 fetch_intensity8(const struct gl_texture_image
*texImage
,
869 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
871 GLchan
*rgba
= (GLchan
*) texelOut
;
872 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
873 const GLubyte
*texel
;
878 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
879 rgba
[RCOMP
] = *texel
;
880 rgba
[GCOMP
] = *texel
;
881 rgba
[BCOMP
] = *texel
;
882 rgba
[ACOMP
] = *texel
;
887 fetch_luminance8(const struct gl_texture_image
*texImage
,
888 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
890 GLchan
*rgba
= (GLchan
*) texelOut
;
891 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
892 const GLubyte
*texel
;
897 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
898 rgba
[RCOMP
] = *texel
;
899 rgba
[GCOMP
] = *texel
;
900 rgba
[BCOMP
] = *texel
;
906 fetch_alpha8(const struct gl_texture_image
*texImage
,
907 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
909 GLchan
*rgba
= (GLchan
*) texelOut
;
910 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
911 const GLubyte
*texel
;
915 i
= i
* mml
->width
/ texImage
->Width
;
916 j
= j
* mml
->height
/ texImage
->Height
;
918 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
922 rgba
[ACOMP
] = *texel
;
927 fetch_index8(const struct gl_texture_image
*texImage
,
928 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
935 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
936 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
938 GLchan
*rgba
= (GLchan
*) texelOut
;
939 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
940 const GLubyte
*texel
;
945 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
946 rgba
[RCOMP
] = texel
[0];
947 rgba
[GCOMP
] = texel
[0];
948 rgba
[BCOMP
] = texel
[0];
949 rgba
[ACOMP
] = texel
[1];
954 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
955 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
957 GLchan
*rgba
= (GLchan
*) texelOut
;
958 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
959 const GLushort
*texel
;
964 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
965 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
966 rgba
[GCOMP
] = (((*texel
) >> 5) & 0x3f) * 255 / 63;
967 rgba
[BCOMP
] = (((*texel
) >> 0) & 0x1f) * 255 / 31;
973 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
974 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
976 GLchan
*rgba
= (GLchan
*) texelOut
;
977 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
978 const GLushort
*texel
;
983 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
984 rgba
[RCOMP
] = (((*texel
) >> 12) & 0xf) * 255 / 15;
985 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xf) * 255 / 15;
986 rgba
[BCOMP
] = (((*texel
) >> 4) & 0xf) * 255 / 15;
987 rgba
[ACOMP
] = (((*texel
) >> 0) & 0xf) * 255 / 15;
992 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
993 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
995 GLchan
*rgba
= (GLchan
*) texelOut
;
996 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
997 const GLushort
*texel
;
1000 j
= j
* mml
->hScale
;
1002 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1003 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1004 rgba
[GCOMP
] = (((*texel
) >> 6) & 0x1f) * 255 / 31;
1005 rgba
[BCOMP
] = (((*texel
) >> 1) & 0x1f) * 255 / 31;
1006 rgba
[ACOMP
] = (((*texel
) >> 0) & 0x01) * 255;
1011 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
1014 for (i
= 0; i
< h
; i
++) {
1015 for (j
= 0; j
< w
; j
++) {
1017 printf("%02x %02x ", data
[0], data
[1]);
1019 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
1028 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1029 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1030 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1031 const struct gl_pixelstore_attrib
*packing
,
1032 struct gl_texture_object
*texObj
,
1033 struct gl_texture_image
*texImage
)
1035 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1036 GrTextureFormat_t gldformat
;
1038 tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
1039 MesaIntTexFormat mesaFormat
;
1043 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1044 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1048 if (!texObj
->DriverData
)
1049 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1050 ti
= fxTMGetTexInfo(texObj
);
1053 texImage
->DriverData
= MALLOC(sizeof(tfxMipMapLevel
));
1054 mml
= FX_MIPMAP_DATA(texImage
);
1057 fxTexGetFormat(internalFormat
, &gldformat
, NULL
);
1059 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1060 NULL
, NULL
, &mml
->wScale
, &mml
->hScale
);
1062 mml
->width
= width
* mml
->wScale
;
1063 mml
->height
= height
* mml
->hScale
;
1065 switch (internalFormat
) {
1069 case GL_INTENSITY12
:
1070 case GL_INTENSITY16
:
1071 texImage
->Format
= GL_INTENSITY
;
1072 texImage
->FetchTexel
= fetch_intensity8
;
1074 mesaFormat
= MESA_I8
;
1080 case GL_LUMINANCE12
:
1081 case GL_LUMINANCE16
:
1082 texImage
->Format
= GL_LUMINANCE
;
1083 texImage
->FetchTexel
= fetch_luminance8
;
1085 mesaFormat
= MESA_L8
;
1092 texImage
->Format
= GL_ALPHA
;
1093 texImage
->FetchTexel
= fetch_alpha8
;
1095 mesaFormat
= MESA_A8
;
1097 case GL_COLOR_INDEX
:
1098 case GL_COLOR_INDEX1_EXT
:
1099 case GL_COLOR_INDEX2_EXT
:
1100 case GL_COLOR_INDEX4_EXT
:
1101 case GL_COLOR_INDEX8_EXT
:
1102 case GL_COLOR_INDEX12_EXT
:
1103 case GL_COLOR_INDEX16_EXT
:
1104 texImage
->Format
= GL_COLOR_INDEX
;
1105 texImage
->FetchTexel
= fetch_index8
;
1107 mesaFormat
= MESA_C8
;
1110 case GL_LUMINANCE_ALPHA
:
1111 case GL_LUMINANCE4_ALPHA4
:
1112 case GL_LUMINANCE6_ALPHA2
:
1113 case GL_LUMINANCE8_ALPHA8
:
1114 case GL_LUMINANCE12_ALPHA4
:
1115 case GL_LUMINANCE12_ALPHA12
:
1116 case GL_LUMINANCE16_ALPHA16
:
1117 texImage
->Format
= GL_LUMINANCE_ALPHA
;
1118 texImage
->FetchTexel
= fetch_luminance8_alpha8
;
1120 mesaFormat
= MESA_A8_L8
;
1131 texImage
->Format
= GL_RGB
;
1132 texImage
->FetchTexel
= fetch_r5g6b5
;
1134 mesaFormat
= MESA_R5_G6_B5
;
1144 texImage
->Format
= GL_RGBA
;
1145 texImage
->FetchTexel
= fetch_r4g4b4a4
;
1147 mesaFormat
= MESA_A4_R4_G4_B4
;
1150 texImage
->Format
= GL_RGBA
;
1151 texImage
->FetchTexel
= fetch_r5g5b5a1
;
1153 mesaFormat
= MESA_A1_R5_G5_B5
;
1156 _mesa_problem(NULL
, "tdfx driver: texbuildimagemap() bad format");
1160 _mesa_set_teximage_component_sizes(mesaFormat
, texImage
);
1161 texImage
->Type
= 0; /* indicates a driver-specific format */
1163 /* allocate storage for texture image */
1164 texImage
->Data
= MALLOC(mml
->width
* mml
->height
* texelSize
);
1165 if (!texImage
->Data
)
1168 mml
->glideFormat
= gldformat
;
1169 fxTexInvalidate(ctx
, texObj
);
1171 /* store the texture image */
1172 if (ctx
->_ImageTransferState
) {
1176 success
= _mesa_convert_teximage(mesaFormat
, mml
->width
, mml
->height
,
1177 texImage
->Data
, mml
->width
* texelSize
,
1179 format
, type
, pixels
, packing
);
1183 /* First attempt at texture conversion failed. We may need to
1184 * do fancy pixel transfer ops or convert from an obscure texture
1187 GLenum simpleFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1188 GLint comps
= _mesa_components_in_format(simpleFormat
);
1191 tempImage
= MALLOC(width
* height
* comps
* sizeof(GLubyte
));
1193 /* Apply pixel transfer ops and convert image format to something
1194 * simple (format = simpleFormat, type = CHAN_TYPE).
1196 _mesa_transfer_teximage(ctx
, 2, /* dimensions */
1197 simpleFormat
, /* dest format */
1198 tempImage
, /* dest addr */
1199 width
, height
, 1, /* src size */
1200 0, 0, 0, /* dst offsets */
1201 width
* comps
, /* dstRowStride */
1202 0, /* dstImageStride */
1203 format
, type
, pixels
, packing
/* src info */ );
1205 /* this conversion better work! */
1206 success
= _mesa_convert_teximage(mesaFormat
, mml
->width
, mml
->height
,
1207 texImage
->Data
, mml
->width
* texelSize
,
1209 simpleFormat
, CHAN_TYPE
, tempImage
,
1210 &_mesa_native_packing
);
1215 if (ti
->validated
&& ti
->isInTM
) {
1216 /*printf("reloadmipmaplevels\n"); */
1217 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1220 /*printf("invalidate2\n"); */
1221 fxTexInvalidate(ctx
, texObj
);
1227 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1228 GLint xoffset
, GLint yoffset
,
1229 GLsizei width
, GLsizei height
,
1230 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1231 const struct gl_pixelstore_attrib
*packing
,
1232 struct gl_texture_object
*texObj
,
1233 struct gl_texture_image
*texImage
)
1235 fxMesaContext fxMesa
= (fxMesaContext
) ctx
->DriverCtx
;
1238 tfxMipMapLevel
*mml
;
1240 MesaIntTexFormat mesaFormat
;
1242 if (!texObj
->DriverData
) {
1243 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1247 ti
= fxTMGetTexInfo(texObj
);
1249 mml
= FX_MIPMAP_DATA(texImage
);
1252 assert(texImage
->Data
); /* must have an existing texture image! */
1254 switch (mml
->glideFormat
) {
1255 case GR_TEXFMT_INTENSITY_8
:
1257 mesaFormat
= MESA_I8
;
1259 case GR_TEXFMT_ALPHA_8
:
1261 mesaFormat
= MESA_A8
;
1265 mesaFormat
= MESA_C8
;
1267 case GR_TEXFMT_ALPHA_INTENSITY_88
:
1269 mesaFormat
= MESA_A8_L8
;
1271 case GR_TEXFMT_RGB_565
:
1273 mesaFormat
= MESA_R5_G6_B5
;
1275 case GR_TEXFMT_ARGB_4444
:
1277 mesaFormat
= MESA_A4_R4_G4_B4
;
1279 case GR_TEXFMT_ARGB_1555
:
1281 mesaFormat
= MESA_A1_R5_G5_B5
;
1284 _mesa_problem(NULL
, "tdfx driver: fxTexBuildSubImageMap() bad format");
1288 if (ctx
->_ImageTransferState
) {
1292 success
= _mesa_convert_texsubimage(mesaFormat
, xoffset
, yoffset
,
1293 mml
->width
, mml
->height
,
1295 mml
->width
* texelSize
,
1297 texImage
->Width
, texImage
->Height
,
1298 format
, type
, pixels
, packing
);
1302 /* Incoming image might need scale/bias or is in an uncommon format
1303 * that _mesa_convert_texsubimage() can't deal with. Convert it to
1304 * a simpler format now.
1307 GLenum simpleFormat
= _mesa_base_tex_format(ctx
, texImage
->IntFormat
);
1308 GLint comps
= _mesa_components_in_format(simpleFormat
);
1312 tempImage
= MALLOC(width
* height
* comps
* sizeof(GLubyte
));
1314 /* Apply pixel transfer ops and convert image format to something
1315 * simple (format = simpleFormat, type = CHAN_TYPE).
1317 _mesa_transfer_teximage(ctx
, 2, /* dimensions */
1318 simpleFormat
, /* dest format */
1319 tempImage
, /* dest addr */
1320 width
, height
, 1, /* src size */
1321 0, 0, 0, /* dst offsets */
1322 width
* comps
, /* dstRowStride */
1323 0, /* dstImageStride */
1324 format
, type
, pixels
, packing
/* src info */ );
1326 /* this conversion better work! */
1327 success
= _mesa_convert_texsubimage(mesaFormat
, xoffset
, yoffset
,
1328 mml
->width
, mml
->height
,
1329 texImage
->Data
, mml
->width
* texelSize
, /* dstRowStride */
1330 width
* mml
->wScale
,
1331 height
* mml
->hScale
,
1333 simpleFormat
, CHAN_TYPE
, tempImage
,
1334 &_mesa_native_packing
);
1339 if (ti
->validated
&& ti
->isInTM
)
1340 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1342 fxTexInvalidate(ctx
, texObj
);
1350 * Need this to provide at least one external definition.
1353 extern int gl_fx_dummy_function_ddtex(void);
1355 gl_fx_dummy_function_ddtex(void)