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.
26 #include "main/context.h"
28 #include "main/macros.h"
29 #include "main/texstore.h"
30 #include "main/texobj.h"
31 #include "main/convolve.h"
32 #include "main/colormac.h"
33 #include "main/simple_list.h"
34 #include "main/enums.h"
36 #include "savagecontext.h"
37 #include "savagetex.h"
38 #include "savagetris.h"
39 #include "savageioctl.h"
40 #include "savage_bci.h"
44 #define TILE_INDEX_DXT1 0
45 #define TILE_INDEX_8 1
46 #define TILE_INDEX_16 2
47 #define TILE_INDEX_DXTn 3
48 #define TILE_INDEX_32 4
50 /* On Savage4 the texure LOD-bias needs an offset of ~ 0.3 to get
51 * somewhere close to software rendering.
53 #define SAVAGE4_LOD_OFFSET 10
55 /* Tile info for S3TC formats counts in 4x4 blocks instead of texels.
56 * In DXT1 each block is encoded in 64 bits. In DXT3 and 5 each block is
57 * encoded in 128 bits. */
59 /* Size 1, 2 and 4 images are packed into the last subtile. Each image
60 * is repeated to fill a 4x4 pixel area. The figure below shows the
61 * layout of those 4x4 pixel areas in the 8x8 subtile.
66 * Yuck! 8-bit texture formats use 4x8 subtiles. See below.
68 static const savageTileInfo tileInfo_pro
[5] = {
69 {16, 16, 16, 8, 1, 2, {0x18, 0x10}}, /* DXT1 */
70 {64, 32, 16, 4, 4, 8, {0x30, 0x20}}, /* 8-bit */
71 {64, 16, 8, 2, 8, 8, {0x48, 0x08}}, /* 16-bit */
72 {16, 8, 16, 4, 1, 2, {0x30, 0x20}}, /* DXT3, DXT5 */
73 {32, 16, 4, 2, 8, 8, {0x90, 0x10}}, /* 32-bit */
76 /* Size 1, 2 and 4 images are packed into the last two subtiles. Each
77 * image is repeated to fill a 4x4 pixel area. The figures below show
78 * the layout of those 4x4 pixel areas in the two 4x8 subtiles.
80 * second last subtile: 4 last subtile: 2
83 static const savageTileInfo tileInfo_s3d_s4
[5] = {
84 {16, 16, 16, 8, 1, 2, {0x18, 0x10}}, /* DXT1 */
85 {64, 32, 16, 4, 4, 8, {0x30, 0x20}}, /* 8-bit */
86 {64, 16, 16, 2, 4, 8, {0x60, 0x40}}, /* 16-bit */
87 {16, 8, 16, 4, 1, 2, {0x30, 0x20}}, /* DXT3, DXT5 */
88 {32, 16, 8, 2, 4, 8, {0xc0, 0x80}}, /* 32-bit */
91 /** \brief Template for subtile uploads.
92 * \param h height in pixels
93 * \param w width in bytes
95 #define SUBTILE_FUNC(w,h) \
96 static INLINE GLubyte *savageUploadSubtile_##w##x##h \
97 (GLubyte *dest, GLubyte *src, GLuint srcStride) \
100 for (y = 0; y < h; ++y) { \
101 memcpy (dest, src, w); \
108 SUBTILE_FUNC(2, 8) /* 4 bits per pixel, 4 pixels wide */
112 SUBTILE_FUNC(32, 8) /* 4 bytes per pixel, 8 pixels wide */
114 SUBTILE_FUNC(8, 2) /* DXT1 */
115 SUBTILE_FUNC(16, 2) /* DXT3 and DXT5 */
117 /** \brief Upload a complete tile from src (srcStride) to dest
119 * \param tileInfo Pointer to tiling information
120 * \param wInSub Width of source/dest image in subtiles
121 * \param hInSub Height of source/dest image in subtiles
122 * \param bpp Bytes per pixel
123 * \param src Pointer to source data
124 * \param srcStride Byte stride of rows in the source data
125 * \param dest Pointer to destination
127 * Writes linearly to the destination memory in order to exploit write
130 * For a complete tile wInSub and hInSub are set to the same values as
131 * in tileInfo. If the source image is smaller than a whole tile in
132 * one or both dimensions then they are set to the values of the
133 * source image. This only works as long as the source image is bigger
136 static void savageUploadTile (const savageTileInfo
*tileInfo
,
137 GLuint wInSub
, GLuint hInSub
, GLuint bpp
,
138 GLubyte
*src
, GLuint srcStride
, GLubyte
*dest
) {
139 GLuint subStride
= tileInfo
->subWidth
* bpp
;
140 GLubyte
*srcSRow
= src
, *srcSTile
= src
;
141 GLubyte
*(*subtileFunc
) (GLubyte
*, GLubyte
*, GLuint
);
144 case 2: subtileFunc
= savageUploadSubtile_2x8
; break;
145 case 4: subtileFunc
= savageUploadSubtile_4x8
; break;
146 case 8: subtileFunc
= tileInfo
->subHeight
== 8 ?
147 savageUploadSubtile_8x8
: savageUploadSubtile_8x2
; break;
148 case 16: subtileFunc
= tileInfo
->subHeight
== 8 ?
149 savageUploadSubtile_16x8
: savageUploadSubtile_16x2
; break;
150 case 32: subtileFunc
= savageUploadSubtile_32x8
; break;
153 for (sy
= 0; sy
< hInSub
; ++sy
) {
155 for (sx
= 0; sx
< wInSub
; ++sx
) {
157 dest
= subtileFunc (dest
, src
, srcStride
);
158 srcSTile
+= subStride
;
160 srcSRow
+= srcStride
* tileInfo
->subHeight
;
164 /** \brief Upload a image that is smaller than 8 pixels in either dimension.
166 * \param tileInfo Pointer to tiling information
167 * \param width Width of the image
168 * \param height Height of the image
169 * \param bpp Bytes per pixel
170 * \param src Pointer to source data
171 * \param dest Pointer to destination
173 * This function handles all the special cases that need to be taken
174 * care off. The caller may need to call this function multiple times
175 * with the destination offset in different ways since small texture
176 * images must be repeated in order to fill a whole tile (or 4x4 for
177 * the last 3 levels).
179 * FIXME: Repeating inside this function would be more efficient.
181 static void savageUploadTiny (const savageTileInfo
*tileInfo
,
182 GLuint pixWidth
, GLuint pixHeight
,
183 GLuint width
, GLuint height
, GLuint bpp
,
184 GLubyte
*src
, GLubyte
*dest
) {
185 GLuint size
= MAX2(pixWidth
, pixHeight
);
187 if (width
> tileInfo
->subWidth
) { /* assert: height <= subtile height */
188 GLuint wInSub
= width
/ tileInfo
->subWidth
;
189 GLuint srcStride
= width
* bpp
;
190 GLuint subStride
= tileInfo
->subWidth
* bpp
;
191 GLuint subSkip
= (tileInfo
->subHeight
- height
) * subStride
;
192 GLubyte
*srcSTile
= src
;
194 for (sx
= 0; sx
< wInSub
; ++sx
) {
196 for (y
= 0; y
< height
; ++y
) {
197 memcpy (dest
, src
, subStride
);
202 srcSTile
+= subStride
;
204 } else if (size
> 4) { /* a tile or less wide, except the last 3 levels */
205 GLuint srcStride
= width
* bpp
;
206 GLuint subStride
= tileInfo
->subWidth
* bpp
;
207 /* if the subtile width is 4 we have to skip every other subtile */
208 GLuint subSkip
= tileInfo
->subWidth
<= 4 ?
209 subStride
* tileInfo
->subHeight
: 0;
210 GLuint skipRemainder
= tileInfo
->subHeight
- 1;
212 for (y
= 0; y
< height
; ++y
) {
213 memcpy (dest
, src
, srcStride
);
216 if ((y
& skipRemainder
) == skipRemainder
)
219 } else { /* the last 3 mipmap levels */
220 GLuint offset
= (size
<= 2 ? tileInfo
->tinyOffset
[size
-1] : 0);
221 GLuint subStride
= tileInfo
->subWidth
* bpp
;
224 for (y
= 0; y
< height
; ++y
) {
225 memcpy (dest
, src
, bpp
*width
);
232 /** \brief Upload an image from mesa's internal copy.
234 static void savageUploadTexLevel( savageTexObjPtr t
, int level
)
236 const struct gl_texture_image
*image
= t
->base
.tObj
->Image
[0][level
];
237 const savageTileInfo
*tileInfo
= t
->tileInfo
;
238 GLuint pixWidth
= image
->Width2
, pixHeight
= image
->Height2
;
239 GLuint bpp
= t
->texelBytes
;
240 GLuint width
, height
;
242 /* FIXME: Need triangle (rather than pixel) fallbacks to simulate
243 * this using normal textured triangles.
245 * DO THIS IN DRIVER STATE MANAGMENT, not hardware state.
247 if(image
->Border
!= 0)
248 fprintf (stderr
, "Not supported texture border %d.\n",
249 (int) image
->Border
);
251 if (t
->hwFormat
== TFT_S3TC4A4Bit
|| t
->hwFormat
== TFT_S3TC4CA4Bit
||
252 t
->hwFormat
== TFT_S3TC4Bit
) {
253 width
= (pixWidth
+3) / 4;
254 height
= (pixHeight
+3) / 4;
260 if (pixWidth
>= 8 && pixHeight
>= 8) {
261 GLuint
*dirtyPtr
= t
->image
[level
].dirtyTiles
;
262 GLuint dirtyMask
= 1;
264 if (width
>= tileInfo
->width
&& height
>= tileInfo
->height
) {
265 GLuint wInTiles
= width
/ tileInfo
->width
;
266 GLuint hInTiles
= height
/ tileInfo
->height
;
267 GLubyte
*srcTRow
= image
->Data
, *src
;
268 GLubyte
*dest
= (GLubyte
*)(t
->bufAddr
+ t
->image
[level
].offset
);
270 for (y
= 0; y
< hInTiles
; ++y
) {
272 for (x
= 0; x
< wInTiles
; ++x
) {
273 if (*dirtyPtr
& dirtyMask
) {
274 savageUploadTile (tileInfo
,
275 tileInfo
->wInSub
, tileInfo
->hInSub
,
276 bpp
, src
, width
* bpp
, dest
);
278 src
+= tileInfo
->width
* bpp
;
279 dest
+= 2048; /* tile size is always 2k */
280 if (dirtyMask
== 1<<31) {
286 srcTRow
+= width
* tileInfo
->height
* bpp
;
288 } else if (width
>= tileInfo
->width
) {
289 GLuint wInTiles
= width
/ tileInfo
->width
;
290 GLubyte
*src
= image
->Data
;
291 GLubyte
*dest
= (GLubyte
*)(t
->bufAddr
+ t
->image
[level
].offset
);
292 GLuint tileStride
= tileInfo
->width
* bpp
* height
;
293 savageContextPtr imesa
= (savageContextPtr
)t
->base
.heap
->driverContext
;
295 /* Savage3D-based chips seem so use a constant tile stride
296 * of 2048 for vertically incomplete tiles, but only if
297 * the color depth is 32bpp. Nobody said this was supposed
300 if (bpp
== 4 && imesa
->savageScreen
->chipset
< S3_SAVAGE4
)
302 for (x
= 0; x
< wInTiles
; ++x
) {
303 if (*dirtyPtr
& dirtyMask
) {
304 savageUploadTile (tileInfo
,
306 height
/ tileInfo
->subHeight
,
307 bpp
, src
, width
* bpp
, dest
);
309 src
+= tileInfo
->width
* bpp
;
311 if (dirtyMask
== 1<<31) {
318 savageUploadTile (tileInfo
, width
/ tileInfo
->subWidth
,
319 height
/ tileInfo
->subHeight
, bpp
,
320 image
->Data
, width
* bpp
,
321 (GLubyte
*)(t
->bufAddr
+t
->image
[level
].offset
));
324 GLuint minHeight
, minWidth
, hRepeat
, vRepeat
, x
, y
;
325 if (t
->hwFormat
== TFT_S3TC4A4Bit
|| t
->hwFormat
== TFT_S3TC4CA4Bit
||
326 t
->hwFormat
== TFT_S3TC4Bit
)
327 minWidth
= minHeight
= 1;
329 minWidth
= minHeight
= 4;
330 if (width
> minWidth
|| height
> minHeight
) {
331 minWidth
= tileInfo
->subWidth
;
332 minHeight
= tileInfo
->subHeight
;
334 hRepeat
= width
>= minWidth
? 1 : minWidth
/ width
;
335 vRepeat
= height
>= minHeight
? 1 : minHeight
/ height
;
336 for (y
= 0; y
< vRepeat
; ++y
) {
337 GLuint offset
= y
* tileInfo
->subWidth
*height
* bpp
;
338 for (x
= 0; x
< hRepeat
; ++x
) {
339 savageUploadTiny (tileInfo
, pixWidth
, pixHeight
,
340 width
, height
, bpp
, image
->Data
,
341 (GLubyte
*)(t
->bufAddr
+
342 t
->image
[level
].offset
+offset
));
343 offset
+= width
* bpp
;
349 /** \brief Compute the destination size of a texture image
351 static GLuint
savageTexImageSize (GLuint width
, GLuint height
, GLuint bpp
) {
353 if (width
>= 8 && height
>= 8)
354 return width
* height
* bpp
;
355 /* special case for the last three mipmap levels: the hardware computes
356 * the offset internally */
357 else if (width
<= 4 && height
<= 4)
359 /* partially filled sub tiles waste memory
360 * on Savage3D and Savage4 with subtile width 4 every other subtile is
361 * skipped if width < 8 so we can assume a uniform subtile width of 8 */
363 return width
* 8 * bpp
;
364 else if (height
>= 8)
365 return 8 * height
* bpp
;
370 /** \brief Compute the destination size of a compressed texture image
372 static GLuint
savageCompressedTexImageSize (GLuint width
, GLuint height
,
374 width
= (width
+3) / 4;
375 height
= (height
+3) / 4;
377 if (width
>= 2 && height
>= 2)
378 return width
* height
* bpp
;
379 /* special case for the last three mipmap levels: the hardware computes
380 * the offset internally */
381 else if (width
<= 1 && height
<= 1)
383 /* partially filled sub tiles waste memory
384 * on Savage3D and Savage4 with subtile width 4 every other subtile is
385 * skipped if width < 8 so we can assume a uniform subtile width of 8 */
387 return width
* 2 * bpp
;
388 else if (height
>= 2)
389 return 2 * height
* bpp
;
394 /** \brief Compute the number of (partial) tiles of a texture image
396 static GLuint
savageTexImageTiles (GLuint width
, GLuint height
,
397 const savageTileInfo
*tileInfo
)
399 return (width
+ tileInfo
->width
- 1) / tileInfo
->width
*
400 (height
+ tileInfo
->height
- 1) / tileInfo
->height
;
403 /** \brief Mark dirty tiles
405 * Some care must be taken because tileInfo may not be set or not
406 * up-to-date. So we check if tileInfo is initialized and if the number
407 * of tiles in the bit vector matches the number of tiles computed from
408 * the current tileInfo.
410 static void savageMarkDirtyTiles (savageTexObjPtr t
, GLuint level
,
411 GLuint totalWidth
, GLuint totalHeight
,
412 GLint xoffset
, GLint yoffset
,
413 GLsizei width
, GLsizei height
)
415 GLuint wInTiles
, hInTiles
;
416 GLuint x0
, y0
, x1
, y1
;
420 wInTiles
= (totalWidth
+ t
->tileInfo
->width
- 1) / t
->tileInfo
->width
;
421 hInTiles
= (totalHeight
+ t
->tileInfo
->height
- 1) / t
->tileInfo
->height
;
422 if (wInTiles
* hInTiles
!= t
->image
[level
].nTiles
)
425 x0
= xoffset
/ t
->tileInfo
->width
;
426 y0
= yoffset
/ t
->tileInfo
->height
;
427 x1
= (xoffset
+ width
- 1) / t
->tileInfo
->width
;
428 y1
= (yoffset
+ height
- 1) / t
->tileInfo
->height
;
430 for (y
= y0
; y
<= y1
; ++y
) {
431 GLuint
*ptr
= t
->image
[level
].dirtyTiles
+ (y
* wInTiles
+ x0
) / 32;
432 GLuint mask
= 1 << (y
* wInTiles
+ x0
) % 32;
433 for (x
= x0
; x
<= x1
; ++x
) {
435 if (mask
== (1<<31)) {
445 /** \brief Mark all tiles as dirty
447 static void savageMarkAllTiles (savageTexObjPtr t
, GLuint level
)
449 GLuint words
= (t
->image
[level
].nTiles
+ 31) / 32;
451 memset(t
->image
[level
].dirtyTiles
, ~0, words
*sizeof(GLuint
));
455 static void savageSetTexWrapping(savageTexObjPtr tex
, GLenum s
, GLenum t
)
457 tex
->setup
.sWrapMode
= s
;
458 tex
->setup
.tWrapMode
= t
;
461 static void savageSetTexFilter(savageTexObjPtr t
, GLenum minf
, GLenum magf
)
463 t
->setup
.minFilter
= minf
;
464 t
->setup
.magFilter
= magf
;
470 static void savageSetTexBorderColor(savageTexObjPtr t
, const GLfloat color
[4])
472 /* t->Setup[SAVAGE_TEXREG_TEXBORDERCOL] = */
473 /*t->setup.borderColor = SAVAGEPACKCOLOR8888(color[0],color[1],color[2],color[3]); */
478 static savageTexObjPtr
479 savageAllocTexObj( struct gl_texture_object
*texObj
)
483 t
= (savageTexObjPtr
) calloc(1,sizeof(*t
));
484 texObj
->DriverData
= t
;
488 /* Initialize non-image-dependent parts of the state:
490 t
->base
.tObj
= texObj
;
491 t
->base
.dirty_images
[0] = 0;
492 t
->dirtySubImages
= 0;
495 /* Initialize dirty tiles bit vectors
497 for (i
= 0; i
< SAVAGE_TEX_MAXLEVELS
; ++i
)
498 t
->image
[i
].nTiles
= 0;
500 /* FIXME Something here to set initial values for other parts of
504 make_empty_list( &t
->base
);
506 savageSetTexWrapping(t
,texObj
->WrapS
,texObj
->WrapT
);
507 savageSetTexFilter(t
,texObj
->MinFilter
,texObj
->MagFilter
);
508 savageSetTexBorderColor(t
,texObj
->BorderColor
.f
);
514 /* Mesa texture formats for alpha-images on Savage3D/IX/MX
516 * Promoting texture images to ARGB888 or ARGB4444 doesn't work
517 * because we can't tell the hardware to ignore the color components
518 * and only use the alpha component. So we define our own texture
519 * formats that promote to ARGB8888 or ARGB4444 and set the color
520 * components to white. This way we get the correct result.
524 /* Using MESA_FORMAT_RGBA8888 to store alpha-only textures should
525 * work but is space inefficient.
529 _savage_texstore_a1114444(TEXSTORE_PARAMS
);
532 _savage_texstore_a1118888(TEXSTORE_PARAMS
);
534 static struct gl_texture_format _savage_texformat_a1114444
= {
535 MESA_FORMAT_ARGB4444
, /* MesaFormat */
536 GL_RGBA
, /* BaseFormat */
537 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
542 0, /* LuminanceBits */
543 0, /* IntensityBits */
548 _savage_texstore_a1114444
, /* StoreTexImageFunc */
549 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* FetchTexel* filled in by
550 * savageDDInitTextureFuncs */
552 static struct gl_texture_format _savage_texformat_a1118888
= {
553 MESA_FORMAT_ARGB8888
, /* MesaFormat */
554 GL_RGBA
, /* BaseFormat */
555 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
560 0, /* LuminanceBits */
561 0, /* IntensityBits */
566 _savage_texstore_a1118888
, /* StoreTexImageFunc */
567 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* FetchTexel* filled in by
568 * savageDDInitTextureFuncs */
573 _savage_texstore_a1114444(TEXSTORE_PARAMS
)
575 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
578 srcWidth
, srcHeight
, srcDepth
,
579 srcFormat
, srcType
, srcAddr
,
581 const GLchan
*src
= tempImage
;
584 ASSERT(dstFormat
== &_savage_texformat_a1114444
);
585 ASSERT(baseInternalFormat
== GL_ALPHA
);
589 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
590 for (img
= 0; img
< srcDepth
; img
++) {
591 GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
592 GLubyte
*dstRow
= (GLubyte
*) dstAddr
593 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
594 + dstYoffset
* dstRowStride
595 + dstXoffset
* texelBytes
;
596 for (row
= 0; row
< srcHeight
; row
++) {
597 GLushort
*dstUI
= (GLushort
*) dstRow
;
598 for (col
= 0; col
< srcWidth
; col
++) {
599 dstUI
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[0]),
603 dstRow
+= dstRowStride
;
606 _mesa_free((void *) tempImage
);
613 _savage_texstore_a1118888(TEXSTORE_PARAMS
)
615 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
618 srcWidth
, srcHeight
, srcDepth
,
619 srcFormat
, srcType
, srcAddr
,
621 const GLchan
*src
= tempImage
;
624 ASSERT(dstFormat
== &_savage_texformat_a1118888
);
625 ASSERT(baseInternalFormat
== GL_ALPHA
);
629 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
630 for (img
= 0; img
< srcDepth
; img
++) {
631 GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
632 GLubyte
*dstRow
= (GLubyte
*) dstAddr
633 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
634 + dstYoffset
* dstRowStride
635 + dstXoffset
* texelBytes
;
636 for (row
= 0; row
< srcHeight
; row
++) {
637 GLuint
*dstUI
= (GLuint
*) dstRow
;
638 for (col
= 0; col
< srcWidth
; col
++) {
639 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[0]),
643 dstRow
+= dstRowStride
;
646 _mesa_free((void *) tempImage
);
653 /* Called by the _mesa_store_teximage[123]d() functions. */
655 savageChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
656 GLenum format
, GLenum type
)
658 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
659 const GLboolean do32bpt
=
660 ( imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_32
);
661 const GLboolean force16bpt
=
662 ( imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FORCE_16
);
663 const GLboolean isSavage4
= (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
);
666 switch ( internalFormat
) {
669 case GL_COMPRESSED_RGBA
:
671 case GL_UNSIGNED_INT_10_10_10_2
:
672 case GL_UNSIGNED_INT_2_10_10_10_REV
:
673 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB1555
;
674 case GL_UNSIGNED_SHORT_4_4_4_4
:
675 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
676 return MESA_FORMAT_ARGB4444
;
677 case GL_UNSIGNED_SHORT_5_5_5_1
:
678 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
679 return MESA_FORMAT_ARGB1555
;
681 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
686 case GL_COMPRESSED_RGB
:
688 case GL_UNSIGNED_SHORT_4_4_4_4
:
689 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
690 return MESA_FORMAT_ARGB4444
;
691 case GL_UNSIGNED_SHORT_5_5_5_1
:
692 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
693 return MESA_FORMAT_ARGB1555
;
694 case GL_UNSIGNED_SHORT_5_6_5
:
695 case GL_UNSIGNED_SHORT_5_6_5_REV
:
696 return MESA_FORMAT_RGB565
;
698 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
705 MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
709 MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB1555
;
713 return MESA_FORMAT_ARGB4444
;
716 return MESA_FORMAT_ARGB1555
;
722 return !force16bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_RGB565
;
727 return MESA_FORMAT_RGB565
;
730 case GL_COMPRESSED_ALPHA
:
732 return isSavage4
? MESA_FORMAT_a8
: (
733 do32bpt
? &_savage_texformat_a1118888
: &_savage_texformat_a1114444
);
736 return MESA_FORMAT_A8
;
738 return MESA_FORMAT_ARGB8888
;
740 return MESA_FORMAT_ARGB4444
;
744 return isSavage4
? MESA_FORMAT_a8
: &_savage_texformat_a1114444
;
747 return MESA_FORMAT_A8
;
749 return MESA_FORMAT_ARGB4444
;
755 return isSavage4
? MESA_FORMAT_a8
: (
756 !force16bpt
? &_savage_texformat_a1118888
: &_savage_texformat_a1114444
);
759 return MESA_FORMAT_A8
;
761 return MESA_FORMAT_ARGB4444
;
763 return MESA_FORMAT_ARGB8888
;
767 case GL_COMPRESSED_LUMINANCE
:
768 /* no alpha, but use argb1555 in 16bit case to get pure grey values */
769 return isSavage4
? MESA_FORMAT_L8
: (
770 do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB1555
);
772 return isSavage4
? MESA_FORMAT_L8
: MESA_FORMAT_ARGB1555
;
776 return isSavage4
? MESA_FORMAT_L8
: (
777 !force16bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB1555
);
780 case GL_LUMINANCE_ALPHA
:
781 case GL_COMPRESSED_LUMINANCE_ALPHA
:
782 /* Savage4 has a al44 texture format. But it's not supported by Mesa. */
783 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
784 case GL_LUMINANCE4_ALPHA4
:
785 case GL_LUMINANCE6_ALPHA2
:
786 return MESA_FORMAT_ARGB4444
;
787 case GL_LUMINANCE8_ALPHA8
:
788 case GL_LUMINANCE12_ALPHA4
:
789 case GL_LUMINANCE12_ALPHA12
:
790 case GL_LUMINANCE16_ALPHA16
:
791 return !force16bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
793 /* TFT_I8 produces garbage on ProSavageDDR and subsequent texture
794 * disable keeps rendering garbage. Disabled for now. */
796 case GL_COMPRESSED_INTENSITY
:
797 return isSavage4
? MESA_FORMAT_i8
: (
798 do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
);
800 return isSavage4
? MESA_FORMAT_i8
: MESA_FORMAT_ARGB4444
;
804 return isSavage4
? MESA_FORMAT_i8
: (
805 !force16bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
);
808 case GL_COMPRESSED_INTENSITY
:
809 return do32bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
811 return MESA_FORMAT_ARGB4444
;
815 return !force16bpt
? MESA_FORMAT_ARGB8888
: MESA_FORMAT_ARGB4444
;
820 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
821 return MESA_FORMAT_RGB_DXT1
;
822 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
823 return MESA_FORMAT_RGBA_DXT1
;
825 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
826 return MESA_FORMAT_RGBA_DXT3
;
831 /* Not the best choice but Savage3D/MX/IX don't support DXT3 or DXT5. */
832 return MESA_FORMAT_RGBA_DXT1
;
834 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
835 return MESA_FORMAT_RGBA_DXT5
;
839 case GL_COLOR_INDEX1_EXT:
840 case GL_COLOR_INDEX2_EXT:
841 case GL_COLOR_INDEX4_EXT:
842 case GL_COLOR_INDEX8_EXT:
843 case GL_COLOR_INDEX12_EXT:
844 case GL_COLOR_INDEX16_EXT:
845 return &_mesa_texformat_ci8;
848 _mesa_problem(ctx
, "unexpected texture format in %s", __FUNCTION__
);
849 return MESA_FORMAT_NONE
;
853 static void savageSetTexImages( savageContextPtr imesa
,
854 const struct gl_texture_object
*tObj
)
856 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
857 struct gl_texture_image
*image
= tObj
->Image
[0][tObj
->BaseLevel
];
858 GLuint offset
, i
, textureFormat
, tileIndex
, size
;
859 GLint firstLevel
, lastLevel
;
864 switch (image
->TexFormat
) {
865 case MESA_FORMAT_ARGB8888
:
866 textureFormat
= TFT_ARGB8888
;
867 t
->texelBytes
= tileIndex
= 4;
869 case MESA_FORMAT_ARGB1555
:
870 textureFormat
= TFT_ARGB1555
;
871 t
->texelBytes
= tileIndex
= 2;
873 case MESA_FORMAT_ARGB4444
:
874 textureFormat
= TFT_ARGB4444
;
875 t
->texelBytes
= tileIndex
= 2;
877 case MESA_FORMAT_RGB565
:
878 textureFormat
= TFT_RGB565
;
879 t
->texelBytes
= tileIndex
= 2;
882 textureFormat
= TFT_L8
;
883 t
->texelBytes
= tileIndex
= 1;
886 textureFormat
= TFT_I8
;
887 t
->texelBytes
= tileIndex
= 1;
890 textureFormat
= TFT_A8
;
891 t
->texelBytes
= tileIndex
= 1;
893 case MESA_FORMAT_RGB_DXT1
:
894 textureFormat
= TFT_S3TC4Bit
;
895 tileIndex
= TILE_INDEX_DXT1
;
898 case MESA_FORMAT_RGBA_DXT1
:
899 textureFormat
= TFT_S3TC4Bit
;
900 tileIndex
= TILE_INDEX_DXT1
;
903 case MESA_FORMAT_RGBA_DXT3
:
904 textureFormat
= TFT_S3TC4A4Bit
;
905 tileIndex
= TILE_INDEX_DXTn
;
908 case MESA_FORMAT_RGBA_DXT5
:
909 textureFormat
= TFT_S3TC4CA4Bit
;
910 tileIndex
= TILE_INDEX_DXTn
;
914 _mesa_problem(imesa
->glCtx
, "Bad texture format in %s", __FUNCTION__
);
917 t
->hwFormat
= textureFormat
;
919 /* Select tiling format depending on the chipset and texture format */
920 if (imesa
->savageScreen
->chipset
<= S3_SAVAGE4
)
921 t
->tileInfo
= &tileInfo_s3d_s4
[tileIndex
];
923 t
->tileInfo
= &tileInfo_pro
[tileIndex
];
925 /* Compute which mipmap levels we really want to send to the hardware.
927 driCalculateTextureFirstLastLevel( &t
->base
);
928 firstLevel
= t
->base
.firstLevel
;
929 lastLevel
= t
->base
.lastLevel
;
931 /* Figure out the size now (and count the levels). Upload won't be
932 * done until later. If the number of tiles changes, it means that
933 * this function is called for the first time on this tex object or
934 * the image or the destination color format changed. So all tiles
935 * are marked as dirty.
939 for ( i
= firstLevel
; i
<= lastLevel
&& tObj
->Image
[0][i
] ; i
++ ) {
941 nTiles
= savageTexImageTiles (image
->Width2
, image
->Height2
, t
->tileInfo
);
942 if (t
->image
[i
].nTiles
!= nTiles
) {
943 GLuint words
= (nTiles
+ 31) / 32;
944 if (t
->image
[i
].nTiles
!= 0) {
945 free(t
->image
[i
].dirtyTiles
);
947 t
->image
[i
].dirtyTiles
= malloc(words
*sizeof(GLuint
));
948 memset(t
->image
[i
].dirtyTiles
, ~0, words
*sizeof(GLuint
));
950 t
->image
[i
].nTiles
= nTiles
;
952 t
->image
[i
].offset
= offset
;
954 image
= tObj
->Image
[0][i
];
955 if (t
->texelBytes
>= 8)
956 size
= savageCompressedTexImageSize (image
->Width2
, image
->Height2
,
959 size
= savageTexImageSize (image
->Width2
, image
->Height2
,
964 t
->base
.lastLevel
= i
-1;
965 t
->base
.totalSize
= offset
;
966 /* the last three mipmap levels don't add to the offset. They are packed
969 t
->base
.totalSize
+= (t
->texelBytes
>= 8 ? 4 : 64) * t
->texelBytes
;
970 /* 2k-aligned (really needed?) */
971 t
->base
.totalSize
= (t
->base
.totalSize
+ 2047UL) & ~2047UL;
974 void savageDestroyTexObj(savageContextPtr imesa
, savageTexObjPtr t
)
978 /* Free dirty tiles bit vectors */
979 for (i
= 0; i
< SAVAGE_TEX_MAXLEVELS
; ++i
) {
980 if (t
->image
[i
].nTiles
)
981 free (t
->image
[i
].dirtyTiles
);
984 /* See if it was the driver's current object.
988 for ( i
= 0 ; i
< imesa
->glCtx
->Const
.MaxTextureUnits
; i
++ )
990 if ( &t
->base
== imesa
->CurrentTexObj
[ i
] ) {
991 assert( t
->base
.bound
& (1 << i
) );
992 imesa
->CurrentTexObj
[ i
] = NULL
;
998 /* Upload a texture's images to one of the texture heaps. May have to
999 * eject our own and/or other client's texture objects to make room
1002 static void savageUploadTexImages( savageContextPtr imesa
, savageTexObjPtr t
)
1004 const GLint numLevels
= t
->base
.lastLevel
- t
->base
.firstLevel
+ 1;
1009 LOCK_HARDWARE(imesa
);
1011 /* Do we need to eject LRU texture objects?
1013 if (!t
->base
.memBlock
) {
1017 heap
= driAllocateTexture(imesa
->textureHeaps
, imesa
->lastTexHeap
,
1018 (driTextureObject
*)t
);
1020 UNLOCK_HARDWARE(imesa
);
1024 ofs
= t
->base
.memBlock
->ofs
;
1025 t
->setup
.physAddr
= imesa
->savageScreen
->textureOffset
[heap
] + ofs
;
1026 t
->bufAddr
= (GLubyte
*)imesa
->savageScreen
->texVirtual
[heap
] + ofs
;
1027 imesa
->dirty
|= SAVAGE_UPLOAD_GLOBAL
; /* FIXME: really needed? */
1030 /* Let the world know we've used this memory recently.
1032 driUpdateTextureLRU( &t
->base
);
1033 UNLOCK_HARDWARE(imesa
);
1035 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1036 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1037 fprintf(stderr
, "Texture upload: |");
1039 /* Heap timestamps are only reliable with Savage DRM 2.3.x or
1040 * later. Earlier versions had only 16 bit time stamps which
1041 * would wrap too frequently. */
1042 if (imesa
->savageScreen
->driScrnPriv
->drm_version
.minor
>= 3) {
1043 unsigned int heap
= t
->base
.heap
->heapId
;
1044 LOCK_HARDWARE(imesa
);
1045 savageWaitEvent (imesa
, imesa
->textureHeaps
[heap
]->timestamp
);
1047 savageFlushVertices (imesa
);
1048 LOCK_HARDWARE(imesa
);
1049 savageFlushCmdBufLocked (imesa
, GL_FALSE
);
1050 WAIT_IDLE_EMPTY_LOCKED(imesa
);
1053 for (i
= 0 ; i
< numLevels
; i
++) {
1054 const GLint j
= t
->base
.firstLevel
+ i
; /* the texObj's level */
1055 if (t
->base
.dirty_images
[0] & (1 << j
)) {
1056 savageMarkAllTiles(t
, j
);
1057 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1058 fprintf (stderr
, "*");
1059 } else if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
) {
1060 if (t
->dirtySubImages
& (1 << j
))
1061 fprintf (stderr
, ".");
1063 fprintf (stderr
, " ");
1065 if ((t
->base
.dirty_images
[0] | t
->dirtySubImages
) & (1 << j
))
1066 savageUploadTexLevel( t
, j
);
1069 UNLOCK_HARDWARE(imesa
);
1070 t
->base
.dirty_images
[0] = 0;
1071 t
->dirtySubImages
= 0;
1073 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1074 fprintf(stderr
, "|\n");
1080 savage4_set_wrap_mode( savageContextPtr imesa
, unsigned unit
,
1081 GLenum s_mode
, GLenum t_mode
)
1085 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Wrap
;
1088 case GL_CLAMP_TO_EDGE
:
1089 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Clamp
;
1091 case GL_MIRRORED_REPEAT
:
1092 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Mirror
;
1098 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Wrap
;
1101 case GL_CLAMP_TO_EDGE
:
1102 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Clamp
;
1104 case GL_MIRRORED_REPEAT
:
1105 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Mirror
;
1112 * Sets the hardware bits for the specified GL texture filter modes.
1115 * Does the Savage4 have the ability to select the magnification filter?
1118 savage4_set_filter_mode( savageContextPtr imesa
, unsigned unit
,
1119 GLenum minFilter
, GLenum magFilter
)
1123 switch (minFilter
) {
1125 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1126 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1130 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1131 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1134 case GL_NEAREST_MIPMAP_NEAREST
:
1135 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1136 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1139 case GL_LINEAR_MIPMAP_NEAREST
:
1140 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1141 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1144 case GL_NEAREST_MIPMAP_LINEAR
:
1145 case GL_LINEAR_MIPMAP_LINEAR
:
1146 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Trilin
;
1147 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1153 static void savageUpdateTex0State_s4( GLcontext
*ctx
)
1155 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1156 struct gl_texture_object
*tObj
;
1157 struct gl_texture_image
*image
;
1162 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_FALSE
;
1163 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_NoTexMap
;
1164 imesa
->regs
.s4
.texCtrl
[0].ui
= 0x20f040;
1165 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1168 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1169 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1170 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1171 /* 3D texturing enabled, or texture border - fallback */
1172 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1176 /* Do 2D texture setup */
1178 t
= tObj
->DriverData
;
1180 t
= savageAllocTexObj( tObj
);
1185 imesa
->CurrentTexObj
[0] = &t
->base
;
1188 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1189 savageSetTexImages(imesa
, tObj
);
1190 savageUploadTexImages(imesa
, t
);
1193 driUpdateTextureLRU( &t
->base
);
1195 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1197 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1199 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1204 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1207 case GL_LUMINANCE_ALPHA
:
1210 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Copy
;
1214 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1217 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1218 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1222 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1227 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1232 case GL_LUMINANCE_ALPHA
:
1233 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_DecalAlpha
;
1237 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1238 are undefined with GL_DECAL
1242 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1245 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1246 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1250 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1251 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1252 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1253 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1257 imesa
->regs
.s4
.texBlendColor
.ui
= imesa
->texEnvColor
;
1262 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1263 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1268 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Blend0
;
1269 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1270 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1271 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1272 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1273 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1274 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1275 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1276 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1278 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1279 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Blend1
;
1281 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1282 imesa
->bTexEn1
= GL_TRUE
;
1285 case GL_LUMINANCE_ALPHA
:
1287 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendAlpha0
;
1288 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1289 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1290 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1291 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1292 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1293 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1294 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1295 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1297 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1298 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendAlpha1
;
1300 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1301 imesa
->bTexEn1
= GL_TRUE
;
1305 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendInt0
;
1306 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1307 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1308 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1309 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1310 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1311 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1312 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1313 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1315 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1316 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendInt1
;
1318 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1319 imesa
->regs
.s4
.texCtrl
[0].ni
.alphaArg1Invert
= GL_TRUE
;
1320 imesa
->bTexEn1
= GL_TRUE
;
1323 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1324 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1328 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1332 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1337 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1340 case GL_LUMINANCE_ALPHA
:
1342 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1346 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_AddAlpha
;
1349 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1350 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1353 #if GL_ARB_texture_env_combine
1354 case GL_COMBINE_ARB
:
1355 __HWParseTexEnvCombine(imesa
, 0, &imesa
->regs
.s4
.texCtrl
[0],
1356 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1361 fprintf(stderr
, "unknown tex env mode");
1366 savage4_set_wrap_mode( imesa
, 0, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1367 savage4_set_filter_mode( imesa
, 0, t
->setup
.minFilter
, t
->setup
.magFilter
);
1369 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1370 (imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
!= 0))
1372 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 32.0) +
1376 else if (bias
> 255)
1378 imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
= bias
& 0x1ff;
1381 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1382 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_TRUE
;
1383 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
= image
->WidthLog2
;
1384 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
= image
->HeightLog2
;
1385 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
= t
->hwFormat
;
1386 imesa
->regs
.s4
.texCtrl
[0].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1388 if (imesa
->regs
.s4
.texDescr
.ni
.tex1En
)
1389 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1391 imesa
->regs
.s4
.texAddr
[0].ui
= (uint32_t) t
->setup
.physAddr
| 0x2;
1392 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1393 imesa
->regs
.s4
.texAddr
[0].ui
|= 0x1;
1397 static void savageUpdateTex1State_s4( GLcontext
*ctx
)
1399 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1400 struct gl_texture_object
*tObj
;
1401 struct gl_texture_image
*image
;
1408 imesa
->bTexEn1
= GL_FALSE
;
1412 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_FALSE
;
1413 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_NoTexMap1
;
1414 imesa
->regs
.s4
.texCtrl
[1].ui
= 0x20f040;
1415 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_FALSE
;
1416 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
== 0)
1419 tObj
= ctx
->Texture
.Unit
[1]._Current
;
1421 if ((ctx
->Texture
.Unit
[1]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1422 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1423 /* 3D texturing enabled, or texture border - fallback */
1424 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1428 /* Do 2D texture setup */
1430 t
= tObj
->DriverData
;
1432 t
= savageAllocTexObj( tObj
);
1437 imesa
->CurrentTexObj
[1] = &t
->base
;
1441 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1442 savageSetTexImages(imesa
, tObj
);
1443 savageUploadTexImages(imesa
, t
);
1446 driUpdateTextureLRU( &t
->base
);
1448 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1450 switch (ctx
->Texture
.Unit
[1].EnvMode
) {
1452 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1457 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal
;
1460 case GL_LUMINANCE_ALPHA
:
1463 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Copy
;
1467 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1470 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1473 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1474 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1475 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1479 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1483 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1488 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1491 case GL_LUMINANCE_ALPHA
:
1493 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1497 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_AddAlpha1
;
1500 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1503 #if GL_ARB_texture_env_combine
1504 case GL_COMBINE_ARB
:
1505 __HWParseTexEnvCombine(imesa
, 1, &texCtrl
, &imesa
->regs
.s4
.texBlendCtrl
);
1510 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1516 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal1
;
1518 case GL_LUMINANCE_ALPHA
:
1521 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_DecalAlpha1
;
1525 // GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1526 // are undefined with GL_DECAL
1529 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1532 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1536 if (format
== GL_LUMINANCE
)
1539 // This is a hack for GLQuake, invert.
1541 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_TRUE
;
1542 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= 0;
1544 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1548 fprintf(stderr
, "unknown tex 1 env mode\n");
1553 savage4_set_wrap_mode( imesa
, 1, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1554 savage4_set_filter_mode( imesa
, 1, t
->setup
.minFilter
, t
->setup
.magFilter
);
1556 if((ctx
->Texture
.Unit
[1].LodBias
!=0.0F
) ||
1557 (imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
!= 0))
1559 int bias
= (int)(ctx
->Texture
.Unit
[1].LodBias
* 32.0) +
1563 else if (bias
> 255)
1565 imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
= bias
& 0x1ff;
1568 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1569 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1570 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
= image
->WidthLog2
;
1571 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
= image
->HeightLog2
;
1572 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
= t
->hwFormat
;
1573 imesa
->regs
.s4
.texCtrl
[1].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1574 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1576 imesa
->regs
.s4
.texAddr
[1].ui
= (uint32_t) t
->setup
.physAddr
| 2;
1577 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1578 imesa
->regs
.s4
.texAddr
[1].ui
|= 0x1;
1580 static void savageUpdateTexState_s3d( GLcontext
*ctx
)
1582 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1583 struct gl_texture_object
*tObj
;
1584 struct gl_texture_image
*image
;
1589 imesa
->regs
.s3d
.texCtrl
.ui
= 0;
1590 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_FALSE
;
1591 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= 0x08;
1592 imesa
->regs
.s3d
.texCtrl
.ni
.texXprEn
= GL_TRUE
;
1593 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1596 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1597 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1598 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1599 /* 3D texturing enabled, or texture border - fallback */
1600 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1604 /* Do 2D texture setup */
1605 t
= tObj
->DriverData
;
1607 t
= savageAllocTexObj( tObj
);
1612 imesa
->CurrentTexObj
[0] = &t
->base
;
1615 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1616 savageSetTexImages(imesa
, tObj
);
1617 savageUploadTexImages(imesa
, t
);
1620 driUpdateTextureLRU( &t
->base
);
1622 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1624 /* FIXME: copied from utah-glx, probably needs some tuning */
1625 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1627 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECALALPHA_S3D
;
1631 case GL_ALPHA
: /* FIXME */
1632 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 1;
1634 case GL_LUMINANCE_ALPHA
:
1636 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 4;
1640 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECAL_S3D
;
1643 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_COPY_S3D
;
1646 case GL_BLEND
: /* hardware can't do GL_BLEND */
1647 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1650 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_MODULATEALPHA_S3D
;
1653 fprintf(stderr
, "unknown tex env mode\n");
1658 /* The Savage3D can't handle different wrapping modes in s and t.
1659 * If they are not the same, fall back to software. */
1660 if (t
->setup
.sWrapMode
!= t
->setup
.tWrapMode
) {
1661 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1664 imesa
->regs
.s3d
.texCtrl
.ni
.uWrapEn
= 0;
1665 imesa
->regs
.s3d
.texCtrl
.ni
.vWrapEn
= 0;
1666 imesa
->regs
.s3d
.texCtrl
.ni
.wrapMode
=
1667 (t
->setup
.sWrapMode
== GL_REPEAT
) ? TAM_Wrap
: TAM_Clamp
;
1669 switch (t
->setup
.minFilter
) {
1671 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1672 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1676 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1677 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1680 case GL_NEAREST_MIPMAP_NEAREST
:
1681 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1682 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1685 case GL_LINEAR_MIPMAP_NEAREST
:
1686 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1687 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1690 case GL_NEAREST_MIPMAP_LINEAR
:
1691 case GL_LINEAR_MIPMAP_LINEAR
:
1692 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Trilin
;
1693 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1697 /* There is no way to specify a maximum mipmap level. We may have to
1698 disable mipmapping completely. */
1700 if (t->max_level < t->image[0].image->WidthLog2 ||
1701 t->max_level < t->image[0].image->HeightLog2) {
1702 texCtrl.ni.mipmapEnable = GL_TRUE;
1703 if (texCtrl.ni.filterMode == TFM_Trilin)
1704 texCtrl.ni.filterMode = TFM_Bilin;
1705 texCtrl.ni.filterMode = TFM_Point;
1709 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1710 (imesa
->regs
.s3d
.texCtrl
.ni
.dBias
!= 0))
1712 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 16.0);
1715 else if (bias
> 255)
1717 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= bias
& 0x1ff;
1720 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1721 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_TRUE
;
1722 imesa
->regs
.s3d
.texDescr
.ni
.texWidth
= image
->WidthLog2
;
1723 imesa
->regs
.s3d
.texDescr
.ni
.texHeight
= image
->HeightLog2
;
1724 assert (t
->hwFormat
<= 7);
1725 imesa
->regs
.s3d
.texDescr
.ni
.texFmt
= t
->hwFormat
;
1727 imesa
->regs
.s3d
.texAddr
.ui
= (uint32_t) t
->setup
.physAddr
| 2;
1728 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1729 imesa
->regs
.s3d
.texAddr
.ui
|= 0x1;
1733 static void savageTimestampTextures( savageContextPtr imesa
)
1735 /* Timestamp current texture objects for texture heap aging.
1736 * Only useful with long-lived 32-bit event tags available
1737 * with Savage DRM 2.3.x or later. */
1738 if ((imesa
->CurrentTexObj
[0] || imesa
->CurrentTexObj
[1]) &&
1739 imesa
->savageScreen
->driScrnPriv
->drm_version
.minor
>= 3) {
1742 e
= savageEmitEvent(imesa
, SAVAGE_WAIT_3D
);
1743 if (imesa
->CurrentTexObj
[0])
1744 imesa
->CurrentTexObj
[0]->timestamp
= e
;
1745 if (imesa
->CurrentTexObj
[1])
1746 imesa
->CurrentTexObj
[1]->timestamp
= e
;
1751 static void savageUpdateTextureState_s4( GLcontext
*ctx
)
1753 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1755 /* When a texture is about to change or be disabled, timestamp the
1756 * old texture(s). We'll have to wait for this time stamp before
1757 * uploading anything to the same texture heap.
1759 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1760 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1761 (imesa
->CurrentTexObj
[1] && ctx
->Texture
.Unit
[1]._ReallyEnabled
&&
1762 ctx
->Texture
.Unit
[1]._Current
->DriverData
!= imesa
->CurrentTexObj
[1]) ||
1763 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
) ||
1764 (imesa
->CurrentTexObj
[1] && !ctx
->Texture
.Unit
[1]._ReallyEnabled
))
1765 savageTimestampTextures(imesa
);
1767 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1768 if (imesa
->CurrentTexObj
[1]) imesa
->CurrentTexObj
[1]->bound
&= ~2;
1769 imesa
->CurrentTexObj
[0] = 0;
1770 imesa
->CurrentTexObj
[1] = 0;
1771 savageUpdateTex0State_s4( ctx
);
1772 savageUpdateTex1State_s4( ctx
);
1773 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
|
1774 SAVAGE_UPLOAD_TEX1
);
1776 static void savageUpdateTextureState_s3d( GLcontext
*ctx
)
1778 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1780 /* When a texture is about to change or be disabled, timestamp the
1781 * old texture(s). We'll have to wait for this time stamp before
1782 * uploading anything to the same texture heap.
1784 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1785 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1786 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
))
1787 savageTimestampTextures(imesa
);
1789 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1790 imesa
->CurrentTexObj
[0] = 0;
1791 savageUpdateTexState_s3d( ctx
);
1792 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
);
1794 void savageUpdateTextureState( GLcontext
*ctx
)
1796 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1797 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_FALSE
);
1798 FALLBACK(ctx
, SAVAGE_FALLBACK_PROJ_TEXTURE
, GL_FALSE
);
1799 if (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
)
1800 savageUpdateTextureState_s4 (ctx
);
1802 savageUpdateTextureState_s3d (ctx
);
1807 /*****************************************
1809 *****************************************/
1811 static void savageTexEnv( GLcontext
*ctx
, GLenum target
,
1812 GLenum pname
, const GLfloat
*param
)
1814 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1816 if (pname
== GL_TEXTURE_ENV_MODE
) {
1818 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
1820 } else if (pname
== GL_TEXTURE_ENV_COLOR
) {
1822 struct gl_texture_unit
*texUnit
=
1823 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1824 const GLfloat
*fc
= texUnit
->EnvColor
;
1826 CLAMPED_FLOAT_TO_UBYTE(r
, fc
[0]);
1827 CLAMPED_FLOAT_TO_UBYTE(g
, fc
[1]);
1828 CLAMPED_FLOAT_TO_UBYTE(b
, fc
[2]);
1829 CLAMPED_FLOAT_TO_UBYTE(a
, fc
[3]);
1831 imesa
->texEnvColor
= ((a
<< 24) | (r
<< 16) |
1832 (g
<< 8) | (b
<< 0));
1838 /* Update the heap's time stamp, so the new image is not uploaded
1839 * while the old one is still in use. If the texture that is going to
1840 * be changed is currently bound, we need to timestamp the texture
1842 static void savageTexImageChanged (savageTexObjPtr t
) {
1845 savageTimestampTextures(
1846 (savageContextPtr
)t
->base
.heap
->driverContext
);
1847 if (t
->base
.timestamp
> t
->base
.heap
->timestamp
)
1848 t
->base
.heap
->timestamp
= t
->base
.timestamp
;
1852 static void savageTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
1853 GLint internalFormat
,
1854 GLint width
, GLint border
,
1855 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1856 const struct gl_pixelstore_attrib
*packing
,
1857 struct gl_texture_object
*texObj
,
1858 struct gl_texture_image
*texImage
)
1860 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1862 savageTexImageChanged (t
);
1864 t
= savageAllocTexObj(texObj
);
1866 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1870 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
1871 width
, border
, format
, type
,
1872 pixels
, packing
, texObj
, texImage
);
1873 t
->base
.dirty_images
[0] |= (1 << level
);
1874 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1877 static void savageTexSubImage1D( GLcontext
*ctx
,
1882 GLenum format
, GLenum type
,
1883 const GLvoid
*pixels
,
1884 const struct gl_pixelstore_attrib
*packing
,
1885 struct gl_texture_object
*texObj
,
1886 struct gl_texture_image
*texImage
)
1888 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1889 assert( t
); /* this _should_ be true */
1891 savageTexImageChanged (t
);
1892 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, 1,
1893 xoffset
, 0, width
, 1);
1895 t
= savageAllocTexObj(texObj
);
1897 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
1900 t
->base
.dirty_images
[0] |= (1 << level
);
1902 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
1903 format
, type
, pixels
, packing
, texObj
,
1905 t
->dirtySubImages
|= (1 << level
);
1906 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1909 static void savageTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1910 GLint internalFormat
,
1911 GLint width
, GLint height
, GLint border
,
1912 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1913 const struct gl_pixelstore_attrib
*packing
,
1914 struct gl_texture_object
*texObj
,
1915 struct gl_texture_image
*texImage
)
1917 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1919 savageTexImageChanged (t
);
1921 t
= savageAllocTexObj(texObj
);
1923 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1927 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
1928 width
, height
, border
, format
, type
,
1929 pixels
, packing
, texObj
, texImage
);
1930 t
->base
.dirty_images
[0] |= (1 << level
);
1931 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1934 static void savageTexSubImage2D( GLcontext
*ctx
,
1937 GLint xoffset
, GLint yoffset
,
1938 GLsizei width
, GLsizei height
,
1939 GLenum format
, GLenum type
,
1940 const GLvoid
*pixels
,
1941 const struct gl_pixelstore_attrib
*packing
,
1942 struct gl_texture_object
*texObj
,
1943 struct gl_texture_image
*texImage
)
1945 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1946 assert( t
); /* this _should_ be true */
1948 savageTexImageChanged (t
);
1949 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
1950 xoffset
, yoffset
, width
, height
);
1952 t
= savageAllocTexObj(texObj
);
1954 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1957 t
->base
.dirty_images
[0] |= (1 << level
);
1959 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
1960 height
, format
, type
, pixels
, packing
, texObj
,
1962 t
->dirtySubImages
|= (1 << level
);
1963 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1967 savageCompressedTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1968 GLint internalFormat
,
1969 GLint width
, GLint height
, GLint border
,
1970 GLsizei imageSize
, const GLvoid
*data
,
1971 struct gl_texture_object
*texObj
,
1972 struct gl_texture_image
*texImage
)
1974 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1976 savageTexImageChanged (t
);
1978 t
= savageAllocTexObj(texObj
);
1980 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1984 _mesa_store_compressed_teximage2d( ctx
, target
, level
, internalFormat
,
1985 width
, height
, border
, imageSize
,
1986 data
, texObj
, texImage
);
1987 t
->base
.dirty_images
[0] |= (1 << level
);
1988 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1992 savageCompressedTexSubImage2D( GLcontext
*ctx
,
1995 GLint xoffset
, GLint yoffset
,
1996 GLsizei width
, GLsizei height
,
1997 GLenum format
, GLsizei imageSize
,
1999 struct gl_texture_object
*texObj
,
2000 struct gl_texture_image
*texImage
)
2002 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
2003 assert( t
); /* this _should_ be true */
2005 savageTexImageChanged (t
);
2006 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
2007 xoffset
, yoffset
, width
, height
);
2009 t
= savageAllocTexObj(texObj
);
2011 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
2014 t
->base
.dirty_images
[0] |= (1 << level
);
2016 _mesa_store_compressed_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
,
2017 width
, height
, format
, imageSize
,
2018 data
, texObj
, texImage
);
2019 t
->dirtySubImages
|= (1 << level
);
2020 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
2023 static void savageTexParameter( GLcontext
*ctx
, GLenum target
,
2024 struct gl_texture_object
*tObj
,
2025 GLenum pname
, const GLfloat
*params
)
2027 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
2028 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2030 if (!t
|| (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
))
2034 case GL_TEXTURE_MIN_FILTER
:
2035 case GL_TEXTURE_MAG_FILTER
:
2036 savageSetTexFilter(t
,tObj
->MinFilter
,tObj
->MagFilter
);
2039 case GL_TEXTURE_WRAP_S
:
2040 case GL_TEXTURE_WRAP_T
:
2041 savageSetTexWrapping(t
,tObj
->WrapS
,tObj
->WrapT
);
2044 case GL_TEXTURE_BORDER_COLOR
:
2045 savageSetTexBorderColor(t
,tObj
->BorderColor
.f
);
2052 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2055 static void savageBindTexture( GLcontext
*ctx
, GLenum target
,
2056 struct gl_texture_object
*tObj
)
2058 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2060 assert( (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
) ||
2061 (tObj
->DriverData
!= NULL
) );
2063 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2066 static void savageDeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
2068 driTextureObject
*t
= (driTextureObject
*)tObj
->DriverData
;
2069 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2073 savageTimestampTextures(imesa
);
2075 driDestroyTextureObject(t
);
2077 /* Free mipmap images and the texture object itself */
2078 _mesa_delete_texture_object(ctx
, tObj
);
2082 static struct gl_texture_object
*
2083 savageNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
2085 struct gl_texture_object
*obj
;
2086 obj
= _mesa_new_texture_object(ctx
, name
, target
);
2087 savageAllocTexObj( obj
);
2092 void savageDDInitTextureFuncs( struct dd_function_table
*functions
)
2094 functions
->TexEnv
= savageTexEnv
;
2095 functions
->ChooseTextureFormat
= savageChooseTextureFormat
;
2096 functions
->TexImage1D
= savageTexImage1D
;
2097 functions
->TexSubImage1D
= savageTexSubImage1D
;
2098 functions
->TexImage2D
= savageTexImage2D
;
2099 functions
->TexSubImage2D
= savageTexSubImage2D
;
2100 functions
->CompressedTexImage2D
= savageCompressedTexImage2D
;
2101 functions
->CompressedTexSubImage2D
= savageCompressedTexSubImage2D
;
2102 functions
->BindTexture
= savageBindTexture
;
2103 functions
->NewTextureObject
= savageNewTextureObject
;
2104 functions
->DeleteTexture
= savageDeleteTexture
;
2105 functions
->IsTextureResident
= driIsTextureResident
;
2106 functions
->TexParameter
= savageTexParameter
;
2108 /* Texel fetching with our custom texture formats works just like
2109 * the standard argb formats. */
2111 _savage_texformat_a1114444
.FetchTexel1D
= _mesa_texformat_argb4444
.FetchTexel1D
;
2112 _savage_texformat_a1114444
.FetchTexel2D
= _mesa_texformat_argb4444
.FetchTexel2D
;
2113 _savage_texformat_a1114444
.FetchTexel3D
= _mesa_texformat_argb4444
.FetchTexel3D
;
2114 _savage_texformat_a1114444
.FetchTexel1Df
= _mesa_texformat_argb4444
.FetchTexel1Df
;
2115 _savage_texformat_a1114444
.FetchTexel2Df
= _mesa_texformat_argb4444
.FetchTexel2Df
;
2116 _savage_texformat_a1114444
.FetchTexel3Df
= _mesa_texformat_argb4444
.FetchTexel3Df
;
2118 _savage_texformat_a1118888
.FetchTexel1D
= _mesa_texformat_argb8888
.FetchTexel1D
;
2119 _savage_texformat_a1118888
.FetchTexel2D
= _mesa_texformat_argb8888
.FetchTexel2D
;
2120 _savage_texformat_a1118888
.FetchTexel3D
= _mesa_texformat_argb8888
.FetchTexel3D
;
2121 _savage_texformat_a1118888
.FetchTexel1Df
= _mesa_texformat_argb8888
.FetchTexel1Df
;
2122 _savage_texformat_a1118888
.FetchTexel2Df
= _mesa_texformat_argb8888
.FetchTexel2Df
;
2123 _savage_texformat_a1118888
.FetchTexel3Df
= _mesa_texformat_argb8888
.FetchTexel3Df
;