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
== MESA_FORMAT_RGB565
) {
76 _t
= GL_UNSIGNED_SHORT_5_6_5_REV
;
78 } else if (texImage
->TexFormat
== MESA_FORMAT_ARGB4444
) {
79 _t
= GL_UNSIGNED_SHORT_4_4_4_4_REV
;
81 } else if (texImage
->TexFormat
== 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(ctx
, 2, GL_RGBA
,
97 MESA_FORMAT_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 _mesa_texstore(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 tdfxGenerateMipmap(GLcontext
*ctx
, GLenum target
,
181 struct gl_texture_object
*texObj
)
183 GLint mipWidth
, mipHeight
;
184 tdfxMipMapLevel
*mip
;
185 struct gl_texture_image
*mipImage
; /* the new/next image */
186 struct gl_texture_image
*texImage
;
187 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, texObj
->Target
);
188 GLint level
= texObj
->BaseLevel
;
189 GLsizei width
, height
, texelBytes
;
190 const tdfxMipMapLevel
*mml
;
192 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
193 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
195 mml
= TDFX_TEXIMAGE_DATA(texImage
);
197 width
= texImage
->Width
;
198 height
= texImage
->Height
;
199 while (level
< texObj
->MaxLevel
&& level
< maxLevels
- 1) {
200 mipWidth
= width
/ 2;
204 mipHeight
= height
/ 2;
208 if ((mipWidth
== width
) && (mipHeight
== height
)) {
212 mipImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
213 mip
= TDFX_TEXIMAGE_DATA(mipImage
);
214 _mesa_halve2x2_teximage2d(ctx
,
217 mml
->width
, mml
->height
,
218 texImage
->Data
, mipImage
->Data
);
228 * Compute various texture image parameters.
229 * Input: w, h - source texture width and height
230 * Output: lodlevel - Glide lod level token for the larger texture dimension
231 * aspectratio - Glide aspect ratio token
232 * sscale - S scale factor used during triangle setup
233 * tscale - T scale factor used during triangle setup
234 * wscale - OpenGL -> Glide image width scale factor
235 * hscale - OpenGL -> Glide image height scale factor
238 * w h lodlevel aspectRatio
239 * 128 128 GR_LOD_LOG2_128 (=7) GR_ASPECT_LOG2_1x1 (=0)
240 * 64 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x1 (=0)
241 * 64 32 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_2x1 (=1)
242 * 32 64 GR_LOD_LOG2_64 (=6) GR_ASPECT_LOG2_1x2 (=-1)
243 * 32 32 GR_LOD_LOG2_32 (=5) GR_ASPECT_LOG2_1x1 (=0)
246 tdfxTexGetInfo(const GLcontext
*ctx
, int w
, int h
,
247 GrLOD_t
*lodlevel
, GrAspectRatio_t
*aspectratio
,
248 float *sscale
, float *tscale
,
249 int *wscale
, int *hscale
)
251 int logw
, logh
, ar
, lod
, ws
, hs
;
259 ar
= logw
- logh
; /* aspect ratio = difference in log dimensions */
263 /* Hardware only allows a maximum aspect ratio of 8x1, so handle
264 |ar| > 3 by scaling the image and using an 8x1 aspect ratio */
268 if (ar
<= GR_ASPECT_LOG2_8x1
) {
272 /* have to stretch image height */
275 ar
= GR_ASPECT_LOG2_8x1
;
281 if (ar
>= GR_ASPECT_LOG2_1x8
) {
285 /* have to stretch image width */
288 ar
= GR_ASPECT_LOG2_1x8
;
293 *lodlevel
= (GrLOD_t
) lod
;
295 *aspectratio
= (GrAspectRatio_t
) ar
;
308 * We need to call this when a texture object's minification filter
309 * or texture image sizes change.
311 static void RevalidateTexture(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
313 tdfxTexInfo
*ti
= TDFX_TEXTURE_DATA(tObj
);
319 minl
= maxl
= tObj
->BaseLevel
;
321 if (tObj
->Image
[0][minl
]) {
322 maxl
= MIN2(tObj
->MaxLevel
, tObj
->Image
[0][minl
]->MaxLog2
);
324 /* compute largeLodLog2, aspect ratio and texcoord scale factors */
325 tdfxTexGetInfo(ctx
, tObj
->Image
[0][minl
]->Width
, tObj
->Image
[0][minl
]->Height
,
326 &ti
->info
.largeLodLog2
,
327 &ti
->info
.aspectRatioLog2
,
328 &(ti
->sScale
), &(ti
->tScale
), NULL
, NULL
);
331 if (tObj
->Image
[0][maxl
] && (tObj
->MinFilter
!= GL_NEAREST
) && (tObj
->MinFilter
!= GL_LINEAR
)) {
332 /* mipmapping: need to compute smallLodLog2 */
333 tdfxTexGetInfo(ctx
, tObj
->Image
[0][maxl
]->Width
,
334 tObj
->Image
[0][maxl
]->Height
,
335 &ti
->info
.smallLodLog2
, NULL
,
336 NULL
, NULL
, NULL
, NULL
);
339 /* not mipmapping: smallLodLog2 = largeLodLog2 */
340 ti
->info
.smallLodLog2
= ti
->info
.largeLodLog2
;
346 ti
->info
.data
= NULL
;
348 /* this is necessary because of fxDDCompressedTexImage2D */
350 struct gl_texture_image
*texImage
= tObj
->Image
[0][minl
];
351 tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
352 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
353 ti
->sScale
/= mml
->wScale
;
354 ti
->tScale
/= mml
->hScale
;
361 fxAllocTexObjData(tdfxContextPtr fxMesa
)
365 if (!(ti
= CALLOC(sizeof(tdfxTexInfo
)))) {
366 _mesa_problem(NULL
, "tdfx driver: out of memory");
370 ti
->isInTM
= GL_FALSE
;
372 ti
->whichTMU
= TDFX_TMU_NONE
;
374 ti
->tm
[TDFX_TMU0
] = NULL
;
375 ti
->tm
[TDFX_TMU1
] = NULL
;
377 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
378 ti
->magFilt
= GR_TEXTUREFILTER_BILINEAR
;
380 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
381 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
383 ti
->mmMode
= GR_MIPMAP_NEAREST
;
384 ti
->LODblend
= FXFALSE
;
391 * Called via glBindTexture.
394 tdfxBindTexture(GLcontext
* ctx
, GLenum target
,
395 struct gl_texture_object
*tObj
)
397 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
400 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
401 fprintf(stderr
, "fxmesa: fxDDTexBind(%d,%p)\n", tObj
->Name
,
405 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
408 if (!tObj
->DriverData
) {
409 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
412 ti
= TDFX_TEXTURE_DATA(tObj
);
413 ti
->lastTimeUsed
= fxMesa
->texBindNumber
++;
415 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
420 * Called via glTexEnv.
423 tdfxTexEnv(GLcontext
* ctx
, GLenum target
, GLenum pname
,
424 const GLfloat
* param
)
426 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
428 if ( TDFX_DEBUG
& DEBUG_VERBOSE_API
) {
430 fprintf(stderr
, "fxmesa: texenv(%x,%x)\n", pname
,
433 fprintf(stderr
, "fxmesa: texenv(%x)\n", pname
);
436 /* XXX this is a bit of a hack to force the Glide texture
437 * state to be updated.
439 fxMesa
->TexState
.EnvMode
[ctx
->Texture
.CurrentUnit
] = 0;
441 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
446 * Called via glTexParameter.
449 tdfxTexParameter(GLcontext
* ctx
, GLenum target
,
450 struct gl_texture_object
*tObj
,
451 GLenum pname
, const GLfloat
* params
)
453 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
454 GLenum param
= (GLenum
) (GLint
) params
[0];
457 if (MESA_VERBOSE
& VERBOSE_DRIVER
) {
458 fprintf(stderr
, "fxmesa: fxDDTexParam(%d,%p,%x,%x)\n", tObj
->Name
,
459 tObj
->DriverData
, pname
, param
);
462 if ((target
!= GL_TEXTURE_1D
) && (target
!= GL_TEXTURE_2D
))
465 if (!tObj
->DriverData
)
466 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
468 ti
= TDFX_TEXTURE_DATA(tObj
);
471 case GL_TEXTURE_MIN_FILTER
:
474 ti
->mmMode
= GR_MIPMAP_DISABLE
;
475 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
476 ti
->LODblend
= FXFALSE
;
479 ti
->mmMode
= GR_MIPMAP_DISABLE
;
480 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
481 ti
->LODblend
= FXFALSE
;
483 case GL_NEAREST_MIPMAP_LINEAR
:
484 if (!fxMesa
->Glide
.HaveCombineExt
) {
485 if (fxMesa
->haveTwoTMUs
) {
486 ti
->mmMode
= GR_MIPMAP_NEAREST
;
487 ti
->LODblend
= FXTRUE
;
490 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
491 ti
->LODblend
= FXFALSE
;
493 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
496 /* XXX Voodoo3/Banshee mipmap blending seems to produce
497 * incorrectly filtered colors for the smallest mipmap levels.
498 * To work-around we fall-through here and use a different filter.
500 case GL_NEAREST_MIPMAP_NEAREST
:
501 ti
->mmMode
= GR_MIPMAP_NEAREST
;
502 ti
->minFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
503 ti
->LODblend
= FXFALSE
;
505 case GL_LINEAR_MIPMAP_LINEAR
:
506 if (!fxMesa
->Glide
.HaveCombineExt
) {
507 if (fxMesa
->haveTwoTMUs
) {
508 ti
->mmMode
= GR_MIPMAP_NEAREST
;
509 ti
->LODblend
= FXTRUE
;
512 ti
->mmMode
= GR_MIPMAP_NEAREST_DITHER
;
513 ti
->LODblend
= FXFALSE
;
515 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
518 /* XXX Voodoo3/Banshee mipmap blending seems to produce
519 * incorrectly filtered colors for the smallest mipmap levels.
520 * To work-around we fall-through here and use a different filter.
522 case GL_LINEAR_MIPMAP_NEAREST
:
523 ti
->mmMode
= GR_MIPMAP_NEAREST
;
524 ti
->minFilt
= GR_TEXTUREFILTER_BILINEAR
;
525 ti
->LODblend
= FXFALSE
;
530 ti
->reloadImages
= GL_TRUE
;
531 RevalidateTexture(ctx
, tObj
);
532 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
535 case GL_TEXTURE_MAG_FILTER
:
538 ti
->magFilt
= GR_TEXTUREFILTER_POINT_SAMPLED
;
541 ti
->magFilt
= GR_TEXTUREFILTER_BILINEAR
;
546 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
549 case GL_TEXTURE_WRAP_S
:
551 case GL_CLAMP_TO_BORDER
:
552 case GL_CLAMP_TO_EDGE
:
554 ti
->sClamp
= GR_TEXTURECLAMP_CLAMP
;
557 ti
->sClamp
= GR_TEXTURECLAMP_WRAP
;
559 case GL_MIRRORED_REPEAT
:
560 ti
->sClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
565 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
568 case GL_TEXTURE_WRAP_T
:
570 case GL_CLAMP_TO_BORDER
:
571 case GL_CLAMP_TO_EDGE
:
573 ti
->tClamp
= GR_TEXTURECLAMP_CLAMP
;
576 ti
->tClamp
= GR_TEXTURECLAMP_WRAP
;
578 case GL_MIRRORED_REPEAT
:
579 ti
->tClamp
= GR_TEXTURECLAMP_MIRROR_EXT
;
584 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
587 case GL_TEXTURE_BORDER_COLOR
:
590 case GL_TEXTURE_MIN_LOD
:
593 case GL_TEXTURE_MAX_LOD
:
596 case GL_TEXTURE_BASE_LEVEL
:
597 RevalidateTexture(ctx
, tObj
);
599 case GL_TEXTURE_MAX_LEVEL
:
600 RevalidateTexture(ctx
, tObj
);
610 * Called via glDeleteTextures to delete a texture object.
611 * Here, we delete the Glide data associated with the texture.
614 tdfxDeleteTexture(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
616 if (ctx
&& ctx
->DriverCtx
) {
617 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
618 tdfxTMFreeTexture(fxMesa
, tObj
);
619 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
620 /* Free mipmap images and the texture object itself */
621 _mesa_delete_texture_object(ctx
, tObj
);
627 * Return true if texture is resident, false otherwise.
630 tdfxIsTextureResident(GLcontext
*ctx
, struct gl_texture_object
*tObj
)
632 tdfxTexInfo
*ti
= TDFX_TEXTURE_DATA(tObj
);
633 return (GLboolean
) (ti
&& ti
->isInTM
);
639 * Convert a gl_color_table texture palette to Glide's format.
642 convertPalette(FxU32 data
[256], const struct gl_color_table
*table
)
644 const GLubyte
*tableUB
= table
->TableUB
;
645 GLint width
= table
->Size
;
649 switch (table
->_BaseFormat
) {
651 for (i
= 0; i
< width
; i
++) {
656 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
658 return GR_TEXTABLE_PALETTE_6666_EXT
;
660 for (i
= 0; i
< width
; i
++) {
665 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
667 return GR_TEXTABLE_PALETTE
;
669 for (i
= 0; i
< width
; i
++) {
672 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
674 return GR_TEXTABLE_PALETTE_6666_EXT
;
675 case GL_LUMINANCE_ALPHA
:
676 for (i
= 0; i
< width
; i
++) {
677 r
= g
= b
= tableUB
[i
* 2 + 0];
678 a
= tableUB
[i
* 2 + 1];
679 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
681 return GR_TEXTABLE_PALETTE_6666_EXT
;
683 for (i
= 0; i
< width
; i
++) {
684 r
= tableUB
[i
* 3 + 0];
685 g
= tableUB
[i
* 3 + 1];
686 b
= tableUB
[i
* 3 + 2];
688 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
690 return GR_TEXTABLE_PALETTE
;
692 for (i
= 0; i
< width
; i
++) {
693 r
= tableUB
[i
* 4 + 0];
694 g
= tableUB
[i
* 4 + 1];
695 b
= tableUB
[i
* 4 + 2];
696 a
= tableUB
[i
* 4 + 3];
697 data
[i
] = (a
<< 24) | (r
<< 16) | (g
<< 8) | b
;
699 return GR_TEXTABLE_PALETTE_6666_EXT
;
701 /* XXX fixme: how can this happen? */
702 _mesa_error(NULL
, GL_INVALID_ENUM
, "convertPalette: table->Format == %s",
703 _mesa_lookup_enum_by_nr(table
->Format
));
704 return GR_TEXTABLE_PALETTE
;
711 tdfxUpdateTexturePalette(GLcontext
* ctx
, struct gl_texture_object
*tObj
)
713 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
716 /* per-texture palette */
719 /* This might be a proxy texture. */
720 if (!tObj
->Palette
.TableUB
)
723 if (!tObj
->DriverData
)
724 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
725 ti
= TDFX_TEXTURE_DATA(tObj
);
727 ti
->paltype
= convertPalette(ti
->palette
.data
, &tObj
->Palette
);
728 /*tdfxTexInvalidate(ctx, tObj);*/
731 /* global texture palette */
732 fxMesa
->TexPalette
.Type
= convertPalette(fxMesa
->glbPalette
.data
, &ctx
->Texture
.Palette
);
733 fxMesa
->TexPalette
.Data
= &(fxMesa
->glbPalette
.data
);
734 fxMesa
->dirty
|= TDFX_UPLOAD_TEXTURE_PALETTE
;
736 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
; /* XXX too heavy-handed */
740 /**********************************************************************/
741 /**** NEW TEXTURE IMAGE FUNCTIONS ****/
742 /**********************************************************************/
745 static FxBool TexusFatalError
= FXFALSE
;
746 static FxBool TexusError
= FXFALSE
;
748 #define TX_DITHER_NONE 0x00000000
751 fxTexusError(const char *string
, FxBool fatal
)
753 _mesa_problem(NULL
, string
);
755 * Just propagate the fatal value up.
758 TexusFatalError
= fatal
;
764 tdfxChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
765 GLenum srcFormat
, GLenum srcType
)
767 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
768 const GLboolean allow32bpt
= TDFX_IS_NAPALM(fxMesa
);
770 switch (internalFormat
) {
776 case GL_COMPRESSED_ALPHA
:
777 return MESA_FORMAT_A8
;
784 case GL_COMPRESSED_LUMINANCE
:
785 return MESA_FORMAT_L8
;
787 case GL_LUMINANCE_ALPHA
:
788 case GL_LUMINANCE4_ALPHA4
:
789 case GL_LUMINANCE6_ALPHA2
:
790 case GL_LUMINANCE8_ALPHA8
:
791 case GL_LUMINANCE12_ALPHA4
:
792 case GL_LUMINANCE12_ALPHA12
:
793 case GL_LUMINANCE16_ALPHA16
:
794 case GL_COMPRESSED_LUMINANCE_ALPHA
:
795 return MESA_FORMAT_AL88
;
801 case GL_COMPRESSED_INTENSITY
:
802 return MESA_FORMAT_I8
;
806 return MESA_FORMAT_RGB565
;
807 case GL_COMPRESSED_RGB
:
808 /* intentional fall-through */
811 if ( srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
812 return MESA_FORMAT_RGB565
;
814 /* intentional fall through */
819 return (allow32bpt
) ? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
822 return MESA_FORMAT_ARGB4444
;
823 case GL_COMPRESSED_RGBA
:
824 /* intentional fall-through */
827 if ( srcFormat
== GL_BGRA
) {
828 if ( srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) {
829 return MESA_FORMAT_ARGB8888
;
831 else if ( srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
832 return MESA_FORMAT_ARGB4444
;
834 else if ( srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
835 return MESA_FORMAT_ARGB1555
;
838 /* intentional fall through */
843 return allow32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
845 return MESA_FORMAT_ARGB1555
;
847 case GL_COLOR_INDEX1_EXT
:
848 case GL_COLOR_INDEX2_EXT
:
849 case GL_COLOR_INDEX4_EXT
:
850 case GL_COLOR_INDEX8_EXT
:
851 case GL_COLOR_INDEX12_EXT
:
852 case GL_COLOR_INDEX16_EXT
:
853 return MESA_FORMAT_CI8
;
854 /* GL_EXT_texture_compression_s3tc */
856 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
859 return MESA_FORMAT_RGB_DXT1
;
860 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
861 return MESA_FORMAT_RGBA_DXT1
;
862 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
865 return MESA_FORMAT_RGBA_DXT3
;
866 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
867 return MESA_FORMAT_RGBA_DXT5
;
868 /* GL_3DFX_texture_compression_FXT1 */
869 case GL_COMPRESSED_RGB_FXT1_3DFX
:
870 return MESA_FORMAT_RGB_FXT1
;
871 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
872 return MESA_FORMAT_RGBA_FXT1
;
874 _mesa_problem(ctx
, "unexpected format in tdfxChooseTextureFormat");
875 return MESA_FORMAT_NONE
;
881 * Return the Glide format for the given mesa texture format.
883 static GrTextureFormat_t
884 fxGlideFormat(GLint mesaFormat
)
886 switch (mesaFormat
) {
888 return GR_TEXFMT_ALPHA_8
;
890 return GR_TEXFMT_ALPHA_8
;
892 return GR_TEXFMT_INTENSITY_8
;
893 case MESA_FORMAT_CI8
:
894 return GR_TEXFMT_P_8
;
895 case MESA_FORMAT_AL88
:
896 return GR_TEXFMT_ALPHA_INTENSITY_88
;
897 case MESA_FORMAT_RGB565
:
898 return GR_TEXFMT_RGB_565
;
899 case MESA_FORMAT_ARGB4444
:
900 return GR_TEXFMT_ARGB_4444
;
901 case MESA_FORMAT_ARGB1555
:
902 return GR_TEXFMT_ARGB_1555
;
903 case MESA_FORMAT_ARGB8888
:
904 return GR_TEXFMT_ARGB_8888
;
905 case MESA_FORMAT_RGB_FXT1
:
906 case MESA_FORMAT_RGBA_FXT1
:
907 return GR_TEXFMT_ARGB_CMP_FXT1
;
908 case MESA_FORMAT_RGB_DXT1
:
909 case MESA_FORMAT_RGBA_DXT1
:
910 return GR_TEXFMT_ARGB_CMP_DXT1
;
911 case MESA_FORMAT_RGBA_DXT3
:
912 return GR_TEXFMT_ARGB_CMP_DXT3
;
913 case MESA_FORMAT_RGBA_DXT5
:
914 return GR_TEXFMT_ARGB_CMP_DXT5
;
916 _mesa_problem(NULL
, "Unexpected format in fxGlideFormat");
922 /* Texel-fetch functions for software texturing and glGetTexImage().
923 * We should have been able to use some "standard" fetch functions (which
924 * may get defined in texutil.c) but we have to account for scaled texture
925 * images on tdfx hardware (the 8:1 aspect ratio limit).
926 * Hence, we need special functions here.
929 fxt1_decode_1 (const void *texture
, int width
,
930 int i
, int j
, unsigned char *rgba
);
933 fetch_intensity8(const struct gl_texture_image
*texImage
,
934 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
936 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
937 const GLubyte
*texel
;
942 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
943 rgba
[RCOMP
] = *texel
;
944 rgba
[GCOMP
] = *texel
;
945 rgba
[BCOMP
] = *texel
;
946 rgba
[ACOMP
] = *texel
;
951 fetch_luminance8(const struct gl_texture_image
*texImage
,
952 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
954 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
955 const GLubyte
*texel
;
960 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
961 rgba
[RCOMP
] = *texel
;
962 rgba
[GCOMP
] = *texel
;
963 rgba
[BCOMP
] = *texel
;
969 fetch_alpha8(const struct gl_texture_image
*texImage
,
970 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
972 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
973 const GLubyte
*texel
;
978 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
982 rgba
[ACOMP
] = *texel
;
987 fetch_index8(const struct gl_texture_image
*texImage
,
988 GLint i
, GLint j
, GLint k
, GLchan
* indexOut
)
990 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
991 const GLubyte
*texel
;
996 texel
= ((GLubyte
*) texImage
->Data
) + j
* mml
->width
+ i
;
1002 fetch_luminance8_alpha8(const struct gl_texture_image
*texImage
,
1003 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1005 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1006 const GLubyte
*texel
;
1008 i
= i
* mml
->wScale
;
1009 j
= j
* mml
->hScale
;
1011 texel
= ((GLubyte
*) texImage
->Data
) + (j
* mml
->width
+ i
) * 2;
1012 rgba
[RCOMP
] = texel
[0];
1013 rgba
[GCOMP
] = texel
[0];
1014 rgba
[BCOMP
] = texel
[0];
1015 rgba
[ACOMP
] = texel
[1];
1020 fetch_r5g6b5(const struct gl_texture_image
*texImage
,
1021 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1023 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1024 const GLushort
*texel
;
1026 i
= i
* mml
->wScale
;
1027 j
= j
* mml
->hScale
;
1029 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1030 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1031 rgba
[GCOMP
] = (((*texel
) >> 5) & 0x3f) * 255 / 63;
1032 rgba
[BCOMP
] = (((*texel
) >> 0) & 0x1f) * 255 / 31;
1038 fetch_r4g4b4a4(const struct gl_texture_image
*texImage
,
1039 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1041 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1042 const GLushort
*texel
;
1044 i
= i
* mml
->wScale
;
1045 j
= j
* mml
->hScale
;
1047 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1048 rgba
[RCOMP
] = (((*texel
) >> 12) & 0xf) * 255 / 15;
1049 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xf) * 255 / 15;
1050 rgba
[BCOMP
] = (((*texel
) >> 4) & 0xf) * 255 / 15;
1051 rgba
[ACOMP
] = (((*texel
) >> 0) & 0xf) * 255 / 15;
1056 fetch_r5g5b5a1(const struct gl_texture_image
*texImage
,
1057 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1059 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1060 const GLushort
*texel
;
1062 i
= i
* mml
->wScale
;
1063 j
= j
* mml
->hScale
;
1065 texel
= ((GLushort
*) texImage
->Data
) + j
* mml
->width
+ i
;
1066 rgba
[RCOMP
] = (((*texel
) >> 11) & 0x1f) * 255 / 31;
1067 rgba
[GCOMP
] = (((*texel
) >> 6) & 0x1f) * 255 / 31;
1068 rgba
[BCOMP
] = (((*texel
) >> 1) & 0x1f) * 255 / 31;
1069 rgba
[ACOMP
] = (((*texel
) >> 0) & 0x01) * 255;
1074 fetch_a8r8g8b8(const struct gl_texture_image
*texImage
,
1075 GLint i
, GLint j
, GLint k
, GLchan
* rgba
)
1077 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1078 const GLuint
*texel
;
1080 i
= i
* mml
->wScale
;
1081 j
= j
* mml
->hScale
;
1083 texel
= ((GLuint
*) texImage
->Data
) + j
* mml
->width
+ i
;
1084 rgba
[RCOMP
] = (((*texel
) >> 16) & 0xff);
1085 rgba
[GCOMP
] = (((*texel
) >> 8) & 0xff);
1086 rgba
[BCOMP
] = (((*texel
) ) & 0xff);
1087 rgba
[ACOMP
] = (((*texel
) >> 24) & 0xff);
1092 fetch_rgb_fxt1(const struct gl_texture_image
*texImage
,
1093 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1095 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1097 i
= i
* mml
->wScale
;
1098 j
= j
* mml
->hScale
;
1100 fxt1_decode_1(texImage
->Data
, mml
->width
, i
, j
, rgba
);
1106 fetch_rgba_fxt1(const struct gl_texture_image
*texImage
,
1107 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1109 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1111 i
= i
* mml
->wScale
;
1112 j
= j
* mml
->hScale
;
1114 fxt1_decode_1(texImage
->Data
, mml
->width
, i
, j
, rgba
);
1119 fetch_rgb_dxt1(const struct gl_texture_image
*texImage
,
1120 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1122 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1124 i
= i
* mml
->wScale
;
1125 j
= j
* mml
->hScale
;
1127 /* XXX Get fetch func from _mesa_get_texel_fetch_func()
1128 _mesa_texformat_rgb_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
1134 fetch_rgba_dxt1(const struct gl_texture_image
*texImage
,
1135 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1137 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1139 i
= i
* mml
->wScale
;
1140 j
= j
* mml
->hScale
;
1142 /* XXX Get fetch func from _mesa_get_texel_fetch_func()
1143 _mesa_texformat_rgba_dxt1.FetchTexel2D(texImage, i, j, k, rgba);
1149 fetch_rgba_dxt3(const struct gl_texture_image
*texImage
,
1150 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1152 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1154 i
= i
* mml
->wScale
;
1155 j
= j
* mml
->hScale
;
1157 /* XXX Get fetch func from _mesa_get_texel_fetch_func()
1158 _mesa_texformat_rgba_dxt3.FetchTexel2D(texImage, i, j, k, rgba);
1164 fetch_rgba_dxt5(const struct gl_texture_image
*texImage
,
1165 GLint i
, GLint j
, GLint k
, GLchan
*rgba
)
1167 const tdfxMipMapLevel
*mml
= TDFX_TEXIMAGE_DATA(texImage
);
1169 i
= i
* mml
->wScale
;
1170 j
= j
* mml
->hScale
;
1172 /* XXX Get fetch func from _mesa_get_texel_fetch_func()
1173 _mesa_texformat_rgba_dxt5.FetchTexel2D(texImage, i, j, k, rgba);
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 tdfxMipMapLevel
*mml
,
1226 struct gl_texture_image
*texImage
,
1230 const GLint newWidth
= width
* mml
->wScale
;
1231 const GLint newHeight
= height
* mml
->hScale
;
1233 GLuint dstImageOffsets
= 0;
1235 if (!_mesa_is_format_compressed(texImage
->TexFormat
)) {
1238 tempImage
= MALLOC(width
* height
* texelBytes
);
1243 _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
1244 texImage
->TexFormat
, tempImage
,
1245 0, 0, 0, /* dstX/Y/Zoffset */
1246 width
* texelBytes
, /* dstRowStride */
1249 format
, type
, pixels
, packing
);
1252 /* compute address of dest subimage within the overal tex image */
1253 destAddr
= (GLubyte
*) texImage
->Data
1254 + (yoffset
* mml
->hScale
* mml
->width
1255 + xoffset
* mml
->wScale
) * texelBytes
;
1257 _mesa_rescale_teximage2d(texelBytes
,
1259 dstRowStride
, /* dst stride */
1261 newWidth
, newHeight
,
1262 tempImage
, destAddr
);
1264 const GLint rawBytes
= 4;
1265 GLvoid
*rawImage
= MALLOC(width
* height
* rawBytes
);
1270 tempImage
= MALLOC(newWidth
* newHeight
* rawBytes
);
1275 /* unpack image, apply transfer ops and store in rawImage */
1276 _mesa_texstore(ctx
, 2, GL_RGBA
,
1277 MESA_FORMAT_RGBA8888_REV
, rawImage
,
1278 0, 0, 0, /* dstX/Y/Zoffset */
1279 width
* rawBytes
, /* dstRowStride */
1282 format
, type
, pixels
, packing
);
1283 _mesa_rescale_teximage2d(rawBytes
,
1285 newWidth
* rawBytes
, /* dst stride */
1286 width
, height
, /* src */
1287 newWidth
, newHeight
, /* dst */
1288 rawImage
/*src*/, tempImage
/*dst*/ );
1289 _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
1290 texImage
->TexFormat
, texImage
->Data
,
1291 xoffset
* mml
->wScale
, yoffset
* mml
->hScale
, 0, /* dstX/Y/Zoffset */
1294 newWidth
, newHeight
, 1,
1295 GL_RGBA
, CHAN_TYPE
, tempImage
, &ctx
->DefaultPacking
);
1306 tdfxTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
1307 GLint internalFormat
, GLint width
, GLint height
, GLint border
,
1308 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1309 const struct gl_pixelstore_attrib
*packing
,
1310 struct gl_texture_object
*texObj
,
1311 struct gl_texture_image
*texImage
)
1313 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1315 tdfxMipMapLevel
*mml
;
1316 GLint texelBytes
, dstRowStride
;
1320 printf("TexImage id=%d int 0x%x format 0x%x type 0x%x %dx%d\n",
1321 texObj->Name, texImage->InternalFormat, format, type,
1322 texImage->Width, texImage->Height);
1325 ti
= TDFX_TEXTURE_DATA(texObj
);
1327 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1328 if (!texObj
->DriverData
) {
1329 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1332 ti
= TDFX_TEXTURE_DATA(texObj
);
1336 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1338 texImage
->DriverData
= CALLOC(sizeof(tdfxMipMapLevel
));
1339 if (!texImage
->DriverData
) {
1340 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1343 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1346 /* Determine width and height scale factors for texture.
1347 * Remember, Glide is limited to 8:1 aspect ratios.
1350 texImage
->Width
, texImage
->Height
,
1351 NULL
, /* lod level */
1352 NULL
, /* aspect ratio */
1353 NULL
, NULL
, /* sscale, tscale */
1354 &mml
->wScale
, &mml
->hScale
);
1356 /* rescaled size: */
1357 mml
->width
= width
* mml
->wScale
;
1358 mml
->height
= height
* mml
->hScale
;
1360 #if FX_COMPRESS_S3TC_AS_FXT1_HACK
1361 /* [koolsmoky] substitute FXT1 for DXTn and Legacy S3TC */
1362 /* [dBorca] we should update texture's attribute, then,
1363 * because if the application asks us to decompress, we
1364 * have to know the REAL format! Also, DXT3/5 might not
1365 * be correct, since it would mess with "compressedSize".
1366 * Ditto for GL_RGBA[4]_S3TC, which is always mapped to DXT3.
1368 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
1369 switch (internalFormat
) {
1370 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1373 internalFormat
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1375 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1376 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1377 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1380 internalFormat
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1382 texImage
->InternalFormat
= internalFormat
;
1386 if (fxMesa
->type
>= GR_SSTTYPE_Voodoo4
) {
1387 GLenum texNapalm
= 0;
1388 if (internalFormat
== GL_COMPRESSED_RGB
) {
1389 texNapalm
= GL_COMPRESSED_RGB_FXT1_3DFX
;
1390 } else if (internalFormat
== GL_COMPRESSED_RGBA
) {
1391 texNapalm
= GL_COMPRESSED_RGBA_FXT1_3DFX
;
1394 texImage
->InternalFormat
= internalFormat
= texNapalm
;
1395 _mesa_is_format_compressed(texImage
->TexFormat
) = GL_TRUE
;
1400 /* choose the texture format */
1401 assert(ctx
->Driver
.ChooseTextureFormat
);
1402 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1403 internalFormat
, format
, type
);
1404 assert(texImage
->TexFormat
);
1405 mesaFormat
= texImage
->TexFormat
;
1406 mml
->glideFormat
= fxGlideFormat(mesaFormat
);
1407 ti
->info
.format
= mml
->glideFormat
;
1408 texImage
->FetchTexelc
= fxFetchFunction(mesaFormat
);
1409 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
1411 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
1412 texImage
->CompressedSize
= _mesa_compressed_texture_size(ctx
,
1417 dstRowStride
= _mesa_compressed_row_stride(texImage
->TexFormat
, mml
->width
);
1418 texImage
->Data
= _mesa_alloc_texmemory(texImage
->CompressedSize
);
1420 dstRowStride
= mml
->width
* texelBytes
;
1421 texImage
->Data
= _mesa_alloc_texmemory(mml
->width
* mml
->height
* texelBytes
);
1423 if (!texImage
->Data
) {
1424 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1428 if (pixels
!= NULL
) {
1429 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1430 /* rescale image to overcome 1:8 aspect limitation */
1431 if (!adjust2DRatio(ctx
,
1434 format
, type
, pixels
,
1441 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1446 /* no rescaling needed */
1447 /* unpack image, apply transfer ops and store in texImage->Data */
1448 _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
1449 texImage
->TexFormat
, texImage
->Data
,
1450 0, 0, 0, /* dstX/Y/Zoffset */
1452 texImage
->ImageOffsets
,
1454 format
, type
, pixels
, packing
);
1458 RevalidateTexture(ctx
, texObj
);
1460 ti
->reloadImages
= GL_TRUE
;
1461 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
1466 tdfxTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
1467 GLint xoffset
, GLint yoffset
,
1468 GLsizei width
, GLsizei height
,
1469 GLenum format
, GLenum type
,
1470 const GLvoid
*pixels
,
1471 const struct gl_pixelstore_attrib
*packing
,
1472 struct gl_texture_object
*texObj
,
1473 struct gl_texture_image
*texImage
)
1475 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1477 tdfxMipMapLevel
*mml
;
1478 GLint texelBytes
, dstRowStride
;
1480 if (!texObj
->DriverData
) {
1481 _mesa_problem(ctx
, "problem in fxDDTexSubImage2D");
1485 ti
= TDFX_TEXTURE_DATA(texObj
);
1487 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1490 assert(texImage
->Data
); /* must have an existing texture image! */
1491 assert(texImage
->_BaseFormat
);
1493 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
1494 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
1495 dstRowStride
= _mesa_compressed_row_stride(texImage
->TexFormat
, mml
->width
);
1497 dstRowStride
= mml
->width
* texelBytes
;
1500 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1501 /* need to rescale subimage to match mipmap level's rescale factors */
1502 if (!adjust2DRatio(ctx
,
1505 format
, type
, pixels
,
1512 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1517 /* no rescaling needed */
1518 _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
1519 texImage
->TexFormat
, texImage
->Data
,
1520 xoffset
, yoffset
, 0,
1522 texImage
->ImageOffsets
,
1524 format
, type
, pixels
, packing
);
1527 ti
->reloadImages
= GL_TRUE
; /* signal the image needs to be reloaded */
1528 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
; /* XXX this might be a bit much */
1533 tdfxTexImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
1534 GLint internalFormat
, GLint width
, GLint border
,
1535 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1536 const struct gl_pixelstore_attrib
*packing
,
1537 struct gl_texture_object
*texObj
,
1538 struct gl_texture_image
*texImage
)
1540 tdfxTexImage2D(ctx
, target
, level
,
1541 internalFormat
, width
, 1, border
,
1542 format
, type
, pixels
,
1549 tdfxTexSubImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
1552 GLenum format
, GLenum type
,
1553 const GLvoid
*pixels
,
1554 const struct gl_pixelstore_attrib
*packing
,
1555 struct gl_texture_object
*texObj
,
1556 struct gl_texture_image
*texImage
)
1558 tdfxTexSubImage2D(ctx
, target
, level
,
1568 /**********************************************************************/
1569 /**** COMPRESSED TEXTURE IMAGE FUNCTIONS ****/
1570 /**********************************************************************/
1573 tdfxCompressedTexImage2D (GLcontext
*ctx
, GLenum target
,
1574 GLint level
, GLint internalFormat
,
1575 GLsizei width
, GLsizei height
, GLint border
,
1576 GLsizei imageSize
, const GLvoid
*data
,
1577 struct gl_texture_object
*texObj
,
1578 struct gl_texture_image
*texImage
)
1580 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1582 tdfxMipMapLevel
*mml
;
1585 if (TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
1586 fprintf(stderr
, "tdfxCompressedTexImage2D: id=%d int 0x%x %dx%d\n",
1587 texObj
->Name
, internalFormat
,
1591 if ((target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
) || texImage
->Border
> 0) {
1592 _mesa_problem(NULL
, "tdfx: unsupported texture in tdfxCompressedTexImg()\n");
1596 ti
= TDFX_TEXTURE_DATA(texObj
);
1598 texObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1599 if (!texObj
->DriverData
) {
1600 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1603 ti
= TDFX_TEXTURE_DATA(texObj
);
1607 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1609 texImage
->DriverData
= CALLOC(sizeof(tdfxMipMapLevel
));
1610 if (!texImage
->DriverData
) {
1611 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1614 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1617 tdfxTexGetInfo(ctx
, width
, height
, NULL
, NULL
, NULL
, NULL
,
1618 &mml
->wScale
, &mml
->hScale
);
1620 mml
->width
= width
* mml
->wScale
;
1621 mml
->height
= height
* mml
->hScale
;
1624 /* choose the texture format */
1625 assert(ctx
->Driver
.ChooseTextureFormat
);
1626 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
1627 internalFormat
, -1/*format*/, -1/*type*/);
1628 assert(texImage
->TexFormat
);
1630 /* Determine the appropriate Glide texel format,
1631 * given the user's internal texture format hint.
1633 mesaFormat
= texImage
->TexFormat
;
1634 mml
->glideFormat
= fxGlideFormat(mesaFormat
);
1635 ti
->info
.format
= mml
->glideFormat
;
1636 texImage
->FetchTexelc
= fxFetchFunction(mesaFormat
);
1638 /* allocate new storage for texture image, if needed */
1639 if (!texImage
->Data
) {
1640 texImage
->CompressedSize
= _mesa_compressed_texture_size(ctx
,
1645 texImage
->Data
= _mesa_alloc_texmemory(texImage
->CompressedSize
);
1646 if (!texImage
->Data
) {
1647 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1652 /* save the texture data */
1653 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1654 /* [dBorca] Hack alert:
1655 * now we're screwed. We can't decompress,
1656 * unless we do it in HW (via textureBuffer).
1657 * We still have some chances:
1658 * 1) we got FXT1 textures - we CAN decompress, rescale for
1659 * aspectratio, then compress back.
1660 * 2) there is a chance that MIN("s", "t") won't be overflowed.
1661 * Thus, we don't care about textureclamp and we could lower
1662 * MIN("uscale", "vscale") below 32. We still have to have
1663 * our data aligned inside a 8:1 rectangle.
1664 * 3) just in case if MIN("s", "t") gets overflowed with GL_REPEAT,
1665 * we replicate the data over the padded area.
1666 * For now, we take 2) + 3) but texelfetchers will be wrong!
1668 const GLuint mesaFormat
= texImage
->TexFormat
;
1669 GLuint srcRowStride
= _mesa_compressed_row_stride(mesaFormat
, width
);
1671 GLuint destRowStride
= _mesa_compressed_row_stride(mesaFormat
,
1674 _mesa_upscale_teximage2d(srcRowStride
, (height
+3) / 4,
1675 destRowStride
, (mml
->height
+3) / 4,
1676 1, data
, srcRowStride
,
1678 ti
->padded
= GL_TRUE
;
1680 MEMCPY(texImage
->Data
, data
, texImage
->CompressedSize
);
1683 RevalidateTexture(ctx
, texObj
);
1685 ti
->reloadImages
= GL_TRUE
;
1686 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
1691 tdfxCompressedTexSubImage2D( GLcontext
*ctx
, GLenum target
,
1692 GLint level
, GLint xoffset
,
1693 GLint yoffset
, GLsizei width
,
1694 GLint height
, GLenum format
,
1695 GLsizei imageSize
, const GLvoid
*data
,
1696 struct gl_texture_object
*texObj
,
1697 struct gl_texture_image
*texImage
)
1699 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1701 tdfxMipMapLevel
*mml
;
1702 GLint destRowStride
, srcRowStride
;
1705 const GLuint mesaFormat
= texImage
->TexFormat
;
1707 if (TDFX_DEBUG
& DEBUG_VERBOSE_DRI
) {
1708 fprintf(stderr
, "tdfxCompressedTexSubImage2D: id=%d\n", texObj
->Name
);
1711 ti
= TDFX_TEXTURE_DATA(texObj
);
1713 mml
= TDFX_TEXIMAGE_DATA(texImage
);
1716 srcRowStride
= _mesa_compressed_row_stride(mesaFormat
, width
);
1718 destRowStride
= _mesa_compressed_row_stride(mesaFormat
, mml
->width
);
1719 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
1722 (GLubyte
*) texImage
->Data
);
1724 rows
= height
/ 4; /* [dBorca] hardcoded 4, but works for FXT1/DXTC */
1726 for (i
= 0; i
< rows
; i
++) {
1727 MEMCPY(dest
, data
, srcRowStride
);
1728 dest
+= destRowStride
;
1729 data
= (GLvoid
*)((intptr_t)data
+ (intptr_t)srcRowStride
);
1732 /* [dBorca] Hack alert:
1733 * see fxDDCompressedTexImage2D for caveats
1735 if (mml
->wScale
!= 1 || mml
->hScale
!= 1) {
1736 srcRowStride
= _mesa_compressed_row_stride(mesaFormat
, texImage
->Width
);
1738 destRowStride
= _mesa_compressed_row_stride(mesaFormat
, mml
->width
);
1739 _mesa_upscale_teximage2d(srcRowStride
, texImage
->Height
/ 4,
1740 destRowStride
, mml
->height
/ 4,
1741 1, texImage
->Data
, destRowStride
,
1745 RevalidateTexture(ctx
, texObj
);
1747 ti
->reloadImages
= GL_TRUE
;
1748 fxMesa
->new_state
|= TDFX_NEW_TEXTURE
;
1754 PrintTexture(int w
, int h
, int c
, const GLubyte
* data
)
1757 for (i
= 0; i
< h
; i
++) {
1758 for (j
= 0; j
< w
; j
++) {
1760 printf("%02x %02x ", data
[0], data
[1]);
1762 printf("%02x %02x %02x ", data
[0], data
[1], data
[2]);
1772 tdfxTestProxyTexImage(GLcontext
*ctx
, GLenum target
,
1773 GLint level
, GLint internalFormat
,
1774 GLenum format
, GLenum type
,
1775 GLint width
, GLint height
,
1776 GLint depth
, GLint border
)
1778 tdfxContextPtr fxMesa
= TDFX_CONTEXT(ctx
);
1779 struct gl_shared_state
*mesaShared
= fxMesa
->glCtx
->Shared
;
1780 struct tdfxSharedState
*shared
= (struct tdfxSharedState
*) mesaShared
->DriverData
;
1783 case GL_PROXY_TEXTURE_1D
:
1785 case GL_PROXY_TEXTURE_2D
:
1787 struct gl_texture_object
*tObj
;
1791 tObj
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
1792 if (!tObj
->DriverData
)
1793 tObj
->DriverData
= fxAllocTexObjData(fxMesa
);
1794 ti
= TDFX_TEXTURE_DATA(tObj
);
1797 /* assign the parameters to test against */
1798 tObj
->Image
[0][level
]->Width
= width
;
1799 tObj
->Image
[0][level
]->Height
= height
;
1800 tObj
->Image
[0][level
]->Border
= border
;
1802 tObj
->Image
[0][level
]->InternalFormat
= internalFormat
;
1805 /* don't use mipmap levels > 0 */
1806 tObj
->MinFilter
= tObj
->MagFilter
= GL_NEAREST
;
1809 /* test with all mipmap levels */
1810 tObj
->MinFilter
= GL_LINEAR_MIPMAP_LINEAR
;
1811 tObj
->MagFilter
= GL_NEAREST
;
1813 RevalidateTexture(ctx
, tObj
);
1816 printf("small lodlog2 0x%x\n", ti->info.smallLodLog2);
1817 printf("large lodlog2 0x%x\n", ti->info.largeLodLog2);
1818 printf("aspect ratio 0x%x\n", ti->info.aspectRatioLog2);
1819 printf("glide format 0x%x\n", ti->info.format);
1820 printf("data %p\n", ti->info.data);
1821 printf("lodblend %d\n", (int) ti->LODblend);
1824 /* determine where texture will reside */
1825 if (ti
->LODblend
&& !shared
->umaTexMemory
) {
1826 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1827 memNeeded
= fxMesa
->Glide
.grTexTextureMemRequired(
1828 GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
1831 /* XXX GR_MIPMAPLEVELMASK_BOTH might not be right, but works */
1832 memNeeded
= fxMesa
->Glide
.grTexTextureMemRequired(
1833 GR_MIPMAPLEVELMASK_BOTH
, &(ti
->info
));
1836 printf("Proxy test %d > %d\n", memNeeded, shared->totalTexMem[0]);
1838 if (memNeeded
> shared
->totalTexMem
[0])
1843 case GL_PROXY_TEXTURE_3D
:
1844 return GL_TRUE
; /* software rendering */
1846 return GL_TRUE
; /* never happens, silence compiler */
1852 * Allocate a new texture object.
1853 * Called via ctx->Driver.NewTextureObject.
1854 * Note: this function will be called during context creation to
1855 * allocate the default texture objects.
1856 * Note: we could use containment here to 'derive' the driver-specific
1857 * texture object from the core mesa gl_texture_object. Not done at this time.
1859 static struct gl_texture_object
*
1860 tdfxNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
1862 struct gl_texture_object
*obj
;
1863 obj
= _mesa_new_texture_object(ctx
, name
, target
);
1868 void tdfxInitTextureFuncs( struct dd_function_table
*functions
)
1870 functions
->BindTexture
= tdfxBindTexture
;
1871 functions
->NewTextureObject
= tdfxNewTextureObject
;
1872 functions
->DeleteTexture
= tdfxDeleteTexture
;
1873 functions
->TexEnv
= tdfxTexEnv
;
1874 functions
->TexParameter
= tdfxTexParameter
;
1875 functions
->ChooseTextureFormat
= tdfxChooseTextureFormat
;
1876 functions
->TexImage1D
= tdfxTexImage1D
;
1877 functions
->TexSubImage1D
= tdfxTexSubImage1D
;
1878 functions
->TexImage2D
= tdfxTexImage2D
;
1879 functions
->TexSubImage2D
= tdfxTexSubImage2D
;
1880 functions
->IsTextureResident
= tdfxIsTextureResident
;
1881 functions
->CompressedTexImage2D
= tdfxCompressedTexImage2D
;
1882 functions
->CompressedTexSubImage2D
= tdfxCompressedTexSubImage2D
;
1883 functions
->UpdateTexturePalette
= tdfxUpdateTexturePalette
;
1884 functions
->GenerateMipmap
= tdfxGenerateMipmap
;