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 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 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 assert(t
->base
.memBlock
);
1025 ofs
= t
->base
.memBlock
->ofs
;
1026 t
->setup
.physAddr
= imesa
->savageScreen
->textureOffset
[heap
] + ofs
;
1027 t
->bufAddr
= (GLubyte
*)imesa
->savageScreen
->texVirtual
[heap
] + ofs
;
1028 imesa
->dirty
|= SAVAGE_UPLOAD_GLOBAL
; /* FIXME: really needed? */
1031 /* Let the world know we've used this memory recently.
1033 driUpdateTextureLRU( &t
->base
);
1034 UNLOCK_HARDWARE(imesa
);
1036 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1037 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1038 fprintf(stderr
, "Texture upload: |");
1040 /* Heap timestamps are only reliable with Savage DRM 2.3.x or
1041 * later. Earlier versions had only 16 bit time stamps which
1042 * would wrap too frequently. */
1043 if (imesa
->savageScreen
->driScrnPriv
->drm_version
.minor
>= 3) {
1044 unsigned int heap
= t
->base
.heap
->heapId
;
1045 LOCK_HARDWARE(imesa
);
1046 savageWaitEvent (imesa
, imesa
->textureHeaps
[heap
]->timestamp
);
1048 savageFlushVertices (imesa
);
1049 LOCK_HARDWARE(imesa
);
1050 savageFlushCmdBufLocked (imesa
, GL_FALSE
);
1051 WAIT_IDLE_EMPTY_LOCKED(imesa
);
1054 for (i
= 0 ; i
< numLevels
; i
++) {
1055 const GLint j
= t
->base
.firstLevel
+ i
; /* the texObj's level */
1056 if (t
->base
.dirty_images
[0] & (1 << j
)) {
1057 savageMarkAllTiles(t
, j
);
1058 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1059 fprintf (stderr
, "*");
1060 } else if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
) {
1061 if (t
->dirtySubImages
& (1 << j
))
1062 fprintf (stderr
, ".");
1064 fprintf (stderr
, " ");
1066 if ((t
->base
.dirty_images
[0] | t
->dirtySubImages
) & (1 << j
))
1067 savageUploadTexLevel( t
, j
);
1070 UNLOCK_HARDWARE(imesa
);
1071 t
->base
.dirty_images
[0] = 0;
1072 t
->dirtySubImages
= 0;
1074 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1075 fprintf(stderr
, "|\n");
1081 savage4_set_wrap_mode( savageContextPtr imesa
, unsigned unit
,
1082 GLenum s_mode
, GLenum t_mode
)
1086 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Wrap
;
1089 case GL_CLAMP_TO_EDGE
:
1090 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Clamp
;
1092 case GL_MIRRORED_REPEAT
:
1093 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Mirror
;
1099 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Wrap
;
1102 case GL_CLAMP_TO_EDGE
:
1103 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Clamp
;
1105 case GL_MIRRORED_REPEAT
:
1106 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Mirror
;
1113 * Sets the hardware bits for the specified GL texture filter modes.
1116 * Does the Savage4 have the ability to select the magnification filter?
1119 savage4_set_filter_mode( savageContextPtr imesa
, unsigned unit
,
1120 GLenum minFilter
, GLenum magFilter
)
1124 switch (minFilter
) {
1126 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1127 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1131 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1132 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1135 case GL_NEAREST_MIPMAP_NEAREST
:
1136 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1137 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1140 case GL_LINEAR_MIPMAP_NEAREST
:
1141 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1142 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1145 case GL_NEAREST_MIPMAP_LINEAR
:
1146 case GL_LINEAR_MIPMAP_LINEAR
:
1147 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Trilin
;
1148 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1154 static void savageUpdateTex0State_s4( GLcontext
*ctx
)
1156 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1157 struct gl_texture_object
*tObj
;
1158 struct gl_texture_image
*image
;
1163 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_FALSE
;
1164 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_NoTexMap
;
1165 imesa
->regs
.s4
.texCtrl
[0].ui
= 0x20f040;
1166 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1169 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1170 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1171 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1172 /* 3D texturing enabled, or texture border - fallback */
1173 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1177 /* Do 2D texture setup */
1179 t
= tObj
->DriverData
;
1181 t
= savageAllocTexObj( tObj
);
1186 imesa
->CurrentTexObj
[0] = &t
->base
;
1189 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1190 savageSetTexImages(imesa
, tObj
);
1191 savageUploadTexImages(imesa
, t
);
1194 driUpdateTextureLRU( &t
->base
);
1196 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1198 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1200 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1205 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1208 case GL_LUMINANCE_ALPHA
:
1211 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Copy
;
1215 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1218 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1219 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1223 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1228 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1233 case GL_LUMINANCE_ALPHA
:
1234 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_DecalAlpha
;
1238 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1239 are undefined with GL_DECAL
1243 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1246 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1247 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1251 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1252 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1253 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1254 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1258 imesa
->regs
.s4
.texBlendColor
.ui
= imesa
->texEnvColor
;
1263 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1264 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1269 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Blend0
;
1270 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1271 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1272 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1273 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1274 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1275 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1276 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1277 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1279 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1280 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Blend1
;
1282 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1283 imesa
->bTexEn1
= GL_TRUE
;
1286 case GL_LUMINANCE_ALPHA
:
1288 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendAlpha0
;
1289 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1290 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1291 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1292 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1293 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1294 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1295 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1296 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1298 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1299 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendAlpha1
;
1301 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1302 imesa
->bTexEn1
= GL_TRUE
;
1306 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendInt0
;
1307 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1308 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1309 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1310 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1311 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1312 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1313 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1314 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1316 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1317 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendInt1
;
1319 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1320 imesa
->regs
.s4
.texCtrl
[0].ni
.alphaArg1Invert
= GL_TRUE
;
1321 imesa
->bTexEn1
= GL_TRUE
;
1324 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1325 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1329 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1333 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1338 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1341 case GL_LUMINANCE_ALPHA
:
1343 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1347 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_AddAlpha
;
1350 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1351 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1354 #if GL_ARB_texture_env_combine
1355 case GL_COMBINE_ARB
:
1356 __HWParseTexEnvCombine(imesa
, 0, &imesa
->regs
.s4
.texCtrl
[0],
1357 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1362 fprintf(stderr
, "unknown tex env mode");
1367 savage4_set_wrap_mode( imesa
, 0, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1368 savage4_set_filter_mode( imesa
, 0, t
->setup
.minFilter
, t
->setup
.magFilter
);
1370 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1371 (imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
!= 0))
1373 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 32.0) +
1377 else if (bias
> 255)
1379 imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
= bias
& 0x1ff;
1382 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1383 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_TRUE
;
1384 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
= image
->WidthLog2
;
1385 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
= image
->HeightLog2
;
1386 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
= t
->hwFormat
;
1387 imesa
->regs
.s4
.texCtrl
[0].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1389 if (imesa
->regs
.s4
.texDescr
.ni
.tex1En
)
1390 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1392 imesa
->regs
.s4
.texAddr
[0].ui
= (uint32_t) t
->setup
.physAddr
| 0x2;
1393 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1394 imesa
->regs
.s4
.texAddr
[0].ui
|= 0x1;
1398 static void savageUpdateTex1State_s4( GLcontext
*ctx
)
1400 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1401 struct gl_texture_object
*tObj
;
1402 struct gl_texture_image
*image
;
1409 imesa
->bTexEn1
= GL_FALSE
;
1413 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_FALSE
;
1414 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_NoTexMap1
;
1415 imesa
->regs
.s4
.texCtrl
[1].ui
= 0x20f040;
1416 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_FALSE
;
1417 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
== 0)
1420 tObj
= ctx
->Texture
.Unit
[1]._Current
;
1422 if ((ctx
->Texture
.Unit
[1]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1423 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1424 /* 3D texturing enabled, or texture border - fallback */
1425 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1429 /* Do 2D texture setup */
1431 t
= tObj
->DriverData
;
1433 t
= savageAllocTexObj( tObj
);
1438 imesa
->CurrentTexObj
[1] = &t
->base
;
1442 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1443 savageSetTexImages(imesa
, tObj
);
1444 savageUploadTexImages(imesa
, t
);
1447 driUpdateTextureLRU( &t
->base
);
1449 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1451 switch (ctx
->Texture
.Unit
[1].EnvMode
) {
1453 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1458 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal
;
1461 case GL_LUMINANCE_ALPHA
:
1464 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Copy
;
1468 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1471 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1474 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1475 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1476 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1480 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1484 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1489 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1492 case GL_LUMINANCE_ALPHA
:
1494 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1498 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_AddAlpha1
;
1501 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1504 #if GL_ARB_texture_env_combine
1505 case GL_COMBINE_ARB
:
1506 __HWParseTexEnvCombine(imesa
, 1, &texCtrl
, &imesa
->regs
.s4
.texBlendCtrl
);
1511 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1517 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal1
;
1519 case GL_LUMINANCE_ALPHA
:
1522 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_DecalAlpha1
;
1526 // GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1527 // are undefined with GL_DECAL
1530 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1533 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1537 if (format
== GL_LUMINANCE
)
1540 // This is a hack for GLQuake, invert.
1542 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_TRUE
;
1543 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= 0;
1545 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1549 fprintf(stderr
, "unknown tex 1 env mode\n");
1554 savage4_set_wrap_mode( imesa
, 1, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1555 savage4_set_filter_mode( imesa
, 1, t
->setup
.minFilter
, t
->setup
.magFilter
);
1557 if((ctx
->Texture
.Unit
[1].LodBias
!=0.0F
) ||
1558 (imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
!= 0))
1560 int bias
= (int)(ctx
->Texture
.Unit
[1].LodBias
* 32.0) +
1564 else if (bias
> 255)
1566 imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
= bias
& 0x1ff;
1569 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1570 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1571 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
= image
->WidthLog2
;
1572 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
= image
->HeightLog2
;
1573 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
= t
->hwFormat
;
1574 imesa
->regs
.s4
.texCtrl
[1].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1575 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1577 imesa
->regs
.s4
.texAddr
[1].ui
= (uint32_t) t
->setup
.physAddr
| 2;
1578 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1579 imesa
->regs
.s4
.texAddr
[1].ui
|= 0x1;
1581 static void savageUpdateTexState_s3d( GLcontext
*ctx
)
1583 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1584 struct gl_texture_object
*tObj
;
1585 struct gl_texture_image
*image
;
1590 imesa
->regs
.s3d
.texCtrl
.ui
= 0;
1591 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_FALSE
;
1592 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= 0x08;
1593 imesa
->regs
.s3d
.texCtrl
.ni
.texXprEn
= GL_TRUE
;
1594 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1597 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1598 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1599 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1600 /* 3D texturing enabled, or texture border - fallback */
1601 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1605 /* Do 2D texture setup */
1606 t
= tObj
->DriverData
;
1608 t
= savageAllocTexObj( tObj
);
1613 imesa
->CurrentTexObj
[0] = &t
->base
;
1616 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1617 savageSetTexImages(imesa
, tObj
);
1618 savageUploadTexImages(imesa
, t
);
1621 driUpdateTextureLRU( &t
->base
);
1623 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1625 /* FIXME: copied from utah-glx, probably needs some tuning */
1626 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1628 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECALALPHA_S3D
;
1632 case GL_ALPHA
: /* FIXME */
1633 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 1;
1635 case GL_LUMINANCE_ALPHA
:
1637 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 4;
1641 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECAL_S3D
;
1644 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_COPY_S3D
;
1647 case GL_BLEND
: /* hardware can't do GL_BLEND */
1648 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1651 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_MODULATEALPHA_S3D
;
1654 fprintf(stderr
, "unknown tex env mode\n");
1659 /* The Savage3D can't handle different wrapping modes in s and t.
1660 * If they are not the same, fall back to software. */
1661 if (t
->setup
.sWrapMode
!= t
->setup
.tWrapMode
) {
1662 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1665 imesa
->regs
.s3d
.texCtrl
.ni
.uWrapEn
= 0;
1666 imesa
->regs
.s3d
.texCtrl
.ni
.vWrapEn
= 0;
1667 imesa
->regs
.s3d
.texCtrl
.ni
.wrapMode
=
1668 (t
->setup
.sWrapMode
== GL_REPEAT
) ? TAM_Wrap
: TAM_Clamp
;
1670 switch (t
->setup
.minFilter
) {
1672 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1673 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1677 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1678 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1681 case GL_NEAREST_MIPMAP_NEAREST
:
1682 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1683 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1686 case GL_LINEAR_MIPMAP_NEAREST
:
1687 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1688 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1691 case GL_NEAREST_MIPMAP_LINEAR
:
1692 case GL_LINEAR_MIPMAP_LINEAR
:
1693 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Trilin
;
1694 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1698 /* There is no way to specify a maximum mipmap level. We may have to
1699 disable mipmapping completely. */
1701 if (t->max_level < t->image[0].image->WidthLog2 ||
1702 t->max_level < t->image[0].image->HeightLog2) {
1703 texCtrl.ni.mipmapEnable = GL_TRUE;
1704 if (texCtrl.ni.filterMode == TFM_Trilin)
1705 texCtrl.ni.filterMode = TFM_Bilin;
1706 texCtrl.ni.filterMode = TFM_Point;
1710 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1711 (imesa
->regs
.s3d
.texCtrl
.ni
.dBias
!= 0))
1713 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 16.0);
1716 else if (bias
> 255)
1718 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= bias
& 0x1ff;
1721 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1722 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_TRUE
;
1723 imesa
->regs
.s3d
.texDescr
.ni
.texWidth
= image
->WidthLog2
;
1724 imesa
->regs
.s3d
.texDescr
.ni
.texHeight
= image
->HeightLog2
;
1725 assert (t
->hwFormat
<= 7);
1726 imesa
->regs
.s3d
.texDescr
.ni
.texFmt
= t
->hwFormat
;
1728 imesa
->regs
.s3d
.texAddr
.ui
= (uint32_t) t
->setup
.physAddr
| 2;
1729 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1730 imesa
->regs
.s3d
.texAddr
.ui
|= 0x1;
1734 static void savageTimestampTextures( savageContextPtr imesa
)
1736 /* Timestamp current texture objects for texture heap aging.
1737 * Only useful with long-lived 32-bit event tags available
1738 * with Savage DRM 2.3.x or later. */
1739 if ((imesa
->CurrentTexObj
[0] || imesa
->CurrentTexObj
[1]) &&
1740 imesa
->savageScreen
->driScrnPriv
->drm_version
.minor
>= 3) {
1743 e
= savageEmitEvent(imesa
, SAVAGE_WAIT_3D
);
1744 if (imesa
->CurrentTexObj
[0])
1745 imesa
->CurrentTexObj
[0]->timestamp
= e
;
1746 if (imesa
->CurrentTexObj
[1])
1747 imesa
->CurrentTexObj
[1]->timestamp
= e
;
1752 static void savageUpdateTextureState_s4( GLcontext
*ctx
)
1754 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1756 /* When a texture is about to change or be disabled, timestamp the
1757 * old texture(s). We'll have to wait for this time stamp before
1758 * uploading anything to the same texture heap.
1760 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1761 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1762 (imesa
->CurrentTexObj
[1] && ctx
->Texture
.Unit
[1]._ReallyEnabled
&&
1763 ctx
->Texture
.Unit
[1]._Current
->DriverData
!= imesa
->CurrentTexObj
[1]) ||
1764 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
) ||
1765 (imesa
->CurrentTexObj
[1] && !ctx
->Texture
.Unit
[1]._ReallyEnabled
))
1766 savageTimestampTextures(imesa
);
1768 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1769 if (imesa
->CurrentTexObj
[1]) imesa
->CurrentTexObj
[1]->bound
&= ~2;
1770 imesa
->CurrentTexObj
[0] = 0;
1771 imesa
->CurrentTexObj
[1] = 0;
1772 savageUpdateTex0State_s4( ctx
);
1773 savageUpdateTex1State_s4( ctx
);
1774 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
|
1775 SAVAGE_UPLOAD_TEX1
);
1777 static void savageUpdateTextureState_s3d( GLcontext
*ctx
)
1779 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1781 /* When a texture is about to change or be disabled, timestamp the
1782 * old texture(s). We'll have to wait for this time stamp before
1783 * uploading anything to the same texture heap.
1785 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1786 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1787 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
))
1788 savageTimestampTextures(imesa
);
1790 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1791 imesa
->CurrentTexObj
[0] = 0;
1792 savageUpdateTexState_s3d( ctx
);
1793 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
);
1795 void savageUpdateTextureState( GLcontext
*ctx
)
1797 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1798 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_FALSE
);
1799 FALLBACK(ctx
, SAVAGE_FALLBACK_PROJ_TEXTURE
, GL_FALSE
);
1800 if (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
)
1801 savageUpdateTextureState_s4 (ctx
);
1803 savageUpdateTextureState_s3d (ctx
);
1808 /*****************************************
1810 *****************************************/
1812 static void savageTexEnv( GLcontext
*ctx
, GLenum target
,
1813 GLenum pname
, const GLfloat
*param
)
1815 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1817 if (pname
== GL_TEXTURE_ENV_MODE
) {
1819 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
1821 } else if (pname
== GL_TEXTURE_ENV_COLOR
) {
1823 struct gl_texture_unit
*texUnit
=
1824 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1825 const GLfloat
*fc
= texUnit
->EnvColor
;
1827 CLAMPED_FLOAT_TO_UBYTE(r
, fc
[0]);
1828 CLAMPED_FLOAT_TO_UBYTE(g
, fc
[1]);
1829 CLAMPED_FLOAT_TO_UBYTE(b
, fc
[2]);
1830 CLAMPED_FLOAT_TO_UBYTE(a
, fc
[3]);
1832 imesa
->texEnvColor
= ((a
<< 24) | (r
<< 16) |
1833 (g
<< 8) | (b
<< 0));
1839 /* Update the heap's time stamp, so the new image is not uploaded
1840 * while the old one is still in use. If the texture that is going to
1841 * be changed is currently bound, we need to timestamp the texture
1843 static void savageTexImageChanged (savageTexObjPtr t
) {
1846 savageTimestampTextures(
1847 (savageContextPtr
)t
->base
.heap
->driverContext
);
1848 if (t
->base
.timestamp
> t
->base
.heap
->timestamp
)
1849 t
->base
.heap
->timestamp
= t
->base
.timestamp
;
1853 static void savageTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
1854 GLint internalFormat
,
1855 GLint width
, GLint border
,
1856 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1857 const struct gl_pixelstore_attrib
*packing
,
1858 struct gl_texture_object
*texObj
,
1859 struct gl_texture_image
*texImage
)
1861 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1863 savageTexImageChanged (t
);
1865 t
= savageAllocTexObj(texObj
);
1867 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1871 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
1872 width
, border
, format
, type
,
1873 pixels
, packing
, texObj
, texImage
);
1874 t
->base
.dirty_images
[0] |= (1 << level
);
1875 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1878 static void savageTexSubImage1D( GLcontext
*ctx
,
1883 GLenum format
, GLenum type
,
1884 const GLvoid
*pixels
,
1885 const struct gl_pixelstore_attrib
*packing
,
1886 struct gl_texture_object
*texObj
,
1887 struct gl_texture_image
*texImage
)
1889 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1890 assert( t
); /* this _should_ be true */
1892 savageTexImageChanged (t
);
1893 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, 1,
1894 xoffset
, 0, width
, 1);
1896 t
= savageAllocTexObj(texObj
);
1898 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
1901 t
->base
.dirty_images
[0] |= (1 << level
);
1903 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
1904 format
, type
, pixels
, packing
, texObj
,
1906 t
->dirtySubImages
|= (1 << level
);
1907 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1910 static void savageTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1911 GLint internalFormat
,
1912 GLint width
, GLint height
, GLint border
,
1913 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1914 const struct gl_pixelstore_attrib
*packing
,
1915 struct gl_texture_object
*texObj
,
1916 struct gl_texture_image
*texImage
)
1918 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1920 savageTexImageChanged (t
);
1922 t
= savageAllocTexObj(texObj
);
1924 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1928 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
1929 width
, height
, border
, format
, type
,
1930 pixels
, packing
, texObj
, texImage
);
1931 t
->base
.dirty_images
[0] |= (1 << level
);
1932 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1935 static void savageTexSubImage2D( GLcontext
*ctx
,
1938 GLint xoffset
, GLint yoffset
,
1939 GLsizei width
, GLsizei height
,
1940 GLenum format
, GLenum type
,
1941 const GLvoid
*pixels
,
1942 const struct gl_pixelstore_attrib
*packing
,
1943 struct gl_texture_object
*texObj
,
1944 struct gl_texture_image
*texImage
)
1946 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1947 assert( t
); /* this _should_ be true */
1949 savageTexImageChanged (t
);
1950 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
1951 xoffset
, yoffset
, width
, height
);
1953 t
= savageAllocTexObj(texObj
);
1955 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1958 t
->base
.dirty_images
[0] |= (1 << level
);
1960 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
1961 height
, format
, type
, pixels
, packing
, texObj
,
1963 t
->dirtySubImages
|= (1 << level
);
1964 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1968 savageCompressedTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1969 GLint internalFormat
,
1970 GLint width
, GLint height
, GLint border
,
1971 GLsizei imageSize
, const GLvoid
*data
,
1972 struct gl_texture_object
*texObj
,
1973 struct gl_texture_image
*texImage
)
1975 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1977 savageTexImageChanged (t
);
1979 t
= savageAllocTexObj(texObj
);
1981 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1985 _mesa_store_compressed_teximage2d( ctx
, target
, level
, internalFormat
,
1986 width
, height
, border
, imageSize
,
1987 data
, texObj
, texImage
);
1988 t
->base
.dirty_images
[0] |= (1 << level
);
1989 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1993 savageCompressedTexSubImage2D( GLcontext
*ctx
,
1996 GLint xoffset
, GLint yoffset
,
1997 GLsizei width
, GLsizei height
,
1998 GLenum format
, GLsizei imageSize
,
2000 struct gl_texture_object
*texObj
,
2001 struct gl_texture_image
*texImage
)
2003 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
2004 assert( t
); /* this _should_ be true */
2006 savageTexImageChanged (t
);
2007 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
2008 xoffset
, yoffset
, width
, height
);
2010 t
= savageAllocTexObj(texObj
);
2012 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
2015 t
->base
.dirty_images
[0] |= (1 << level
);
2017 _mesa_store_compressed_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
,
2018 width
, height
, format
, imageSize
,
2019 data
, texObj
, texImage
);
2020 t
->dirtySubImages
|= (1 << level
);
2021 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
2024 static void savageTexParameter( GLcontext
*ctx
, GLenum target
,
2025 struct gl_texture_object
*tObj
,
2026 GLenum pname
, const GLfloat
*params
)
2028 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
2029 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2031 if (!t
|| (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
))
2035 case GL_TEXTURE_MIN_FILTER
:
2036 case GL_TEXTURE_MAG_FILTER
:
2037 savageSetTexFilter(t
,tObj
->MinFilter
,tObj
->MagFilter
);
2040 case GL_TEXTURE_WRAP_S
:
2041 case GL_TEXTURE_WRAP_T
:
2042 savageSetTexWrapping(t
,tObj
->WrapS
,tObj
->WrapT
);
2045 case GL_TEXTURE_BORDER_COLOR
:
2046 savageSetTexBorderColor(t
,tObj
->BorderColor
.f
);
2053 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2056 static void savageBindTexture( GLcontext
*ctx
, GLenum target
,
2057 struct gl_texture_object
*tObj
)
2059 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2061 assert( (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
) ||
2062 (tObj
->DriverData
!= NULL
) );
2064 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2067 static void savageDeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
2069 driTextureObject
*t
= (driTextureObject
*)tObj
->DriverData
;
2070 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2074 savageTimestampTextures(imesa
);
2076 driDestroyTextureObject(t
);
2078 /* Free mipmap images and the texture object itself */
2079 _mesa_delete_texture_object(ctx
, tObj
);
2083 static struct gl_texture_object
*
2084 savageNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
2086 struct gl_texture_object
*obj
;
2087 obj
= _mesa_new_texture_object(ctx
, name
, target
);
2088 savageAllocTexObj( obj
);
2093 void savageDDInitTextureFuncs( struct dd_function_table
*functions
)
2095 functions
->TexEnv
= savageTexEnv
;
2096 functions
->ChooseTextureFormat
= savageChooseTextureFormat
;
2097 functions
->TexImage1D
= savageTexImage1D
;
2098 functions
->TexSubImage1D
= savageTexSubImage1D
;
2099 functions
->TexImage2D
= savageTexImage2D
;
2100 functions
->TexSubImage2D
= savageTexSubImage2D
;
2101 functions
->CompressedTexImage2D
= savageCompressedTexImage2D
;
2102 functions
->CompressedTexSubImage2D
= savageCompressedTexSubImage2D
;
2103 functions
->BindTexture
= savageBindTexture
;
2104 functions
->NewTextureObject
= savageNewTextureObject
;
2105 functions
->DeleteTexture
= savageDeleteTexture
;
2106 functions
->IsTextureResident
= driIsTextureResident
;
2107 functions
->TexParameter
= savageTexParameter
;
2109 /* Texel fetching with our custom texture formats works just like
2110 * the standard argb formats. */
2112 _savage_texformat_a1114444
.FetchTexel1D
= _mesa_texformat_argb4444
.FetchTexel1D
;
2113 _savage_texformat_a1114444
.FetchTexel2D
= _mesa_texformat_argb4444
.FetchTexel2D
;
2114 _savage_texformat_a1114444
.FetchTexel3D
= _mesa_texformat_argb4444
.FetchTexel3D
;
2115 _savage_texformat_a1114444
.FetchTexel1Df
= _mesa_texformat_argb4444
.FetchTexel1Df
;
2116 _savage_texformat_a1114444
.FetchTexel2Df
= _mesa_texformat_argb4444
.FetchTexel2Df
;
2117 _savage_texformat_a1114444
.FetchTexel3Df
= _mesa_texformat_argb4444
.FetchTexel3Df
;
2119 _savage_texformat_a1118888
.FetchTexel1D
= _mesa_texformat_argb8888
.FetchTexel1D
;
2120 _savage_texformat_a1118888
.FetchTexel2D
= _mesa_texformat_argb8888
.FetchTexel2D
;
2121 _savage_texformat_a1118888
.FetchTexel3D
= _mesa_texformat_argb8888
.FetchTexel3D
;
2122 _savage_texformat_a1118888
.FetchTexel1Df
= _mesa_texformat_argb8888
.FetchTexel1Df
;
2123 _savage_texformat_a1118888
.FetchTexel2Df
= _mesa_texformat_argb8888
.FetchTexel2Df
;
2124 _savage_texformat_a1118888
.FetchTexel3Df
= _mesa_texformat_argb8888
.FetchTexel3Df
;