2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
32 #include "savagecontext.h"
33 #include "savagetex.h"
34 #include "savagetris.h"
35 #include "savageioctl.h"
36 #include "main/simple_list.h"
37 #include "main/enums.h"
38 #include "savage_bci.h"
40 #include "main/macros.h"
41 #include "main/texformat.h"
42 #include "main/texstore.h"
43 #include "main/texobj.h"
44 #include "main/convolve.h"
45 #include "main/colormac.h"
47 #include "swrast/swrast.h"
51 #define TILE_INDEX_DXT1 0
52 #define TILE_INDEX_8 1
53 #define TILE_INDEX_16 2
54 #define TILE_INDEX_DXTn 3
55 #define TILE_INDEX_32 4
57 /* On Savage4 the texure LOD-bias needs an offset of ~ 0.3 to get
58 * somewhere close to software rendering.
60 #define SAVAGE4_LOD_OFFSET 10
62 /* Tile info for S3TC formats counts in 4x4 blocks instead of texels.
63 * In DXT1 each block is encoded in 64 bits. In DXT3 and 5 each block is
64 * encoded in 128 bits. */
66 /* Size 1, 2 and 4 images are packed into the last subtile. Each image
67 * is repeated to fill a 4x4 pixel area. The figure below shows the
68 * layout of those 4x4 pixel areas in the 8x8 subtile.
73 * Yuck! 8-bit texture formats use 4x8 subtiles. See below.
75 static const savageTileInfo tileInfo_pro
[5] = {
76 {16, 16, 16, 8, 1, 2, {0x18, 0x10}}, /* DXT1 */
77 {64, 32, 16, 4, 4, 8, {0x30, 0x20}}, /* 8-bit */
78 {64, 16, 8, 2, 8, 8, {0x48, 0x08}}, /* 16-bit */
79 {16, 8, 16, 4, 1, 2, {0x30, 0x20}}, /* DXT3, DXT5 */
80 {32, 16, 4, 2, 8, 8, {0x90, 0x10}}, /* 32-bit */
83 /* Size 1, 2 and 4 images are packed into the last two subtiles. Each
84 * image is repeated to fill a 4x4 pixel area. The figures below show
85 * the layout of those 4x4 pixel areas in the two 4x8 subtiles.
87 * second last subtile: 4 last subtile: 2
90 static const savageTileInfo tileInfo_s3d_s4
[5] = {
91 {16, 16, 16, 8, 1, 2, {0x18, 0x10}}, /* DXT1 */
92 {64, 32, 16, 4, 4, 8, {0x30, 0x20}}, /* 8-bit */
93 {64, 16, 16, 2, 4, 8, {0x60, 0x40}}, /* 16-bit */
94 {16, 8, 16, 4, 1, 2, {0x30, 0x20}}, /* DXT3, DXT5 */
95 {32, 16, 8, 2, 4, 8, {0xc0, 0x80}}, /* 32-bit */
98 /** \brief Template for subtile uploads.
99 * \param h height in pixels
100 * \param w width in bytes
102 #define SUBTILE_FUNC(w,h) \
103 static INLINE GLubyte *savageUploadSubtile_##w##x##h \
104 (GLubyte *dest, GLubyte *src, GLuint srcStride) \
107 for (y = 0; y < h; ++y) { \
108 memcpy (dest, src, w); \
115 SUBTILE_FUNC(2, 8) /* 4 bits per pixel, 4 pixels wide */
119 SUBTILE_FUNC(32, 8) /* 4 bytes per pixel, 8 pixels wide */
121 SUBTILE_FUNC(8, 2) /* DXT1 */
122 SUBTILE_FUNC(16, 2) /* DXT3 and DXT5 */
124 /** \brief Upload a complete tile from src (srcStride) to dest
126 * \param tileInfo Pointer to tiling information
127 * \param wInSub Width of source/dest image in subtiles
128 * \param hInSub Height of source/dest image in subtiles
129 * \param bpp Bytes per pixel
130 * \param src Pointer to source data
131 * \param srcStride Byte stride of rows in the source data
132 * \param dest Pointer to destination
134 * Writes linearly to the destination memory in order to exploit write
137 * For a complete tile wInSub and hInSub are set to the same values as
138 * in tileInfo. If the source image is smaller than a whole tile in
139 * one or both dimensions then they are set to the values of the
140 * source image. This only works as long as the source image is bigger
143 static void savageUploadTile (const savageTileInfo
*tileInfo
,
144 GLuint wInSub
, GLuint hInSub
, GLuint bpp
,
145 GLubyte
*src
, GLuint srcStride
, GLubyte
*dest
) {
146 GLuint subStride
= tileInfo
->subWidth
* bpp
;
147 GLubyte
*srcSRow
= src
, *srcSTile
= src
;
148 GLubyte
*(*subtileFunc
) (GLubyte
*, GLubyte
*, GLuint
);
151 case 2: subtileFunc
= savageUploadSubtile_2x8
; break;
152 case 4: subtileFunc
= savageUploadSubtile_4x8
; break;
153 case 8: subtileFunc
= tileInfo
->subHeight
== 8 ?
154 savageUploadSubtile_8x8
: savageUploadSubtile_8x2
; break;
155 case 16: subtileFunc
= tileInfo
->subHeight
== 8 ?
156 savageUploadSubtile_16x8
: savageUploadSubtile_16x2
; break;
157 case 32: subtileFunc
= savageUploadSubtile_32x8
; break;
160 for (sy
= 0; sy
< hInSub
; ++sy
) {
162 for (sx
= 0; sx
< wInSub
; ++sx
) {
164 dest
= subtileFunc (dest
, src
, srcStride
);
165 srcSTile
+= subStride
;
167 srcSRow
+= srcStride
* tileInfo
->subHeight
;
171 /** \brief Upload a image that is smaller than 8 pixels in either dimension.
173 * \param tileInfo Pointer to tiling information
174 * \param width Width of the image
175 * \param height Height of the image
176 * \param bpp Bytes per pixel
177 * \param src Pointer to source data
178 * \param dest Pointer to destination
180 * This function handles all the special cases that need to be taken
181 * care off. The caller may need to call this function multiple times
182 * with the destination offset in different ways since small texture
183 * images must be repeated in order to fill a whole tile (or 4x4 for
184 * the last 3 levels).
186 * FIXME: Repeating inside this function would be more efficient.
188 static void savageUploadTiny (const savageTileInfo
*tileInfo
,
189 GLuint pixWidth
, GLuint pixHeight
,
190 GLuint width
, GLuint height
, GLuint bpp
,
191 GLubyte
*src
, GLubyte
*dest
) {
192 GLuint size
= MAX2(pixWidth
, pixHeight
);
194 if (width
> tileInfo
->subWidth
) { /* assert: height <= subtile height */
195 GLuint wInSub
= width
/ tileInfo
->subWidth
;
196 GLuint srcStride
= width
* bpp
;
197 GLuint subStride
= tileInfo
->subWidth
* bpp
;
198 GLuint subSkip
= (tileInfo
->subHeight
- height
) * subStride
;
199 GLubyte
*srcSTile
= src
;
201 for (sx
= 0; sx
< wInSub
; ++sx
) {
203 for (y
= 0; y
< height
; ++y
) {
204 memcpy (dest
, src
, subStride
);
209 srcSTile
+= subStride
;
211 } else if (size
> 4) { /* a tile or less wide, except the last 3 levels */
212 GLuint srcStride
= width
* bpp
;
213 GLuint subStride
= tileInfo
->subWidth
* bpp
;
214 /* if the subtile width is 4 we have to skip every other subtile */
215 GLuint subSkip
= tileInfo
->subWidth
<= 4 ?
216 subStride
* tileInfo
->subHeight
: 0;
217 GLuint skipRemainder
= tileInfo
->subHeight
- 1;
219 for (y
= 0; y
< height
; ++y
) {
220 memcpy (dest
, src
, srcStride
);
223 if ((y
& skipRemainder
) == skipRemainder
)
226 } else { /* the last 3 mipmap levels */
227 GLuint offset
= (size
<= 2 ? tileInfo
->tinyOffset
[size
-1] : 0);
228 GLuint subStride
= tileInfo
->subWidth
* bpp
;
231 for (y
= 0; y
< height
; ++y
) {
232 memcpy (dest
, src
, bpp
*width
);
239 /** \brief Upload an image from mesa's internal copy.
241 static void savageUploadTexLevel( savageTexObjPtr t
, int level
)
243 const struct gl_texture_image
*image
= t
->base
.tObj
->Image
[0][level
];
244 const savageTileInfo
*tileInfo
= t
->tileInfo
;
245 GLuint pixWidth
= image
->Width2
, pixHeight
= image
->Height2
;
246 GLuint bpp
= t
->texelBytes
;
247 GLuint width
, height
;
249 /* FIXME: Need triangle (rather than pixel) fallbacks to simulate
250 * this using normal textured triangles.
252 * DO THIS IN DRIVER STATE MANAGMENT, not hardware state.
254 if(image
->Border
!= 0)
255 fprintf (stderr
, "Not supported texture border %d.\n",
256 (int) image
->Border
);
258 if (t
->hwFormat
== TFT_S3TC4A4Bit
|| t
->hwFormat
== TFT_S3TC4CA4Bit
||
259 t
->hwFormat
== TFT_S3TC4Bit
) {
260 width
= (pixWidth
+3) / 4;
261 height
= (pixHeight
+3) / 4;
267 if (pixWidth
>= 8 && pixHeight
>= 8) {
268 GLuint
*dirtyPtr
= t
->image
[level
].dirtyTiles
;
269 GLuint dirtyMask
= 1;
271 if (width
>= tileInfo
->width
&& height
>= tileInfo
->height
) {
272 GLuint wInTiles
= width
/ tileInfo
->width
;
273 GLuint hInTiles
= height
/ tileInfo
->height
;
274 GLubyte
*srcTRow
= image
->Data
, *src
;
275 GLubyte
*dest
= (GLubyte
*)(t
->bufAddr
+ t
->image
[level
].offset
);
277 for (y
= 0; y
< hInTiles
; ++y
) {
279 for (x
= 0; x
< wInTiles
; ++x
) {
280 if (*dirtyPtr
& dirtyMask
) {
281 savageUploadTile (tileInfo
,
282 tileInfo
->wInSub
, tileInfo
->hInSub
,
283 bpp
, src
, width
* bpp
, dest
);
285 src
+= tileInfo
->width
* bpp
;
286 dest
+= 2048; /* tile size is always 2k */
287 if (dirtyMask
== 1<<31) {
293 srcTRow
+= width
* tileInfo
->height
* bpp
;
295 } else if (width
>= tileInfo
->width
) {
296 GLuint wInTiles
= width
/ tileInfo
->width
;
297 GLubyte
*src
= image
->Data
;
298 GLubyte
*dest
= (GLubyte
*)(t
->bufAddr
+ t
->image
[level
].offset
);
299 GLuint tileStride
= tileInfo
->width
* bpp
* height
;
300 savageContextPtr imesa
= (savageContextPtr
)t
->base
.heap
->driverContext
;
302 /* Savage3D-based chips seem so use a constant tile stride
303 * of 2048 for vertically incomplete tiles, but only if
304 * the color depth is 32bpp. Nobody said this was supposed
307 if (bpp
== 4 && imesa
->savageScreen
->chipset
< S3_SAVAGE4
)
309 for (x
= 0; x
< wInTiles
; ++x
) {
310 if (*dirtyPtr
& dirtyMask
) {
311 savageUploadTile (tileInfo
,
313 height
/ tileInfo
->subHeight
,
314 bpp
, src
, width
* bpp
, dest
);
316 src
+= tileInfo
->width
* bpp
;
318 if (dirtyMask
== 1<<31) {
325 savageUploadTile (tileInfo
, width
/ tileInfo
->subWidth
,
326 height
/ tileInfo
->subHeight
, bpp
,
327 image
->Data
, width
* bpp
,
328 (GLubyte
*)(t
->bufAddr
+t
->image
[level
].offset
));
331 GLuint minHeight
, minWidth
, hRepeat
, vRepeat
, x
, y
;
332 if (t
->hwFormat
== TFT_S3TC4A4Bit
|| t
->hwFormat
== TFT_S3TC4CA4Bit
||
333 t
->hwFormat
== TFT_S3TC4Bit
)
334 minWidth
= minHeight
= 1;
336 minWidth
= minHeight
= 4;
337 if (width
> minWidth
|| height
> minHeight
) {
338 minWidth
= tileInfo
->subWidth
;
339 minHeight
= tileInfo
->subHeight
;
341 hRepeat
= width
>= minWidth
? 1 : minWidth
/ width
;
342 vRepeat
= height
>= minHeight
? 1 : minHeight
/ height
;
343 for (y
= 0; y
< vRepeat
; ++y
) {
344 GLuint offset
= y
* tileInfo
->subWidth
*height
* bpp
;
345 for (x
= 0; x
< hRepeat
; ++x
) {
346 savageUploadTiny (tileInfo
, pixWidth
, pixHeight
,
347 width
, height
, bpp
, image
->Data
,
348 (GLubyte
*)(t
->bufAddr
+
349 t
->image
[level
].offset
+offset
));
350 offset
+= width
* bpp
;
356 /** \brief Compute the destination size of a texture image
358 static GLuint
savageTexImageSize (GLuint width
, GLuint height
, GLuint bpp
) {
360 if (width
>= 8 && height
>= 8)
361 return width
* height
* bpp
;
362 /* special case for the last three mipmap levels: the hardware computes
363 * the offset internally */
364 else if (width
<= 4 && height
<= 4)
366 /* partially filled sub tiles waste memory
367 * on Savage3D and Savage4 with subtile width 4 every other subtile is
368 * skipped if width < 8 so we can assume a uniform subtile width of 8 */
370 return width
* 8 * bpp
;
371 else if (height
>= 8)
372 return 8 * height
* bpp
;
377 /** \brief Compute the destination size of a compressed texture image
379 static GLuint
savageCompressedTexImageSize (GLuint width
, GLuint height
,
381 width
= (width
+3) / 4;
382 height
= (height
+3) / 4;
384 if (width
>= 2 && height
>= 2)
385 return width
* height
* bpp
;
386 /* special case for the last three mipmap levels: the hardware computes
387 * the offset internally */
388 else if (width
<= 1 && height
<= 1)
390 /* partially filled sub tiles waste memory
391 * on Savage3D and Savage4 with subtile width 4 every other subtile is
392 * skipped if width < 8 so we can assume a uniform subtile width of 8 */
394 return width
* 2 * bpp
;
395 else if (height
>= 2)
396 return 2 * height
* bpp
;
401 /** \brief Compute the number of (partial) tiles of a texture image
403 static GLuint
savageTexImageTiles (GLuint width
, GLuint height
,
404 const savageTileInfo
*tileInfo
)
406 return (width
+ tileInfo
->width
- 1) / tileInfo
->width
*
407 (height
+ tileInfo
->height
- 1) / tileInfo
->height
;
410 /** \brief Mark dirty tiles
412 * Some care must be taken because tileInfo may not be set or not
413 * up-to-date. So we check if tileInfo is initialized and if the number
414 * of tiles in the bit vector matches the number of tiles computed from
415 * the current tileInfo.
417 static void savageMarkDirtyTiles (savageTexObjPtr t
, GLuint level
,
418 GLuint totalWidth
, GLuint totalHeight
,
419 GLint xoffset
, GLint yoffset
,
420 GLsizei width
, GLsizei height
)
422 GLuint wInTiles
, hInTiles
;
423 GLuint x0
, y0
, x1
, y1
;
427 wInTiles
= (totalWidth
+ t
->tileInfo
->width
- 1) / t
->tileInfo
->width
;
428 hInTiles
= (totalHeight
+ t
->tileInfo
->height
- 1) / t
->tileInfo
->height
;
429 if (wInTiles
* hInTiles
!= t
->image
[level
].nTiles
)
432 x0
= xoffset
/ t
->tileInfo
->width
;
433 y0
= yoffset
/ t
->tileInfo
->height
;
434 x1
= (xoffset
+ width
- 1) / t
->tileInfo
->width
;
435 y1
= (yoffset
+ height
- 1) / t
->tileInfo
->height
;
437 for (y
= y0
; y
<= y1
; ++y
) {
438 GLuint
*ptr
= t
->image
[level
].dirtyTiles
+ (y
* wInTiles
+ x0
) / 32;
439 GLuint mask
= 1 << (y
* wInTiles
+ x0
) % 32;
440 for (x
= x0
; x
<= x1
; ++x
) {
442 if (mask
== (1<<31)) {
452 /** \brief Mark all tiles as dirty
454 static void savageMarkAllTiles (savageTexObjPtr t
, GLuint level
)
456 GLuint words
= (t
->image
[level
].nTiles
+ 31) / 32;
458 memset(t
->image
[level
].dirtyTiles
, ~0, words
*sizeof(GLuint
));
462 static void savageSetTexWrapping(savageTexObjPtr tex
, GLenum s
, GLenum t
)
464 tex
->setup
.sWrapMode
= s
;
465 tex
->setup
.tWrapMode
= t
;
468 static void savageSetTexFilter(savageTexObjPtr t
, GLenum minf
, GLenum magf
)
470 t
->setup
.minFilter
= minf
;
471 t
->setup
.magFilter
= magf
;
477 static void savageSetTexBorderColor(savageTexObjPtr t
, const GLfloat color
[4])
479 /* t->Setup[SAVAGE_TEXREG_TEXBORDERCOL] = */
480 /*t->setup.borderColor = SAVAGEPACKCOLOR8888(color[0],color[1],color[2],color[3]); */
485 static savageTexObjPtr
486 savageAllocTexObj( struct gl_texture_object
*texObj
)
490 t
= (savageTexObjPtr
) calloc(1,sizeof(*t
));
491 texObj
->DriverData
= t
;
495 /* Initialize non-image-dependent parts of the state:
497 t
->base
.tObj
= texObj
;
498 t
->base
.dirty_images
[0] = 0;
499 t
->dirtySubImages
= 0;
502 /* Initialize dirty tiles bit vectors
504 for (i
= 0; i
< SAVAGE_TEX_MAXLEVELS
; ++i
)
505 t
->image
[i
].nTiles
= 0;
507 /* FIXME Something here to set initial values for other parts of
511 make_empty_list( &t
->base
);
513 savageSetTexWrapping(t
,texObj
->WrapS
,texObj
->WrapT
);
514 savageSetTexFilter(t
,texObj
->MinFilter
,texObj
->MagFilter
);
515 savageSetTexBorderColor(t
,texObj
->BorderColor
);
521 /* Mesa texture formats for alpha-images on Savage3D/IX/MX
523 * Promoting texture images to ARGB888 or ARGB4444 doesn't work
524 * because we can't tell the hardware to ignore the color components
525 * and only use the alpha component. So we define our own texture
526 * formats that promote to ARGB8888 or ARGB4444 and set the color
527 * components to white. This way we get the correct result.
531 _savage_texstore_a1114444(TEXSTORE_PARAMS
);
534 _savage_texstore_a1118888(TEXSTORE_PARAMS
);
536 static struct gl_texture_format _savage_texformat_a1114444
= {
537 MESA_FORMAT_ARGB4444
, /* MesaFormat */
538 GL_RGBA
, /* BaseFormat */
539 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
544 0, /* LuminanceBits */
545 0, /* IntensityBits */
550 _savage_texstore_a1114444
, /* StoreTexImageFunc */
551 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* FetchTexel* filled in by
552 * savageDDInitTextureFuncs */
554 static struct gl_texture_format _savage_texformat_a1118888
= {
555 MESA_FORMAT_ARGB8888
, /* MesaFormat */
556 GL_RGBA
, /* BaseFormat */
557 GL_UNSIGNED_NORMALIZED_ARB
, /* DataType */
562 0, /* LuminanceBits */
563 0, /* IntensityBits */
568 _savage_texstore_a1118888
, /* StoreTexImageFunc */
569 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* FetchTexel* filled in by
570 * savageDDInitTextureFuncs */
575 _savage_texstore_a1114444(TEXSTORE_PARAMS
)
577 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
580 srcWidth
, srcHeight
, srcDepth
,
581 srcFormat
, srcType
, srcAddr
,
583 const GLchan
*src
= tempImage
;
586 ASSERT(dstFormat
== &_savage_texformat_a1114444
);
587 ASSERT(baseInternalFormat
== GL_ALPHA
);
591 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
592 for (img
= 0; img
< srcDepth
; img
++) {
593 GLubyte
*dstRow
= (GLubyte
*) dstAddr
594 + dstImageOffsets
[dstZoffset
+ img
] * dstFormat
->TexelBytes
595 + dstYoffset
* dstRowStride
596 + dstXoffset
* dstFormat
->TexelBytes
;
597 for (row
= 0; row
< srcHeight
; row
++) {
598 GLushort
*dstUI
= (GLushort
*) dstRow
;
599 for (col
= 0; col
< srcWidth
; col
++) {
600 dstUI
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[0]),
604 dstRow
+= dstRowStride
;
607 _mesa_free((void *) tempImage
);
614 _savage_texstore_a1118888(TEXSTORE_PARAMS
)
616 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
619 srcWidth
, srcHeight
, srcDepth
,
620 srcFormat
, srcType
, srcAddr
,
622 const GLchan
*src
= tempImage
;
625 ASSERT(dstFormat
== &_savage_texformat_a1118888
);
626 ASSERT(baseInternalFormat
== GL_ALPHA
);
630 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
631 for (img
= 0; img
< srcDepth
; img
++) {
632 GLubyte
*dstRow
= (GLubyte
*) dstAddr
633 + dstImageOffsets
[dstZoffset
+ img
] * dstFormat
->TexelBytes
634 + dstYoffset
* dstRowStride
635 + dstXoffset
* dstFormat
->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
);
652 /* Called by the _mesa_store_teximage[123]d() functions. */
653 static const struct gl_texture_format
*
654 savageChooseTextureFormat( GLcontext
*ctx
, GLint internalFormat
,
655 GLenum format
, GLenum type
)
657 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
658 const GLboolean do32bpt
=
659 ( imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_32
);
660 const GLboolean force16bpt
=
661 ( imesa
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FORCE_16
);
662 const GLboolean isSavage4
= (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
);
665 switch ( internalFormat
) {
668 case GL_COMPRESSED_RGBA
:
670 case GL_UNSIGNED_INT_10_10_10_2
:
671 case GL_UNSIGNED_INT_2_10_10_10_REV
:
672 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
;
673 case GL_UNSIGNED_SHORT_4_4_4_4
:
674 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
675 return &_mesa_texformat_argb4444
;
676 case GL_UNSIGNED_SHORT_5_5_5_1
:
677 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
678 return &_mesa_texformat_argb1555
;
680 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
685 case GL_COMPRESSED_RGB
:
687 case GL_UNSIGNED_SHORT_4_4_4_4
:
688 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
689 return &_mesa_texformat_argb4444
;
690 case GL_UNSIGNED_SHORT_5_5_5_1
:
691 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
692 return &_mesa_texformat_argb1555
;
693 case GL_UNSIGNED_SHORT_5_6_5
:
694 case GL_UNSIGNED_SHORT_5_6_5_REV
:
695 return &_mesa_texformat_rgb565
;
697 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_rgb565
;
704 &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
708 &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
;
712 return &_mesa_texformat_argb4444
;
715 return &_mesa_texformat_argb1555
;
721 return !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_rgb565
;
726 return &_mesa_texformat_rgb565
;
729 case GL_COMPRESSED_ALPHA
:
730 return isSavage4
? &_mesa_texformat_a8
: (
731 do32bpt
? &_savage_texformat_a1118888
: &_savage_texformat_a1114444
);
733 return isSavage4
? &_mesa_texformat_a8
: &_savage_texformat_a1114444
;
737 return isSavage4
? &_mesa_texformat_a8
: (
738 !force16bpt
? &_savage_texformat_a1118888
: &_savage_texformat_a1114444
);
742 case GL_COMPRESSED_LUMINANCE
:
743 /* no alpha, but use argb1555 in 16bit case to get pure grey values */
744 return isSavage4
? &_mesa_texformat_l8
: (
745 do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
);
747 return isSavage4
? &_mesa_texformat_l8
: &_mesa_texformat_argb1555
;
751 return isSavage4
? &_mesa_texformat_l8
: (
752 !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb1555
);
755 case GL_LUMINANCE_ALPHA
:
756 case GL_COMPRESSED_LUMINANCE_ALPHA
:
757 /* Savage4 has a al44 texture format. But it's not supported by Mesa. */
758 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
759 case GL_LUMINANCE4_ALPHA4
:
760 case GL_LUMINANCE6_ALPHA2
:
761 return &_mesa_texformat_argb4444
;
762 case GL_LUMINANCE8_ALPHA8
:
763 case GL_LUMINANCE12_ALPHA4
:
764 case GL_LUMINANCE12_ALPHA12
:
765 case GL_LUMINANCE16_ALPHA16
:
766 return !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
768 /* TFT_I8 produces garbage on ProSavageDDR and subsequent texture
769 * disable keeps rendering garbage. Disabled for now. */
771 case GL_COMPRESSED_INTENSITY
:
772 return isSavage4
? &_mesa_texformat_i8
: (
773 do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
);
775 return isSavage4
? &_mesa_texformat_i8
: &_mesa_texformat_argb4444
;
779 return isSavage4
? &_mesa_texformat_i8
: (
780 !force16bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
);
783 case GL_COMPRESSED_INTENSITY
:
784 return do32bpt
? &_mesa_texformat_argb8888
: &_mesa_texformat_argb4444
;
786 return &_mesa_texformat_argb4444
;
790 return !force16bpt
? &_mesa_texformat_argb8888
:
791 &_mesa_texformat_argb4444
;
796 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
797 return &_mesa_texformat_rgb_dxt1
;
798 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
799 return &_mesa_texformat_rgba_dxt1
;
801 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
802 return &_mesa_texformat_rgba_dxt3
;
807 /* Not the best choice but Savage3D/MX/IX don't support DXT3 or DXT5. */
808 return &_mesa_texformat_rgba_dxt1
;
810 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
811 return &_mesa_texformat_rgba_dxt5
;
815 case GL_COLOR_INDEX1_EXT:
816 case GL_COLOR_INDEX2_EXT:
817 case GL_COLOR_INDEX4_EXT:
818 case GL_COLOR_INDEX8_EXT:
819 case GL_COLOR_INDEX12_EXT:
820 case GL_COLOR_INDEX16_EXT:
821 return &_mesa_texformat_ci8;
824 _mesa_problem(ctx
, "unexpected texture format in %s", __FUNCTION__
);
829 static void savageSetTexImages( savageContextPtr imesa
,
830 const struct gl_texture_object
*tObj
)
832 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
833 struct gl_texture_image
*image
= tObj
->Image
[0][tObj
->BaseLevel
];
834 GLuint offset
, i
, textureFormat
, tileIndex
, size
;
835 GLint firstLevel
, lastLevel
;
840 switch (image
->TexFormat
->MesaFormat
) {
841 case MESA_FORMAT_ARGB8888
:
842 textureFormat
= TFT_ARGB8888
;
843 t
->texelBytes
= tileIndex
= 4;
845 case MESA_FORMAT_ARGB1555
:
846 textureFormat
= TFT_ARGB1555
;
847 t
->texelBytes
= tileIndex
= 2;
849 case MESA_FORMAT_ARGB4444
:
850 textureFormat
= TFT_ARGB4444
;
851 t
->texelBytes
= tileIndex
= 2;
853 case MESA_FORMAT_RGB565
:
854 textureFormat
= TFT_RGB565
;
855 t
->texelBytes
= tileIndex
= 2;
858 textureFormat
= TFT_L8
;
859 t
->texelBytes
= tileIndex
= 1;
862 textureFormat
= TFT_I8
;
863 t
->texelBytes
= tileIndex
= 1;
866 textureFormat
= TFT_A8
;
867 t
->texelBytes
= tileIndex
= 1;
869 case MESA_FORMAT_RGB_DXT1
:
870 textureFormat
= TFT_S3TC4Bit
;
871 tileIndex
= TILE_INDEX_DXT1
;
874 case MESA_FORMAT_RGBA_DXT1
:
875 textureFormat
= TFT_S3TC4Bit
;
876 tileIndex
= TILE_INDEX_DXT1
;
879 case MESA_FORMAT_RGBA_DXT3
:
880 textureFormat
= TFT_S3TC4A4Bit
;
881 tileIndex
= TILE_INDEX_DXTn
;
884 case MESA_FORMAT_RGBA_DXT5
:
885 textureFormat
= TFT_S3TC4CA4Bit
;
886 tileIndex
= TILE_INDEX_DXTn
;
890 _mesa_problem(imesa
->glCtx
, "Bad texture format in %s", __FUNCTION__
);
893 t
->hwFormat
= textureFormat
;
895 /* Select tiling format depending on the chipset and texture format */
896 if (imesa
->savageScreen
->chipset
<= S3_SAVAGE4
)
897 t
->tileInfo
= &tileInfo_s3d_s4
[tileIndex
];
899 t
->tileInfo
= &tileInfo_pro
[tileIndex
];
901 /* Compute which mipmap levels we really want to send to the hardware.
903 driCalculateTextureFirstLastLevel( &t
->base
);
904 firstLevel
= t
->base
.firstLevel
;
905 lastLevel
= t
->base
.lastLevel
;
907 /* Figure out the size now (and count the levels). Upload won't be
908 * done until later. If the number of tiles changes, it means that
909 * this function is called for the first time on this tex object or
910 * the image or the destination color format changed. So all tiles
911 * are marked as dirty.
915 for ( i
= firstLevel
; i
<= lastLevel
&& tObj
->Image
[0][i
] ; i
++ ) {
917 nTiles
= savageTexImageTiles (image
->Width2
, image
->Height2
, t
->tileInfo
);
918 if (t
->image
[i
].nTiles
!= nTiles
) {
919 GLuint words
= (nTiles
+ 31) / 32;
920 if (t
->image
[i
].nTiles
!= 0) {
921 free(t
->image
[i
].dirtyTiles
);
923 t
->image
[i
].dirtyTiles
= malloc(words
*sizeof(GLuint
));
924 memset(t
->image
[i
].dirtyTiles
, ~0, words
*sizeof(GLuint
));
926 t
->image
[i
].nTiles
= nTiles
;
928 t
->image
[i
].offset
= offset
;
930 image
= tObj
->Image
[0][i
];
931 if (t
->texelBytes
>= 8)
932 size
= savageCompressedTexImageSize (image
->Width2
, image
->Height2
,
935 size
= savageTexImageSize (image
->Width2
, image
->Height2
,
940 t
->base
.lastLevel
= i
-1;
941 t
->base
.totalSize
= offset
;
942 /* the last three mipmap levels don't add to the offset. They are packed
945 t
->base
.totalSize
+= (t
->texelBytes
>= 8 ? 4 : 64) * t
->texelBytes
;
946 /* 2k-aligned (really needed?) */
947 t
->base
.totalSize
= (t
->base
.totalSize
+ 2047UL) & ~2047UL;
950 void savageDestroyTexObj(savageContextPtr imesa
, savageTexObjPtr t
)
954 /* Free dirty tiles bit vectors */
955 for (i
= 0; i
< SAVAGE_TEX_MAXLEVELS
; ++i
) {
956 if (t
->image
[i
].nTiles
)
957 free (t
->image
[i
].dirtyTiles
);
960 /* See if it was the driver's current object.
964 for ( i
= 0 ; i
< imesa
->glCtx
->Const
.MaxTextureUnits
; i
++ )
966 if ( &t
->base
== imesa
->CurrentTexObj
[ i
] ) {
967 assert( t
->base
.bound
& (1 << i
) );
968 imesa
->CurrentTexObj
[ i
] = NULL
;
974 /* Upload a texture's images to one of the texture heaps. May have to
975 * eject our own and/or other client's texture objects to make room
978 static void savageUploadTexImages( savageContextPtr imesa
, savageTexObjPtr t
)
980 const GLint numLevels
= t
->base
.lastLevel
- t
->base
.firstLevel
+ 1;
985 LOCK_HARDWARE(imesa
);
987 /* Do we need to eject LRU texture objects?
989 if (!t
->base
.memBlock
) {
993 heap
= driAllocateTexture(imesa
->textureHeaps
, imesa
->lastTexHeap
,
994 (driTextureObject
*)t
);
996 UNLOCK_HARDWARE(imesa
);
1000 ofs
= t
->base
.memBlock
->ofs
;
1001 t
->setup
.physAddr
= imesa
->savageScreen
->textureOffset
[heap
] + ofs
;
1002 t
->bufAddr
= (GLubyte
*)imesa
->savageScreen
->texVirtual
[heap
] + ofs
;
1003 imesa
->dirty
|= SAVAGE_UPLOAD_GLOBAL
; /* FIXME: really needed? */
1006 /* Let the world know we've used this memory recently.
1008 driUpdateTextureLRU( &t
->base
);
1009 UNLOCK_HARDWARE(imesa
);
1011 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1012 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1013 fprintf(stderr
, "Texture upload: |");
1015 /* Heap timestamps are only reliable with Savage DRM 2.3.x or
1016 * later. Earlier versions had only 16 bit time stamps which
1017 * would wrap too frequently. */
1018 if (imesa
->savageScreen
->driScrnPriv
->drm_version
.minor
>= 3) {
1019 unsigned int heap
= t
->base
.heap
->heapId
;
1020 LOCK_HARDWARE(imesa
);
1021 savageWaitEvent (imesa
, imesa
->textureHeaps
[heap
]->timestamp
);
1023 savageFlushVertices (imesa
);
1024 LOCK_HARDWARE(imesa
);
1025 savageFlushCmdBufLocked (imesa
, GL_FALSE
);
1026 WAIT_IDLE_EMPTY_LOCKED(imesa
);
1029 for (i
= 0 ; i
< numLevels
; i
++) {
1030 const GLint j
= t
->base
.firstLevel
+ i
; /* the texObj's level */
1031 if (t
->base
.dirty_images
[0] & (1 << j
)) {
1032 savageMarkAllTiles(t
, j
);
1033 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1034 fprintf (stderr
, "*");
1035 } else if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
) {
1036 if (t
->dirtySubImages
& (1 << j
))
1037 fprintf (stderr
, ".");
1039 fprintf (stderr
, " ");
1041 if ((t
->base
.dirty_images
[0] | t
->dirtySubImages
) & (1 << j
))
1042 savageUploadTexLevel( t
, j
);
1045 UNLOCK_HARDWARE(imesa
);
1046 t
->base
.dirty_images
[0] = 0;
1047 t
->dirtySubImages
= 0;
1049 if (SAVAGE_DEBUG
& DEBUG_VERBOSE_TEX
)
1050 fprintf(stderr
, "|\n");
1056 savage4_set_wrap_mode( savageContextPtr imesa
, unsigned unit
,
1057 GLenum s_mode
, GLenum t_mode
)
1061 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Wrap
;
1064 case GL_CLAMP_TO_EDGE
:
1065 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Clamp
;
1067 case GL_MIRRORED_REPEAT
:
1068 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.uMode
= TAM_Mirror
;
1074 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Wrap
;
1077 case GL_CLAMP_TO_EDGE
:
1078 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Clamp
;
1080 case GL_MIRRORED_REPEAT
:
1081 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.vMode
= TAM_Mirror
;
1088 * Sets the hardware bits for the specified GL texture filter modes.
1091 * Does the Savage4 have the ability to select the magnification filter?
1094 savage4_set_filter_mode( savageContextPtr imesa
, unsigned unit
,
1095 GLenum minFilter
, GLenum magFilter
)
1099 switch (minFilter
) {
1101 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1102 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1106 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1107 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_FALSE
;
1110 case GL_NEAREST_MIPMAP_NEAREST
:
1111 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Point
;
1112 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1115 case GL_LINEAR_MIPMAP_NEAREST
:
1116 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Bilin
;
1117 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1120 case GL_NEAREST_MIPMAP_LINEAR
:
1121 case GL_LINEAR_MIPMAP_LINEAR
:
1122 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.filterMode
= TFM_Trilin
;
1123 imesa
->regs
.s4
.texCtrl
[ unit
].ni
.mipmapEnable
= GL_TRUE
;
1129 static void savageUpdateTex0State_s4( GLcontext
*ctx
)
1131 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1132 struct gl_texture_object
*tObj
;
1133 struct gl_texture_image
*image
;
1138 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_FALSE
;
1139 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_NoTexMap
;
1140 imesa
->regs
.s4
.texCtrl
[0].ui
= 0x20f040;
1141 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1144 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1145 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1146 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1147 /* 3D texturing enabled, or texture border - fallback */
1148 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1152 /* Do 2D texture setup */
1154 t
= tObj
->DriverData
;
1156 t
= savageAllocTexObj( tObj
);
1161 imesa
->CurrentTexObj
[0] = &t
->base
;
1164 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1165 savageSetTexImages(imesa
, tObj
);
1166 savageUploadTexImages(imesa
, t
);
1169 driUpdateTextureLRU( &t
->base
);
1171 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1173 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1175 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1180 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1183 case GL_LUMINANCE_ALPHA
:
1186 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Copy
;
1190 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1193 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1194 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1198 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1203 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Decal
;
1208 case GL_LUMINANCE_ALPHA
:
1209 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_DecalAlpha
;
1213 GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1214 are undefined with GL_DECAL
1218 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_CopyAlpha
;
1221 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1222 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1226 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1227 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1228 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1229 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1233 imesa
->regs
.s4
.texBlendColor
.ui
= imesa
->texEnvColor
;
1238 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1239 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1244 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Blend0
;
1245 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1246 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1247 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1248 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1249 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1250 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1251 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1252 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1254 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1255 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Blend1
;
1257 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1258 imesa
->bTexEn1
= GL_TRUE
;
1261 case GL_LUMINANCE_ALPHA
:
1263 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendAlpha0
;
1264 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1265 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1266 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1267 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1268 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1269 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1270 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1271 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1273 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1274 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendAlpha1
;
1276 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1277 imesa
->bTexEn1
= GL_TRUE
;
1281 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_BlendInt0
;
1282 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1283 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1284 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
=
1285 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
;
1286 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
=
1287 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
;
1288 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
=
1289 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
;
1291 imesa
->regs
.s4
.texAddr
[1].ui
= imesa
->regs
.s4
.texAddr
[0].ui
;
1292 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_BlendInt1
;
1294 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_TRUE
;
1295 imesa
->regs
.s4
.texCtrl
[0].ni
.alphaArg1Invert
= GL_TRUE
;
1296 imesa
->bTexEn1
= GL_TRUE
;
1299 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1300 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1304 imesa
->regs
.s4
.texCtrl
[0].ni
.clrArg1Invert
= GL_FALSE
;
1308 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_ModulAlpha
;
1313 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1316 case GL_LUMINANCE_ALPHA
:
1318 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_Add
;
1322 imesa
->regs
.s4
.texBlendCtrl
[0].ui
= TBC_AddAlpha
;
1325 __HWEnvCombineSingleUnitScale(imesa
, 0, 0,
1326 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1329 #if GL_ARB_texture_env_combine
1330 case GL_COMBINE_ARB
:
1331 __HWParseTexEnvCombine(imesa
, 0, &imesa
->regs
.s4
.texCtrl
[0],
1332 &imesa
->regs
.s4
.texBlendCtrl
[0]);
1337 fprintf(stderr
, "unknown tex env mode");
1342 savage4_set_wrap_mode( imesa
, 0, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1343 savage4_set_filter_mode( imesa
, 0, t
->setup
.minFilter
, t
->setup
.magFilter
);
1345 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1346 (imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
!= 0))
1348 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 32.0) +
1352 else if (bias
> 255)
1354 imesa
->regs
.s4
.texCtrl
[0].ni
.dBias
= bias
& 0x1ff;
1357 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1358 imesa
->regs
.s4
.texDescr
.ni
.tex0En
= GL_TRUE
;
1359 imesa
->regs
.s4
.texDescr
.ni
.tex0Width
= image
->WidthLog2
;
1360 imesa
->regs
.s4
.texDescr
.ni
.tex0Height
= image
->HeightLog2
;
1361 imesa
->regs
.s4
.texDescr
.ni
.tex0Fmt
= t
->hwFormat
;
1362 imesa
->regs
.s4
.texCtrl
[0].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1364 if (imesa
->regs
.s4
.texDescr
.ni
.tex1En
)
1365 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1367 imesa
->regs
.s4
.texAddr
[0].ui
= (uint32_t) t
->setup
.physAddr
| 0x2;
1368 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1369 imesa
->regs
.s4
.texAddr
[0].ui
|= 0x1;
1373 static void savageUpdateTex1State_s4( GLcontext
*ctx
)
1375 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1376 struct gl_texture_object
*tObj
;
1377 struct gl_texture_image
*image
;
1384 imesa
->bTexEn1
= GL_FALSE
;
1388 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_FALSE
;
1389 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_NoTexMap1
;
1390 imesa
->regs
.s4
.texCtrl
[1].ui
= 0x20f040;
1391 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_FALSE
;
1392 if (ctx
->Texture
.Unit
[1]._ReallyEnabled
== 0)
1395 tObj
= ctx
->Texture
.Unit
[1]._Current
;
1397 if ((ctx
->Texture
.Unit
[1]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1398 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1399 /* 3D texturing enabled, or texture border - fallback */
1400 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1404 /* Do 2D texture setup */
1406 t
= tObj
->DriverData
;
1408 t
= savageAllocTexObj( tObj
);
1413 imesa
->CurrentTexObj
[1] = &t
->base
;
1417 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1418 savageSetTexImages(imesa
, tObj
);
1419 savageUploadTexImages(imesa
, t
);
1422 driUpdateTextureLRU( &t
->base
);
1424 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1426 switch (ctx
->Texture
.Unit
[1].EnvMode
) {
1428 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1433 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal
;
1436 case GL_LUMINANCE_ALPHA
:
1439 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Copy
;
1443 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1446 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1449 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1450 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1451 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1455 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1459 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_ModulAlpha1
;
1464 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1467 case GL_LUMINANCE_ALPHA
:
1469 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Add1
;
1473 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_AddAlpha1
;
1476 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1479 #if GL_ARB_texture_env_combine
1480 case GL_COMBINE_ARB
:
1481 __HWParseTexEnvCombine(imesa
, 1, &texCtrl
, &imesa
->regs
.s4
.texBlendCtrl
);
1486 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_FALSE
;
1492 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_Decal1
;
1494 case GL_LUMINANCE_ALPHA
:
1497 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_DecalAlpha1
;
1501 // GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_ALPHA, GL_INTENSITY
1502 // are undefined with GL_DECAL
1505 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= TBC_CopyAlpha1
;
1508 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1512 if (format
== GL_LUMINANCE
)
1515 // This is a hack for GLQuake, invert.
1517 imesa
->regs
.s4
.texCtrl
[1].ni
.clrArg1Invert
= GL_TRUE
;
1518 imesa
->regs
.s4
.texBlendCtrl
[1].ui
= 0;
1520 __HWEnvCombineSingleUnitScale(imesa
, 0, 1, &imesa
->regs
.s4
.texBlendCtrl
);
1524 fprintf(stderr
, "unknown tex 1 env mode\n");
1529 savage4_set_wrap_mode( imesa
, 1, t
->setup
.sWrapMode
, t
->setup
.tWrapMode
);
1530 savage4_set_filter_mode( imesa
, 1, t
->setup
.minFilter
, t
->setup
.magFilter
);
1532 if((ctx
->Texture
.Unit
[1].LodBias
!=0.0F
) ||
1533 (imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
!= 0))
1535 int bias
= (int)(ctx
->Texture
.Unit
[1].LodBias
* 32.0) +
1539 else if (bias
> 255)
1541 imesa
->regs
.s4
.texCtrl
[1].ni
.dBias
= bias
& 0x1ff;
1544 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1545 imesa
->regs
.s4
.texDescr
.ni
.tex1En
= GL_TRUE
;
1546 imesa
->regs
.s4
.texDescr
.ni
.tex1Width
= image
->WidthLog2
;
1547 imesa
->regs
.s4
.texDescr
.ni
.tex1Height
= image
->HeightLog2
;
1548 imesa
->regs
.s4
.texDescr
.ni
.tex1Fmt
= t
->hwFormat
;
1549 imesa
->regs
.s4
.texCtrl
[1].ni
.dMax
= t
->base
.lastLevel
- t
->base
.firstLevel
;
1550 imesa
->regs
.s4
.texDescr
.ni
.texBLoopEn
= GL_TRUE
;
1552 imesa
->regs
.s4
.texAddr
[1].ui
= (uint32_t) t
->setup
.physAddr
| 2;
1553 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1554 imesa
->regs
.s4
.texAddr
[1].ui
|= 0x1;
1556 static void savageUpdateTexState_s3d( GLcontext
*ctx
)
1558 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1559 struct gl_texture_object
*tObj
;
1560 struct gl_texture_image
*image
;
1565 imesa
->regs
.s3d
.texCtrl
.ui
= 0;
1566 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_FALSE
;
1567 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= 0x08;
1568 imesa
->regs
.s3d
.texCtrl
.ni
.texXprEn
= GL_TRUE
;
1569 if (ctx
->Texture
.Unit
[0]._ReallyEnabled
== 0)
1572 tObj
= ctx
->Texture
.Unit
[0]._Current
;
1573 if ((ctx
->Texture
.Unit
[0]._ReallyEnabled
& ~(TEXTURE_1D_BIT
|TEXTURE_2D_BIT
))
1574 || tObj
->Image
[0][tObj
->BaseLevel
]->Border
> 0) {
1575 /* 3D texturing enabled, or texture border - fallback */
1576 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1580 /* Do 2D texture setup */
1581 t
= tObj
->DriverData
;
1583 t
= savageAllocTexObj( tObj
);
1588 imesa
->CurrentTexObj
[0] = &t
->base
;
1591 if (t
->base
.dirty_images
[0] || t
->dirtySubImages
) {
1592 savageSetTexImages(imesa
, tObj
);
1593 savageUploadTexImages(imesa
, t
);
1596 driUpdateTextureLRU( &t
->base
);
1598 format
= tObj
->Image
[0][tObj
->BaseLevel
]->_BaseFormat
;
1600 /* FIXME: copied from utah-glx, probably needs some tuning */
1601 switch (ctx
->Texture
.Unit
[0].EnvMode
) {
1603 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECALALPHA_S3D
;
1607 case GL_ALPHA
: /* FIXME */
1608 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 1;
1610 case GL_LUMINANCE_ALPHA
:
1612 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= 4;
1616 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_DECAL_S3D
;
1619 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_COPY_S3D
;
1622 case GL_BLEND
: /* hardware can't do GL_BLEND */
1623 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1626 imesa
->regs
.s3d
.drawCtrl
.ni
.texBlendCtrl
= SAVAGETBC_MODULATEALPHA_S3D
;
1629 fprintf(stderr
, "unknown tex env mode\n");
1634 /* The Savage3D can't handle different wrapping modes in s and t.
1635 * If they are not the same, fall back to software. */
1636 if (t
->setup
.sWrapMode
!= t
->setup
.tWrapMode
) {
1637 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_TRUE
);
1640 imesa
->regs
.s3d
.texCtrl
.ni
.uWrapEn
= 0;
1641 imesa
->regs
.s3d
.texCtrl
.ni
.vWrapEn
= 0;
1642 imesa
->regs
.s3d
.texCtrl
.ni
.wrapMode
=
1643 (t
->setup
.sWrapMode
== GL_REPEAT
) ? TAM_Wrap
: TAM_Clamp
;
1645 switch (t
->setup
.minFilter
) {
1647 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1648 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1652 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1653 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_TRUE
;
1656 case GL_NEAREST_MIPMAP_NEAREST
:
1657 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Point
;
1658 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1661 case GL_LINEAR_MIPMAP_NEAREST
:
1662 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Bilin
;
1663 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1666 case GL_NEAREST_MIPMAP_LINEAR
:
1667 case GL_LINEAR_MIPMAP_LINEAR
:
1668 imesa
->regs
.s3d
.texCtrl
.ni
.filterMode
= TFM_Trilin
;
1669 imesa
->regs
.s3d
.texCtrl
.ni
.mipmapDisable
= GL_FALSE
;
1673 /* There is no way to specify a maximum mipmap level. We may have to
1674 disable mipmapping completely. */
1676 if (t->max_level < t->image[0].image->WidthLog2 ||
1677 t->max_level < t->image[0].image->HeightLog2) {
1678 texCtrl.ni.mipmapEnable = GL_TRUE;
1679 if (texCtrl.ni.filterMode == TFM_Trilin)
1680 texCtrl.ni.filterMode = TFM_Bilin;
1681 texCtrl.ni.filterMode = TFM_Point;
1685 if((ctx
->Texture
.Unit
[0].LodBias
!=0.0F
) ||
1686 (imesa
->regs
.s3d
.texCtrl
.ni
.dBias
!= 0))
1688 int bias
= (int)(ctx
->Texture
.Unit
[0].LodBias
* 16.0);
1691 else if (bias
> 255)
1693 imesa
->regs
.s3d
.texCtrl
.ni
.dBias
= bias
& 0x1ff;
1696 image
= tObj
->Image
[0][tObj
->BaseLevel
];
1697 imesa
->regs
.s3d
.texCtrl
.ni
.texEn
= GL_TRUE
;
1698 imesa
->regs
.s3d
.texDescr
.ni
.texWidth
= image
->WidthLog2
;
1699 imesa
->regs
.s3d
.texDescr
.ni
.texHeight
= image
->HeightLog2
;
1700 assert (t
->hwFormat
<= 7);
1701 imesa
->regs
.s3d
.texDescr
.ni
.texFmt
= t
->hwFormat
;
1703 imesa
->regs
.s3d
.texAddr
.ui
= (uint32_t) t
->setup
.physAddr
| 2;
1704 if(t
->base
.heap
->heapId
== SAVAGE_AGP_HEAP
)
1705 imesa
->regs
.s3d
.texAddr
.ui
|= 0x1;
1709 static void savageTimestampTextures( savageContextPtr imesa
)
1711 /* Timestamp current texture objects for texture heap aging.
1712 * Only useful with long-lived 32-bit event tags available
1713 * with Savage DRM 2.3.x or later. */
1714 if ((imesa
->CurrentTexObj
[0] || imesa
->CurrentTexObj
[1]) &&
1715 imesa
->savageScreen
->driScrnPriv
->drm_version
.minor
>= 3) {
1718 e
= savageEmitEvent(imesa
, SAVAGE_WAIT_3D
);
1719 if (imesa
->CurrentTexObj
[0])
1720 imesa
->CurrentTexObj
[0]->timestamp
= e
;
1721 if (imesa
->CurrentTexObj
[1])
1722 imesa
->CurrentTexObj
[1]->timestamp
= e
;
1727 static void savageUpdateTextureState_s4( GLcontext
*ctx
)
1729 savageContextPtr imesa
= SAVAGE_CONTEXT(ctx
);
1731 /* When a texture is about to change or be disabled, timestamp the
1732 * old texture(s). We'll have to wait for this time stamp before
1733 * uploading anything to the same texture heap.
1735 if ((imesa
->CurrentTexObj
[0] && ctx
->Texture
.Unit
[0]._ReallyEnabled
&&
1736 ctx
->Texture
.Unit
[0]._Current
->DriverData
!= imesa
->CurrentTexObj
[0]) ||
1737 (imesa
->CurrentTexObj
[1] && ctx
->Texture
.Unit
[1]._ReallyEnabled
&&
1738 ctx
->Texture
.Unit
[1]._Current
->DriverData
!= imesa
->CurrentTexObj
[1]) ||
1739 (imesa
->CurrentTexObj
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
) ||
1740 (imesa
->CurrentTexObj
[1] && !ctx
->Texture
.Unit
[1]._ReallyEnabled
))
1741 savageTimestampTextures(imesa
);
1743 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1744 if (imesa
->CurrentTexObj
[1]) imesa
->CurrentTexObj
[1]->bound
&= ~2;
1745 imesa
->CurrentTexObj
[0] = 0;
1746 imesa
->CurrentTexObj
[1] = 0;
1747 savageUpdateTex0State_s4( ctx
);
1748 savageUpdateTex1State_s4( ctx
);
1749 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
|
1750 SAVAGE_UPLOAD_TEX1
);
1752 static void savageUpdateTextureState_s3d( 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
[0] && !ctx
->Texture
.Unit
[0]._ReallyEnabled
))
1763 savageTimestampTextures(imesa
);
1765 if (imesa
->CurrentTexObj
[0]) imesa
->CurrentTexObj
[0]->bound
&= ~1;
1766 imesa
->CurrentTexObj
[0] = 0;
1767 savageUpdateTexState_s3d( ctx
);
1768 imesa
->dirty
|= (SAVAGE_UPLOAD_TEX0
);
1770 void savageUpdateTextureState( GLcontext
*ctx
)
1772 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1773 FALLBACK (ctx
, SAVAGE_FALLBACK_TEXTURE
, GL_FALSE
);
1774 FALLBACK(ctx
, SAVAGE_FALLBACK_PROJ_TEXTURE
, GL_FALSE
);
1775 if (imesa
->savageScreen
->chipset
>= S3_SAVAGE4
)
1776 savageUpdateTextureState_s4 (ctx
);
1778 savageUpdateTextureState_s3d (ctx
);
1783 /*****************************************
1785 *****************************************/
1787 static void savageTexEnv( GLcontext
*ctx
, GLenum target
,
1788 GLenum pname
, const GLfloat
*param
)
1790 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
1792 if (pname
== GL_TEXTURE_ENV_MODE
) {
1794 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
1796 } else if (pname
== GL_TEXTURE_ENV_COLOR
) {
1798 struct gl_texture_unit
*texUnit
=
1799 &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1800 const GLfloat
*fc
= texUnit
->EnvColor
;
1802 CLAMPED_FLOAT_TO_UBYTE(r
, fc
[0]);
1803 CLAMPED_FLOAT_TO_UBYTE(g
, fc
[1]);
1804 CLAMPED_FLOAT_TO_UBYTE(b
, fc
[2]);
1805 CLAMPED_FLOAT_TO_UBYTE(a
, fc
[3]);
1807 imesa
->texEnvColor
= ((a
<< 24) | (r
<< 16) |
1808 (g
<< 8) | (b
<< 0));
1814 /* Update the heap's time stamp, so the new image is not uploaded
1815 * while the old one is still in use. If the texture that is going to
1816 * be changed is currently bound, we need to timestamp the texture
1818 static void savageTexImageChanged (savageTexObjPtr t
) {
1821 savageTimestampTextures(
1822 (savageContextPtr
)t
->base
.heap
->driverContext
);
1823 if (t
->base
.timestamp
> t
->base
.heap
->timestamp
)
1824 t
->base
.heap
->timestamp
= t
->base
.timestamp
;
1828 static void savageTexImage1D( GLcontext
*ctx
, GLenum target
, GLint level
,
1829 GLint internalFormat
,
1830 GLint width
, GLint border
,
1831 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1832 const struct gl_pixelstore_attrib
*packing
,
1833 struct gl_texture_object
*texObj
,
1834 struct gl_texture_image
*texImage
)
1836 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1838 savageTexImageChanged (t
);
1840 t
= savageAllocTexObj(texObj
);
1842 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1846 _mesa_store_teximage1d( ctx
, target
, level
, internalFormat
,
1847 width
, border
, format
, type
,
1848 pixels
, packing
, texObj
, texImage
);
1849 t
->base
.dirty_images
[0] |= (1 << level
);
1850 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1853 static void savageTexSubImage1D( GLcontext
*ctx
,
1858 GLenum format
, GLenum type
,
1859 const GLvoid
*pixels
,
1860 const struct gl_pixelstore_attrib
*packing
,
1861 struct gl_texture_object
*texObj
,
1862 struct gl_texture_image
*texImage
)
1864 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1865 assert( t
); /* this _should_ be true */
1867 savageTexImageChanged (t
);
1868 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, 1,
1869 xoffset
, 0, width
, 1);
1871 t
= savageAllocTexObj(texObj
);
1873 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
1876 t
->base
.dirty_images
[0] |= (1 << level
);
1878 _mesa_store_texsubimage1d(ctx
, target
, level
, xoffset
, width
,
1879 format
, type
, pixels
, packing
, texObj
,
1881 t
->dirtySubImages
|= (1 << level
);
1882 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1885 static void savageTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1886 GLint internalFormat
,
1887 GLint width
, GLint height
, GLint border
,
1888 GLenum format
, GLenum type
, const GLvoid
*pixels
,
1889 const struct gl_pixelstore_attrib
*packing
,
1890 struct gl_texture_object
*texObj
,
1891 struct gl_texture_image
*texImage
)
1893 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1895 savageTexImageChanged (t
);
1897 t
= savageAllocTexObj(texObj
);
1899 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1903 _mesa_store_teximage2d( ctx
, target
, level
, internalFormat
,
1904 width
, height
, border
, format
, type
,
1905 pixels
, packing
, texObj
, texImage
);
1906 t
->base
.dirty_images
[0] |= (1 << level
);
1907 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1910 static void savageTexSubImage2D( GLcontext
*ctx
,
1913 GLint xoffset
, GLint yoffset
,
1914 GLsizei width
, GLsizei height
,
1915 GLenum format
, GLenum type
,
1916 const GLvoid
*pixels
,
1917 const struct gl_pixelstore_attrib
*packing
,
1918 struct gl_texture_object
*texObj
,
1919 struct gl_texture_image
*texImage
)
1921 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1922 assert( t
); /* this _should_ be true */
1924 savageTexImageChanged (t
);
1925 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
1926 xoffset
, yoffset
, width
, height
);
1928 t
= savageAllocTexObj(texObj
);
1930 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1933 t
->base
.dirty_images
[0] |= (1 << level
);
1935 _mesa_store_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
, width
,
1936 height
, format
, type
, pixels
, packing
, texObj
,
1938 t
->dirtySubImages
|= (1 << level
);
1939 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1943 savageCompressedTexImage2D( GLcontext
*ctx
, GLenum target
, GLint level
,
1944 GLint internalFormat
,
1945 GLint width
, GLint height
, GLint border
,
1946 GLsizei imageSize
, const GLvoid
*data
,
1947 struct gl_texture_object
*texObj
,
1948 struct gl_texture_image
*texImage
)
1950 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1952 savageTexImageChanged (t
);
1954 t
= savageAllocTexObj(texObj
);
1956 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
1960 _mesa_store_compressed_teximage2d( ctx
, target
, level
, internalFormat
,
1961 width
, height
, border
, imageSize
,
1962 data
, texObj
, texImage
);
1963 t
->base
.dirty_images
[0] |= (1 << level
);
1964 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1968 savageCompressedTexSubImage2D( GLcontext
*ctx
,
1971 GLint xoffset
, GLint yoffset
,
1972 GLsizei width
, GLsizei height
,
1973 GLenum format
, GLsizei imageSize
,
1975 struct gl_texture_object
*texObj
,
1976 struct gl_texture_image
*texImage
)
1978 savageTexObjPtr t
= (savageTexObjPtr
) texObj
->DriverData
;
1979 assert( t
); /* this _should_ be true */
1981 savageTexImageChanged (t
);
1982 savageMarkDirtyTiles(t
, level
, texImage
->Width2
, texImage
->Height2
,
1983 xoffset
, yoffset
, width
, height
);
1985 t
= savageAllocTexObj(texObj
);
1987 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
1990 t
->base
.dirty_images
[0] |= (1 << level
);
1992 _mesa_store_compressed_texsubimage2d(ctx
, target
, level
, xoffset
, yoffset
,
1993 width
, height
, format
, imageSize
,
1994 data
, texObj
, texImage
);
1995 t
->dirtySubImages
|= (1 << level
);
1996 SAVAGE_CONTEXT(ctx
)->new_state
|= SAVAGE_NEW_TEXTURE
;
1999 static void savageTexParameter( GLcontext
*ctx
, GLenum target
,
2000 struct gl_texture_object
*tObj
,
2001 GLenum pname
, const GLfloat
*params
)
2003 savageTexObjPtr t
= (savageTexObjPtr
) tObj
->DriverData
;
2004 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2006 if (!t
|| (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
))
2010 case GL_TEXTURE_MIN_FILTER
:
2011 case GL_TEXTURE_MAG_FILTER
:
2012 savageSetTexFilter(t
,tObj
->MinFilter
,tObj
->MagFilter
);
2015 case GL_TEXTURE_WRAP_S
:
2016 case GL_TEXTURE_WRAP_T
:
2017 savageSetTexWrapping(t
,tObj
->WrapS
,tObj
->WrapT
);
2020 case GL_TEXTURE_BORDER_COLOR
:
2021 savageSetTexBorderColor(t
,tObj
->BorderColor
);
2028 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2031 static void savageBindTexture( GLcontext
*ctx
, GLenum target
,
2032 struct gl_texture_object
*tObj
)
2034 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2036 assert( (target
!= GL_TEXTURE_1D
&& target
!= GL_TEXTURE_2D
) ||
2037 (tObj
->DriverData
!= NULL
) );
2039 imesa
->new_state
|= SAVAGE_NEW_TEXTURE
;
2042 static void savageDeleteTexture( GLcontext
*ctx
, struct gl_texture_object
*tObj
)
2044 driTextureObject
*t
= (driTextureObject
*)tObj
->DriverData
;
2045 savageContextPtr imesa
= SAVAGE_CONTEXT( ctx
);
2049 savageTimestampTextures(imesa
);
2051 driDestroyTextureObject(t
);
2053 /* Free mipmap images and the texture object itself */
2054 _mesa_delete_texture_object(ctx
, tObj
);
2058 static struct gl_texture_object
*
2059 savageNewTextureObject( GLcontext
*ctx
, GLuint name
, GLenum target
)
2061 struct gl_texture_object
*obj
;
2062 obj
= _mesa_new_texture_object(ctx
, name
, target
);
2063 savageAllocTexObj( obj
);
2068 void savageDDInitTextureFuncs( struct dd_function_table
*functions
)
2070 functions
->TexEnv
= savageTexEnv
;
2071 functions
->ChooseTextureFormat
= savageChooseTextureFormat
;
2072 functions
->TexImage1D
= savageTexImage1D
;
2073 functions
->TexSubImage1D
= savageTexSubImage1D
;
2074 functions
->TexImage2D
= savageTexImage2D
;
2075 functions
->TexSubImage2D
= savageTexSubImage2D
;
2076 functions
->CompressedTexImage2D
= savageCompressedTexImage2D
;
2077 functions
->CompressedTexSubImage2D
= savageCompressedTexSubImage2D
;
2078 functions
->BindTexture
= savageBindTexture
;
2079 functions
->NewTextureObject
= savageNewTextureObject
;
2080 functions
->DeleteTexture
= savageDeleteTexture
;
2081 functions
->IsTextureResident
= driIsTextureResident
;
2082 functions
->TexParameter
= savageTexParameter
;
2084 /* Texel fetching with our custom texture formats works just like
2085 * the standard argb formats. */
2086 _savage_texformat_a1114444
.FetchTexel1D
= _mesa_texformat_argb4444
.FetchTexel1D
;
2087 _savage_texformat_a1114444
.FetchTexel2D
= _mesa_texformat_argb4444
.FetchTexel2D
;
2088 _savage_texformat_a1114444
.FetchTexel3D
= _mesa_texformat_argb4444
.FetchTexel3D
;
2089 _savage_texformat_a1114444
.FetchTexel1Df
= _mesa_texformat_argb4444
.FetchTexel1Df
;
2090 _savage_texformat_a1114444
.FetchTexel2Df
= _mesa_texformat_argb4444
.FetchTexel2Df
;
2091 _savage_texformat_a1114444
.FetchTexel3Df
= _mesa_texformat_argb4444
.FetchTexel3Df
;
2093 _savage_texformat_a1118888
.FetchTexel1D
= _mesa_texformat_argb8888
.FetchTexel1D
;
2094 _savage_texformat_a1118888
.FetchTexel2D
= _mesa_texformat_argb8888
.FetchTexel2D
;
2095 _savage_texformat_a1118888
.FetchTexel3D
= _mesa_texformat_argb8888
.FetchTexel3D
;
2096 _savage_texformat_a1118888
.FetchTexel1Df
= _mesa_texformat_argb8888
.FetchTexel1Df
;
2097 _savage_texformat_a1118888
.FetchTexel2Df
= _mesa_texformat_argb8888
.FetchTexel2Df
;
2098 _savage_texformat_a1118888
.FetchTexel3Df
= _mesa_texformat_argb8888
.FetchTexel3Df
;