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"
46 #include "texcompress.h"
51 /* no borders! can't halve 1x1! (stride > width * comp) not allowed */
53 _mesa_halve2x2_teximage2d ( GLcontext
*ctx
,
54 struct gl_texture_image
*texImage
,
56 GLint srcWidth
, GLint srcHeight
,
57 const GLvoid
*srcImage
, GLvoid
*dstImage
)
60 GLint dstWidth
= srcWidth
/ 2;
61 GLint dstHeight
= srcHeight
/ 2;
62 GLint srcRowStride
= srcWidth
* bytesPerPixel
;
63 GLubyte
*src
= (GLubyte
*)srcImage
;
64 GLubyte
*dst
= dstImage
;
71 if (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_RGB565
) {
72 _t
= GL_UNSIGNED_SHORT_5_6_5_REV
;
74 } else if (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_ARGB4444
) {
75 _t
= GL_UNSIGNED_SHORT_4_4_4_4_REV
;
77 } else if (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_ARGB1555
) {
78 _t
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
83 srcRowStride
= srcWidth
* bytesPerPixel
;
90 _s
= src
= MALLOC(srcRowStride
* srcHeight
);
91 _d
= dst
= MALLOC(dstWidth
* bytesPerPixel
* dstHeight
);
92 _mesa_texstore_rgba8888(ctx
, 2, GL_RGBA
,
93 &_mesa_texformat_rgba8888_rev
, src
,
94 0, 0, 0, /* dstX/Y/Zoffset */
95 srcRowStride
, /* dstRowStride */
96 0, /* dstImageStride */
97 srcWidth
, srcHeight
, 1,
98 texImage
->Format
, _t
, srcImage
, &ctx
->DefaultPacking
);
101 if (srcHeight
== 1) {
102 for (i
= 0; i
< dstWidth
; i
++) {
103 for (k
= 0; k
< bytesPerPixel
; k
++) {
104 dst
[0] = (src
[0] + src
[bytesPerPixel
] + 1) / 2;
108 src
+= bytesPerPixel
;
110 } else if (srcWidth
== 1) {
111 for (j
= 0; j
< dstHeight
; j
++) {
112 for (k
= 0; k
< bytesPerPixel
; k
++) {
113 dst
[0] = (src
[0] + src
[srcRowStride
] + 1) / 2;
120 for (j
= 0; j
< dstHeight
; j
++) {
121 for (i
= 0; i
< dstWidth
; i
++) {
122 for (k
= 0; k
< bytesPerPixel
; k
++) {
126 src
[srcRowStride
+ bytesPerPixel
] + 2) / 4;
130 src
+= bytesPerPixel
;
139 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->Format
,
140 texImage
->TexFormat
, dstImage
,
141 0, 0, 0, /* dstX/Y/Zoffset */
143 0, /* dstImageStride */
144 dstWidth
, dstHeight
, 1,
145 GL_BGRA
, CHAN_TYPE
, dst
, &ctx
->DefaultPacking
);
153 fxPrintTextureData(tfxTexInfo
* ti
)
155 fprintf(stderr
, "Texture Data:\n");
157 fprintf(stderr
, "\tName: %d\n", ti
->tObj
->Name
);
158 fprintf(stderr
, "\tBaseLevel: %d\n", ti
->tObj
->BaseLevel
);
159 fprintf(stderr
, "\tSize: %d x %d\n",
160 ti
->tObj
->Image
[0][ti
->tObj
->BaseLevel
]->Width
,
161 ti
->tObj
->Image
[0][ti
->tObj
->BaseLevel
]->Height
);
164 fprintf(stderr
, "\tName: UNNAMED\n");
165 fprintf(stderr
, "\tLast used: %d\n", ti
->lastTimeUsed
);
166 fprintf(stderr
, "\tTMU: %ld\n", ti
->whichTMU
);
167 fprintf(stderr
, "\t%s\n", (ti
->isInTM
) ? "In TMU" : "Not in TMU");
169 fprintf(stderr
, "\tMem0: %x-%x\n", (unsigned) ti
->tm
[0]->startAddr
,
170 (unsigned) ti
->tm
[0]->endAddr
);
172 fprintf(stderr
, "\tMem1: %x-%x\n", (unsigned) ti
->tm
[1]->startAddr
,
173 (unsigned) ti
->tm
[1]->endAddr
);
174 fprintf(stderr
, "\tMipmaps: %d-%d\n", ti
->minLevel
, ti
->maxLevel
);
175 fprintf(stderr
, "\tFilters: min %d max %d\n",
176 (int) ti
->minFilt
, (int) ti
->maxFilt
);
177 fprintf(stderr
, "\tClamps: s %d t %d\n", (int) ti
->sClamp
,
179 fprintf(stderr
, "\tScales: s %f t %f\n", ti
->sScale
, ti
->tScale
);
180 fprintf(stderr
, "\t%s\n",
181 (ti
->fixedPalette
) ? "Fixed palette" : "Non fixed palette");
182 fprintf(stderr
, "\t%s\n", (ti
->validated
) ? "Validated" : "Not validated");
186 /************************************************************************/
187 /*************************** Texture Mapping ****************************/
188 /************************************************************************/
191 fxTexInvalidate(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
193 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
196 ti
= fxTMGetTexInfo(tObj
);
198 fxTMMoveOutTM(fxMesa
, tObj
); /* TO DO: SLOW but easy to write */
200 ti
->validated
= GL_FALSE
;
201 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
205 fxAllocTexObjData(fxMesaContext fxMesa
)
209 if (!(ti
= CALLOC(sizeof(tfxTexInfo
)))) {
210 fprintf(stderr
, "fxAllocTexObjData: ERROR: out of memory !\n");
215 ti
->validated
= GL_FALSE
;
216 ti
->isInTM
= GL_FALSE
;
218 ti
->whichTMU
= FX_TMU_NONE
;
220 ti
->tm
[FX_TMU0
] = NULL
;
221 ti
->tm
[FX_TMU1
] = NULL
;
223 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
224 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
226 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
227 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
229 ti
->mmMode
= GR_MIPMAP_NEAREST
;
230 ti
->LODblend
= FXFALSE
;
236 fxDDTexBind(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
)
238 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
241 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
242 fprintf(stderr
, "fxDDTexBind(%d, %x)\n", tObj
->Name
, (GLuint
)tObj
->DriverData
);
245 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
248 if (!tObj
->DriverData
) {
249 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
251 ti
= fxTMGetTexInfo(tObj
);
253 fxMesa
->texBindNumber
++;
254 ti
->lastTimeUsed
= fxMesa
->texBindNumber
;
256 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
260 fxDDTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
261 const GLfloat
* param
)
263 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
265 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
267 fprintf(stderr
, "fxDDTexEnv(%x, %x)\n", pname
, (GLint
) (*param
));
269 fprintf(stderr
, "fxDDTexEnv(%x)\n", pname
);
272 /* apply any lod biasing right now */
273 if (pname
== GL_TEXTURE_LOD_BIAS_EXT
) {
274 GLfloat bias
= *param
;
275 CLAMP_SELF(bias
, -ctx
->Const
.MaxTextureLodBias
,
276 ctx
->Const
.MaxTextureLodBias
- 0.25);
278 grTexLodBiasValue(GR_TMU0
, bias
);
280 if (fxMesa
->haveTwoTMUs
) {
281 grTexLodBiasValue(GR_TMU1
, bias
);
286 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
290 fxDDTexParam(GLcontext
* ctx
, GLenum target
, struct gl_texture_object
*tObj
,
291 GLenum pname
, const GLfloat
* params
)
293 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
294 GLenum param
= (GLenum
) (GLint
) params
[0];
297 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
298 fprintf(stderr
, "fxDDTexParam(%d, %x, %s, %s)\n",
299 tObj
->Name
, (GLuint
) tObj
->DriverData
,
300 _mesa_lookup_enum_by_nr(pname
),
301 _mesa_lookup_enum_by_nr(param
));
304 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
307 if (!tObj
->DriverData
)
308 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
309 ti
= fxTMGetTexInfo(tObj
);
312 case GL_TEXTURE_MIN_FILTER
:
315 ti
->mmMode
= GR_MIPMAP_DISABLE
;
316 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
317 ti
->LODblend
= FXFALSE
;
320 ti
->mmMode
= GR_MIPMAP_DISABLE
;
321 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
322 ti
->LODblend
= FXFALSE
;
324 case GL_NEAREST_MIPMAP_LINEAR
:
326 * currently Napalm can't do single-pass trilinear,
327 * because the way its combiners are set. So we fall back
328 * to GL_NEAREST_MIPMAP_NEAREST. We'll let true trilinear
329 * enabled for V2, V3.
331 if (!fxMesa
->HaveCmbExt
) {
332 if (fxMesa
->haveTwoTMUs
) {
333 ti
->mmMode
= GR_MIPMAP_NEAREST
;
334 ti
->LODblend
= FXTRUE
;
336 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
337 ti
->LODblend
= FXFALSE
;
339 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
342 case GL_NEAREST_MIPMAP_NEAREST
:
343 ti
->mmMode
= GR_MIPMAP_NEAREST
;
344 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
345 ti
->LODblend
= FXFALSE
;
347 case GL_LINEAR_MIPMAP_LINEAR
:
349 * currently Napalm can't do single-pass trilinear,
350 * because the way its combiners are set. So we fall back
351 * to GL_LINEAR_MIPMAP_NEAREST. We'll let true trilinear
352 * enabled for V2, V3.
354 if (!fxMesa
->HaveCmbExt
) {
355 if (fxMesa
->haveTwoTMUs
) {
356 ti
->mmMode
= GR_MIPMAP_NEAREST
;
357 ti
->LODblend
= FXTRUE
;
359 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
360 ti
->LODblend
= FXFALSE
;
362 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
365 case GL_LINEAR_MIPMAP_NEAREST
:
366 ti
->mmMode
= GR_MIPMAP_NEAREST
;
367 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
368 ti
->LODblend
= FXFALSE
;
373 fxTexInvalidate(ctx
, tObj
);
376 case GL_TEXTURE_MAG_FILTER
:
379 ti
->maxFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
382 ti
->maxFilt
= GR_TEXTUREFILTER_BILINEAR
;
387 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
390 case GL_TEXTURE_WRAP_S
:
392 case GL_MIRRORED_REPEAT
:
393 ti
->sClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
395 case GL_CLAMP_TO_BORDER
: /* no-no, but don't REPEAT, either */
396 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
398 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
401 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
406 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
409 case GL_TEXTURE_WRAP_T
:
411 case GL_MIRRORED_REPEAT
:
412 ti
->tClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
414 case GL_CLAMP_TO_BORDER
: /* no-no, but don't REPEAT, either */
415 case GL_CLAMP_TO_EDGE
: /* CLAMP discarding border */
417 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
420 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
425 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
428 case GL_TEXTURE_BORDER_COLOR
:
432 case GL_TEXTURE_MIN_LOD
:
435 case GL_TEXTURE_MAX_LOD
:
438 case GL_TEXTURE_BASE_LEVEL
:
439 fxTexInvalidate(ctx
, tObj
);
441 case GL_TEXTURE_MAX_LEVEL
:
442 fxTexInvalidate(ctx
, tObj
);
451 fxDDTexDel(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
453 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
454 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
456 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
457 fprintf(stderr
, "fxDDTexDel(%d, %p)\n", tObj
->Name
, (void *) ti
);
463 fxTMFreeTexture(fxMesa
, tObj
);
466 tObj
->DriverData
= NULL
;
468 /* Free mipmap images and the texture object itself */
469 _mesa_delete_texture_object(ctx
, tObj
);
474 * Allocate a new texture object.
475 * Called via ctx->Driver.NewTextureObject.
476 * Note: this function will be called during context creation to
477 * allocate the default texture objects.
479 struct gl_texture_object
*
480 fxDDNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
482 struct gl_texture_object
*obj
;
483 obj
= _mesa_new_texture_object(ctx
, name
, target
);
489 * Return true if texture is resident, false otherwise.
492 fxDDIsTextureResident(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
494 tfxTexInfo
*ti
= fxTMGetTexInfo(tObj
);
495 return (ti
&& ti
->isInTM
);
501 * Convert a gl_color_table texture palette to Glide's format.
504 convertPalette(const fxMesaContext fxMesa
, FxU32 data
[256], const struct gl_color_table
*table
)
506 const GLubyte
*tableUB
= (const GLubyte
*) table
->Table
;
507 GLint width
= table
->Size
;
511 ASSERT(table
->Type
== GL_UNSIGNED_BYTE
);
513 switch (table
->Format
) {
515 for (i
= 0; i
< width
; i
++) {
520 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
522 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
524 for (i
= 0; i
< width
; i
++) {
529 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
531 return GR_TEXTABLE_PALETTE
;
533 for (i
= 0; i
< width
; i
++) {
536 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
538 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
539 case GL_LUMINANCE_ALPHA
:
540 for (i
= 0; i
< width
; i
++) {
541 r
= g
= b
= tableUB
[i
* 2 + 0];
542 a
= tableUB
[i
* 2 + 1];
543 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
545 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
548 for (i
= 0; i
< width
; i
++) {
549 r
= tableUB
[i
* 3 + 0];
550 g
= tableUB
[i
* 3 + 1];
551 b
= tableUB
[i
* 3 + 2];
553 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
555 return GR_TEXTABLE_PALETTE
;
557 for (i
= 0; i
< width
; i
++) {
558 r
= tableUB
[i
* 4 + 0];
559 g
= tableUB
[i
* 4 + 1];
560 b
= tableUB
[i
* 4 + 2];
561 a
= tableUB
[i
* 4 + 3];
562 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
564 return fxMesa
->HavePalExt
? GR_TEXTABLE_PALETTE_6666_EXT
: GR_TEXTABLE_PALETTE
;
570 fxDDTexPalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
572 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
575 /* per-texture palette */
577 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
578 fprintf(stderr
, "fxDDTexPalette(%d, %x)\n",
579 tObj
->Name
, (GLuint
) tObj
->DriverData
);
581 /* This might be a proxy texture. */
582 if (!tObj
->Palette
.Table
)
584 if (!tObj
->DriverData
)
585 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
586 ti
= fxTMGetTexInfo(tObj
);
587 ti
->paltype
= convertPalette(fxMesa
, ti
->palette
.data
, &tObj
->Palette
);
588 fxTexInvalidate(ctx
, tObj
);
591 /* global texture palette */
592 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
593 fprintf(stderr
, "fxDDTexPalette(global)\n");
595 fxMesa
->glbPalType
= convertPalette(fxMesa
, fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
596 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
598 grTexDownloadTable(fxMesa
->glbPalType
, &(fxMesa
->glbPalette
));
604 fxDDTexUseGlbPalette(GLcontext
* ctx
, GLboolean state
)
606 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
608 if (TDFX_DEBUG
& VERBOSE_DRIVER
) {
609 fprintf(stderr
, "fxDDTexUseGlbPalette(%d)\n", state
);
612 fxMesa
->haveGlobalPaletteTexture
= state
;
613 fxMesa
->new_state
|= FX_NEW_TEXTURING
;
641 * w, h - source texture width and height
642 * lodlevel - Glide lod level token for the larger texture dimension
643 * ar - Glide aspect ratio token
644 * sscale - S scale factor used during triangle setup
645 * tscale - T scale factor used during triangle setup
646 * wscale - OpenGL -> Glide image width scale factor
647 * hscale - OpenGL -> Glide image height scale factor
650 fxTexGetInfo(int w
, int h
, GrLOD_t
* lodlevel
, GrAspectRatio_t
* ar
,
651 float *sscale
, float *tscale
,
652 int *wscale
, int *hscale
)
654 int logw
, logh
, ws
, hs
;
656 GrAspectRatio_t aspectratio
;
662 l
= MAX2(logw
, logh
);
663 aspectratio
= logw
- logh
;
667 /* hardware only allows a maximum aspect ratio of 8x1, so handle
668 * |aspectratio| > 3 by scaling the image and using an 8x1 aspect
671 switch (aspectratio
) {
693 if (aspectratio
> 3) {
695 hs
= 1 << (aspectratio
- 3);
696 aspectratio
= GR_ASPECT_LOG2_8x1
;
697 } else /*if (aspectratio < -3)*/ {
699 ws
= 1 << (-aspectratio
- 3);
700 aspectratio
= GR_ASPECT_LOG2_1x8
;
727 fxIsTexSupported(GLenum target
, GLint internalFormat
,
728 const struct gl_texture_image
*image
)
730 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
734 if (!fxTexGetInfo(image
->Width
, image
->Height
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
))
738 if (image
->Border
> 0)
745 /**********************************************************************/
746 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
747 /**********************************************************************/
749 fxt1_decode_1 (const void *texture
, int width
,
750 int i
, int j
, unsigned char *rgba
);
752 /* Texel-fetch functions for software texturing and glGetTexImage().
753 * We should have been able to use some "standard" fetch functions (which
754 * may get defined in texutil.c) but we have to account for scaled texture
755 * images on tdfx hardware (the 8:1 aspect ratio limit).
756 * Hence, we need special functions here.
760 fetch_intensity8(const struct gl_texture_image
*texImage
,
761 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
763 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
764 const GLubyte
*texel
;
769 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
770 rgba
[RCOMP
] = *texel
;
771 rgba
[GCOMP
] = *texel
;
772 rgba
[BCOMP
] = *texel
;
773 rgba
[ACOMP
] = *texel
;
778 fetch_luminance8(const struct gl_texture_image
*texImage
,
779 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
781 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
782 const GLubyte
*texel
;
787 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
788 rgba
[RCOMP
] = *texel
;
789 rgba
[GCOMP
] = *texel
;
790 rgba
[BCOMP
] = *texel
;
796 fetch_alpha8(const struct gl_texture_image
*texImage
,
797 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
799 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
800 const GLubyte
*texel
;
805 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
809 rgba
[ACOMP
] = *texel
;
814 fetch_index8(const struct gl_texture_image
*texImage
,
815 GLint i
, GLint j
, GLint k
, GLchan
*indexOut
)
817 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
818 const GLubyte
*texel
;
823 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
829 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
830 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
832 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
833 const GLubyte
*texel
;
838 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
839 rgba
[RCOMP
] = texel
[0];
840 rgba
[GCOMP
] = texel
[0];
841 rgba
[BCOMP
] = texel
[0];
842 rgba
[ACOMP
] = texel
[1];
847 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
848 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
850 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
851 const GLushort
*texel
;
856 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
857 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 11) & 0x1F];
858 rgba
[GCOMP
] = FX_rgb_scale_6
[(*texel
>> 5) & 0x3F];
859 rgba
[BCOMP
] = FX_rgb_scale_5
[ *texel
& 0x1F];
865 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
866 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
868 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
869 const GLushort
*texel
;
874 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
875 rgba
[RCOMP
] = FX_rgb_scale_4
[(*texel
>> 8) & 0xF];
876 rgba
[GCOMP
] = FX_rgb_scale_4
[(*texel
>> 4) & 0xF];
877 rgba
[BCOMP
] = FX_rgb_scale_4
[ *texel
& 0xF];
878 rgba
[ACOMP
] = FX_rgb_scale_4
[(*texel
>> 12) & 0xF];
883 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
884 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
886 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
887 const GLushort
*texel
;
892 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
893 rgba
[RCOMP
] = FX_rgb_scale_5
[(*texel
>> 10) & 0x1F];
894 rgba
[GCOMP
] = FX_rgb_scale_5
[(*texel
>> 5) & 0x1F];
895 rgba
[BCOMP
] = FX_rgb_scale_5
[ *texel
& 0x1F];
896 rgba
[ACOMP
] = (*texel
>> 15) * 255;
901 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
902 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
904 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
910 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
911 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
912 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
913 rgba
[BCOMP
] = (((*texel
) ) & 0xff);
914 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
919 fetch_rgb_fxt1(const struct gl_texture_image
*texImage
,
920 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
922 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
927 fxt1_decode_1(texImage
->Data
, mml
->width
, i
, j
, rgba
);
933 fetch_rgba_fxt1(const struct gl_texture_image
*texImage
,
934 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
936 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
941 fxt1_decode_1(texImage
->Data
, mml
->width
, i
, j
, rgba
);
946 fetch_rgb_dxt1(const struct gl_texture_image
*texImage
,
947 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
949 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
954 _mesa_texformat_rgb_dxt1
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
959 fetch_rgba_dxt1(const struct gl_texture_image
*texImage
,
960 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
962 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
967 _mesa_texformat_rgba_dxt1
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
972 fetch_rgba_dxt3(const struct gl_texture_image
*texImage
,
973 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
975 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
980 _mesa_texformat_rgba_dxt3
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
985 fetch_rgba_dxt5(const struct gl_texture_image
*texImage
,
986 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
988 const tfxMipMapLevel
*mml
= FX_MIPMAP_DATA(texImage
);
993 _mesa_texformat_rgba_dxt5
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
997 #if 0 /* break glass in case of emergency */
999 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
1002 for (i
= 0; i
< h
; i
++) {
1003 for (j
= 0; j
< w
; j
++) {
1005 fprintf(stderr
, "%02x %02x ", data
[0], data
[1]);
1007 fprintf(stderr
, "%02x %02x %02x ", data
[0], data
[1], data
[2]);
1010 fprintf(stderr
, "\n");
1016 const struct gl_texture_format
*
1017 fxDDChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
1018 GLenum srcFormat
, GLenum srcType
)
1020 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1021 GLboolean allow32bpt
= fxMesa
->HaveTexFmt
;
1023 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1024 fprintf(stderr
, "fxDDChooseTextureFormat(...)\n");
1027 switch (internalFormat
) {
1028 case GL_COMPRESSED_RGB
:
1029 /* intentional fall through */
1032 if ( srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1033 return &_mesa_texformat_rgb565
;
1035 /* intentional fall through */
1040 return (allow32bpt
) ? &_mesa_texformat_argb8888
1041 : &_mesa_texformat_rgb565
;
1044 return &_mesa_texformat_argb4444
;
1045 case GL_COMPRESSED_RGBA
:
1046 /* intentional fall through */
1049 if ( srcFormat
== GL_BGRA
) {
1050 if ( srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) {
1051 return &_mesa_texformat_argb8888
;
1053 else if ( srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1054 return &_mesa_texformat_argb4444
;
1056 else if ( srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1057 return &_mesa_texformat_argb1555
;
1060 /* intentional fall through */
1065 return (allow32bpt
) ? &_mesa_texformat_argb8888
1066 : &_mesa_texformat_argb4444
;
1070 case GL_INTENSITY12
:
1071 case GL_INTENSITY16
:
1072 case GL_COMPRESSED_INTENSITY
:
1073 return &_mesa_texformat_i8
;
1078 case GL_LUMINANCE12
:
1079 case GL_LUMINANCE16
:
1080 case GL_COMPRESSED_LUMINANCE
:
1081 return &_mesa_texformat_l8
;
1087 case GL_COMPRESSED_ALPHA
:
1088 return &_mesa_texformat_a8
;
1089 case GL_COLOR_INDEX
:
1090 case GL_COLOR_INDEX1_EXT
:
1091 case GL_COLOR_INDEX2_EXT
:
1092 case GL_COLOR_INDEX4_EXT
:
1093 case GL_COLOR_INDEX8_EXT
:
1094 case GL_COLOR_INDEX12_EXT
:
1095 case GL_COLOR_INDEX16_EXT
:
1096 return &_mesa_texformat_ci8
;
1098 case GL_LUMINANCE_ALPHA
:
1099 case GL_LUMINANCE4_ALPHA4
:
1100 case GL_LUMINANCE6_ALPHA2
:
1101 case GL_LUMINANCE8_ALPHA8
:
1102 case GL_LUMINANCE12_ALPHA4
:
1103 case GL_LUMINANCE12_ALPHA12
:
1104 case GL_LUMINANCE16_ALPHA16
:
1105 case GL_COMPRESSED_LUMINANCE_ALPHA
:
1106 return &_mesa_texformat_al88
;
1110 return &_mesa_texformat_rgb565
;
1112 return &_mesa_texformat_argb1555
;
1113 /* GL_EXT_texture_compression_s3tc */
1115 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1118 return &_mesa_texformat_rgb_dxt1
;
1119 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1120 return &_mesa_texformat_rgba_dxt1
;
1121 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1124 return &_mesa_texformat_rgba_dxt3
;
1125 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1126 return &_mesa_texformat_rgba_dxt5
;
1127 /* GL_3DFX_texture_compression_FXT1 */
1128 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1129 return &_mesa_texformat_rgb_fxt1
;
1130 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1131 return &_mesa_texformat_rgba_fxt1
;
1133 _mesa_problem(NULL
, "unexpected format in fxDDChooseTextureFormat");
1139 static GrTextureFormat_t
1140 fxGlideFormat(GLint mesaFormat
)
1142 switch (mesaFormat
) {
1143 case MESA_FORMAT_I8
:
1144 return GR_TEXFMT_ALPHA_8
;
1145 case MESA_FORMAT_A8
:
1146 return GR_TEXFMT_ALPHA_8
;
1147 case MESA_FORMAT_L8
:
1148 return GR_TEXFMT_INTENSITY_8
;
1149 case MESA_FORMAT_CI8
:
1150 return GR_TEXFMT_P_8
;
1151 case MESA_FORMAT_AL88
:
1152 return GR_TEXFMT_ALPHA_INTENSITY_88
;
1153 case MESA_FORMAT_RGB565
:
1154 return GR_TEXFMT_RGB_565
;
1155 case MESA_FORMAT_ARGB4444
:
1156 return GR_TEXFMT_ARGB_4444
;
1157 case MESA_FORMAT_ARGB1555
:
1158 return GR_TEXFMT_ARGB_1555
;
1159 case MESA_FORMAT_ARGB8888
:
1160 return GR_TEXFMT_ARGB_8888
;
1161 case MESA_FORMAT_RGB_FXT1
:
1162 case MESA_FORMAT_RGBA_FXT1
:
1163 return GR_TEXFMT_ARGB_CMP_FXT1
;
1164 case MESA_FORMAT_RGB_DXT1
:
1165 case MESA_FORMAT_RGBA_DXT1
:
1166 return GR_TEXFMT_ARGB_CMP_DXT1
;
1167 case MESA_FORMAT_RGBA_DXT3
:
1168 return GR_TEXFMT_ARGB_CMP_DXT3
;
1169 case MESA_FORMAT_RGBA_DXT5
:
1170 return GR_TEXFMT_ARGB_CMP_DXT5
;
1172 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
1178 static FetchTexelFuncC
1179 fxFetchFunction(GLint mesaFormat
)
1181 switch (mesaFormat
) {
1182 case MESA_FORMAT_I8
:
1183 return &fetch_intensity8
;
1184 case MESA_FORMAT_A8
:
1185 return &fetch_alpha8
;
1186 case MESA_FORMAT_L8
:
1187 return &fetch_luminance8
;
1188 case MESA_FORMAT_CI8
:
1189 return &fetch_index8
;
1190 case MESA_FORMAT_AL88
:
1191 return &fetch_luminance8_alpha8
;
1192 case MESA_FORMAT_RGB565
:
1193 return &fetch_r5g6b5
;
1194 case MESA_FORMAT_ARGB4444
:
1195 return &fetch_r4g4b4a4
;
1196 case MESA_FORMAT_ARGB1555
:
1197 return &fetch_r5g5b5a1
;
1198 case MESA_FORMAT_ARGB8888
:
1199 return &fetch_a8r8g8b8
;
1200 case MESA_FORMAT_RGB_FXT1
:
1201 return &fetch_rgb_fxt1
;
1202 case MESA_FORMAT_RGBA_FXT1
:
1203 return &fetch_rgba_fxt1
;
1204 case MESA_FORMAT_RGB_DXT1
:
1205 return &fetch_rgb_dxt1
;
1206 case MESA_FORMAT_RGBA_DXT1
:
1207 return &fetch_rgba_dxt1
;
1208 case MESA_FORMAT_RGBA_DXT3
:
1209 return &fetch_rgba_dxt3
;
1210 case MESA_FORMAT_RGBA_DXT5
:
1211 return &fetch_rgba_dxt5
;
1213 _mesa_problem(NULL
, "Unexpected format in fxFetchFunction");
1220 adjust2DRatio (GLcontext
*ctx
,
1221 GLint xoffset
, GLint yoffset
,
1222 GLint width
, GLint height
,
1223 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1224 const struct gl_pixelstore_attrib
*packing
,
1225 tfxMipMapLevel
*mml
,
1226 struct gl_texture_image
*texImage
,
1230 const GLint newWidth
= width
* mml
->wScale
;
1231 const GLint newHeight
= height
* mml
->hScale
;
1234 if (!texImage
->IsCompressed
) {
1236 tempImage
= MALLOC(width
* height
* texelBytes
);
1241 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->Format
,
1242 texImage
->TexFormat
, tempImage
,
1243 0, 0, 0, /* dstX/Y/Zoffset */
1244 width
* texelBytes
, /* dstRowStride */
1245 0, /* dstImageStride */
1247 format
, type
, pixels
, packing
);
1250 /* compute address of dest subimage within the overal tex image */
1251 destAddr
= (GLubyte
*) texImage
->Data
1252 + (yoffset
* mml
->hScale
* mml
->width
1253 + xoffset
* mml
->wScale
) * texelBytes
;
1255 _mesa_rescale_teximage2d(texelBytes
,
1257 dstRowStride
, /* dst stride */
1259 newWidth
, newHeight
,
1260 tempImage
, destAddr
);
1262 const GLint rawBytes
= 4;
1263 GLvoid
*rawImage
= MALLOC(width
* height
* rawBytes
);
1267 tempImage
= MALLOC(newWidth
* newHeight
* rawBytes
);
1271 /* unpack image, apply transfer ops and store in rawImage */
1272 _mesa_texstore_rgba8888(ctx
, 2, GL_RGBA
,
1273 &_mesa_texformat_rgba8888_rev
, rawImage
,
1274 0, 0, 0, /* dstX/Y/Zoffset */
1275 width
* rawBytes
, /* dstRowStride */
1276 0, /* dstImageStride */
1278 format
, type
, pixels
, packing
);
1279 _mesa_rescale_teximage2d(rawBytes
,
1281 newWidth
* rawBytes
, /* dst stride */
1282 width
, height
, /* src */
1283 newWidth
, newHeight
, /* dst */
1284 rawImage
/*src*/, tempImage
/*dst*/ );
1285 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->Format
,
1286 texImage
->TexFormat
, texImage
->Data
,
1287 xoffset
* mml
->wScale
, yoffset
* mml
->hScale
, 0, /* dstX/Y/Zoffset */
1289 0, /* dstImageStride */
1290 newWidth
, newHeight
, 1,
1291 GL_RGBA
, CHAN_TYPE
, tempImage
, &ctx
->DefaultPacking
);
1302 fxDDTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1303 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1304 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1305 const struct gl_pixelstore_attrib
*packing
,
1306 struct gl_texture_object
*texObj
,
1307 struct gl_texture_image
*texImage
)
1309 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1311 tfxMipMapLevel
*mml
;
1312 GLint texelBytes
, dstRowStride
;
1314 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1315 fprintf(stderr
, "fxDDTexImage2D: id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1316 texObj
->Name
, texImage
->IntFormat
, format
, type
,
1317 texImage
->Width
, texImage
->Height
);
1320 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1321 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDTexImg()\n");
1325 if (!texObj
->DriverData
) {
1326 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1327 if (!texObj
->DriverData
) {
1328 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1332 ti
= fxTMGetTexInfo(texObj
);
1334 if (!texImage
->DriverData
) {
1335 texImage
->DriverData
= CALLOC(sizeof(tfxMipMapLevel
));
1336 if (!texImage
->DriverData
) {
1337 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1341 mml
= FX_MIPMAP_DATA(texImage
);
1343 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1344 &mml
->wScale
, &mml
->hScale
);
1346 mml
->width
= width
* mml
->wScale
;
1347 mml
->height
= height
* mml
->hScale
;
1349 #if FX_COMPRESS_S3TC_AS_FXT1_HACK
1350 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1351 if (!ctx
->Mesa_DXTn
&& texImage
->IsCompressed
) {
1352 switch (internalFormat
) {
1353 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1356 internalFormat
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1358 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1359 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1360 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1363 internalFormat
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1365 texImage
->IntFormat
= internalFormat
;
1369 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1370 GLenum texNapalm
= 0;
1371 if (internalFormat
== GL_COMPRESSED_RGB
) {
1372 texNapalm
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1373 } else if (internalFormat
== GL_COMPRESSED_RGBA
) {
1374 texNapalm
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1377 texImage
->IntFormat
= internalFormat
= texNapalm
;
1378 texImage
->IsCompressed
= GL_TRUE
;
1383 /* choose the texture format */
1384 assert(ctx
->Driver
.ChooseTextureFormat
);
1385 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1386 internalFormat
, format
, type
);
1387 assert(texImage
->TexFormat
);
1388 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1389 /*if (!fxMesa->HaveTexFmt) assert(texelBytes == 1 || texelBytes == 2);*/
1391 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1393 /* allocate mipmap buffer */
1394 assert(!texImage
->Data
);
1395 if (texImage
->IsCompressed
) {
1396 texImage
->CompressedSize
= _mesa_compressed_texture_size(ctx
,
1401 dstRowStride
= _mesa_compressed_row_stride(internalFormat
, mml
->width
);
1402 texImage
->Data
= MESA_PBUFFER_ALLOC(texImage
->CompressedSize
);
1404 dstRowStride
= mml
->width
* texelBytes
;
1405 texImage
->Data
= MESA_PBUFFER_ALLOC(mml
->width
* mml
->height
* texelBytes
);
1407 if (!texImage
->Data
) {
1408 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1412 if (pixels
!= NULL
) {
1413 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1414 /* rescale image to overcome 1:8 aspect limitation */
1415 if (!adjust2DRatio(ctx
,
1418 format
, type
, pixels
,
1425 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1430 /* no rescaling needed */
1431 /* unpack image, apply transfer ops and store in texImage->Data */
1432 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->Format
,
1433 texImage
->TexFormat
, texImage
->Data
,
1434 0, 0, 0, /* dstX/Y/Zoffset */
1436 0, /* dstImageStride */
1438 format
, type
, pixels
, packing
);
1441 /* GL_SGIS_generate_mipmap */
1442 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1443 GLint mipWidth
, mipHeight
;
1444 tfxMipMapLevel
*mip
;
1445 struct gl_texture_image
*mipImage
;
1446 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1447 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1449 assert(!texImage
->IsCompressed
);
1451 while (level
< texObj
->MaxLevel
&& level
< maxLevels
- 1) {
1452 mipWidth
= width
/ 2;
1456 mipHeight
= height
/ 2;
1460 if ((mipWidth
== width
) && (mipHeight
== height
)) {
1463 _mesa_TexImage2D(target
, ++level
, internalFormat
,
1464 mipWidth
, mipHeight
, border
,
1467 mipImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1468 mip
= FX_MIPMAP_DATA(mipImage
);
1469 _mesa_halve2x2_teximage2d(ctx
,
1472 mml
->width
, mml
->height
,
1473 texImage
->Data
, mipImage
->Data
);
1474 texImage
= mipImage
;
1482 ti
->info
.format
= mml
->glideFormat
;
1483 texImage
->FetchTexelc
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1485 fxTexInvalidate(ctx
, texObj
);
1490 fxDDTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
1491 GLint xoffset
, GLint yoffset
,
1492 GLsizei width
, GLsizei height
,
1493 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1494 const struct gl_pixelstore_attrib
*packing
,
1495 struct gl_texture_object
*texObj
,
1496 struct gl_texture_image
*texImage
)
1498 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1500 tfxMipMapLevel
*mml
;
1501 GLint texelBytes
, dstRowStride
;
1503 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1504 fprintf(stderr
, "fxDDTexSubImage2D: id=%d\n", texObj
->Name
);
1507 if (!texObj
->DriverData
) {
1508 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1512 ti
= fxTMGetTexInfo(texObj
);
1514 mml
= FX_MIPMAP_DATA(texImage
);
1517 assert(texImage
->Data
); /* must have an existing texture image! */
1518 assert(texImage
->Format
);
1520 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1521 if (texImage
->IsCompressed
) {
1522 dstRowStride
= _mesa_compressed_row_stride(texImage
->IntFormat
, mml
->width
);
1524 dstRowStride
= mml
->width
* texelBytes
;
1527 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1528 /* need to rescale subimage to match mipmap level's rescale factors */
1529 if (!adjust2DRatio(ctx
,
1532 format
, type
, pixels
,
1539 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1544 /* no rescaling needed */
1545 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->Format
,
1546 texImage
->TexFormat
, (GLubyte
*) texImage
->Data
,
1547 xoffset
, yoffset
, 0, /* dstX/Y/Zoffset */
1549 0, /* dstImageStride */
1551 format
, type
, pixels
, packing
);
1554 /* GL_SGIS_generate_mipmap */
1555 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1556 GLint mipWidth
, mipHeight
;
1557 tfxMipMapLevel
*mip
;
1558 struct gl_texture_image
*mipImage
;
1559 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1560 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1562 assert(!texImage
->IsCompressed
);
1564 width
= texImage
->Width
;
1565 height
= texImage
->Height
;
1566 while (level
< texObj
->MaxLevel
&& level
< maxLevels
- 1) {
1567 mipWidth
= width
/ 2;
1571 mipHeight
= height
/ 2;
1575 if ((mipWidth
== width
) && (mipHeight
== height
)) {
1579 mipImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1580 mip
= FX_MIPMAP_DATA(mipImage
);
1581 _mesa_halve2x2_teximage2d(ctx
,
1584 mml
->width
, mml
->height
,
1585 texImage
->Data
, mipImage
->Data
);
1586 texImage
= mipImage
;
1593 if (ti
->validated
&& ti
->isInTM
&& !texObj
->GenerateMipmap
)
1594 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1596 fxTexInvalidate(ctx
, texObj
);
1601 fxDDCompressedTexImage2D (GLcontext
*ctx
, GLenum target
,
1602 GLint level
, GLint internalFormat
,
1603 GLsizei width
, GLsizei height
, GLint border
,
1604 GLsizei imageSize
, const GLvoid
*data
,
1605 struct gl_texture_object
*texObj
,
1606 struct gl_texture_image
*texImage
)
1608 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1610 tfxMipMapLevel
*mml
;
1612 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1613 fprintf(stderr
, "fxDDCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1614 texObj
->Name
, internalFormat
,
1618 assert(texImage
->IsCompressed
);
1620 if (!fxIsTexSupported(target
, internalFormat
, texImage
)) {
1621 _mesa_problem(NULL
, "fx Driver: unsupported texture in fxDDCompressedTexImg()\n");
1625 if (!texObj
->DriverData
) {
1626 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1627 if (!texObj
->DriverData
) {
1628 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1632 ti
= fxTMGetTexInfo(texObj
);
1634 if (!texImage
->DriverData
) {
1635 texImage
->DriverData
= CALLOC(sizeof(tfxMipMapLevel
));
1636 if (!texImage
->DriverData
) {
1637 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1641 mml
= FX_MIPMAP_DATA(texImage
);
1643 fxTexGetInfo(width
, height
, NULL
, NULL
, NULL
, NULL
,
1644 &mml
->wScale
, &mml
->hScale
);
1646 mml
->width
= width
* mml
->wScale
;
1647 mml
->height
= height
* mml
->hScale
;
1650 /* choose the texture format */
1651 assert(ctx
->Driver
.ChooseTextureFormat
);
1652 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1653 internalFormat
, -1/*format*/, -1/*type*/);
1654 assert(texImage
->TexFormat
);
1656 /* Determine the appropriate Glide texel format,
1657 * given the user's internal texture format hint.
1659 mml
->glideFormat
= fxGlideFormat(texImage
->TexFormat
->MesaFormat
);
1661 /* allocate new storage for texture image, if needed */
1662 if (!texImage
->Data
) {
1663 texImage
->CompressedSize
= _mesa_compressed_texture_size(ctx
,
1668 texImage
->Data
= MESA_PBUFFER_ALLOC(texImage
->CompressedSize
);
1669 if (!texImage
->Data
) {
1670 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1675 /* save the texture data */
1676 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1677 /* [dBorca] Hack alert:
1678 * now we're screwed. We can't decompress,
1679 * unless we do it in HW (via textureBuffer).
1680 * We still have some chances:
1681 * 1) we got FXT1 textures - we CAN decompress, rescale for
1682 * aspectratio, then compress back.
1683 * 2) there is a chance that MIN("s", "t") won't be overflowed.
1684 * Thus, we don't care about textureclamp and we could lower
1685 * MIN("uscale", "vscale") below 32. We still have to have
1686 * our data aligned inside a 8:1 rectangle.
1687 * 3) just in case if MIN("s", "t") gets overflowed with GL_REPEAT,
1688 * we replicate the data over the padded area.
1689 * For now, we take 2) + 3) but texelfetchers will be wrong!
1691 GLuint srcRowStride
= _mesa_compressed_row_stride(internalFormat
, width
);
1693 GLuint destRowStride
= _mesa_compressed_row_stride(internalFormat
,
1696 _mesa_upscale_teximage2d(srcRowStride
, (height
+3) / 4,
1697 destRowStride
, (mml
->height
+3) / 4,
1698 1, data
, srcRowStride
,
1700 ti
->padded
= GL_TRUE
;
1702 MEMCPY(texImage
->Data
, data
, texImage
->CompressedSize
);
1705 ti
->info
.format
= mml
->glideFormat
;
1706 texImage
->FetchTexelc
= fxFetchFunction(texImage
->TexFormat
->MesaFormat
);
1708 /* GL_SGIS_generate_mipmap */
1709 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1710 assert(!texImage
->IsCompressed
);
1713 fxTexInvalidate(ctx
, texObj
);
1718 fxDDCompressedTexSubImage2D( GLcontext
*ctx
, GLenum target
,
1719 GLint level
, GLint xoffset
,
1720 GLint yoffset
, GLsizei width
,
1721 GLint height
, GLenum format
,
1722 GLsizei imageSize
, const GLvoid
*data
,
1723 struct gl_texture_object
*texObj
,
1724 struct gl_texture_image
*texImage
)
1726 fxMesaContext fxMesa
= FX_CONTEXT(ctx
);
1728 tfxMipMapLevel
*mml
;
1729 GLint destRowStride
, srcRowStride
;
1733 if (TDFX_DEBUG
& VERBOSE_TEXTURE
) {
1734 fprintf(stderr
, "fxDDCompressedTexSubImage2D: id=%d\n", texObj
->Name
);
1737 ti
= fxTMGetTexInfo(texObj
);
1739 mml
= FX_MIPMAP_DATA(texImage
);
1742 srcRowStride
= _mesa_compressed_row_stride(texImage
->IntFormat
, width
);
1744 destRowStride
= _mesa_compressed_row_stride(texImage
->IntFormat
,
1746 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
1747 texImage
->IntFormat
,
1749 (GLubyte
*) texImage
->Data
);
1751 rows
= height
/ 4; /* hardcoded 4, but works for FXT1/DXTC */
1753 for (i
= 0; i
< rows
; i
++) {
1754 MEMCPY(dest
, data
, srcRowStride
);
1755 dest
+= destRowStride
;
1756 data
= (GLvoid
*)((GLuint
)data
+ (GLuint
)srcRowStride
);
1759 /* [dBorca] Hack alert:
1760 * see fxDDCompressedTexImage2D for caveats
1762 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1763 srcRowStride
= _mesa_compressed_row_stride(texImage
->IntFormat
, texImage
->Width
);
1765 destRowStride
= _mesa_compressed_row_stride(texImage
->IntFormat
,
1767 _mesa_upscale_teximage2d(srcRowStride
, texImage
->Height
/ 4,
1768 destRowStride
, mml
->height
/ 4,
1769 1, texImage
->Data
, destRowStride
,
1773 /* GL_SGIS_generate_mipmap */
1774 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1775 assert(!texImage
->IsCompressed
);
1778 if (ti
->validated
&& ti
->isInTM
)
1779 fxTMReloadMipMapLevel(fxMesa
, texObj
, level
);
1781 fxTexInvalidate(ctx
, texObj
);
1786 fxDDTexImage1D (GLcontext
*ctx
, GLenum target
, GLint level
,
1787 GLint internalFormat
, GLint width
, GLint border
,
1788 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1789 const struct gl_pixelstore_attrib
*packing
,
1790 struct gl_texture_object
*texObj
,
1791 struct gl_texture_image
*texImage
)
1793 fxDDTexImage2D(ctx
, target
, level
,
1794 internalFormat
, width
, 1, border
,
1795 format
, type
, pixels
,
1803 fxDDTexSubImage1D(GLcontext
* ctx
, GLenum target
, GLint level
,
1806 GLenum format
, GLenum type
, const GLvoid
* pixels
,
1807 const struct gl_pixelstore_attrib
*packing
,
1808 struct gl_texture_object
*texObj
,
1809 struct gl_texture_image
*texImage
)
1811 fxDDTexSubImage2D(ctx
, target
, level
,
1812 xoffset
, 0, width
, 1,
1813 format
, type
, pixels
,
1821 fxDDTestProxyTexImage (GLcontext
*ctx
, GLenum target
,
1822 GLint level
, GLint internalFormat
,
1823 GLenum format
, GLenum type
,
1824 GLint width
, GLint height
,
1825 GLint depth
, GLint border
)
1827 /* XXX todo - maybe through fxTexValidate() */
1828 return _mesa_test_proxy_teximage(ctx
, target
,
1829 level
, internalFormat
,
1839 * Need this to provide at least one external definition.
1842 extern int gl_fx_dummy_function_ddtex(void);
1844 gl_fx_dummy_function_ddtex(void)