2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45 #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 max %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
, "\t%s\n",
80 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
81 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
85 /************************************************************************/
86 /*************************** Texture Mapping ****************************/
87 /************************************************************************/
90 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
92 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
95 ti
= fxTMGetTexInfo(tObj
);
97 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
99 ti
->validated
= GL_FALSE
;
100 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
104 fxAllocTexObjData(fxMesaContext fxMesa
)
108 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
109 fprintf(stderr
, "fxAllocTexObjData: ERROR: out of memory !\n");
114 ti
->validated
= GL_FALSE
;
115 ti
->isInTM
= GL_FALSE
;
117 ti
->whichTMU
= FX_TMU_NONE
;
119 ti
->tm
[FX_TMU0
] = NULL
;
120 ti
->tm
[FX_TMU1
] = NULL
;
122 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
123 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
125 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
126 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
128 ti
->mmMode
= GR_MIPMAP_NEAREST
;
129 ti
->LODblend
= FXFALSE
;
135 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
137 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
140 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
141 fprintf(stderr
, "fxDDTexBind(%d, %x)\n", tObj
->Name
, (GLuint
)tObj
->DriverData
);
144 if (target
!= GL_TEXTURE_2D
)
147 if (!tObj
->DriverData
) {
148 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
151 ti
= fxTMGetTexInfo(tObj
);
153 fxMesa
->texBindNumber
++;
154 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
156 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
160 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
161 const GLfloat
* param
)
163 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
165 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
167 fprintf(stderr
, "fxDDTexEnv(%x, %x)\n", pname
, (GLint
) (*param
));
169 fprintf(stderr
, "fxDDTexEnv(%x)\n", pname
);
172 /* apply any lod biasing right now */
173 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
174 grTexLodBiasValue(GR_TMU0
, *param
);
176 if (fxMesa
->haveTwoTMUs
) {
177 grTexLodBiasValue(GR_TMU1
, *param
);
182 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
186 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
187 GLenum pname
, const GLfloat
* params
)
189 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
190 GLenum param
= (GLenum
) (GLint
) params
[0];
193 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
194 fprintf(stderr
, "fxDDTexParam(%d, %x, %s, %s)\n",
195 tObj
->Name
, (GLuint
) tObj
->DriverData
,
196 _mesa_lookup_enum_by_nr(pname
),
197 _mesa_lookup_enum_by_nr(param
));
200 if (target
!= GL_TEXTURE_2D
)
203 if (!tObj
->DriverData
)
204 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
206 ti
= fxTMGetTexInfo(tObj
);
210 case GL_TEXTURE_MIN_FILTER
:
213 ti
->mmMode
= GR_MIPMAP_DISABLE
;
214 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
215 ti
->LODblend
= FXFALSE
;
218 ti
->mmMode
= GR_MIPMAP_DISABLE
;
219 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
220 ti
->LODblend
= FXFALSE
;
222 case GL_NEAREST_MIPMAP_LINEAR
:
224 * trilinear is bugged! mipmap blending produce
225 * incorrect filtered colors for the smallest mipmap levels.
227 * currently Napalm can't do single-pass trilinear,
228 * because the way its combiners are set. So we fall back
229 * to GL_NEAREST_MIPMAP_NEAREST. We'll let true trilinear
230 * enabled for V2, V3. If user shoots foot, not our problem!
232 if (!fxMesa
->HaveCmbExt
) {
233 if (fxMesa
->haveTwoTMUs
) {
234 ti
->mmMode
= GR_MIPMAP_NEAREST
;
235 ti
->LODblend
= FXTRUE
;
237 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
238 ti
->LODblend
= FXFALSE
;
240 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
243 case GL_NEAREST_MIPMAP_NEAREST
:
244 ti
->mmMode
= GR_MIPMAP_NEAREST
;
245 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
246 ti
->LODblend
= FXFALSE
;
248 case GL_LINEAR_MIPMAP_LINEAR
:
250 * trilinear is bugged! mipmap blending produce
251 * incorrect filtered colors for the smallest mipmap levels.
253 * currently Napalm can't do single-pass trilinear,
254 * because the way its combiners are set. So we fall back
255 * to GL_LINEAR_MIPMAP_NEAREST. We'll let true trilinear
256 * enabled for V2, V3. If user shoots foot, not our problem!
258 if (!fxMesa
->HaveCmbExt
) {
259 if (fxMesa
->haveTwoTMUs
) {
260 ti
->mmMode
= GR_MIPMAP_NEAREST
;
261 ti
->LODblend
= FXTRUE
;
263 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
264 ti
->LODblend
= FXFALSE
;
266 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
269 case GL_LINEAR_MIPMAP_NEAREST
:
270 ti
->mmMode
= GR_MIPMAP_NEAREST
;
271 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
272 ti
->LODblend
= FXFALSE
;
277 fxTexInvalidate(ctx
, tObj
);
280 case GL_TEXTURE_MAG_FILTER
:
283 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
286 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
291 fxTexInvalidate(ctx
, tObj
);
294 case GL_TEXTURE_WRAP_S
:
296 case GL_MIRRORED_REPEAT
:
297 ti
->sClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
299 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
301 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
304 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
309 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
312 case GL_TEXTURE_WRAP_T
:
314 case GL_MIRRORED_REPEAT
:
315 ti
->tClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
317 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
319 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
322 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
327 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
330 case GL_TEXTURE_BORDER_COLOR
:
334 case GL_TEXTURE_MIN_LOD
:
337 case GL_TEXTURE_MAX_LOD
:
340 case GL_TEXTURE_BASE_LEVEL
:
341 fxTexInvalidate(ctx
, tObj
);
343 case GL_TEXTURE_MAX_LEVEL
:
344 fxTexInvalidate(ctx
, tObj
);
353 fxDDTexDel(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
355 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
356 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
358 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
359 fprintf(stderr
, "fxDDTexDel(%d, %p)\n", tObj
->Name
, (void *) ti
);
365 fxTMFreeTexture(fxMesa
, tObj
);
368 tObj
->DriverData
= NULL
;
370 /* Free mipmap images and the texture object itself */
371 _mesa_delete_texture_object(ctx
, tObj
);
375 * Return true if texture is resident, false otherwise.
378 fxDDIsTextureResident(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
380 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
381 return (ti
&& ti
->isInTM
);
387 * Convert a gl_color_table texture palette to Glide's format.
390 convertPalette(const fxMesaContext fxMesa
, FxU32 data
[256], const struct gl_color_table
*table
)
392 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
393 GLint width
= table
->Size
;
397 ASSERT(!table
->FloatTable
);
399 switch (table
->Format
) {
401 for (i
= 0; i
< width
; i
++) {
406 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
408 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
410 for (i
= 0; i
< width
; i
++) {
415 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
417 return GR_TEXTABLE_PALETTE
;
419 for (i
= 0; i
< width
; i
++) {
422 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
424 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
425 case GL_LUMINANCE_ALPHA
:
426 for (i
= 0; i
< width
; i
++) {
427 r
= g
= b
= tableUB
[i
* 2 + 0];
428 a
= tableUB
[i
* 2 + 1];
429 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
431 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
434 for (i
= 0; i
< width
; i
++) {
435 r
= tableUB
[i
* 3 + 0];
436 g
= tableUB
[i
* 3 + 1];
437 b
= tableUB
[i
* 3 + 2];
439 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
441 return GR_TEXTABLE_PALETTE
;
443 for (i
= 0; i
< width
; i
++) {
444 r
= tableUB
[i
* 4 + 0];
445 g
= tableUB
[i
* 4 + 1];
446 b
= tableUB
[i
* 4 + 2];
447 a
= tableUB
[i
* 4 + 3];
448 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
450 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
456 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
458 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
461 /* per-texture palette */
463 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
464 fprintf(stderr
, "fxDDTexPalette(%d, %x)\n",
465 tObj
->Name
, (GLuint
) tObj
->DriverData
);
467 if (!tObj
->DriverData
)
468 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
469 ti
= fxTMGetTexInfo(tObj
);
470 ti
->paltype
= convertPalette(fxMesa
, ti
->palette
.data
, &tObj
->Palette
);
471 fxTexInvalidate(ctx
, tObj
);
474 /* global texture palette */
475 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
476 fprintf(stderr
, "fxDDTexPalette(global)\n");
478 fxMesa
->glbPalType
= convertPalette(fxMesa
, fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
479 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
481 grTexDownloadTable(fxMesa
->glbPalType
, &(fxMesa
->glbPalette
));
487 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
489 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
491 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
492 fprintf(stderr
, "fxDDTexUseGlbPalette(%d)\n", state
);
496 fxMesa
->haveGlobalPaletteTexture
= 1;
499 fxMesa
->haveGlobalPaletteTexture
= 0;
501 if ((ctx
->Texture
.Unit
[0]._Current
== ctx
->Texture
.Unit
[0].Current2D
) &&
502 (ctx
->Texture
.Unit
[0]._Current
!= NULL
)) {
503 struct gl_texture_object
*tObj
= ctx
->Texture
.Unit
[0]._Current
;
505 if (!tObj
->DriverData
)
506 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
508 fxTexInvalidate(ctx
, tObj
);
538 * w, h - source texture width and height
539 * lodlevel - Glide lod level token for the larger texture dimension
540 * ar - Glide aspect ratio token
541 * sscale - S scale factor used during triangle setup
542 * tscale - T scale factor used during triangle setup
543 * wscale - OpenGL -> Glide image width scale factor
544 * hscale - OpenGL -> Glide image height scale factor
547 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
548 float *sscale
, float *tscale
,
549 int *wscale
, int *hscale
)
551 int logw
, logh
, ws
, hs
;
553 GrAspectRatio_t aspectratio
;
559 l
= MAX2(logw
, logh
);
560 aspectratio
= logw
- logh
;
564 /* hardware only allows a maximum aspect ratio of 8x1, so handle
565 * |aspectratio| > 3 by scaling the image and using an 8x1 aspect
568 switch (aspectratio
) {
590 if (aspectratio
> 3) {
592 hs
= 1 << (aspectratio
- 3);
593 aspectratio
= GR_ASPECT_LOG2_8x1
;
594 } else /*if (aspectratio < -3)*/ {
596 ws
= 1 << (-aspectratio
- 3);
597 aspectratio
= GR_ASPECT_LOG2_1x8
;
624 fxIsTexSupported(GLenum target
, GLint internalFormat
,
625 const struct gl_texture_image
*image
)
627 if (target
!= GL_TEXTURE_2D
)
631 if (!fxTexGetInfo(image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
))
635 if (image
->Border
> 0)
642 /**********************************************************************/
643 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
644 /**********************************************************************/
646 /* Texel-fetch functions for software texturing and glGetTexImage().
647 * We should have been able to use some "standard" fetch functions (which
648 * may get defined in texutil.c) but we have to account for scaled texture
649 * images on tdfx hardware (the 8:1 aspect ratio limit).
650 * Hence, we need special functions here.
653 * this better be right, if we will advertise GL_SGIS_generate_mipmap!
657 fetch_intensity8(const struct gl_texture_image
*texImage
,
658 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
660 GLchan
*rgba
= (GLchan
*) texelOut
;
661 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
662 const GLubyte
*texel
;
667 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
668 rgba
[RCOMP
] = *texel
;
669 rgba
[GCOMP
] = *texel
;
670 rgba
[BCOMP
] = *texel
;
671 rgba
[ACOMP
] = *texel
;
676 fetch_luminance8(const struct gl_texture_image
*texImage
,
677 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
679 GLchan
*rgba
= (GLchan
*) texelOut
;
680 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
681 const GLubyte
*texel
;
686 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
687 rgba
[RCOMP
] = *texel
;
688 rgba
[GCOMP
] = *texel
;
689 rgba
[BCOMP
] = *texel
;
695 fetch_alpha8(const struct gl_texture_image
*texImage
,
696 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
698 GLchan
*rgba
= (GLchan
*) texelOut
;
699 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
700 const GLubyte
*texel
;
705 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
709 rgba
[ACOMP
] = *texel
;
714 fetch_index8(const struct gl_texture_image
*texImage
,
715 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
717 GLchan
*indexOut
= (GLchan
*) texelOut
;
718 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
719 const GLubyte
*texel
;
724 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
730 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
731 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
733 GLchan
*rgba
= (GLchan
*) texelOut
;
734 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
735 const GLubyte
*texel
;
740 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
741 rgba
[RCOMP
] = texel
[0];
742 rgba
[GCOMP
] = texel
[0];
743 rgba
[BCOMP
] = texel
[0];
744 rgba
[ACOMP
] = texel
[1];
749 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
750 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
752 GLchan
*rgba
= (GLchan
*) texelOut
;
753 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
754 const GLushort
*texel
;
759 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
760 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
761 rgba
[GCOMP
] = FX_rgb_scale_6
[(*texel
>> 5) & 0x3F];
762 rgba
[BCOMP
] = FX_rgb_scale_5
[ *texel
& 0x1F];
768 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
769 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
771 GLchan
*rgba
= (GLchan
*) texelOut
;
772 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
773 const GLushort
*texel
;
778 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
779 rgba
[RCOMP
] = FX_rgb_scale_4
[(*texel
>> 12) & 0xF];
780 rgba
[GCOMP
] = FX_rgb_scale_4
[(*texel
>> 8) & 0xF];
781 rgba
[BCOMP
] = FX_rgb_scale_4
[(*texel
>> 4) & 0xF];
782 rgba
[ACOMP
] = FX_rgb_scale_4
[ *texel
& 0xF];
787 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
788 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
790 GLchan
*rgba
= (GLchan
*) texelOut
;
791 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
792 const GLushort
*texel
;
797 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
798 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
799 rgba
[GCOMP
] = FX_rgb_scale_5
[(*texel
>> 6) & 0x1F];
800 rgba
[BCOMP
] = FX_rgb_scale_5
[(*texel
>> 1) & 0x1F];
801 rgba
[ACOMP
] = ((*texel
) & 0x01) * 255;
806 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
807 GLint i
, GLint j
, GLint k
, GLvoid
* texelOut
)
809 GLchan
*rgba
= (GLchan
*) texelOut
;
810 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
816 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
817 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
818 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
819 rgba
[BCOMP
] = (((*texel
) ) & 0xff);
820 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
825 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
828 for (i
= 0; i
< h
; i
++) {
829 for (j
= 0; j
< w
; j
++) {
831 fprintf(stderr
, "%02x %02x ", data
[0], data
[1]);
833 fprintf(stderr
, "%02x %02x %02x ", data
[0], data
[1], data
[2]);
836 fprintf(stderr
, "\n");
841 GLboolean
fxDDIsCompressedFormat ( GLcontext
*ctx
, GLenum internalFormat
)
843 if ((internalFormat
== GL_COMPRESSED_RGB_FXT1_3DFX
) ||
844 (internalFormat
== GL_COMPRESSED_RGBA_FXT1_3DFX
) ||
845 (internalFormat
== GL_COMPRESSED_RGB_S3TC_DXT1_EXT
) ||
846 (internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
) ||
847 (internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
) ||
848 (internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
) ||
849 (internalFormat
== GL_RGB_S3TC
) ||
850 (internalFormat
== GL_RGB4_S3TC
) ||
851 (internalFormat
== GL_RGBA_S3TC
) ||
852 (internalFormat
== GL_RGBA4_S3TC
)) {
857 * we are handling differently the above formats from the generic
858 * GL_COMPRESSED_RGB[A]. For this, we will always have to separately
859 * check for the ones below!
862 #if FX_TC_NCC || FX_TC_NAPALM
863 if ((internalFormat
== GL_COMPRESSED_RGB
) || (internalFormat
== GL_COMPRESSED_RGBA
)) {
872 GLuint
fxDDCompressedTextureSize (GLcontext
*ctx
,
873 GLsizei width
, GLsizei height
, GLsizei depth
,
881 /* Determine width and height scale factors for texture.
882 * Remember, Glide is limited to 8:1 aspect ratios.
884 fxTexGetInfo(width
, height
,
885 NULL
, /* lod level */
886 NULL
, /* aspect ratio */
887 NULL
, NULL
, /* sscale, tscale */
894 case GL_COMPRESSED_RGB_FXT1_3DFX
:
895 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
896 /* round up width to next multiple of 8, height to next multiple of 4 */
897 width
= (width
+ 7) & ~7;
898 height
= (height
+ 3) & ~3;
899 /* 16 bytes per 8x4 tile of RGB[A] texels */
900 size
= width
* height
/ 2;
901 /* Textures smaller than 8x4 will effectively be made into 8x4 and
907 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
908 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
911 /* round up width, height to next multiple of 4 */
912 width
= (width
+ 3) & ~3;
913 height
= (height
+ 3) & ~3;
914 /* 8 bytes per 4x4 tile of RGB[A] texels */
915 size
= width
* height
/ 2;
916 /* Textures smaller than 4x4 will effectively be made into 4x4 and
922 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
923 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
926 /* round up width, height to next multiple of 4 */
927 width
= (width
+ 3) & ~3;
928 height
= (height
+ 3) & ~3;
929 /* 16 bytes per 4x4 tile of RGBA texels */
930 size
= width
* height
; /* simple! */
931 /* Textures smaller than 4x4 will effectively be made into 4x4 and
937 case GL_COMPRESSED_RGB
:
940 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
941 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
942 return fxDDCompressedTextureSize(ctx
, width
, height
, 1, GL_COMPRESSED_RGB_FXT1_3DFX
);
947 return (width
* height
* 8 >> 3) + 12 * 4;
949 case GL_COMPRESSED_RGBA
:
952 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
953 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
954 return fxDDCompressedTextureSize(ctx
, width
, height
, 1, GL_COMPRESSED_RGBA_FXT1_3DFX
);
959 return (width
* height
* 16 >> 3) + 12 * 4;
962 _mesa_problem(ctx
, "bad texformat in fxDDCompressedTextureSize");
968 const struct gl_texture_format
*
969 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
970 GLenum srcFormat
, GLenum srcType
)
972 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
973 GLboolean allow32bpt
= fxMesa
->HaveTexFmt
;
975 /* [dBorca] Hack alert:
976 * There is something wrong with this!!! Take an example:
977 * 1) start HW rendering
978 * 2) create a texture like this:
979 * glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,
980 * GL_RGB, GL_UNSIGNED_BYTE, floorTexture);
981 * glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
982 * 3) we get here with internalFormat==3 and return either
983 * _mesa_texformat_rgb565 or _mesa_texformat_argb8888
984 * 4) at some point, we encounter total rasterization fallback
985 * 5) displaying a polygon with the above textures yield garbage on areas
986 * where pixel is larger than a texel, because our already set texel
987 * function doesn't match the real _mesa_texformat_argb888
990 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
991 fprintf(stderr
, "fxDDChooseTextureFormat(...)\n");
994 switch (internalFormat
) {
995 case GL_COMPRESSED_RGB
:
996 #if 0 && FX_TC_NAPALM /* [koolsmoky] */
997 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
998 return &_mesa_texformat_rgb_fxt1
;
999 } else if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
1000 return &_mesa_texformat_rgb_dxt1
;
1003 /* intentional fall through */
1006 if ( srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1007 return &_mesa_texformat_rgb565
;
1009 /* intentional fall through */
1014 return (allow32bpt
) ? &_mesa_texformat_argb8888
1015 : &_mesa_texformat_rgb565
;
1018 return &_mesa_texformat_argb4444
;
1019 case GL_COMPRESSED_RGBA
:
1020 #if 0 && FX_TC_NAPALM /* [koolsmoky] */
1021 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
1022 return &_mesa_texformat_rgba_fxt1
;
1023 } else if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
1024 return &_mesa_texformat_rgba_dxt3
;
1027 /* intentional fall through */
1030 if ( srcFormat
== GL_BGRA
) {
1031 if ( srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) {
1032 return &_mesa_texformat_argb8888
;
1034 else if ( srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1035 return &_mesa_texformat_argb4444
;
1037 else if ( srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1038 return &_mesa_texformat_argb1555
;
1041 /* intentional fall through */
1046 return (allow32bpt
) ? &_mesa_texformat_argb8888
1047 : &_mesa_texformat_argb4444
;
1051 case GL_INTENSITY12
:
1052 case GL_INTENSITY16
:
1053 case GL_COMPRESSED_INTENSITY
:
1054 return &_mesa_texformat_i8
;
1059 case GL_LUMINANCE12
:
1060 case GL_LUMINANCE16
:
1061 case GL_COMPRESSED_LUMINANCE
:
1062 return &_mesa_texformat_l8
;
1068 case GL_COMPRESSED_ALPHA
:
1069 return &_mesa_texformat_a8
;
1070 case GL_COLOR_INDEX
:
1071 case GL_COLOR_INDEX1_EXT
:
1072 case GL_COLOR_INDEX2_EXT
:
1073 case GL_COLOR_INDEX4_EXT
:
1074 case GL_COLOR_INDEX8_EXT
:
1075 case GL_COLOR_INDEX12_EXT
:
1076 case GL_COLOR_INDEX16_EXT
:
1077 return &_mesa_texformat_ci8
;
1079 case GL_LUMINANCE_ALPHA
:
1080 case GL_LUMINANCE4_ALPHA4
:
1081 case GL_LUMINANCE6_ALPHA2
:
1082 case GL_LUMINANCE8_ALPHA8
:
1083 case GL_LUMINANCE12_ALPHA4
:
1084 case GL_LUMINANCE12_ALPHA12
:
1085 case GL_LUMINANCE16_ALPHA16
:
1086 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1087 return &_mesa_texformat_al88
;
1091 return &_mesa_texformat_rgb565
;
1093 return &_mesa_texformat_argb1555
;
1094 /* GL_EXT_texture_compression_s3tc */
1096 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1099 return &_mesa_texformat_rgb_dxt1
;
1100 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1101 return &_mesa_texformat_rgba_dxt1
;
1102 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1105 return &_mesa_texformat_rgba_dxt3
;
1106 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1107 return &_mesa_texformat_rgba_dxt5
;
1108 /* GL_3DFX_texture_compression_FXT1 */
1109 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1110 return &_mesa_texformat_rgb_fxt1
;
1111 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1112 return &_mesa_texformat_rgba_fxt1
;
1114 _mesa_problem(NULL
, "unexpected format in fxDDChooseTextureFormat");
1120 static GrTextureFormat_t
1121 fxGlideFormat(GLint mesaFormat
)
1123 switch (mesaFormat
) {
1124 case MESA_FORMAT_I8
:
1125 return GR_TEXFMT_ALPHA_8
;
1126 case MESA_FORMAT_A8
:
1127 return GR_TEXFMT_ALPHA_8
;
1128 case MESA_FORMAT_L8
:
1129 return GR_TEXFMT_INTENSITY_8
;
1130 case MESA_FORMAT_CI8
:
1131 return GR_TEXFMT_P_8
;
1132 case MESA_FORMAT_AL88
:
1133 return GR_TEXFMT_ALPHA_INTENSITY_88
;
1134 case MESA_FORMAT_RGB565
:
1135 return GR_TEXFMT_RGB_565
;
1136 case MESA_FORMAT_ARGB4444
:
1137 return GR_TEXFMT_ARGB_4444
;
1138 case MESA_FORMAT_ARGB1555
:
1139 return GR_TEXFMT_ARGB_1555
;
1140 case MESA_FORMAT_ARGB8888
:
1141 return GR_TEXFMT_ARGB_8888
;
1142 case MESA_FORMAT_RGB_FXT1
:
1143 case MESA_FORMAT_RGBA_FXT1
:
1144 return GR_TEXFMT_ARGB_CMP_FXT1
;
1145 case MESA_FORMAT_RGB_DXT1
:
1146 case MESA_FORMAT_RGBA_DXT1
:
1147 return GR_TEXFMT_ARGB_CMP_DXT1
;
1148 case MESA_FORMAT_RGBA_DXT3
:
1149 return GR_TEXFMT_ARGB_CMP_DXT3
;
1150 case MESA_FORMAT_RGBA_DXT5
:
1151 return GR_TEXFMT_ARGB_CMP_DXT5
;
1153 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1159 static FetchTexelFunc
1160 fxFetchFunction(GLint mesaFormat
)
1162 switch (mesaFormat
) {
1163 case MESA_FORMAT_I8
:
1164 return &fetch_intensity8
;
1165 case MESA_FORMAT_A8
:
1166 return &fetch_alpha8
;
1167 case MESA_FORMAT_L8
:
1168 return &fetch_luminance8
;
1169 case MESA_FORMAT_CI8
:
1170 return &fetch_index8
;
1171 case MESA_FORMAT_AL88
:
1172 return &fetch_luminance8_alpha8
;
1173 case MESA_FORMAT_RGB565
:
1174 return &fetch_r5g6b5
;
1175 case MESA_FORMAT_ARGB4444
:
1176 return &fetch_r4g4b4a4
;
1177 case MESA_FORMAT_ARGB1555
:
1178 return &fetch_r5g5b5a1
;
1179 case MESA_FORMAT_ARGB8888
:
1180 return &fetch_a8r8g8b8
;
1181 case MESA_FORMAT_RGB_FXT1
:
1182 case MESA_FORMAT_RGBA_FXT1
:
1183 case MESA_FORMAT_RGB_DXT1
:
1184 case MESA_FORMAT_RGBA_DXT1
:
1185 case MESA_FORMAT_RGBA_DXT3
:
1186 case MESA_FORMAT_RGBA_DXT5
:
1187 return &fetch_r4g4b4a4
;
1189 _mesa_problem(NULL
, "Unexpected format in fxFetchFunction");
1195 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1196 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1197 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1198 const struct gl_pixelstore_attrib
*packing
,
1199 struct gl_texture_object
*texObj
,
1200 struct gl_texture_image
*texImage
)
1202 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1204 tfxMipMapLevel
*mml
;
1207 GLvoid
*_final_texImage_Data
;
1208 const struct gl_texture_format
*_final_texImage_TexFormat
;
1210 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1211 fprintf(stderr
, "fxDDTexImage2D: id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1212 texObj
->Name
, texImage
->IntFormat
, format
, type
,
1213 texImage
->Width
, texImage
->Height
);
1216 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1217 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1221 if (!texObj
->DriverData
) {
1222 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1223 if (!texObj
->DriverData
) {
1224 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1228 ti
= fxTMGetTexInfo(texObj
);
1230 if (!texImage
->DriverData
) {
1231 texImage
->DriverData
= CALLOC(sizeof(tfxMipMapLevel
));
1232 if (!texImage
->DriverData
) {
1233 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1237 mml
= FX_MIPMAP_DATA(texImage
);
1239 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1240 &mml
->wScale
, &mml
->hScale
);
1242 mml
->width
= width
* mml
->wScale
;
1243 mml
->height
= height
* mml
->hScale
;
1245 #if 0 && FX_COMPRESS_S3TC_AS_FXT1_HACK
1246 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1247 /* [dBorca] we should update texture's attribute, then,
1248 * because if the application asks us to decompress, we
1249 * have to know the REAL format! Also, DXT3/5 might not
1250 * be correct, since it would mess with "compressedSize".
1251 * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3.
1253 if (texImage
->IsCompressed
) {
1254 switch (internalFormat
) {
1255 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1258 internalFormat
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1260 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1261 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1262 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1265 internalFormat
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1269 #if 1 || FX_COMPRESS_DXT5_AS_DXT3_HACK
1270 /* [dBorca] either VSA is stupid at DXT5,
1271 * or our compression tool is broken. See
1272 * above for caveats.
1274 if ((texImage
->IsCompressed
) &&
1275 (internalFormat
== GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
)) {
1276 internalFormat
= GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
;
1280 /* choose the texture format */
1281 assert(ctx
->Driver
.ChooseTextureFormat
);
1282 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1283 internalFormat
, format
, type
);
1284 assert(texImage
->TexFormat
);
1285 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1286 /*if (!fxMesa->HaveTexFmt) assert(texelBytes == 1 || texelBytes == 2);*/
1288 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1289 /* dirty trick: will thrash CopyTex[Sub]Image */
1290 #if FX_TC_NCC || FX_TC_NAPALM
1291 if (internalFormat
== GL_COMPRESSED_RGB
) {
1293 mml
->glideFormat
= GR_TEXFMT_YIQ_422
;
1296 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1297 mml
->glideFormat
= GR_TEXFMT_ARGB_CMP_FXT1
;
1300 } else if (internalFormat
== GL_COMPRESSED_RGBA
) {
1302 mml
->glideFormat
= GR_TEXFMT_AYIQ_8422
;
1305 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1306 mml
->glideFormat
= GR_TEXFMT_ARGB_CMP_FXT1
;
1312 /* allocate mipmap buffer */
1313 assert(!texImage
->Data
);
1314 if (texImage
->IsCompressed
) {
1315 texImage
->Data
= MESA_PBUFFER_ALLOC(texImage
->CompressedSize
);
1317 _final_texImage_TexFormat
= &_mesa_texformat_argb8888
;
1318 _final_texImage_Data
= MALLOC(mml
->width
* mml
->height
* 4);
1319 if (!_final_texImage_Data
) {
1320 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1324 texImage
->Data
= MESA_PBUFFER_ALLOC(mml
->width
* mml
->height
* texelBytes
);
1325 _final_texImage_TexFormat
= texImage
->TexFormat
;
1326 _final_texImage_Data
= texImage
->Data
;
1328 if (!texImage
->Data
) {
1329 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1333 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1334 /* rescale image to overcome 1:8 aspect limitation */
1336 tempImage
= MALLOC(width
* height
* texelBytes
);
1338 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1341 /* unpack image, apply transfer ops and store in tempImage */
1342 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1343 _final_texImage_TexFormat
,
1345 width
, height
, 1, 0, 0, 0, /* src */
1346 width
* texelBytes
, /* dstRowStride */
1347 0, /* dstImageStride */
1348 format
, type
, pixels
, packing
);
1349 _mesa_rescale_teximage2d(texelBytes
,
1350 mml
->width
* texelBytes
, /* dst stride */
1351 width
, height
, /* src */
1352 mml
->width
, mml
->height
, /* dst */
1353 tempImage
/*src*/, _final_texImage_Data
/*dst*/ );
1357 /* no rescaling needed */
1358 /* unpack image, apply transfer ops and store in texImage->Data */
1359 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,
1360 _final_texImage_TexFormat
, _final_texImage_Data
,
1361 width
, height
, 1, 0, 0, 0,
1362 mml
->width
* texelBytes
,
1363 0, /* dstImageStride */
1364 format
, type
, pixels
, packing
);
1368 if (texImage
->IsCompressed
) {
1370 if ((mml
->glideFormat
== GR_TEXFMT_AYIQ_8422
) ||
1371 (mml
->glideFormat
== GR_TEXFMT_YIQ_422
)) {
1373 txMip
.width
= mml
->width
;
1374 txMip
.height
= mml
->height
;
1376 txMip
.data
[0] = _final_texImage_Data
;
1377 pxMip
.data
[0] = texImage
->Data
;
1378 fxMesa
->Glide
.txMipQuantize(&pxMip
, &txMip
, mml
->glideFormat
, TX_DITHER_ERR
, TX_COMPRESSION_STATISTICAL
);
1379 fxMesa
->Glide
.txPalToNcc((GuNccTable
*)(&(ti
->palette
)), pxMip
.pal
);
1380 MEMCPY((char *)texImage
->Data
+ texImage
->CompressedSize
- 12 * 4, &(ti
->palette
.data
[16]), 12 * 4);
1383 fxMesa
->Glide
.txImgQuantize(texImage
->Data
, _final_texImage_Data
, mml
->width
, mml
->height
, mml
->glideFormat
, TX_DITHER_NONE
);
1384 FREE(_final_texImage_Data
);
1387 ti
->info
.format
= mml
->glideFormat
;
1388 texImage
->FetchTexel
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1391 * Hack alert: unsure...
1393 if (0 && ti
->validated
&& ti
->isInTM
) {
1394 /*fprintf(stderr, "reloadmipmaplevels\n"); */
1395 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1398 /*fprintf(stderr, "invalidate2\n"); */
1399 fxTexInvalidate(ctx
, texObj
);
1405 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1406 GLint xoffset
, GLint yoffset
,
1407 GLsizei width
, GLsizei height
,
1408 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1409 const struct gl_pixelstore_attrib
*packing
,
1410 struct gl_texture_object
*texObj
,
1411 struct gl_texture_image
*texImage
)
1413 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1415 tfxMipMapLevel
*mml
;
1418 /* [dBorca] Hack alert:
1419 * fix the goddamn texture compression here
1422 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1423 fprintf(stderr
, "fxDDTexSubImage2D: id=%d\n", texObj
->Name
);
1426 if (!texObj
->DriverData
) {
1427 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1431 ti
= fxTMGetTexInfo(texObj
);
1433 mml
= FX_MIPMAP_DATA(texImage
);
1436 assert(texImage
->Data
); /* must have an existing texture image! */
1437 assert(texImage
->Format
);
1439 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1441 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1442 /* need to rescale subimage to match mipmap level's rescale factors */
1443 const GLint newWidth
= width
* mml
->wScale
;
1444 const GLint newHeight
= height
* mml
->hScale
;
1447 tempImage
= MALLOC(width
* height
* texelBytes
);
1449 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1453 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
,/* Tex int format */
1454 texImage
->TexFormat
, /* dest format */
1455 (GLubyte
*) tempImage
, /* dest */
1456 width
, height
, 1, /* subimage size */
1457 0, 0, 0, /* subimage pos */
1458 width
* texelBytes
, /* dest row stride */
1459 0, /* dst image stride */
1460 format
, type
, pixels
, packing
);
1463 /* compute address of dest subimage within the overal tex image */
1464 destAddr
= (GLubyte
*) texImage
->Data
1465 + (yoffset
* mml
->hScale
* mml
->width
1466 + xoffset
* mml
->wScale
) * texelBytes
;
1468 _mesa_rescale_teximage2d(texelBytes
,
1469 mml
->width
* texelBytes
, /* dst stride */
1471 newWidth
, newHeight
,
1472 tempImage
, destAddr
);
1477 /* no rescaling needed */
1478 _mesa_transfer_teximage(ctx
, 2, texImage
->Format
, /* Tex int format */
1479 texImage
->TexFormat
, /* dest format */
1480 (GLubyte
*) texImage
->Data
,/* dest */
1481 width
, height
, 1, /* subimage size */
1482 xoffset
, yoffset
, 0, /* subimage pos */
1483 mml
->width
* texelBytes
, /* dest row stride */
1484 0, /* dst image stride */
1485 format
, type
, pixels
, packing
);
1489 * Hack alert: unsure...
1491 if (0 && ti
->validated
&& ti
->isInTM
)
1492 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1494 fxTexInvalidate(ctx
, texObj
);
1499 fxDDCompressedTexImage2D (GLcontext
*ctx
, GLenum target
,
1500 GLint level
, GLint internalFormat
,
1501 GLsizei width
, GLsizei height
, GLint border
,
1502 GLsizei imageSize
, const GLvoid
*data
,
1503 struct gl_texture_object
*texObj
,
1504 struct gl_texture_image
*texImage
)
1506 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1508 tfxMipMapLevel
*mml
;
1510 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1511 fprintf(stderr
, "fxDDCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1512 texObj
->Name
, internalFormat
,
1516 assert(texImage
->IsCompressed
);
1518 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1519 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDCompressedTexImg()\n");
1523 if (!texObj
->DriverData
) {
1524 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1525 if (!texObj
->DriverData
) {
1526 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1530 ti
= fxTMGetTexInfo(texObj
);
1532 if (!texImage
->DriverData
) {
1533 texImage
->DriverData
= CALLOC(sizeof(tfxMipMapLevel
));
1534 if (!texImage
->DriverData
) {
1535 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1539 mml
= FX_MIPMAP_DATA(texImage
);
1541 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1542 &mml
->wScale
, &mml
->hScale
);
1544 mml
->width
= width
* mml
->wScale
;
1545 mml
->height
= height
* mml
->hScale
;
1548 /* choose the texture format */
1549 assert(ctx
->Driver
.ChooseTextureFormat
);
1550 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1551 internalFormat
, -1/*format*/, -1/*type*/);
1552 assert(texImage
->TexFormat
);
1554 /* Determine the appropriate Glide texel format,
1555 * given the user's internal texture format hint.
1557 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1558 #if FX_TC_NCC || FX_TC_NAPALM
1559 if (internalFormat
== GL_COMPRESSED_RGB
) {
1561 mml
->glideFormat
= GR_TEXFMT_YIQ_422
;
1564 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1565 mml
->glideFormat
= GR_TEXFMT_ARGB_CMP_FXT1
;
1568 } else if (internalFormat
== GL_COMPRESSED_RGBA
) {
1570 mml
->glideFormat
= GR_TEXFMT_AYIQ_8422
;
1573 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1574 mml
->glideFormat
= GR_TEXFMT_ARGB_CMP_FXT1
;
1580 /* allocate new storage for texture image, if needed */
1581 if (!texImage
->Data
) {
1582 texImage
->Data
= MESA_PBUFFER_ALLOC(imageSize
);
1583 if (!texImage
->Data
) {
1584 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1589 /* save the texture data */
1590 MEMCPY(texImage
->Data
, data
, imageSize
);
1592 if ((mml
->glideFormat
== GR_TEXFMT_AYIQ_8422
) ||
1593 (mml
->glideFormat
== GR_TEXFMT_YIQ_422
)) {
1594 MEMCPY(&(ti
->palette
.data
[16]), (char *)data
+ imageSize
- 12 * 4, 12 * 4);
1598 ti
->info
.format
= mml
->glideFormat
;
1599 texImage
->FetchTexel
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1601 /* [dBorca] Hack alert:
1602 * what about different size/texel? other anomalies? SW rescaling?
1606 * Hack alert: unsure...
1608 if (0 && ti
->validated
&& ti
->isInTM
) {
1609 /*fprintf(stderr, "reloadmipmaplevels\n"); */
1610 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1613 /*fprintf(stderr, "invalidate2\n"); */
1614 fxTexInvalidate(ctx
, texObj
);
1620 fxDDCompressedTexSubImage2D( GLcontext
*ctx
, GLenum target
,
1621 GLint level
, GLint xoffset
,
1622 GLint yoffset
, GLsizei width
,
1623 GLint height
, GLenum format
,
1624 GLsizei imageSize
, const GLvoid
*data
,
1625 struct gl_texture_object
*texObj
,
1626 struct gl_texture_image
*texImage
)
1628 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1630 tfxMipMapLevel
*mml
;
1632 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1633 fprintf(stderr
, "fxDDCompressedTexSubImage2D: id=%d\n", texObj
->Name
);
1636 ti
= fxTMGetTexInfo(texObj
);
1638 mml
= FX_MIPMAP_DATA(texImage
);
1642 * We punt if we are not replacing the entire image. This
1643 * is allowed by the spec.
1645 * [dBorca] Hack alert:
1646 * ohwell, we should NOT! Look into _mesa_store_compressed_texsubimage2d
1647 * on how to calculate the sub-image.
1649 if ((xoffset
!= 0) && (yoffset
!= 0)
1650 && (width
!= texImage
->Width
)
1651 && (height
!= texImage
->Height
)) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(CHICKEN)");
1656 /* [dBorca] Hack alert:
1657 * what about different size/texel? other anomalies? SW rescaling?
1659 MEMCPY(texImage
->Data
, data
, imageSize
);
1662 * Hack alert: unsure...
1664 if (0 && ti
->validated
&& ti
->isInTM
)
1665 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1667 fxTexInvalidate(ctx
, texObj
);
1674 * Need this to provide at least one external definition.
1677 extern int gl_fx_dummy_function_ddtex(void);
1679 gl_fx_dummy_function_ddtex(void)