2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
32 #include "savagecontext.h"
33 #include "savagetex.h"
34 #include "savagetris.h"
35 #include "savageioctl.h"
36 #include "simple_list.h"
38 #include "savage_bci.h"
41 #include "texformat.h"
48 #include "swrast/swrast.h"
52 #define TILE_INDEX_DXT1 0
53 #define TILE_INDEX_8 1
54 #define TILE_INDEX_16 2
55 #define TILE_INDEX_DXTn 3
56 #define TILE_INDEX_32 4
58 /* On Savage4 the texure LOD-bias needs an offset of ~ 0.3 to get
59 * somewhere close to software rendering.
61 #define SAVAGE4_LOD_OFFSET 10
63 /* Tile info for S3TC formats counts in 4x4 blocks instead of texels.
64 * In DXT1 each block is encoded in 64 bits. In DXT3 and 5 each block is
65 * encoded in 128 bits. */
67 /* Size 1, 2 and 4 images are packed into the last subtile. Each image
68 * is repeated to fill a 4x4 pixel area. The figure below shows the
69 * layout of those 4x4 pixel areas in the 8x8 subtile.
74 * Yuck! 8-bit texture formats use 4x8 subtiles. See below.
76 static const savageTileInfo tileInfo_pro
[5] = {
77 {16, 16, 16, 8, 1, 2, {0x18, 0x10}}, /* DXT1 */
78 {64, 32, 16, 4, 4, 8, {0x30, 0x20}}, /* 8-bit */
79 {64, 16, 8, 2, 8, 8, {0x48, 0x08}}, /* 16-bit */
80 {16, 8, 16, 4, 1, 2, {0x30, 0x20}}, /* DXT3, DXT5 */
81 {32, 16, 4, 2, 8, 8, {0x90, 0x10}}, /* 32-bit */
84 /* Size 1, 2 and 4 images are packed into the last two subtiles. Each
85 * image is repeated to fill a 4x4 pixel area. The figures below show
86 * the layout of those 4x4 pixel areas in the two 4x8 subtiles.
88 * second last subtile: 4 last subtile: 2
91 static const savageTileInfo tileInfo_s3d_s4
[5] = {
92 {16, 16, 16, 8, 1, 2, {0x18, 0x10}}, /* DXT1 */
93 {64, 32, 16, 4, 4, 8, {0x30, 0x20}}, /* 8-bit */
94 {64, 16, 16, 2, 4, 8, {0x60, 0x40}}, /* 16-bit */
95 {16, 8, 16, 4, 1, 2, {0x30, 0x20}}, /* DXT3, DXT5 */
96 {32, 16, 8, 2, 4, 8, {0xc0, 0x80}}, /* 32-bit */
99 /** \brief Template for subtile uploads.
100 * \param h height in pixels
101 * \param w width in bytes
103 #define SUBTILE_FUNC(w,h) \
104 static __inline GLubyte *savageUploadSubtile_##w##x##h \
105 (GLubyte *dest, GLubyte *src, GLuint srcStride) \
108 for (y = 0; y < h; ++y) { \
109 memcpy (dest, src, w); \
116 SUBTILE_FUNC(2, 8) /* 4 bits per pixel, 4 pixels wide */
120 SUBTILE_FUNC(32, 8) /* 4 bytes per pixel, 8 pixels wide */
122 SUBTILE_FUNC(8, 2) /* DXT1 */
123 SUBTILE_FUNC(16, 2) /* DXT3 and DXT5 */
125 /** \brief Upload a complete tile from src (srcStride) to dest
127 * \param tileInfo Pointer to tiling information
128 * \param wInSub Width of source/dest image in subtiles
129 * \param hInSub Height of source/dest image in subtiles
130 * \param bpp Bytes per pixel
131 * \param src Pointer to source data
132 * \param srcStride Byte stride of rows in the source data
133 * \param dest Pointer to destination
135 * Writes linearly to the destination memory in order to exploit write
138 * For a complete tile wInSub and hInSub are set to the same values as
139 * in tileInfo. If the source image is smaller than a whole tile in
140 * one or both dimensions then they are set to the values of the
141 * source image. This only works as long as the source image is bigger
144 static void savageUploadTile (const savageTileInfo
*tileInfo
,
145 GLuint wInSub
, GLuint hInSub
, GLuint bpp
,
146 GLubyte
*src
, GLuint srcStride
, GLubyte
*dest
) {
147 GLuint subStride
= tileInfo
->subWidth
* bpp
;
148 GLubyte
*srcSRow
= src
, *srcSTile
= src
;
149 GLubyte
*(*subtileFunc
) (GLubyte
*, GLubyte
*, GLuint
);
152 case 2: subtileFunc
= savageUploadSubtile_2x8
; break;
153 case 4: subtileFunc
= savageUploadSubtile_4x8
; break;
154 case 8: subtileFunc
= tileInfo
->subHeight
== 8 ?
155 savageUploadSubtile_8x8
: savageUploadSubtile_8x2
; break;
156 case 16: subtileFunc
= tileInfo
->subHeight
== 8 ?
157 savageUploadSubtile_16x8
: savageUploadSubtile_16x2
; break;
158 case 32: subtileFunc
= savageUploadSubtile_32x8
; break;
161 for (sy
= 0; sy
< hInSub
; ++sy
) {
163 for (sx
= 0; sx
< wInSub
; ++sx
) {
165 dest
= subtileFunc (dest
, src
, srcStride
);
166 srcSTile
+= subStride
;
168 srcSRow
+= srcStride
* tileInfo
->subHeight
;
172 /** \brief Upload a image that is smaller than 8 pixels in either dimension.
174 * \param tileInfo Pointer to tiling information
175 * \param width Width of the image
176 * \param height Height of the image
177 * \param bpp Bytes per pixel
178 * \param src Pointer to source data
179 * \param dest Pointer to destination
181 * This function handles all the special cases that need to be taken
182 * care off. The caller may need to call this function multiple times
183 * with the destination offset in different ways since small texture
184 * images must be repeated in order to fill a whole tile (or 4x4 for
185 * the last 3 levels).
187 * FIXME: Repeating inside this function would be more efficient.
189 static void savageUploadTiny (const savageTileInfo
*tileInfo
,
190 GLuint pixWidth
, GLuint pixHeight
,
191 GLuint width
, GLuint height
, GLuint bpp
,
192 GLubyte
*src
, GLubyte
*dest
) {
193 GLuint size
= MAX2(pixWidth
, pixHeight
);
195 if (width
> tileInfo
->subWidth
) { /* assert: height <= subtile height */
196 GLuint wInSub
= width
/ tileInfo
->subWidth
;
197 GLuint srcStride
= width
* bpp
;
198 GLuint subStride
= tileInfo
->subWidth
* bpp
;
199 GLuint subSkip
= (tileInfo
->subHeight
- height
) * subStride
;
200 GLubyte
*srcSTile
= src
;
202 for (sx
= 0; sx
< wInSub
; ++sx
) {
204 for (y
= 0; y
< height
; ++y
) {
205 memcpy (dest
, src
, subStride
);
210 srcSTile
+= subStride
;
212 } else if (size
> 4) { /* a tile or less wide, except the last 3 levels */
213 GLuint srcStride
= width
* bpp
;
214 GLuint subStride
= tileInfo
->subWidth
* bpp
;
215 /* if the subtile width is 4 we have to skip every other subtile */
216 GLuint subSkip
= tileInfo
->subWidth
<= 4 ?
217 subStride
* tileInfo
->subHeight
: 0;
218 GLuint skipRemainder
= tileInfo
->subHeight
- 1;
220 for (y
= 0; y
< height
; ++y
) {
221 memcpy (dest
, src
, srcStride
);
224 if ((y
& skipRemainder
) == skipRemainder
)
227 } else { /* the last 3 mipmap levels */
228 GLuint offset
= (size
<= 2 ? tileInfo
->tinyOffset
[size
-1] : 0);
229 GLuint subStride
= tileInfo
->subWidth
* bpp
;
232 for (y
= 0; y
< height
; ++y
) {
233 memcpy (dest
, src
, bpp
*width
);
240 /** \brief Upload an image from mesa's internal copy.
242 static void savageUploadTexLevel( savageTexObjPtr t
, int level
)
244 const struct gl_texture_image
*image
= t
->base
.tObj
->Image
[0][level
];
245 const savageTileInfo
*tileInfo
= t
->tileInfo
;
246 GLuint pixWidth
= image
->Width2
, pixHeight
= image
->Height2
;
247 GLuint bpp
= t
->texelBytes
;
248 GLuint width
, height
;
250 /* FIXME: Need triangle (rather than pixel) fallbacks to simulate
251 * this using normal textured triangles.
253 * DO THIS IN DRIVER STATE MANAGMENT, not hardware state.
255 if(image
->Border
!= 0)
256 fprintf (stderr
, "Not supported texture border %d.\n",
257 (int) image
->Border
);
259 if (t
->hwFormat
== TFT_S3TC4A4Bit
|| t
->hwFormat
== TFT_S3TC4CA4Bit
||
260 t
->hwFormat
== TFT_S3TC4Bit
) {
261 width
= (pixWidth
+3) / 4;
262 height
= (pixHeight
+3) / 4;
268 if (pixWidth
>= 8 && pixHeight
>= 8) {
269 GLuint
*dirtyPtr
= t
->image
[level
].dirtyTiles
;
270 GLuint dirtyMask
= 1;
272 if (width
>= tileInfo
->width
&& height
>= tileInfo
->height
) {
273 GLuint wInTiles
= width
/ tileInfo
->width
;
274 GLuint hInTiles
= height
/ tileInfo
->height
;
275 GLubyte
*srcTRow
= image
->Data
, *src
;
276 GLubyte
*dest
= (GLubyte
*)(t
->bufAddr
+ t
->image
[level
].offset
);
278 for (y
= 0; y
< hInTiles
; ++y
) {
280 for (x
= 0; x
< wInTiles
; ++x
) {
281 if (*dirtyPtr
& dirtyMask
) {
282 savageUploadTile (tileInfo
,
283 tileInfo
->wInSub
, tileInfo
->hInSub
,
284 bpp
, src
, width
* bpp
, dest
);
286 src
+= tileInfo
->width
* bpp
;
287 dest
+= 2048; /* tile size is always 2k */
288 if (dirtyMask
== 1<<31) {
294 srcTRow
+= width
* tileInfo
->height
* bpp
;
296 } else if (width
>= tileInfo
->width
) {
297 GLuint wInTiles
= width
/ tileInfo
->width
;
298 GLubyte
*src
= image
->Data
;
299 GLubyte
*dest
= (GLubyte
*)(t
->bufAddr
+ t
->image
[level
].offset
);
300 GLuint tileStride
= tileInfo
->width
* bpp
* height
;
301 savageContextPtr imesa
= (savageContextPtr
)t
->base
.heap
->driverContext
;
303 /* Savage3D-based chips seem so use a constant tile stride
304 * of 2048 for vertically incomplete tiles, but only if
305 * the color depth is 32bpp. Nobody said this was supposed
308 if (bpp
== 4 && imesa
->savageScreen
->chipset
< S3_SAVAGE4
)
310 for (x
= 0; x
< wInTiles
; ++x
) {
311 if (*dirtyPtr
& dirtyMask
) {
312 savageUploadTile (tileInfo
,
314 height
/ tileInfo
->subHeight
,
315 bpp
, src
, width
* bpp
, dest
);
317 src
+= tileInfo
->width
* bpp
;
319 if (dirtyMask
== 1<<31) {
326 savageUploadTile (tileInfo
, width
/ tileInfo
->subWidth
,
327 height
/ tileInfo
->subHeight
, bpp
,
328 image
->Data
, width
* bpp
,
329 (GLubyte
*)(t
->bufAddr
+t
->image
[level
].offset
));
332 GLuint minHeight
, minWidth
, hRepeat
, vRepeat
, x
, y
;
333 if (t
->hwFormat
== TFT_S3TC4A4Bit
|| t
->hwFormat
== TFT_S3TC4CA4Bit
||
334 t
->hwFormat
== TFT_S3TC4Bit
)
335 minWidth
= minHeight
= 1;
337 minWidth
= minHeight
= 4;
338 if (width
> minWidth
|| height
> minHeight
) {
339 minWidth
= tileInfo
->subWidth
;
340 minHeight
= tileInfo
->subHeight
;
342 hRepeat
= width
>= minWidth
? 1 : minWidth
/ width
;
343 vRepeat
= height
>= minHeight
? 1 : minHeight
/ height
;
344 for (y
= 0; y
< vRepeat
; ++y
) {
345 GLuint offset
= y
* tileInfo
->subWidth
*height
* bpp
;
346 for (x
= 0; x
< hRepeat
; ++x
) {
347 savageUploadTiny (tileInfo
, pixWidth
, pixHeight
,
348 width
, height
, bpp
, image
->Data
,
349 (GLubyte
*)(t
->bufAddr
+
350 t
->image
[level
].offset
+offset
));
351 offset
+= width
* bpp
;
357 /** \brief Compute the destination size of a texture image
359 static GLuint
savageTexImageSize (GLuint width
, GLuint height
, GLuint bpp
) {
361 if (width
>= 8 && height
>= 8)
362 return width
* height
* bpp
;
363 /* special case for the last three mipmap levels: the hardware computes
364 * the offset internally */
365 else if (width
<= 4 && height
<= 4)
367 /* partially filled sub tiles waste memory
368 * on Savage3D and Savage4 with subtile width 4 every other subtile is
369 * skipped if width < 8 so we can assume a uniform subtile width of 8 */
371 return width
* 8 * bpp
;
372 else if (height
>= 8)
373 return 8 * height
* bpp
;
378 /** \brief Compute the destination size of a compressed texture image
380 static GLuint
savageCompressedTexImageSize (GLuint width
, GLuint height
,
382 width
= (width
+3) / 4;
383 height
= (height
+3) / 4;
385 if (width
>= 2 && height
>= 2)
386 return width
* height
* bpp
;
387 /* special case for the last three mipmap levels: the hardware computes
388 * the offset internally */
389 else if (width
<= 1 && height
<= 1)
391 /* partially filled sub tiles waste memory
392 * on Savage3D and Savage4 with subtile width 4 every other subtile is
393 * skipped if width < 8 so we can assume a uniform subtile width of 8 */
395 return width
* 2 * bpp
;
396 else if (height
>= 2)
397 return 2 * height
* bpp
;
402 /** \brief Compute the number of (partial) tiles of a texture image
404 static GLuint
savageTexImageTiles (GLuint width
, GLuint height
,
405 const savageTileInfo
*tileInfo
)
407 return (width
+ tileInfo
->width
- 1) / tileInfo
->width
*
408 (height
+ tileInfo
->height
- 1) / tileInfo
->height
;
411 /** \brief Mark dirty tiles
413 * Some care must be taken because tileInfo may not be set or not
414 * up-to-date. So we check if tileInfo is initialized and if the number
415 * of tiles in the bit vector matches the number of tiles computed from
416 * the current tileInfo.
418 static void savageMarkDirtyTiles (savageTexObjPtr t
, GLuint level
,
419 GLuint totalWidth
, GLuint totalHeight
,
420 GLint xoffset
, GLint yoffset
,
421 GLsizei width
, GLsizei height
)
423 GLuint wInTiles
, hInTiles
;
424 GLuint x0
, y0
, x1
, y1
;
428 wInTiles
= (totalWidth
+ t
->tileInfo
->width
- 1) / t
->tileInfo
->width
;
429 hInTiles
= (totalHeight
+ t
->tileInfo
->height
- 1) / t
->tileInfo
->height
;
430 if (wInTiles
* hInTiles
!= t
->image
[level
].nTiles
)
433 x0
= xoffset
/ t
->tileInfo
->width
;
434 y0
= yoffset
/ t
->tileInfo
->height
;
435 x1
= (xoffset
+ width
- 1) / t
->tileInfo
->width
;
436 y1
= (yoffset
+ height
- 1) / t
->tileInfo
->height
;
438 for (y
= y0
; y
<= y1
; ++y
) {
439 GLuint
*ptr
= t
->image
[level
].dirtyTiles
+ (y
* wInTiles
+ x0
) / 32;
440 GLuint mask
= 1 << (y
* wInTiles
+ x0
) % 32;
441 for (x
= x0
; x
<= x1
; ++x
) {
443 if (mask
== (1<<31)) {
453 /** \brief Mark all tiles as dirty
455 static void savageMarkAllTiles (savageTexObjPtr t
, GLuint level
)
457 GLuint words
= (t
->image
[level
].nTiles
+ 31) / 32;
459 memset(t
->image
[level
].dirtyTiles
, ~0, words
*sizeof(GLuint
));
463 static void savageSetTexWrapping(savageTexObjPtr tex
, GLenum s
, GLenum t
)
465 tex
->setup
.sWrapMode
= s
;
466 tex
->setup
.tWrapMode
= t
;
469 static void savageSetTexFilter(savageTexObjPtr t
, GLenum minf
, GLenum magf
)
471 t
->setup
.minFilter
= minf
;
472 t
->setup
.magFilter
= magf
;
478 static void savageSetTexBorderColor(savageTexObjPtr t
, GLubyte color
[4])
480 /* t->Setup[SAVAGE_TEXREG_TEXBORDERCOL] = */
481 /*t->setup.borderColor = SAVAGEPACKCOLOR8888(color[0],color[1],color[2],color[3]); */
486 static savageTexObjPtr
487 savageAllocTexObj( struct gl_texture_object
*texObj
)
491 t
= (savageTexObjPtr
) calloc(1,sizeof(*t
));
492 texObj
->DriverData
= t
;
496 /* Initialize non-image-dependent parts of the state:
498 t
->base
.tObj
= texObj
;
499 t
->base
.dirty_images
[0] = 0;
500 t
->dirtySubImages
= 0;
503 /* Initialize dirty tiles bit vectors
505 for (i
= 0; i
< SAVAGE_TEX_MAXLEVELS
; ++i
)
506 t
->image
[i
].nTiles
= 0;
508 /* FIXME Something here to set initial values for other parts of
512 make_empty_list( &t
->base
);
514 savageSetTexWrapping(t
,texObj
->WrapS
,texObj
->WrapT
);
515 savageSetTexFilter(t
,texObj
->MinFilter
,texObj
->MagFilter
);
516 savageSetTexBorderColor(t
,texObj
->_BorderChan
);
522 /* Mesa texture formats for alpha-images on Savage3D/IX/MX
524 * Promoting texture images to ARGB888 or ARGB4444 doesn't work
525 * because we can't tell the hardware to ignore the color components
526 * and only use the alpha component. So we define our own texture
527 * formats that promote to ARGB8888 or ARGB4444 and set the color
528 * components to white. This way we get the correct result. */
530 _savage_texstore_a1114444 (GLcontext
*ctx
, GLuint dims
,
531 GLenum baseInternalFormat
,
532 const struct gl_texture_format
*dstFormat
,
534 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
535 GLint dstRowStride
, GLint dstImageStride
,
536 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
537 GLenum srcFormat
, GLenum srcType
,
538 const GLvoid
*srcAddr
,
539 const struct gl_pixelstore_attrib
*srcPacking
);
541 _savage_texstore_a1118888 (GLcontext
*ctx
, GLuint dims
,
542 GLenum baseInternalFormat
,
543 const struct gl_texture_format
*dstFormat
,
545 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
546 GLint dstRowStride
, GLint dstImageStride
,
547 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
548 GLenum srcFormat
, GLenum srcType
,
549 const GLvoid
*srcAddr
,
550 const struct gl_pixelstore_attrib
*srcPacking
);
552 static struct gl_texture_format _savage_texformat_a1114444
= {
553 MESA_FORMAT_ARGB4444
, /* MesaFormat */
554 GL_RGBA
, /* BaseFormat */
555 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
560 0, /* LuminanceBits */
561 0, /* IntensityBits */
565 _savage_texstore_a1114444
, /* StoreTexImageFunc */
566 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* FetchTexel* filled in by
567 * savageDDInitTextureFuncs */
569 static struct gl_texture_format _savage_texformat_a1118888
= {
570 MESA_FORMAT_ARGB8888
, /* MesaFormat */
571 GL_RGBA
, /* BaseFormat */
572 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
577 0, /* LuminanceBits */
578 0, /* IntensityBits */
582 _savage_texstore_a1118888
, /* StoreTexImageFunc */
583 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* FetchTexel* filled in by
584 * savageDDInitTextureFuncs */
588 _savage_texstore_a1114444 (GLcontext
*ctx
, GLuint dims
,
589 GLenum baseInternalFormat
,
590 const struct gl_texture_format
*dstFormat
,
592 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
593 GLint dstRowStride
, GLint dstImageStride
,
594 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
595 GLenum srcFormat
, GLenum srcType
,
596 const GLvoid
*srcAddr
,
597 const struct gl_pixelstore_attrib
*srcPacking
)
600 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
603 srcWidth
, srcHeight
, srcDepth
,
604 srcFormat
, srcType
, srcAddr
,
606 const GLchan
*src
= tempImage
;
607 GLubyte
*dstImage
= (GLubyte
*) dstAddr
608 + dstZoffset
* dstImageStride
609 + dstYoffset
* dstRowStride
610 + dstXoffset
* dstFormat
->TexelBytes
;
613 ASSERT(dstFormat
== &_savage_texformat_a1114444
);
614 ASSERT(baseInternalFormat
== GL_ALPHA
);
618 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
619 for (img
= 0; img
< srcDepth
; img
++) {
620 GLubyte
*dstRow
= dstImage
;
621 for (row
= 0; row
< srcHeight
; row
++) {
622 GLushort
*dstUI
= (GLushort
*) dstRow
;
623 for (col
= 0; col
< srcWidth
; col
++) {
624 dstUI
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[0]),
628 dstRow
+= dstRowStride
;
630 dstImage
+= dstImageStride
;
632 _mesa_free((void *) tempImage
);
637 _savage_texstore_a1118888 (GLcontext
*ctx
, GLuint dims
,
638 GLenum baseInternalFormat
,
639 const struct gl_texture_format
*dstFormat
,
641 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
642 GLint dstRowStride
, GLint dstImageStride
,
643 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
644 GLenum srcFormat
, GLenum srcType
,
645 const GLvoid
*srcAddr
,
646 const struct gl_pixelstore_attrib
*srcPacking
)
649 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
652 srcWidth
, srcHeight
, srcDepth
,
653 srcFormat
, srcType
, srcAddr
,
655 const GLchan
*src
= tempImage
;
656 GLubyte
*dstImage
= (GLubyte
*) dstAddr
657 + dstZoffset
* dstImageStride
658 + dstYoffset
* dstRowStride
659 + dstXoffset
* dstFormat
->TexelBytes
;
662 ASSERT(dstFormat
== &_savage_texformat_a1118888
);
663 ASSERT(baseInternalFormat
== GL_ALPHA
);
667 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
668 for (img
= 0; img
< srcDepth
; img
++) {
669 GLubyte
*dstRow
= dstImage
;
670 for (row
= 0; row
< srcHeight
; row
++) {
671 GLuint
*dstUI
= (GLuint
*) dstRow
;
672 for (col
= 0; col
< srcWidth
; col
++) {
673 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[0]),
677 dstRow
+= dstRowStride
;
679 dstImage
+= dstImageStride
;
681 _mesa_free((void *) tempImage
);
686 /* Called by the _mesa_store_teximage[123]d() functions. */
687 static const struct gl_texture_format
*
688 savageChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
689 GLenum format
, GLenum type
)
691 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
692 const GLboolean do32bpt
=
693 ( imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_32
);
694 const GLboolean force16bpt
=
695 ( imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FORCE_16
);
696 const GLboolean isSavage4
= (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
);
699 switch ( internalFormat
) {
702 case GL_COMPRESSED_RGBA
:
704 case GL_UNSIGNED_INT_10_10_10_2
:
705 case GL_UNSIGNED_INT_2_10_10_10_REV
:
706 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
;
707 case GL_UNSIGNED_SHORT_4_4_4_4
:
708 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
709 return &_mesa_texformat_argb4444
;
710 case GL_UNSIGNED_SHORT_5_5_5_1
:
711 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
712 return &_mesa_texformat_argb1555
;
714 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
719 case GL_COMPRESSED_RGB
:
721 case GL_UNSIGNED_SHORT_4_4_4_4
:
722 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
723 return &_mesa_texformat_argb4444
;
724 case GL_UNSIGNED_SHORT_5_5_5_1
:
725 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
726 return &_mesa_texformat_argb1555
;
727 case GL_UNSIGNED_SHORT_5_6_5
:
728 case GL_UNSIGNED_SHORT_5_6_5_REV
:
729 return &_mesa_texformat_rgb565
;
731 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_rgb565
;
738 &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
742 &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
;
746 return &_mesa_texformat_argb4444
;
749 return &_mesa_texformat_argb1555
;
755 return !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_rgb565
;
760 return &_mesa_texformat_rgb565
;
763 case GL_COMPRESSED_ALPHA
:
764 return isSavage4
? &_mesa_texformat_a8
: (
765 do32bpt
? &_savage_texformat_a1118888
: &_savage_texformat_a1114444
);
767 return isSavage4
? &_mesa_texformat_a8
: &_savage_texformat_a1114444
;
771 return isSavage4
? &_mesa_texformat_a8
: (
772 !force16bpt
? &_savage_texformat_a1118888
: &_savage_texformat_a1114444
);
776 case GL_COMPRESSED_LUMINANCE
:
777 /* no alpha, but use argb1555 in 16bit case to get pure grey values */
778 return isSavage4
? &_mesa_texformat_l8
: (
779 do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
);
781 return isSavage4
? &_mesa_texformat_l8
: &_mesa_texformat_argb1555
;
785 return isSavage4
? &_mesa_texformat_l8
: (
786 !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
);
789 case GL_LUMINANCE_ALPHA
:
790 case GL_COMPRESSED_LUMINANCE_ALPHA
:
791 /* Savage4 has a al44 texture format. But it's not supported by Mesa. */
792 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
793 case GL_LUMINANCE4_ALPHA4
:
794 case GL_LUMINANCE6_ALPHA2
:
795 return &_mesa_texformat_argb4444
;
796 case GL_LUMINANCE8_ALPHA8
:
797 case GL_LUMINANCE12_ALPHA4
:
798 case GL_LUMINANCE12_ALPHA12
:
799 case GL_LUMINANCE16_ALPHA16
:
800 return !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
802 /* TFT_I8 produces garbage on ProSavageDDR and subsequent texture
803 * disable keeps rendering garbage. Disabled for now. */
805 case GL_COMPRESSED_INTENSITY
:
806 return isSavage4
? &_mesa_texformat_i8
: (
807 do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
);
809 return isSavage4
? &_mesa_texformat_i8
: &_mesa_texformat_argb4444
;
813 return isSavage4
? &_mesa_texformat_i8
: (
814 !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
);
817 case GL_COMPRESSED_INTENSITY
:
818 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
820 return &_mesa_texformat_argb4444
;
824 return !force16bpt
? &_mesa_texformat_argb8888
:
825 &_mesa_texformat_argb4444
;
830 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
831 return &_mesa_texformat_rgb_dxt1
;
832 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
833 return &_mesa_texformat_rgba_dxt1
;
835 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
836 return &_mesa_texformat_rgba_dxt3
;
841 /* Not the best choice but Savage3D/MX/IX don't support DXT3 or DXT5. */
842 return &_mesa_texformat_rgba_dxt1
;
844 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
845 return &_mesa_texformat_rgba_dxt5
;
849 case GL_COLOR_INDEX1_EXT:
850 case GL_COLOR_INDEX2_EXT:
851 case GL_COLOR_INDEX4_EXT:
852 case GL_COLOR_INDEX8_EXT:
853 case GL_COLOR_INDEX12_EXT:
854 case GL_COLOR_INDEX16_EXT:
855 return &_mesa_texformat_ci8;
858 _mesa_problem(ctx
, "unexpected texture format in %s", __FUNCTION__
);
863 static void savageSetTexImages( savageContextPtr imesa
,
864 const struct gl_texture_object
*tObj
)
866 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
867 struct gl_texture_image
*image
= tObj
->Image
[0][tObj
->BaseLevel
];
868 GLuint offset
, i
, textureFormat
, tileIndex
, size
;
869 GLint firstLevel
, lastLevel
;
874 switch (image
->TexFormat
->MesaFormat
) {
875 case MESA_FORMAT_ARGB8888
:
876 textureFormat
= TFT_ARGB8888
;
877 t
->texelBytes
= tileIndex
= 4;
879 case MESA_FORMAT_ARGB1555
:
880 textureFormat
= TFT_ARGB1555
;
881 t
->texelBytes
= tileIndex
= 2;
883 case MESA_FORMAT_ARGB4444
:
884 textureFormat
= TFT_ARGB4444
;
885 t
->texelBytes
= tileIndex
= 2;
887 case MESA_FORMAT_RGB565
:
888 textureFormat
= TFT_RGB565
;
889 t
->texelBytes
= tileIndex
= 2;
892 textureFormat
= TFT_L8
;
893 t
->texelBytes
= tileIndex
= 1;
896 textureFormat
= TFT_I8
;
897 t
->texelBytes
= tileIndex
= 1;
900 textureFormat
= TFT_A8
;
901 t
->texelBytes
= tileIndex
= 1;
903 case MESA_FORMAT_RGB_DXT1
:
904 textureFormat
= TFT_S3TC4Bit
;
905 tileIndex
= TILE_INDEX_DXT1
;
908 case MESA_FORMAT_RGBA_DXT1
:
909 textureFormat
= TFT_S3TC4Bit
;
910 tileIndex
= TILE_INDEX_DXT1
;
913 case MESA_FORMAT_RGBA_DXT3
:
914 textureFormat
= TFT_S3TC4A4Bit
;
915 tileIndex
= TILE_INDEX_DXTn
;
918 case MESA_FORMAT_RGBA_DXT5
:
919 textureFormat
= TFT_S3TC4CA4Bit
;
920 tileIndex
= TILE_INDEX_DXTn
;
924 _mesa_problem(imesa
->glCtx
, "Bad texture format in %s", __FUNCTION__
);
927 t
->hwFormat
= textureFormat
;
929 /* Select tiling format depending on the chipset and texture format */
930 if (imesa
->savageScreen
->chipset
<= S3_SAVAGE4
)
931 t
->tileInfo
= &tileInfo_s3d_s4
[tileIndex
];
933 t
->tileInfo
= &tileInfo_pro
[tileIndex
];
935 /* Compute which mipmap levels we really want to send to the hardware.
937 driCalculateTextureFirstLastLevel( &t
->base
);
938 firstLevel
= t
->base
.firstLevel
;
939 lastLevel
= t
->base
.lastLevel
;
941 /* Figure out the size now (and count the levels). Upload won't be
942 * done until later. If the number of tiles changes, it means that
943 * this function is called for the first time on this tex object or
944 * the image or the destination color format changed. So all tiles
945 * are marked as dirty.
949 for ( i
= firstLevel
; i
<= lastLevel
&& tObj
->Image
[0][i
] ; i
++ ) {
951 nTiles
= savageTexImageTiles (image
->Width2
, image
->Height2
, t
->tileInfo
);
952 if (t
->image
[i
].nTiles
!= nTiles
) {
953 GLuint words
= (nTiles
+ 31) / 32;
954 if (t
->image
[i
].nTiles
!= 0) {
955 free(t
->image
[i
].dirtyTiles
);
957 t
->image
[i
].dirtyTiles
= malloc(words
*sizeof(GLuint
));
958 memset(t
->image
[i
].dirtyTiles
, ~0, words
*sizeof(GLuint
));
960 t
->image
[i
].nTiles
= nTiles
;
962 t
->image
[i
].offset
= offset
;
964 image
= tObj
->Image
[0][i
];
965 if (t
->texelBytes
>= 8)
966 size
= savageCompressedTexImageSize (image
->Width2
, image
->Height2
,
969 size
= savageTexImageSize (image
->Width2
, image
->Height2
,
974 t
->base
.lastLevel
= i
-1;
975 t
->base
.totalSize
= offset
;
976 /* the last three mipmap levels don't add to the offset. They are packed
979 t
->base
.totalSize
+= (t
->texelBytes
>= 8 ? 4 : 64) * t
->texelBytes
;
980 /* 2k-aligned (really needed?) */
981 t
->base
.totalSize
= (t
->base
.totalSize
+ 2047UL) & ~2047UL;
984 void savageDestroyTexObj(savageContextPtr imesa
, savageTexObjPtr t
)
988 /* Free dirty tiles bit vectors */
989 for (i
= 0; i
< SAVAGE_TEX_MAXLEVELS
; ++i
) {
990 if (t
->image
[i
].nTiles
)
991 free (t
->image
[i
].dirtyTiles
);
994 /* See if it was the driver's current object.
998 for ( i
= 0 ; i
< imesa
->glCtx
->Const
.MaxTextureUnits
; i
++ )
1000 if ( &t
->base
== imesa
->CurrentTexObj
[ i
] ) {
1001 assert( t
->base
.bound
& (1 << i
) );
1002 imesa
->CurrentTexObj
[ i
] = NULL
;
1008 /* Upload a texture's images to one of the texture heaps. May have to
1009 * eject our own and/or other client's texture objects to make room
1012 static void savageUploadTexImages( savageContextPtr imesa
, savageTexObjPtr t
)
1014 const GLint numLevels
= t
->base
.lastLevel
- t
->base
.firstLevel
+ 1;
1019 LOCK_HARDWARE(imesa
);
1021 /* Do we need to eject LRU texture objects?
1023 if (!t
->base
.memBlock
) {
1027 heap
= driAllocateTexture(imesa
->textureHeaps
, imesa
->lastTexHeap
,
1028 (driTextureObject
*)t
);
1030 UNLOCK_HARDWARE(imesa
);
1034 ofs
= t
->base
.memBlock
->ofs
;
1035 t
->setup
.physAddr
= imesa
->savageScreen
->textureOffset
[heap
] + ofs
;
1036 t
->bufAddr
= (GLubyte
*)imesa
->savageScreen
->texVirtual
[heap
] + ofs
;
1037 imesa
->dirty
|= SAVAGE_UPLOAD_GLOBAL
; /* FIXME: really needed? */
1040 /* Let the world know we've used this memory recently.
1042 driUpdateTextureLRU( &t
->base
);
1043 UNLOCK_HARDWARE(imesa
);
1045 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1046 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1047 fprintf(stderr
, "Texture upload: |");
1049 /* Heap timestamps are only reliable with Savage DRM 2.3.x or
1050 * later. Earlier versions had only 16 bit time stamps which
1051 * would wrap too frequently. */
1052 if (imesa
->savageScreen
->driScrnPriv
->drmMinor
>= 3) {
1053 unsigned int heap
= t
->base
.heap
->heapId
;
1054 LOCK_HARDWARE(imesa
);
1055 savageWaitEvent (imesa
, imesa
->textureHeaps
[heap
]->timestamp
);
1057 savageFlushVertices (imesa
);
1058 LOCK_HARDWARE(imesa
);
1059 savageFlushCmdBufLocked (imesa
, GL_FALSE
);
1060 WAIT_IDLE_EMPTY_LOCKED(imesa
);
1063 for (i
= 0 ; i
< numLevels
; i
++) {
1064 const GLint j
= t
->base
.firstLevel
+ i
; /* the texObj's level */
1065 if (t
->base
.dirty_images
[0] & (1 << j
)) {
1066 savageMarkAllTiles(t
, j
);
1067 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1068 fprintf (stderr
, "*");
1069 } else if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
) {
1070 if (t
->dirtySubImages
& (1 << j
))
1071 fprintf (stderr
, ".");
1073 fprintf (stderr
, " ");
1075 if ((t
->base
.dirty_images
[0] | t
->dirtySubImages
) & (1 << j
))
1076 savageUploadTexLevel( t
, j
);
1079 UNLOCK_HARDWARE(imesa
);
1080 t
->base
.dirty_images
[0] = 0;
1081 t
->dirtySubImages
= 0;
1083 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1084 fprintf(stderr
, "|\n");
1090 savage4_set_wrap_mode( savageContextPtr imesa
, unsigned unit
,
1091 GLenum s_mode
, GLenum t_mode
)
1095 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Wrap
;
1098 case GL_CLAMP_TO_EDGE
:
1099 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Clamp
;
1101 case GL_MIRRORED_REPEAT
:
1102 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Mirror
;
1108 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Wrap
;
1111 case GL_CLAMP_TO_EDGE
:
1112 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Clamp
;
1114 case GL_MIRRORED_REPEAT
:
1115 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Mirror
;
1122 * Sets the hardware bits for the specified GL texture filter modes.
1125 * Does the Savage4 have the ability to select the magnification filter?
1128 savage4_set_filter_mode( savageContextPtr imesa
, unsigned unit
,
1129 GLenum minFilter
, GLenum magFilter
)
1133 switch (minFilter
) {
1135 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1136 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1140 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1141 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1144 case GL_NEAREST_MIPMAP_NEAREST
:
1145 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1146 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1149 case GL_LINEAR_MIPMAP_NEAREST
:
1150 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1151 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1154 case GL_NEAREST_MIPMAP_LINEAR
:
1155 case GL_LINEAR_MIPMAP_LINEAR
:
1156 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Trilin
;
1157 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1163 static void savageUpdateTex0State_s4( GLcontext
*ctx
)
1165 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1166 struct gl_texture_object
*tObj
;
1167 struct gl_texture_image
*image
;
1172 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_FALSE
;
1173 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_NoTexMap
;
1174 imesa
->regs
.s4
.texCtrl
[0].ui
= 0x20f040;
1175 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1178 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1179 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1180 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1181 /* 3D texturing enabled, or texture border - fallback */
1182 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1186 /* Do 2D texture setup */
1188 t
= tObj
->DriverData
;
1190 t
= savageAllocTexObj( tObj
);
1195 imesa
->CurrentTexObj
[0] = &t
->base
;
1198 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1199 savageSetTexImages(imesa
, tObj
);
1200 savageUploadTexImages(imesa
, t
);
1203 driUpdateTextureLRU( &t
->base
);
1205 format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
1207 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1209 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1214 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1217 case GL_LUMINANCE_ALPHA
:
1220 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Copy
;
1224 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1227 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1228 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1232 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1237 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1242 case GL_LUMINANCE_ALPHA
:
1243 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_DecalAlpha
;
1247 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1248 are undefined with GL_DECAL
1252 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1255 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1256 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1260 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1261 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1262 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1263 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1267 imesa
->regs
.s4
.texBlendColor
.ui
= imesa
->texEnvColor
;
1272 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1273 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1278 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Blend0
;
1279 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1280 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1281 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1282 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1283 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1284 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1285 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1286 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1288 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1289 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Blend1
;
1291 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1292 imesa
->bTexEn1
= GL_TRUE
;
1295 case GL_LUMINANCE_ALPHA
:
1297 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendAlpha0
;
1298 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1299 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1300 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1301 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1302 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1303 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1304 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1305 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1307 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1308 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendAlpha1
;
1310 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1311 imesa
->bTexEn1
= GL_TRUE
;
1315 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendInt0
;
1316 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1317 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1318 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1319 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1320 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1321 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1322 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1323 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1325 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1326 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendInt1
;
1328 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1329 imesa
->regs
.s4
.texCtrl
[0].ni
.alphaArg1Invert
= GL_TRUE
;
1330 imesa
->bTexEn1
= GL_TRUE
;
1333 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1334 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1338 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1342 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1347 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1350 case GL_LUMINANCE_ALPHA
:
1352 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1356 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_AddAlpha
;
1359 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1360 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1363 #if GL_ARB_texture_env_combine
1364 case GL_COMBINE_ARB
:
1365 __HWParseTexEnvCombine(imesa
, 0, &imesa
->regs
.s4
.texCtrl
[0],
1366 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1371 fprintf(stderr
, "unknown tex env mode");
1376 savage4_set_wrap_mode( imesa
, 0, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1377 savage4_set_filter_mode( imesa
, 0, t
->setup
.minFilter
, t
->setup
.magFilter
);
1379 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1380 (imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
!= 0))
1382 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 32.0) +
1386 else if (bias
> 255)
1388 imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
= bias
& 0x1ff;
1391 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1392 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_TRUE
;
1393 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
= image
->WidthLog2
;
1394 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
= image
->HeightLog2
;
1395 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
= t
->hwFormat
;
1396 imesa
->regs
.s4
.texCtrl
[0].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1398 if (imesa
->regs
.s4
.texDescr
.ni
.tex1En
)
1399 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1401 imesa
->regs
.s4
.texAddr
[0].ui
= (u_int32_t
) t
->setup
.physAddr
| 0x2;
1402 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1403 imesa
->regs
.s4
.texAddr
[0].ui
|= 0x1;
1407 static void savageUpdateTex1State_s4( GLcontext
*ctx
)
1409 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1410 struct gl_texture_object
*tObj
;
1411 struct gl_texture_image
*image
;
1418 imesa
->bTexEn1
= GL_FALSE
;
1422 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_FALSE
;
1423 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_NoTexMap1
;
1424 imesa
->regs
.s4
.texCtrl
[1].ui
= 0x20f040;
1425 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_FALSE
;
1426 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
== 0)
1429 tObj
= ctx
->Texture
.Unit
[1]._Current
;
1431 if ((ctx
->Texture
.Unit
[1]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1432 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1433 /* 3D texturing enabled, or texture border - fallback */
1434 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1438 /* Do 2D texture setup */
1440 t
= tObj
->DriverData
;
1442 t
= savageAllocTexObj( tObj
);
1447 imesa
->CurrentTexObj
[1] = &t
->base
;
1451 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1452 savageSetTexImages(imesa
, tObj
);
1453 savageUploadTexImages(imesa
, t
);
1456 driUpdateTextureLRU( &t
->base
);
1458 format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
1460 switch (ctx
->Texture
.Unit
[1].EnvMode
) {
1462 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1467 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal
;
1470 case GL_LUMINANCE_ALPHA
:
1473 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Copy
;
1477 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1480 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1483 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1484 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1485 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1489 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1493 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1498 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1501 case GL_LUMINANCE_ALPHA
:
1503 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1507 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_AddAlpha1
;
1510 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1513 #if GL_ARB_texture_env_combine
1514 case GL_COMBINE_ARB
:
1515 __HWParseTexEnvCombine(imesa
, 1, &texCtrl
, &imesa
->regs
.s4
.texBlendCtrl
);
1520 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1526 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal1
;
1528 case GL_LUMINANCE_ALPHA
:
1531 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_DecalAlpha1
;
1535 // GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1536 // are undefined with GL_DECAL
1539 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1542 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1546 if (format
== GL_LUMINANCE
)
1549 // This is a hack for GLQuake, invert.
1551 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_TRUE
;
1552 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= 0;
1554 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1558 fprintf(stderr
, "unknown tex 1 env mode\n");
1563 savage4_set_wrap_mode( imesa
, 1, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1564 savage4_set_filter_mode( imesa
, 1, t
->setup
.minFilter
, t
->setup
.magFilter
);
1566 if((ctx
->Texture
.Unit
[1].LodBias
!=0.0F
) ||
1567 (imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
!= 0))
1569 int bias
= (int)(ctx
->Texture
.Unit
[1].LodBias
* 32.0) +
1573 else if (bias
> 255)
1575 imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
= bias
& 0x1ff;
1578 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1579 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1580 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
= image
->WidthLog2
;
1581 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
= image
->HeightLog2
;
1582 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
= t
->hwFormat
;
1583 imesa
->regs
.s4
.texCtrl
[1].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1584 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1586 imesa
->regs
.s4
.texAddr
[1].ui
= (u_int32_t
) t
->setup
.physAddr
| 2;
1587 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1588 imesa
->regs
.s4
.texAddr
[1].ui
|= 0x1;
1590 static void savageUpdateTexState_s3d( GLcontext
*ctx
)
1592 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1593 struct gl_texture_object
*tObj
;
1594 struct gl_texture_image
*image
;
1599 imesa
->regs
.s3d
.texCtrl
.ui
= 0;
1600 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_FALSE
;
1601 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= 0x08;
1602 imesa
->regs
.s3d
.texCtrl
.ni
.texXprEn
= GL_TRUE
;
1603 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1606 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1607 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1608 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1609 /* 3D texturing enabled, or texture border - fallback */
1610 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1614 /* Do 2D texture setup */
1615 t
= tObj
->DriverData
;
1617 t
= savageAllocTexObj( tObj
);
1622 imesa
->CurrentTexObj
[0] = &t
->base
;
1625 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1626 savageSetTexImages(imesa
, tObj
);
1627 savageUploadTexImages(imesa
, t
);
1630 driUpdateTextureLRU( &t
->base
);
1632 format
= tObj
->Image
[0][tObj
->BaseLevel
]->Format
;
1634 /* FIXME: copied from utah-glx, probably needs some tuning */
1635 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1637 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECALALPHA_S3D
;
1641 case GL_ALPHA
: /* FIXME */
1642 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 1;
1644 case GL_LUMINANCE_ALPHA
:
1646 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 4;
1650 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECAL_S3D
;
1653 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_COPY_S3D
;
1656 case GL_BLEND
: /* hardware can't do GL_BLEND */
1657 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1660 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_MODULATEALPHA_S3D
;
1663 fprintf(stderr
, "unknown tex env mode\n");
1668 /* The Savage3D can't handle different wrapping modes in s and t.
1669 * If they are not the same, fall back to software. */
1670 if (t
->setup
.sWrapMode
!= t
->setup
.tWrapMode
) {
1671 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1674 imesa
->regs
.s3d
.texCtrl
.ni
.uWrapEn
= 0;
1675 imesa
->regs
.s3d
.texCtrl
.ni
.vWrapEn
= 0;
1676 imesa
->regs
.s3d
.texCtrl
.ni
.wrapMode
=
1677 (t
->setup
.sWrapMode
== GL_REPEAT
) ? TAM_Wrap
: TAM_Clamp
;
1679 switch (t
->setup
.minFilter
) {
1681 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1682 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1686 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1687 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1690 case GL_NEAREST_MIPMAP_NEAREST
:
1691 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1692 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1695 case GL_LINEAR_MIPMAP_NEAREST
:
1696 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1697 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1700 case GL_NEAREST_MIPMAP_LINEAR
:
1701 case GL_LINEAR_MIPMAP_LINEAR
:
1702 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Trilin
;
1703 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1707 /* There is no way to specify a maximum mipmap level. We may have to
1708 disable mipmapping completely. */
1710 if (t->max_level < t->image[0].image->WidthLog2 ||
1711 t->max_level < t->image[0].image->HeightLog2) {
1712 texCtrl.ni.mipmapEnable = GL_TRUE;
1713 if (texCtrl.ni.filterMode == TFM_Trilin)
1714 texCtrl.ni.filterMode = TFM_Bilin;
1715 texCtrl.ni.filterMode = TFM_Point;
1719 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1720 (imesa
->regs
.s3d
.texCtrl
.ni
.dBias
!= 0))
1722 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 16.0);
1725 else if (bias
> 255)
1727 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= bias
& 0x1ff;
1730 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1731 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_TRUE
;
1732 imesa
->regs
.s3d
.texDescr
.ni
.texWidth
= image
->WidthLog2
;
1733 imesa
->regs
.s3d
.texDescr
.ni
.texHeight
= image
->HeightLog2
;
1734 assert (t
->hwFormat
<= 7);
1735 imesa
->regs
.s3d
.texDescr
.ni
.texFmt
= t
->hwFormat
;
1737 imesa
->regs
.s3d
.texAddr
.ui
= (u_int32_t
) t
->setup
.physAddr
| 2;
1738 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1739 imesa
->regs
.s3d
.texAddr
.ui
|= 0x1;
1743 static void savageTimestampTextures( savageContextPtr imesa
)
1745 /* Timestamp current texture objects for texture heap aging.
1746 * Only useful with long-lived 32-bit event tags available
1747 * with Savage DRM 2.3.x or later. */
1748 if ((imesa
->CurrentTexObj
[0] || imesa
->CurrentTexObj
[1]) &&
1749 imesa
->savageScreen
->driScrnPriv
->drmMinor
>= 3) {
1752 e
= savageEmitEvent(imesa
, SAVAGE_WAIT_3D
);
1753 if (imesa
->CurrentTexObj
[0])
1754 imesa
->CurrentTexObj
[0]->timestamp
= e
;
1755 if (imesa
->CurrentTexObj
[1])
1756 imesa
->CurrentTexObj
[1]->timestamp
= e
;
1761 static void savageUpdateTextureState_s4( GLcontext
*ctx
)
1763 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1765 /* When a texture is about to change or be disabled, timestamp the
1766 * old texture(s). We'll have to wait for this time stamp before
1767 * uploading anything to the same texture heap.
1769 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1770 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1771 (imesa
->CurrentTexObj
[1] && ctx
->Texture
.Unit
[1]._ReallyEnabled
&&
1772 ctx
->Texture
.Unit
[1]._Current
->DriverData
!= imesa
->CurrentTexObj
[1]) ||
1773 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
) ||
1774 (imesa
->CurrentTexObj
[1] && !ctx
->Texture
.Unit
[1]._ReallyEnabled
))
1775 savageTimestampTextures(imesa
);
1777 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1778 if (imesa
->CurrentTexObj
[1]) imesa
->CurrentTexObj
[1]->bound
&= ~2;
1779 imesa
->CurrentTexObj
[0] = 0;
1780 imesa
->CurrentTexObj
[1] = 0;
1781 savageUpdateTex0State_s4( ctx
);
1782 savageUpdateTex1State_s4( ctx
);
1783 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
|
1784 SAVAGE_UPLOAD_TEX1
);
1786 static void savageUpdateTextureState_s3d( GLcontext
*ctx
)
1788 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1790 /* When a texture is about to change or be disabled, timestamp the
1791 * old texture(s). We'll have to wait for this time stamp before
1792 * uploading anything to the same texture heap.
1794 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1795 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1796 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
))
1797 savageTimestampTextures(imesa
);
1799 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1800 imesa
->CurrentTexObj
[0] = 0;
1801 savageUpdateTexState_s3d( ctx
);
1802 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
);
1804 void savageUpdateTextureState( GLcontext
*ctx
)
1806 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1807 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_FALSE
);
1808 FALLBACK(ctx
, SAVAGE_FALLBACK_PROJ_TEXTURE
, GL_FALSE
);
1809 if (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
)
1810 savageUpdateTextureState_s4 (ctx
);
1812 savageUpdateTextureState_s3d (ctx
);
1817 /*****************************************
1819 *****************************************/
1821 static void savageTexEnv( GLcontext
*ctx
, GLenum target
,
1822 GLenum pname
, const GLfloat
*param
)
1824 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1826 if (pname
== GL_TEXTURE_ENV_MODE
) {
1828 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
1830 } else if (pname
== GL_TEXTURE_ENV_COLOR
) {
1832 struct gl_texture_unit
*texUnit
=
1833 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1834 const GLfloat
*fc
= texUnit
->EnvColor
;
1836 CLAMPED_FLOAT_TO_UBYTE(r
, fc
[0]);
1837 CLAMPED_FLOAT_TO_UBYTE(g
, fc
[1]);
1838 CLAMPED_FLOAT_TO_UBYTE(b
, fc
[2]);
1839 CLAMPED_FLOAT_TO_UBYTE(a
, fc
[3]);
1841 imesa
->texEnvColor
= ((a
<< 24) | (r
<< 16) |
1842 (g
<< 8) | (b
<< 0));
1848 /* Update the heap's time stamp, so the new image is not uploaded
1849 * while the old one is still in use. If the texture that is going to
1850 * be changed is currently bound, we need to timestamp the texture
1852 static void savageTexImageChanged (savageTexObjPtr t
) {
1855 savageTimestampTextures(
1856 (savageContextPtr
)t
->base
.heap
->driverContext
);
1857 if (t
->base
.timestamp
> t
->base
.heap
->timestamp
)
1858 t
->base
.heap
->timestamp
= t
->base
.timestamp
;
1862 static void savageTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
1863 GLint internalFormat
,
1864 GLint width
, GLint border
,
1865 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1866 const struct gl_pixelstore_attrib
*packing
,
1867 struct gl_texture_object
*texObj
,
1868 struct gl_texture_image
*texImage
)
1870 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1872 savageTexImageChanged (t
);
1874 t
= savageAllocTexObj(texObj
);
1876 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1880 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
1881 width
, border
, format
, type
,
1882 pixels
, packing
, texObj
, texImage
);
1883 t
->base
.dirty_images
[0] |= (1 << level
);
1884 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1887 static void savageTexSubImage1D( GLcontext
*ctx
,
1892 GLenum format
, GLenum type
,
1893 const GLvoid
*pixels
,
1894 const struct gl_pixelstore_attrib
*packing
,
1895 struct gl_texture_object
*texObj
,
1896 struct gl_texture_image
*texImage
)
1898 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1899 assert( t
); /* this _should_ be true */
1901 savageTexImageChanged (t
);
1902 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, 1,
1903 xoffset
, 0, width
, 1);
1905 t
= savageAllocTexObj(texObj
);
1907 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
1910 t
->base
.dirty_images
[0] |= (1 << level
);
1912 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
1913 format
, type
, pixels
, packing
, texObj
,
1915 t
->dirtySubImages
|= (1 << level
);
1916 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1919 static void savageTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1920 GLint internalFormat
,
1921 GLint width
, GLint height
, GLint border
,
1922 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1923 const struct gl_pixelstore_attrib
*packing
,
1924 struct gl_texture_object
*texObj
,
1925 struct gl_texture_image
*texImage
)
1927 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1929 savageTexImageChanged (t
);
1931 t
= savageAllocTexObj(texObj
);
1933 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1937 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
1938 width
, height
, border
, format
, type
,
1939 pixels
, packing
, texObj
, texImage
);
1940 t
->base
.dirty_images
[0] |= (1 << level
);
1941 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1944 static void savageTexSubImage2D( GLcontext
*ctx
,
1947 GLint xoffset
, GLint yoffset
,
1948 GLsizei width
, GLsizei height
,
1949 GLenum format
, GLenum type
,
1950 const GLvoid
*pixels
,
1951 const struct gl_pixelstore_attrib
*packing
,
1952 struct gl_texture_object
*texObj
,
1953 struct gl_texture_image
*texImage
)
1955 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1956 assert( t
); /* this _should_ be true */
1958 savageTexImageChanged (t
);
1959 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
1960 xoffset
, yoffset
, width
, height
);
1962 t
= savageAllocTexObj(texObj
);
1964 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1967 t
->base
.dirty_images
[0] |= (1 << level
);
1969 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
1970 height
, format
, type
, pixels
, packing
, texObj
,
1972 t
->dirtySubImages
|= (1 << level
);
1973 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1977 savageCompressedTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1978 GLint internalFormat
,
1979 GLint width
, GLint height
, GLint border
,
1980 GLsizei imageSize
, const GLvoid
*data
,
1981 struct gl_texture_object
*texObj
,
1982 struct gl_texture_image
*texImage
)
1984 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1986 savageTexImageChanged (t
);
1988 t
= savageAllocTexObj(texObj
);
1990 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1994 _mesa_store_compressed_teximage2d( ctx
, target
, level
, internalFormat
,
1995 width
, height
, border
, imageSize
,
1996 data
, texObj
, texImage
);
1997 t
->base
.dirty_images
[0] |= (1 << level
);
1998 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
2002 savageCompressedTexSubImage2D( GLcontext
*ctx
,
2005 GLint xoffset
, GLint yoffset
,
2006 GLsizei width
, GLsizei height
,
2007 GLenum format
, GLsizei imageSize
,
2009 struct gl_texture_object
*texObj
,
2010 struct gl_texture_image
*texImage
)
2012 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
2013 assert( t
); /* this _should_ be true */
2015 savageTexImageChanged (t
);
2016 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
2017 xoffset
, yoffset
, width
, height
);
2019 t
= savageAllocTexObj(texObj
);
2021 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
2024 t
->base
.dirty_images
[0] |= (1 << level
);
2026 _mesa_store_compressed_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
,
2027 width
, height
, format
, imageSize
,
2028 data
, texObj
, texImage
);
2029 t
->dirtySubImages
|= (1 << level
);
2030 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
2033 static void savageTexParameter( GLcontext
*ctx
, GLenum target
,
2034 struct gl_texture_object
*tObj
,
2035 GLenum pname
, const GLfloat
*params
)
2037 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
2038 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2040 if (!t
|| (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
))
2044 case GL_TEXTURE_MIN_FILTER
:
2045 case GL_TEXTURE_MAG_FILTER
:
2046 savageSetTexFilter(t
,tObj
->MinFilter
,tObj
->MagFilter
);
2049 case GL_TEXTURE_WRAP_S
:
2050 case GL_TEXTURE_WRAP_T
:
2051 savageSetTexWrapping(t
,tObj
->WrapS
,tObj
->WrapT
);
2054 case GL_TEXTURE_BORDER_COLOR
:
2055 savageSetTexBorderColor(t
,tObj
->_BorderChan
);
2062 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2065 static void savageBindTexture( GLcontext
*ctx
, GLenum target
,
2066 struct gl_texture_object
*tObj
)
2068 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2070 assert( (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
) ||
2071 (tObj
->DriverData
!= NULL
) );
2073 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2076 static void savageDeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
2078 driTextureObject
*t
= (driTextureObject
*)tObj
->DriverData
;
2079 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2083 savageTimestampTextures(imesa
);
2085 driDestroyTextureObject(t
);
2087 /* Free mipmap images and the texture object itself */
2088 _mesa_delete_texture_object(ctx
, tObj
);
2092 static struct gl_texture_object
*
2093 savageNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
2095 struct gl_texture_object
*obj
;
2096 obj
= _mesa_new_texture_object(ctx
, name
, target
);
2097 savageAllocTexObj( obj
);
2102 void savageDDInitTextureFuncs( struct dd_function_table
*functions
)
2104 functions
->TexEnv
= savageTexEnv
;
2105 functions
->ChooseTextureFormat
= savageChooseTextureFormat
;
2106 functions
->TexImage1D
= savageTexImage1D
;
2107 functions
->TexSubImage1D
= savageTexSubImage1D
;
2108 functions
->TexImage2D
= savageTexImage2D
;
2109 functions
->TexSubImage2D
= savageTexSubImage2D
;
2110 functions
->CompressedTexImage2D
= savageCompressedTexImage2D
;
2111 functions
->CompressedTexSubImage2D
= savageCompressedTexSubImage2D
;
2112 functions
->BindTexture
= savageBindTexture
;
2113 functions
->NewTextureObject
= savageNewTextureObject
;
2114 functions
->DeleteTexture
= savageDeleteTexture
;
2115 functions
->IsTextureResident
= driIsTextureResident
;
2116 functions
->TexParameter
= savageTexParameter
;
2118 /* Texel fetching with our custom texture formats works just like
2119 * the standard argb formats. */
2120 _savage_texformat_a1114444
.FetchTexel1D
= _mesa_texformat_argb4444
.FetchTexel1D
;
2121 _savage_texformat_a1114444
.FetchTexel2D
= _mesa_texformat_argb4444
.FetchTexel2D
;
2122 _savage_texformat_a1114444
.FetchTexel3D
= _mesa_texformat_argb4444
.FetchTexel3D
;
2123 _savage_texformat_a1114444
.FetchTexel1Df
= _mesa_texformat_argb4444
.FetchTexel1Df
;
2124 _savage_texformat_a1114444
.FetchTexel2Df
= _mesa_texformat_argb4444
.FetchTexel2Df
;
2125 _savage_texformat_a1114444
.FetchTexel3Df
= _mesa_texformat_argb4444
.FetchTexel3Df
;
2127 _savage_texformat_a1118888
.FetchTexel1D
= _mesa_texformat_argb8888
.FetchTexel1D
;
2128 _savage_texformat_a1118888
.FetchTexel2D
= _mesa_texformat_argb8888
.FetchTexel2D
;
2129 _savage_texformat_a1118888
.FetchTexel3D
= _mesa_texformat_argb8888
.FetchTexel3D
;
2130 _savage_texformat_a1118888
.FetchTexel1Df
= _mesa_texformat_argb8888
.FetchTexel1Df
;
2131 _savage_texformat_a1118888
.FetchTexel2Df
= _mesa_texformat_argb8888
.FetchTexel2Df
;
2132 _savage_texformat_a1118888
.FetchTexel3Df
= _mesa_texformat_argb8888
.FetchTexel3Df
;