1 /* -*- mode: c; c-basic-offset: 3 -*-
3 * Copyright 2000 VA Linux Systems Inc., Fremont, California.
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 (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * VA LINUX SYSTEMS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * Daniel Borca <dborca@users.sourceforge.net>, 19 Jul 2004
32 * Gareth Hughes <gareth@valinux.com>, 29 Sep - 1 Oct 2000
35 * Gareth Hughes <gareth@valinux.com>
36 * Brian Paul <brianp@valinux.com>
41 #include "main/enums.h"
42 #include "main/image.h"
43 #include "main/mipmap.h"
44 #include "main/texcompress.h"
45 #include "main/texformat.h"
46 #include "main/teximage.h"
47 #include "main/texstore.h"
48 #include "main/texobj.h"
49 #include "tdfx_context.h"
51 #include "tdfx_texman.h"
54 /* no borders! can't halve 1x1! (stride > width * comp) not allowed */
56 _mesa_halve2x2_teximage2d ( GLcontext
*ctx
,
57 struct gl_texture_image
*texImage
,
59 GLint srcWidth
, GLint srcHeight
,
60 const GLvoid
*srcImage
, GLvoid
*dstImage
)
63 GLint dstWidth
= srcWidth
/ 2;
64 GLint dstHeight
= srcHeight
/ 2;
65 GLint srcRowStride
= srcWidth
* bytesPerPixel
;
66 GLubyte
*src
= (GLubyte
*)srcImage
;
67 GLubyte
*dst
= dstImage
;
68 GLuint dstImageOffsets
= 0;
75 if (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_RGB565
) {
76 _t
= GL_UNSIGNED_SHORT_5_6_5_REV
;
78 } else if (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_ARGB4444
) {
79 _t
= GL_UNSIGNED_SHORT_4_4_4_4_REV
;
81 } else if (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_ARGB1555
) {
82 _t
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
87 srcRowStride
= srcWidth
* bytesPerPixel
;
94 _s
= src
= MALLOC(srcRowStride
* srcHeight
);
95 _d
= dst
= MALLOC(dstWidth
* bytesPerPixel
* dstHeight
);
96 _mesa_texstore_rgba8888(ctx
, 2, GL_RGBA
,
97 &_mesa_texformat_rgba8888_rev
, src
,
98 0, 0, 0, /* dstX/Y/Zoffset */
99 srcRowStride
, /* dstRowStride */
101 srcWidth
, srcHeight
, 1,
102 texImage
->_BaseFormat
, _t
, srcImage
, &ctx
->DefaultPacking
);
105 if (srcHeight
== 1) {
106 for (i
= 0; i
< dstWidth
; i
++) {
107 for (k
= 0; k
< bytesPerPixel
; k
++) {
108 dst
[0] = (src
[0] + src
[bytesPerPixel
] + 1) / 2;
112 src
+= bytesPerPixel
;
114 } else if (srcWidth
== 1) {
115 for (j
= 0; j
< dstHeight
; j
++) {
116 for (k
= 0; k
< bytesPerPixel
; k
++) {
117 dst
[0] = (src
[0] + src
[srcRowStride
] + 1) / 2;
124 for (j
= 0; j
< dstHeight
; j
++) {
125 for (i
= 0; i
< dstWidth
; i
++) {
126 for (k
= 0; k
< bytesPerPixel
; k
++) {
130 src
[srcRowStride
+ bytesPerPixel
] + 2) / 4;
134 src
+= bytesPerPixel
;
143 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->_BaseFormat
,
144 texImage
->TexFormat
, dstImage
,
145 0, 0, 0, /* dstX/Y/Zoffset */
148 dstWidth
, dstHeight
, 1,
149 GL_BGRA
, CHAN_TYPE
, dst
, &ctx
->DefaultPacking
);
180 * Compute various texture image parameters.
181 * Input: w, h - source texture width and height
182 * Output: lodlevel - Glide lod level token for the larger texture dimension
183 * aspectratio - Glide aspect ratio token
184 * sscale - S scale factor used during triangle setup
185 * tscale - T scale factor used during triangle setup
186 * wscale - OpenGL -> Glide image width scale factor
187 * hscale - OpenGL -> Glide image height scale factor
190 * w h lodlevel aspectRatio
191 * 128 128 GR_LOD_LOG2_128 (=7) GR_ASPECT_LOG2_1x1 (=0)
192 * 64 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x1 (=0)
193 * 64 32 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_2x1 (=1)
194 * 32 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x2 (=-1)
195 * 32 32 GR_LOD_LOG2_32 (=5) GR_ASPECT_LOG2_1x1 (=0)
198 tdfxTexGetInfo(const GLcontext
*ctx
, int w
, int h
,
199 GrLOD_t
*lodlevel
, GrAspectRatio_t
*aspectratio
,
200 float *sscale
, float *tscale
,
201 int *wscale
, int *hscale
)
203 int logw
, logh
, ar
, lod
, ws
, hs
;
211 ar
= logw
- logh
; /* aspect ratio = difference in log dimensions */
215 /* Hardware only allows a maximum aspect ratio of 8x1, so handle
216 |ar| > 3 by scaling the image and using an 8x1 aspect ratio */
220 if (ar
<= GR_ASPECT_LOG2_8x1
) {
224 /* have to stretch image height */
227 ar
= GR_ASPECT_LOG2_8x1
;
233 if (ar
>= GR_ASPECT_LOG2_1x8
) {
237 /* have to stretch image width */
240 ar
= GR_ASPECT_LOG2_1x8
;
245 *lodlevel
= (GrLOD_t
) lod
;
247 *aspectratio
= (GrAspectRatio_t
) ar
;
260 * We need to call this when a texture object's minification filter
261 * or texture image sizes change.
263 static void RevalidateTexture(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
265 tdfxTexInfo
*ti
= TDFX_TEXTURE_DATA(tObj
);
271 minl
= maxl
= tObj
->BaseLevel
;
273 if (tObj
->Image
[0][minl
]) {
274 maxl
= MIN2(tObj
->MaxLevel
, tObj
->Image
[0][minl
]->MaxLog2
);
276 /* compute largeLodLog2, aspect ratio and texcoord scale factors */
277 tdfxTexGetInfo(ctx
, tObj
->Image
[0][minl
]->Width
, tObj
->Image
[0][minl
]->Height
,
278 &ti
->info
.largeLodLog2
,
279 &ti
->info
.aspectRatioLog2
,
280 &(ti
->sScale
), &(ti
->tScale
), NULL
, NULL
);
283 if (tObj
->Image
[0][maxl
] && (tObj
->MinFilter
!= GL_NEAREST
) && (tObj
->MinFilter
!= GL_LINEAR
)) {
284 /* mipmapping: need to compute smallLodLog2 */
285 tdfxTexGetInfo(ctx
, tObj
->Image
[0][maxl
]->Width
,
286 tObj
->Image
[0][maxl
]->Height
,
287 &ti
->info
.smallLodLog2
, NULL
,
288 NULL
, NULL
, NULL
, NULL
);
291 /* not mipmapping: smallLodLog2 = largeLodLog2 */
292 ti
->info
.smallLodLog2
= ti
->info
.largeLodLog2
;
298 ti
->info
.data
= NULL
;
300 /* this is necessary because of fxDDCompressedTexImage2D */
302 struct gl_texture_image
*texImage
= tObj
->Image
[0][minl
];
303 tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
304 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
305 ti
->sScale
/= mml
->wScale
;
306 ti
->tScale
/= mml
->hScale
;
313 fxAllocTexObjData(tdfxContextPtr fxMesa
)
317 if (!(ti
= CALLOC(sizeof(tdfxTexInfo
)))) {
318 _mesa_problem(NULL
, "tdfx driver: out of memory");
322 ti
->isInTM
= GL_FALSE
;
324 ti
->whichTMU
= TDFX_TMU_NONE
;
326 ti
->tm
[TDFX_TMU0
] = NULL
;
327 ti
->tm
[TDFX_TMU1
] = NULL
;
329 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
330 ti
->magFilt
= GR_TEXTUREFILTER_BILINEAR
;
332 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
333 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
335 ti
->mmMode
= GR_MIPMAP_NEAREST
;
336 ti
->LODblend
= FXFALSE
;
343 * Called via glBindTexture.
346 tdfxBindTexture(GLcontext
* ctx
, GLenum target
,
347 struct gl_texture_object
*tObj
)
349 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
352 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
353 fprintf(stderr
, "fxmesa: fxDDTexBind(%d,%p)\n", tObj
->Name
,
357 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
360 if (!tObj
->DriverData
) {
361 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
364 ti
= TDFX_TEXTURE_DATA(tObj
);
365 ti
->lastTimeUsed
= fxMesa
->texBindNumber
++;
367 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
372 * Called via glTexEnv.
375 tdfxTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
376 const GLfloat
* param
)
378 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
380 if ( TDFX_DEBUG
& DEBUG_VERBOSE_API
) {
382 fprintf(stderr
, "fxmesa: texenv(%x,%x)\n", pname
,
385 fprintf(stderr
, "fxmesa: texenv(%x)\n", pname
);
388 /* XXX this is a bit of a hack to force the Glide texture
389 * state to be updated.
391 fxMesa
->TexState
.EnvMode
[ctx
->Texture
.CurrentUnit
] = 0;
393 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
398 * Called via glTexParameter.
401 tdfxTexParameter(GLcontext
* ctx
, GLenum target
,
402 struct gl_texture_object
*tObj
,
403 GLenum pname
, const GLfloat
* params
)
405 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
406 GLenum param
= (GLenum
) (GLint
) params
[0];
409 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
410 fprintf(stderr
, "fxmesa: fxDDTexParam(%d,%p,%x,%x)\n", tObj
->Name
,
411 tObj
->DriverData
, pname
, param
);
414 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
417 if (!tObj
->DriverData
)
418 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
420 ti
= TDFX_TEXTURE_DATA(tObj
);
423 case GL_TEXTURE_MIN_FILTER
:
426 ti
->mmMode
= GR_MIPMAP_DISABLE
;
427 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
428 ti
->LODblend
= FXFALSE
;
431 ti
->mmMode
= GR_MIPMAP_DISABLE
;
432 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
433 ti
->LODblend
= FXFALSE
;
435 case GL_NEAREST_MIPMAP_LINEAR
:
436 if (!fxMesa
->Glide
.HaveCombineExt
) {
437 if (fxMesa
->haveTwoTMUs
) {
438 ti
->mmMode
= GR_MIPMAP_NEAREST
;
439 ti
->LODblend
= FXTRUE
;
442 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
443 ti
->LODblend
= FXFALSE
;
445 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
448 /* XXX Voodoo3/Banshee mipmap blending seems to produce
449 * incorrectly filtered colors for the smallest mipmap levels.
450 * To work-around we fall-through here and use a different filter.
452 case GL_NEAREST_MIPMAP_NEAREST
:
453 ti
->mmMode
= GR_MIPMAP_NEAREST
;
454 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
455 ti
->LODblend
= FXFALSE
;
457 case GL_LINEAR_MIPMAP_LINEAR
:
458 if (!fxMesa
->Glide
.HaveCombineExt
) {
459 if (fxMesa
->haveTwoTMUs
) {
460 ti
->mmMode
= GR_MIPMAP_NEAREST
;
461 ti
->LODblend
= FXTRUE
;
464 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
465 ti
->LODblend
= FXFALSE
;
467 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
470 /* XXX Voodoo3/Banshee mipmap blending seems to produce
471 * incorrectly filtered colors for the smallest mipmap levels.
472 * To work-around we fall-through here and use a different filter.
474 case GL_LINEAR_MIPMAP_NEAREST
:
475 ti
->mmMode
= GR_MIPMAP_NEAREST
;
476 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
477 ti
->LODblend
= FXFALSE
;
482 ti
->reloadImages
= GL_TRUE
;
483 RevalidateTexture(ctx
, tObj
);
484 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
487 case GL_TEXTURE_MAG_FILTER
:
490 ti
->magFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
493 ti
->magFilt
= GR_TEXTUREFILTER_BILINEAR
;
498 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
501 case GL_TEXTURE_WRAP_S
:
503 case GL_CLAMP_TO_BORDER
:
504 case GL_CLAMP_TO_EDGE
:
506 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
509 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
511 case GL_MIRRORED_REPEAT
:
512 ti
->sClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
517 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
520 case GL_TEXTURE_WRAP_T
:
522 case GL_CLAMP_TO_BORDER
:
523 case GL_CLAMP_TO_EDGE
:
525 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
528 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
530 case GL_MIRRORED_REPEAT
:
531 ti
->tClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
536 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
539 case GL_TEXTURE_BORDER_COLOR
:
542 case GL_TEXTURE_MIN_LOD
:
545 case GL_TEXTURE_MAX_LOD
:
548 case GL_TEXTURE_BASE_LEVEL
:
549 RevalidateTexture(ctx
, tObj
);
551 case GL_TEXTURE_MAX_LEVEL
:
552 RevalidateTexture(ctx
, tObj
);
562 * Called via glDeleteTextures to delete a texture object.
563 * Here, we delete the Glide data associated with the texture.
566 tdfxDeleteTexture(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
568 if (ctx
&& ctx
->DriverCtx
) {
569 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
570 tdfxTMFreeTexture(fxMesa
, tObj
);
571 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
572 /* Free mipmap images and the texture object itself */
573 _mesa_delete_texture_object(ctx
, tObj
);
579 * Return true if texture is resident, false otherwise.
582 tdfxIsTextureResident(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
584 tdfxTexInfo
*ti
= TDFX_TEXTURE_DATA(tObj
);
585 return (GLboolean
) (ti
&& ti
->isInTM
);
591 * Convert a gl_color_table texture palette to Glide's format.
594 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
596 const GLubyte
*tableUB
= table
->TableUB
;
597 GLint width
= table
->Size
;
601 switch (table
->_BaseFormat
) {
603 for (i
= 0; i
< width
; i
++) {
608 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
610 return GR_TEXTABLE_PALETTE_6666_EXT
;
612 for (i
= 0; i
< width
; i
++) {
617 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
619 return GR_TEXTABLE_PALETTE
;
621 for (i
= 0; i
< width
; i
++) {
624 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
626 return GR_TEXTABLE_PALETTE_6666_EXT
;
627 case GL_LUMINANCE_ALPHA
:
628 for (i
= 0; i
< width
; i
++) {
629 r
= g
= b
= tableUB
[i
* 2 + 0];
630 a
= tableUB
[i
* 2 + 1];
631 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
633 return GR_TEXTABLE_PALETTE_6666_EXT
;
635 for (i
= 0; i
< width
; i
++) {
636 r
= tableUB
[i
* 3 + 0];
637 g
= tableUB
[i
* 3 + 1];
638 b
= tableUB
[i
* 3 + 2];
640 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
642 return GR_TEXTABLE_PALETTE
;
644 for (i
= 0; i
< width
; i
++) {
645 r
= tableUB
[i
* 4 + 0];
646 g
= tableUB
[i
* 4 + 1];
647 b
= tableUB
[i
* 4 + 2];
648 a
= tableUB
[i
* 4 + 3];
649 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
651 return GR_TEXTABLE_PALETTE_6666_EXT
;
653 /* XXX fixme: how can this happen? */
654 _mesa_error(NULL
, GL_INVALID_ENUM
, "convertPalette: table->Format == %s",
655 _mesa_lookup_enum_by_nr(table
->Format
));
656 return GR_TEXTABLE_PALETTE
;
663 tdfxUpdateTexturePalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
665 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
668 /* per-texture palette */
671 /* This might be a proxy texture. */
672 if (!tObj
->Palette
.TableUB
)
675 if (!tObj
->DriverData
)
676 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
677 ti
= TDFX_TEXTURE_DATA(tObj
);
679 ti
->paltype
= convertPalette(ti
->palette
.data
, &tObj
->Palette
);
680 /*tdfxTexInvalidate(ctx, tObj);*/
683 /* global texture palette */
684 fxMesa
->TexPalette
.Type
= convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
685 fxMesa
->TexPalette
.Data
= &(fxMesa
->glbPalette
.data
);
686 fxMesa
->dirty
|= TDFX_UPLOAD_TEXTURE_PALETTE
;
688 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
; /* XXX too heavy-handed */
692 /**********************************************************************/
693 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
694 /**********************************************************************/
697 static FxBool TexusFatalError
= FXFALSE
;
698 static FxBool TexusError
= FXFALSE
;
700 #define TX_DITHER_NONE 0x00000000
703 fxTexusError(const char *string
, FxBool fatal
)
705 _mesa_problem(NULL
, string
);
707 * Just propagate the fatal value up.
710 TexusFatalError
= fatal
;
715 static const struct gl_texture_format
*
716 tdfxChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
717 GLenum srcFormat
, GLenum srcType
)
719 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
720 const GLboolean allow32bpt
= TDFX_IS_NAPALM(fxMesa
);
722 switch (internalFormat
) {
728 case GL_COMPRESSED_ALPHA
:
729 return &_mesa_texformat_a8
;
736 case GL_COMPRESSED_LUMINANCE
:
737 return &_mesa_texformat_l8
;
739 case GL_LUMINANCE_ALPHA
:
740 case GL_LUMINANCE4_ALPHA4
:
741 case GL_LUMINANCE6_ALPHA2
:
742 case GL_LUMINANCE8_ALPHA8
:
743 case GL_LUMINANCE12_ALPHA4
:
744 case GL_LUMINANCE12_ALPHA12
:
745 case GL_LUMINANCE16_ALPHA16
:
746 case GL_COMPRESSED_LUMINANCE_ALPHA
:
747 return &_mesa_texformat_al88
;
753 case GL_COMPRESSED_INTENSITY
:
754 return &_mesa_texformat_i8
;
758 return &_mesa_texformat_rgb565
;
759 case GL_COMPRESSED_RGB
:
760 /* intentional fall-through */
763 if ( srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
764 return &_mesa_texformat_rgb565
;
766 /* intentional fall through */
771 return (allow32bpt
) ? &_mesa_texformat_argb8888
772 : &_mesa_texformat_rgb565
;
775 return &_mesa_texformat_argb4444
;
776 case GL_COMPRESSED_RGBA
:
777 /* intentional fall-through */
780 if ( srcFormat
== GL_BGRA
) {
781 if ( srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) {
782 return &_mesa_texformat_argb8888
;
784 else if ( srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
785 return &_mesa_texformat_argb4444
;
787 else if ( srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
788 return &_mesa_texformat_argb1555
;
791 /* intentional fall through */
796 return allow32bpt
? &_mesa_texformat_argb8888
797 : &_mesa_texformat_argb4444
;
799 return &_mesa_texformat_argb1555
;
801 case GL_COLOR_INDEX1_EXT
:
802 case GL_COLOR_INDEX2_EXT
:
803 case GL_COLOR_INDEX4_EXT
:
804 case GL_COLOR_INDEX8_EXT
:
805 case GL_COLOR_INDEX12_EXT
:
806 case GL_COLOR_INDEX16_EXT
:
807 return &_mesa_texformat_ci8
;
808 /* GL_EXT_texture_compression_s3tc */
810 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
813 return &_mesa_texformat_rgb_dxt1
;
814 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
815 return &_mesa_texformat_rgba_dxt1
;
816 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
819 return &_mesa_texformat_rgba_dxt3
;
820 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
821 return &_mesa_texformat_rgba_dxt5
;
822 /* GL_3DFX_texture_compression_FXT1 */
823 case GL_COMPRESSED_RGB_FXT1_3DFX
:
824 return &_mesa_texformat_rgb_fxt1
;
825 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
826 return &_mesa_texformat_rgba_fxt1
;
828 _mesa_problem(ctx
, "unexpected format in tdfxChooseTextureFormat");
835 * Return the Glide format for the given mesa texture format.
837 static GrTextureFormat_t
838 fxGlideFormat(GLint mesaFormat
)
840 switch (mesaFormat
) {
842 return GR_TEXFMT_ALPHA_8
;
844 return GR_TEXFMT_ALPHA_8
;
846 return GR_TEXFMT_INTENSITY_8
;
847 case MESA_FORMAT_CI8
:
848 return GR_TEXFMT_P_8
;
849 case MESA_FORMAT_AL88
:
850 return GR_TEXFMT_ALPHA_INTENSITY_88
;
851 case MESA_FORMAT_RGB565
:
852 return GR_TEXFMT_RGB_565
;
853 case MESA_FORMAT_ARGB4444
:
854 return GR_TEXFMT_ARGB_4444
;
855 case MESA_FORMAT_ARGB1555
:
856 return GR_TEXFMT_ARGB_1555
;
857 case MESA_FORMAT_ARGB8888
:
858 return GR_TEXFMT_ARGB_8888
;
859 case MESA_FORMAT_RGB_FXT1
:
860 case MESA_FORMAT_RGBA_FXT1
:
861 return GR_TEXFMT_ARGB_CMP_FXT1
;
862 case MESA_FORMAT_RGB_DXT1
:
863 case MESA_FORMAT_RGBA_DXT1
:
864 return GR_TEXFMT_ARGB_CMP_DXT1
;
865 case MESA_FORMAT_RGBA_DXT3
:
866 return GR_TEXFMT_ARGB_CMP_DXT3
;
867 case MESA_FORMAT_RGBA_DXT5
:
868 return GR_TEXFMT_ARGB_CMP_DXT5
;
870 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
876 /* Texel-fetch functions for software texturing and glGetTexImage().
877 * We should have been able to use some "standard" fetch functions (which
878 * may get defined in texutil.c) but we have to account for scaled texture
879 * images on tdfx hardware (the 8:1 aspect ratio limit).
880 * Hence, we need special functions here.
883 fxt1_decode_1 (const void *texture
, int width
,
884 int i
, int j
, unsigned char *rgba
);
887 fetch_intensity8(const struct gl_texture_image
*texImage
,
888 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
890 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
891 const GLubyte
*texel
;
896 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
897 rgba
[RCOMP
] = *texel
;
898 rgba
[GCOMP
] = *texel
;
899 rgba
[BCOMP
] = *texel
;
900 rgba
[ACOMP
] = *texel
;
905 fetch_luminance8(const struct gl_texture_image
*texImage
,
906 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
908 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
909 const GLubyte
*texel
;
914 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
915 rgba
[RCOMP
] = *texel
;
916 rgba
[GCOMP
] = *texel
;
917 rgba
[BCOMP
] = *texel
;
923 fetch_alpha8(const struct gl_texture_image
*texImage
,
924 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
926 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
927 const GLubyte
*texel
;
932 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
936 rgba
[ACOMP
] = *texel
;
941 fetch_index8(const struct gl_texture_image
*texImage
,
942 GLint i
, GLint j
, GLint k
, GLchan
* indexOut
)
944 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
945 const GLubyte
*texel
;
950 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
956 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
957 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
959 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
960 const GLubyte
*texel
;
965 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
966 rgba
[RCOMP
] = texel
[0];
967 rgba
[GCOMP
] = texel
[0];
968 rgba
[BCOMP
] = texel
[0];
969 rgba
[ACOMP
] = texel
[1];
974 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
975 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
977 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
978 const GLushort
*texel
;
983 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
984 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
985 rgba
[GCOMP
] = (((*texel
) >> 5) & 0x3f) * 255 / 63;
986 rgba
[BCOMP
] = (((*texel
) >> 0) & 0x1f) * 255 / 31;
992 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
993 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
995 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
996 const GLushort
*texel
;
1001 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1002 rgba
[RCOMP
] = (((*texel
) >> 12) & 0xf) * 255 / 15;
1003 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xf) * 255 / 15;
1004 rgba
[BCOMP
] = (((*texel
) >> 4) & 0xf) * 255 / 15;
1005 rgba
[ACOMP
] = (((*texel
) >> 0) & 0xf) * 255 / 15;
1010 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
1011 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1013 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1014 const GLushort
*texel
;
1016 i
= i
* mml
->wScale
;
1017 j
= j
* mml
->hScale
;
1019 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1020 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1021 rgba
[GCOMP
] = (((*texel
) >> 6) & 0x1f) * 255 / 31;
1022 rgba
[BCOMP
] = (((*texel
) >> 1) & 0x1f) * 255 / 31;
1023 rgba
[ACOMP
] = (((*texel
) >> 0) & 0x01) * 255;
1028 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
1029 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1031 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1032 const GLuint
*texel
;
1034 i
= i
* mml
->wScale
;
1035 j
= j
* mml
->hScale
;
1037 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
1038 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
1039 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
1040 rgba
[BCOMP
] = (((*texel
) ) & 0xff);
1041 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
1046 fetch_rgb_fxt1(const struct gl_texture_image
*texImage
,
1047 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1049 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1051 i
= i
* mml
->wScale
;
1052 j
= j
* mml
->hScale
;
1054 fxt1_decode_1(texImage
->Data
, mml
->width
, i
, j
, rgba
);
1060 fetch_rgba_fxt1(const struct gl_texture_image
*texImage
,
1061 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1063 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1065 i
= i
* mml
->wScale
;
1066 j
= j
* mml
->hScale
;
1068 fxt1_decode_1(texImage
->Data
, mml
->width
, i
, j
, rgba
);
1073 fetch_rgb_dxt1(const struct gl_texture_image
*texImage
,
1074 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1076 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1078 i
= i
* mml
->wScale
;
1079 j
= j
* mml
->hScale
;
1081 _mesa_texformat_rgb_dxt1
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
1086 fetch_rgba_dxt1(const struct gl_texture_image
*texImage
,
1087 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1089 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1091 i
= i
* mml
->wScale
;
1092 j
= j
* mml
->hScale
;
1094 _mesa_texformat_rgba_dxt1
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
1099 fetch_rgba_dxt3(const struct gl_texture_image
*texImage
,
1100 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1102 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1104 i
= i
* mml
->wScale
;
1105 j
= j
* mml
->hScale
;
1107 _mesa_texformat_rgba_dxt3
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
1112 fetch_rgba_dxt5(const struct gl_texture_image
*texImage
,
1113 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1115 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1117 i
= i
* mml
->wScale
;
1118 j
= j
* mml
->hScale
;
1120 _mesa_texformat_rgba_dxt5
.FetchTexel2D(texImage
, i
, j
, k
, rgba
);
1124 static FetchTexelFuncC
1125 fxFetchFunction(GLint mesaFormat
)
1127 switch (mesaFormat
) {
1128 case MESA_FORMAT_I8
:
1129 return &fetch_intensity8
;
1130 case MESA_FORMAT_A8
:
1131 return &fetch_alpha8
;
1132 case MESA_FORMAT_L8
:
1133 return &fetch_luminance8
;
1134 case MESA_FORMAT_CI8
:
1135 return &fetch_index8
;
1136 case MESA_FORMAT_AL88
:
1137 return &fetch_luminance8_alpha8
;
1138 case MESA_FORMAT_RGB565
:
1139 return &fetch_r5g6b5
;
1140 case MESA_FORMAT_ARGB4444
:
1141 return &fetch_r4g4b4a4
;
1142 case MESA_FORMAT_ARGB1555
:
1143 return &fetch_r5g5b5a1
;
1144 case MESA_FORMAT_ARGB8888
:
1145 return &fetch_a8r8g8b8
;
1146 case MESA_FORMAT_RGB_FXT1
:
1147 return &fetch_rgb_fxt1
;
1148 case MESA_FORMAT_RGBA_FXT1
:
1149 return &fetch_rgba_fxt1
;
1150 case MESA_FORMAT_RGB_DXT1
:
1151 return &fetch_rgb_dxt1
;
1152 case MESA_FORMAT_RGBA_DXT1
:
1153 return &fetch_rgba_dxt1
;
1154 case MESA_FORMAT_RGBA_DXT3
:
1155 return &fetch_rgba_dxt3
;
1156 case MESA_FORMAT_RGBA_DXT5
:
1157 return &fetch_rgba_dxt5
;
1159 _mesa_problem(NULL
, "Unexpected format in fxFetchFunction");
1166 adjust2DRatio (GLcontext
*ctx
,
1167 GLint xoffset
, GLint yoffset
,
1168 GLint width
, GLint height
,
1169 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1170 const struct gl_pixelstore_attrib
*packing
,
1171 tdfxMipMapLevel
*mml
,
1172 struct gl_texture_image
*texImage
,
1176 const GLint newWidth
= width
* mml
->wScale
;
1177 const GLint newHeight
= height
* mml
->hScale
;
1179 GLuint dstImageOffsets
= 0;
1181 if (!texImage
->IsCompressed
) {
1183 tempImage
= MALLOC(width
* height
* texelBytes
);
1188 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->_BaseFormat
,
1189 texImage
->TexFormat
, tempImage
,
1190 0, 0, 0, /* dstX/Y/Zoffset */
1191 width
* texelBytes
, /* dstRowStride */
1194 format
, type
, pixels
, packing
);
1197 /* compute address of dest subimage within the overal tex image */
1198 destAddr
= (GLubyte
*) texImage
->Data
1199 + (yoffset
* mml
->hScale
* mml
->width
1200 + xoffset
* mml
->wScale
) * texelBytes
;
1202 _mesa_rescale_teximage2d(texelBytes
,
1204 dstRowStride
, /* dst stride */
1206 newWidth
, newHeight
,
1207 tempImage
, destAddr
);
1209 const GLint rawBytes
= 4;
1210 GLvoid
*rawImage
= MALLOC(width
* height
* rawBytes
);
1214 tempImage
= MALLOC(newWidth
* newHeight
* rawBytes
);
1219 /* unpack image, apply transfer ops and store in rawImage */
1220 _mesa_texstore_rgba8888(ctx
, 2, GL_RGBA
,
1221 &_mesa_texformat_rgba8888_rev
, rawImage
,
1222 0, 0, 0, /* dstX/Y/Zoffset */
1223 width
* rawBytes
, /* dstRowStride */
1226 format
, type
, pixels
, packing
);
1227 _mesa_rescale_teximage2d(rawBytes
,
1229 newWidth
* rawBytes
, /* dst stride */
1230 width
, height
, /* src */
1231 newWidth
, newHeight
, /* dst */
1232 rawImage
/*src*/, tempImage
/*dst*/ );
1233 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->_BaseFormat
,
1234 texImage
->TexFormat
, texImage
->Data
,
1235 xoffset
* mml
->wScale
, yoffset
* mml
->hScale
, 0, /* dstX/Y/Zoffset */
1238 newWidth
, newHeight
, 1,
1239 GL_RGBA
, CHAN_TYPE
, tempImage
, &ctx
->DefaultPacking
);
1250 tdfxTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
1251 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1252 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1253 const struct gl_pixelstore_attrib
*packing
,
1254 struct gl_texture_object
*texObj
,
1255 struct gl_texture_image
*texImage
)
1257 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1259 tdfxMipMapLevel
*mml
;
1260 GLint texelBytes
, dstRowStride
;
1264 printf("TexImage id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1265 texObj->Name, texImage->InternalFormat, format, type,
1266 texImage->Width, texImage->Height);
1269 ti
= TDFX_TEXTURE_DATA(texObj
);
1271 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1272 if (!texObj
->DriverData
) {
1273 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1276 ti
= TDFX_TEXTURE_DATA(texObj
);
1280 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1282 texImage
->DriverData
= CALLOC(sizeof(tdfxMipMapLevel
));
1283 if (!texImage
->DriverData
) {
1284 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1287 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1290 /* Determine width and height scale factors for texture.
1291 * Remember, Glide is limited to 8:1 aspect ratios.
1294 texImage
->Width
, texImage
->Height
,
1295 NULL
, /* lod level */
1296 NULL
, /* aspect ratio */
1297 NULL
, NULL
, /* sscale, tscale */
1298 &mml
->wScale
, &mml
->hScale
);
1300 /* rescaled size: */
1301 mml
->width
= width
* mml
->wScale
;
1302 mml
->height
= height
* mml
->hScale
;
1304 #if FX_COMPRESS_S3TC_AS_FXT1_HACK
1305 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1306 /* [dBorca] we should update texture's attribute, then,
1307 * because if the application asks us to decompress, we
1308 * have to know the REAL format! Also, DXT3/5 might not
1309 * be correct, since it would mess with "compressedSize".
1310 * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3.
1312 if (texImage
->IsCompressed
) {
1313 switch (internalFormat
) {
1314 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1317 internalFormat
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1319 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1320 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1321 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1324 internalFormat
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1326 texImage
->InternalFormat
= internalFormat
;
1330 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1331 GLenum texNapalm
= 0;
1332 if (internalFormat
== GL_COMPRESSED_RGB
) {
1333 texNapalm
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1334 } else if (internalFormat
== GL_COMPRESSED_RGBA
) {
1335 texNapalm
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1338 texImage
->InternalFormat
= internalFormat
= texNapalm
;
1339 texImage
->IsCompressed
= GL_TRUE
;
1344 /* choose the texture format */
1345 assert(ctx
->Driver
.ChooseTextureFormat
);
1346 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1347 internalFormat
, format
, type
);
1348 assert(texImage
->TexFormat
);
1349 mesaFormat
= texImage
->TexFormat
->MesaFormat
;
1350 mml
->glideFormat
= fxGlideFormat(mesaFormat
);
1351 ti
->info
.format
= mml
->glideFormat
;
1352 texImage
->FetchTexelc
= fxFetchFunction(mesaFormat
);
1353 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1355 if (texImage
->IsCompressed
) {
1356 texImage
->CompressedSize
= _mesa_compressed_texture_size(ctx
,
1361 dstRowStride
= _mesa_compressed_row_stride(texImage
->TexFormat
->MesaFormat
, mml
->width
);
1362 texImage
->Data
= _mesa_alloc_texmemory(texImage
->CompressedSize
);
1364 dstRowStride
= mml
->width
* texelBytes
;
1365 texImage
->Data
= _mesa_alloc_texmemory(mml
->width
* mml
->height
* texelBytes
);
1367 if (!texImage
->Data
) {
1368 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1372 if (pixels
!= NULL
) {
1373 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1374 /* rescale image to overcome 1:8 aspect limitation */
1375 if (!adjust2DRatio(ctx
,
1378 format
, type
, pixels
,
1385 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1390 /* no rescaling needed */
1391 /* unpack image, apply transfer ops and store in texImage->Data */
1392 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->_BaseFormat
,
1393 texImage
->TexFormat
, texImage
->Data
,
1394 0, 0, 0, /* dstX/Y/Zoffset */
1396 texImage
->ImageOffsets
,
1398 format
, type
, pixels
, packing
);
1401 /* GL_SGIS_generate_mipmap */
1402 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1403 GLint mipWidth
, mipHeight
;
1404 tdfxMipMapLevel
*mip
;
1405 struct gl_texture_image
*mipImage
;
1406 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1408 assert(!texImage
->IsCompressed
);
1410 while (level
< texObj
->MaxLevel
&& level
< maxLevels
- 1) {
1411 mipWidth
= width
/ 2;
1415 mipHeight
= height
/ 2;
1419 if ((mipWidth
== width
) && (mipHeight
== height
)) {
1422 _mesa_TexImage2D(target
, ++level
, internalFormat
,
1423 mipWidth
, mipHeight
, border
,
1426 mipImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1427 mip
= TDFX_TEXIMAGE_DATA(mipImage
);
1428 _mesa_halve2x2_teximage2d(ctx
,
1431 mml
->width
, mml
->height
,
1432 texImage
->Data
, mipImage
->Data
);
1433 texImage
= mipImage
;
1441 RevalidateTexture(ctx
, texObj
);
1443 ti
->reloadImages
= GL_TRUE
;
1444 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
1449 tdfxTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
1450 GLint xoffset
, GLint yoffset
,
1451 GLsizei width
, GLsizei height
,
1452 GLenum format
, GLenum type
,
1453 const GLvoid
*pixels
,
1454 const struct gl_pixelstore_attrib
*packing
,
1455 struct gl_texture_object
*texObj
,
1456 struct gl_texture_image
*texImage
)
1458 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1460 tdfxMipMapLevel
*mml
;
1461 GLint texelBytes
, dstRowStride
;
1463 if (!texObj
->DriverData
) {
1464 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1468 ti
= TDFX_TEXTURE_DATA(texObj
);
1470 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1473 assert(texImage
->Data
); /* must have an existing texture image! */
1474 assert(texImage
->_BaseFormat
);
1476 texelBytes
= texImage
->TexFormat
->TexelBytes
;
1477 if (texImage
->IsCompressed
) {
1478 dstRowStride
= _mesa_compressed_row_stride(texImage
->TexFormat
->MesaFormat
, mml
->width
);
1480 dstRowStride
= mml
->width
* texelBytes
;
1483 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1484 /* need to rescale subimage to match mipmap level's rescale factors */
1485 if (!adjust2DRatio(ctx
,
1488 format
, type
, pixels
,
1495 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1500 /* no rescaling needed */
1501 texImage
->TexFormat
->StoreImage(ctx
, 2, texImage
->_BaseFormat
,
1502 texImage
->TexFormat
, texImage
->Data
,
1503 xoffset
, yoffset
, 0,
1505 texImage
->ImageOffsets
,
1507 format
, type
, pixels
, packing
);
1510 /* GL_SGIS_generate_mipmap */
1511 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1512 GLint mipWidth
, mipHeight
;
1513 tdfxMipMapLevel
*mip
;
1514 struct gl_texture_image
*mipImage
;
1515 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
1517 assert(!texImage
->IsCompressed
);
1519 width
= texImage
->Width
;
1520 height
= texImage
->Height
;
1521 while (level
< texObj
->MaxLevel
&& level
< maxLevels
- 1) {
1522 mipWidth
= width
/ 2;
1526 mipHeight
= height
/ 2;
1530 if ((mipWidth
== width
) && (mipHeight
== height
)) {
1534 mipImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
1535 mip
= TDFX_TEXIMAGE_DATA(mipImage
);
1536 _mesa_halve2x2_teximage2d(ctx
,
1539 mml
->width
, mml
->height
,
1540 texImage
->Data
, mipImage
->Data
);
1541 texImage
= mipImage
;
1548 ti
->reloadImages
= GL_TRUE
; /* signal the image needs to be reloaded */
1549 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
; /* XXX this might be a bit much */
1554 tdfxTexImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
1555 GLint internalFormat
, GLint width
, GLint border
,
1556 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1557 const struct gl_pixelstore_attrib
*packing
,
1558 struct gl_texture_object
*texObj
,
1559 struct gl_texture_image
*texImage
)
1561 tdfxTexImage2D(ctx
, target
, level
,
1562 internalFormat
, width
, 1, border
,
1563 format
, type
, pixels
,
1570 tdfxTexSubImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
1573 GLenum format
, GLenum type
,
1574 const GLvoid
*pixels
,
1575 const struct gl_pixelstore_attrib
*packing
,
1576 struct gl_texture_object
*texObj
,
1577 struct gl_texture_image
*texImage
)
1579 tdfxTexSubImage2D(ctx
, target
, level
,
1589 /**********************************************************************/
1590 /**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/
1591 /**********************************************************************/
1594 tdfxCompressedTexImage2D (GLcontext
*ctx
, GLenum target
,
1595 GLint level
, GLint internalFormat
,
1596 GLsizei width
, GLsizei height
, GLint border
,
1597 GLsizei imageSize
, const GLvoid
*data
,
1598 struct gl_texture_object
*texObj
,
1599 struct gl_texture_image
*texImage
)
1601 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1603 tdfxMipMapLevel
*mml
;
1606 if (TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
1607 fprintf(stderr
, "tdfxCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1608 texObj
->Name
, internalFormat
,
1612 if ((target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
) || texImage
->Border
> 0) {
1613 _mesa_problem(NULL
, "tdfx: unsupported texture in tdfxCompressedTexImg()\n");
1617 assert(texImage
->IsCompressed
);
1619 ti
= TDFX_TEXTURE_DATA(texObj
);
1621 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1622 if (!texObj
->DriverData
) {
1623 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1626 ti
= TDFX_TEXTURE_DATA(texObj
);
1630 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1632 texImage
->DriverData
= CALLOC(sizeof(tdfxMipMapLevel
));
1633 if (!texImage
->DriverData
) {
1634 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1637 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1640 tdfxTexGetInfo(ctx
, width
, height
, NULL
, NULL
, NULL
, NULL
,
1641 &mml
->wScale
, &mml
->hScale
);
1643 mml
->width
= width
* mml
->wScale
;
1644 mml
->height
= height
* mml
->hScale
;
1647 /* choose the texture format */
1648 assert(ctx
->Driver
.ChooseTextureFormat
);
1649 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1650 internalFormat
, -1/*format*/, -1/*type*/);
1651 assert(texImage
->TexFormat
);
1653 /* Determine the appropriate Glide texel format,
1654 * given the user's internal texture format hint.
1656 mesaFormat
= texImage
->TexFormat
->MesaFormat
;
1657 mml
->glideFormat
= fxGlideFormat(mesaFormat
);
1658 ti
->info
.format
= mml
->glideFormat
;
1659 texImage
->FetchTexelc
= fxFetchFunction(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_alloc_texmemory(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 const GLuint mesaFormat
= texImage
->TexFormat
->MesaFormat
;
1692 GLuint srcRowStride
= _mesa_compressed_row_stride(mesaFormat
, width
);
1694 GLuint destRowStride
= _mesa_compressed_row_stride(mesaFormat
,
1697 _mesa_upscale_teximage2d(srcRowStride
, (height
+3) / 4,
1698 destRowStride
, (mml
->height
+3) / 4,
1699 1, data
, srcRowStride
,
1701 ti
->padded
= GL_TRUE
;
1703 MEMCPY(texImage
->Data
, data
, texImage
->CompressedSize
);
1706 /* GL_SGIS_generate_mipmap */
1707 if (level
== texObj
->BaseLevel
&& texObj
->GenerateMipmap
) {
1708 assert(!texImage
->IsCompressed
);
1711 RevalidateTexture(ctx
, texObj
);
1713 ti
->reloadImages
= GL_TRUE
;
1714 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
1719 tdfxCompressedTexSubImage2D( GLcontext
*ctx
, GLenum target
,
1720 GLint level
, GLint xoffset
,
1721 GLint yoffset
, GLsizei width
,
1722 GLint height
, GLenum format
,
1723 GLsizei imageSize
, const GLvoid
*data
,
1724 struct gl_texture_object
*texObj
,
1725 struct gl_texture_image
*texImage
)
1727 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1729 tdfxMipMapLevel
*mml
;
1730 GLint destRowStride
, srcRowStride
;
1733 const GLuint mesaFormat
= texImage
->TexFormat
->MesaFormat
;
1735 if (TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
1736 fprintf(stderr
, "tdfxCompressedTexSubImage2D: id=%d\n", texObj
->Name
);
1739 ti
= TDFX_TEXTURE_DATA(texObj
);
1741 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1744 srcRowStride
= _mesa_compressed_row_stride(mesaFormat
, width
);
1746 destRowStride
= _mesa_compressed_row_stride(mesaFormat
, mml
->width
);
1747 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
1750 (GLubyte
*) texImage
->Data
);
1752 rows
= height
/ 4; /* [dBorca] hardcoded 4, but works for FXT1/DXTC */
1754 for (i
= 0; i
< rows
; i
++) {
1755 MEMCPY(dest
, data
, srcRowStride
);
1756 dest
+= destRowStride
;
1757 data
= (GLvoid
*)((intptr_t)data
+ (intptr_t)srcRowStride
);
1760 /* [dBorca] Hack alert:
1761 * see fxDDCompressedTexImage2D for caveats
1763 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1764 srcRowStride
= _mesa_compressed_row_stride(mesaFormat
, texImage
->Width
);
1766 destRowStride
= _mesa_compressed_row_stride(mesaFormat
, mml
->width
);
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 RevalidateTexture(ctx
, texObj
);
1780 ti
->reloadImages
= GL_TRUE
;
1781 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
1787 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
1790 for (i
= 0; i
< h
; i
++) {
1791 for (j
= 0; j
< w
; j
++) {
1793 printf("%02x %02x ", data
[0], data
[1]);
1795 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
1805 tdfxTestProxyTexImage(GLcontext
*ctx
, GLenum target
,
1806 GLint level
, GLint internalFormat
,
1807 GLenum format
, GLenum type
,
1808 GLint width
, GLint height
,
1809 GLint depth
, GLint border
)
1811 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1812 struct gl_shared_state
*mesaShared
= fxMesa
->glCtx
->Shared
;
1813 struct tdfxSharedState
*shared
= (struct tdfxSharedState
*) mesaShared
->DriverData
;
1816 case GL_PROXY_TEXTURE_1D
:
1818 case GL_PROXY_TEXTURE_2D
:
1820 struct gl_texture_object
*tObj
;
1824 tObj
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
1825 if (!tObj
->DriverData
)
1826 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1827 ti
= TDFX_TEXTURE_DATA(tObj
);
1830 /* assign the parameters to test against */
1831 tObj
->Image
[0][level
]->Width
= width
;
1832 tObj
->Image
[0][level
]->Height
= height
;
1833 tObj
->Image
[0][level
]->Border
= border
;
1835 tObj
->Image
[0][level
]->InternalFormat
= internalFormat
;
1838 /* don't use mipmap levels > 0 */
1839 tObj
->MinFilter
= tObj
->MagFilter
= GL_NEAREST
;
1842 /* test with all mipmap levels */
1843 tObj
->MinFilter
= GL_LINEAR_MIPMAP_LINEAR
;
1844 tObj
->MagFilter
= GL_NEAREST
;
1846 RevalidateTexture(ctx
, tObj
);
1849 printf("small lodlog2 0x%x\n", ti->info.smallLodLog2);
1850 printf("large lodlog2 0x%x\n", ti->info.largeLodLog2);
1851 printf("aspect ratio 0x%x\n", ti->info.aspectRatioLog2);
1852 printf("glide format 0x%x\n", ti->info.format);
1853 printf("data %p\n", ti->info.data);
1854 printf("lodblend %d\n", (int) ti->LODblend);
1857 /* determine where texture will reside */
1858 if (ti
->LODblend
&& !shared
->umaTexMemory
) {
1859 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1860 memNeeded
= fxMesa
->Glide
.grTexTextureMemRequired(
1861 GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
1864 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1865 memNeeded
= fxMesa
->Glide
.grTexTextureMemRequired(
1866 GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
1869 printf("Proxy test %d > %d\n", memNeeded, shared->totalTexMem[0]);
1871 if (memNeeded
> shared
->totalTexMem
[0])
1876 case GL_PROXY_TEXTURE_3D
:
1877 return GL_TRUE
; /* software rendering */
1879 return GL_TRUE
; /* never happens, silence compiler */
1885 * Allocate a new texture object.
1886 * Called via ctx->Driver.NewTextureObject.
1887 * Note: this function will be called during context creation to
1888 * allocate the default texture objects.
1889 * Note: we could use containment here to 'derive' the driver-specific
1890 * texture object from the core mesa gl_texture_object. Not done at this time.
1892 static struct gl_texture_object
*
1893 tdfxNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
1895 struct gl_texture_object
*obj
;
1896 obj
= _mesa_new_texture_object(ctx
, name
, target
);
1901 void tdfxInitTextureFuncs( struct dd_function_table
*functions
)
1903 functions
->BindTexture
= tdfxBindTexture
;
1904 functions
->NewTextureObject
= tdfxNewTextureObject
;
1905 functions
->DeleteTexture
= tdfxDeleteTexture
;
1906 functions
->TexEnv
= tdfxTexEnv
;
1907 functions
->TexParameter
= tdfxTexParameter
;
1908 functions
->ChooseTextureFormat
= tdfxChooseTextureFormat
;
1909 functions
->TexImage1D
= tdfxTexImage1D
;
1910 functions
->TexSubImage1D
= tdfxTexSubImage1D
;
1911 functions
->TexImage2D
= tdfxTexImage2D
;
1912 functions
->TexSubImage2D
= tdfxTexSubImage2D
;
1913 functions
->IsTextureResident
= tdfxIsTextureResident
;
1914 functions
->CompressedTexImage2D
= tdfxCompressedTexImage2D
;
1915 functions
->CompressedTexSubImage2D
= tdfxCompressedTexSubImage2D
;
1916 functions
->UpdateTexturePalette
= tdfxUpdateTexturePalette
;