summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfxkuehl <fxkuehl>2004-02-22 13:49:53 +0000
committerfxkuehl <fxkuehl>2004-02-22 13:49:53 +0000
commit22378f0c2a732700c03e210f873e86fb5bf9eade (patch)
treee5158c04c53872c8589d1e16c74b10e2cfc8ace0
parent05b4eeb17fda82fc34ed1d1f3cb134c76a4cb86a (diff)
First round of texture management overhaul. Provide a ChooseTextureFormat
callback and have Mesa do the texel format conversion. Separate texture allocation and setting the texture images. This should make it a lot easier to port to Mesa 6.
-rwxr-xr-xxc/lib/GL/mesa/src/drv/savage/savagetex.c563
-rwxr-xr-xxc/lib/GL/mesa/src/drv/savage/savagetex.h3
2 files changed, 220 insertions, 346 deletions
diff --git a/xc/lib/GL/mesa/src/drv/savage/savagetex.c b/xc/lib/GL/mesa/src/drv/savage/savagetex.c
index 985a23e83..ac1058381 100755
--- a/xc/lib/GL/mesa/src/drv/savage/savagetex.c
+++ b/xc/lib/GL/mesa/src/drv/savage/savagetex.c
@@ -50,7 +50,6 @@ static GLuint GetTiledCoordinates16_8( GLint iBufferWidth,GLint x,GLint y );
static GLuint GetTiledCoordinates32_4( GLint iBufferWidth, GLint x, GLint y );
static GLuint GetTiledCoordinates32_8( GLint iBufferWidth, GLint x, GLint y );
__inline GLuint GetTiledCoordinates( GLint iDepth,GLint iBufferWidth,GLint x,GLint y );
-__inline GLubyte * savageMakeTexel(savageTextureObjectPtr t, GLubyte * src, GLubyte * dst, GLuint level);
__inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint startx, GLuint starty, GLuint reloc);
__inline void savageTileTex(savageTextureObjectPtr tex, GLuint level);
@@ -256,121 +255,6 @@ __inline GLuint GetTiledCoordinates( GLint iDepth,
}
}
-__inline GLubyte * savageMakeTexel(savageTextureObjectPtr t, GLubyte * src, GLubyte * dst, GLuint level)
-{
-
- GLushort u;
-
- switch(t->image[level].baseFormat)
- {
- case GL_RGB:
- if(t->image[level].internalFormat == TFT_ARGB1555)
- {
- *(GLushort *)dst = SAVAGEPACKCOLOR1555(src[0],src[1],src[2], 1);
- u = *(GLushort *)dst;
- src += 3;
- return src;
- }
- else
- {
- if(t->image[level].internalFormat == TFT_ARGB4444)
- {
- *(GLushort *)dst = SAVAGEPACKCOLOR4444(src[0],src[1],src[2], 0xf0);
- src += 3;
- return src;
- }
- else
- {
- *(GLuint *)dst = SAVAGEPACKCOLOR8888(src[0],src[1],src[2], 0xff);
- src += 3;
- return src;
- }
- }
- break;
-
- case GL_RGBA:
- switch (t->image[level].internalFormat)
- {
- case TFT_ARGB1555:
- *(GLushort *)dst = SAVAGEPACKCOLOR1555(src[0],src[1],src[2], src[3]);
- src += 4;
- return src;
- case TFT_ARGB4444:
- *(GLushort *)dst = SAVAGEPACKCOLOR4444(src[0],src[1],src[2], src[3]);
- src += 4;
- return src;
- case TFT_ARGB8888:
- *(GLuint *)dst = SAVAGEPACKCOLOR8888(src[0],src[1],src[2], src[3]);
- src += 4;
- return src;
- }
- break;
-
- case GL_LUMINANCE:
- switch (t->image[level].internalFormat) {
- case TFT_ARGB1555:
- *(GLushort *)dst = SAVAGEPACKCOLOR1555(*src,*src,*src,0);
- src++;
- return src;
- case TFT_L8:
- *dst = *src;
- src++;
- return src;
- }
- break;
-
- case GL_INTENSITY:
- if(t->image[level].internalFormat == TFT_ARGB8888)
- {
- *(GLuint *)dst = SAVAGEPACKCOLOR8888(src[0],src[0],src[0],src[0]);
- src++;
- return src;
- }
- else
- {
- *(GLushort *)dst = SAVAGEPACKCOLOR4444(src[0],src[0],src[0],src[0]);
- src++;
- return src;
- }
- break;
-
- case GL_LUMINANCE_ALPHA:
- if(t->image[level].internalFormat == TFT_ARGB8888)
- {
- *(GLuint *)dst = SAVAGEPACKCOLOR8888(src[0],src[0],src[0],src[1]);
- src += 2;
- return src;
- }
- else
- {
- *(GLubyte *)dst = SAVAGEPACKCOLORA4L4(src[0],src[1]);
- src += 2;
- return src;
- }
- break;
-
- case GL_ALPHA:
- switch (t->image[level].internalFormat) {
- case TFT_ARGB8888:
- *(GLushort *)dst = SAVAGEPACKCOLOR8888(*src,*src,*src,0);
- src++;
- return src;
- case TFT_L8:
- *dst = *src;
- src++;
- return src;
- }
- break;
- case GL_COLOR_INDEX:
- *dst = *src;
- src++;
- return src;
- break;
- }
- return src;
-}
-
-
__inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint startx, GLuint starty, GLuint reloc)
{
GLuint uMaxTileWidth = gTileWidth[t->texelBytes];
@@ -387,7 +271,7 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
y = starty;
w = image->Width;
- if(t->image[level].baseFormat == GL_COLOR_INDEX)
+ if(image->Format == GL_COLOR_INDEX)
{
if(w < MIN_TILE_CHUNK)
{
@@ -412,7 +296,8 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
for(col = 0; col < image->Width; col++)
{
dst = pBuffer + GetTiledCoordinates(t->texelBytes << 3, w, x + col, y + row);
- src = savageMakeTexel(t, src, dst, level);
+ memcpy (dst, src, t->texelBytes);
+ src += t->texelBytes;
}
}
}
@@ -428,7 +313,8 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
xAdd = (col / (4 * 64)) * 64 + col % 64;
yAdd = row + ((col / 64) & 3) * uChunk;
dst = pBuffer + GetTiledCoordinates(t->texelBytes << 3, 64, x + xAdd, y + yAdd);
- src = savageMakeTexel(t, src, dst,level);
+ memcpy (dst, src, t->texelBytes);
+ src += t->texelBytes;
}
}
}
@@ -442,7 +328,8 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
for(col = 0; col < image->Width; col++)
{
dst = pBuffer + GetTiledCoordinates(t->texelBytes << 3, w, x + xAdd, y + yAdd);
- src = savageMakeTexel(t, src, dst, level);
+ memcpy (dst, src, t->texelBytes);
+ src += t->texelBytes;
}
}
}
@@ -468,7 +355,8 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
for(col = 0; col < image->Width; col++)
{
dst = pBuffer + GetTiledCoordinates(t->texelBytes << 3, w, x + col, y + row);
- src = savageMakeTexel(t, src, dst, level);
+ memcpy (dst, src, t->texelBytes);
+ src += t->texelBytes;
}
}
}
@@ -483,7 +371,8 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
xAdd = (col / (2 * uMaxTileWidth)) * uMaxTileWidth + col % uMaxTileWidth;
yAdd = row + ((col / uMaxTileWidth) & 1) * MIN_TILE_CHUNK;
dst = pBuffer + GetTiledCoordinates(t->texelBytes << 3, w, x + xAdd, y + yAdd);
- src = savageMakeTexel(t, src, dst, level);
+ memcpy (dst, src, t->texelBytes);
+ src += t->texelBytes;
}
}
}
@@ -497,7 +386,8 @@ __inline void savageUploadImage(savageTextureObjectPtr t, GLuint level, GLuint s
for(col = 0; col < image->Width; col++)
{
dst = pBuffer + GetTiledCoordinates(t->texelBytes << 3, w, x + col + xAdd, y + yAdd);
- src = savageMakeTexel(t, src, dst, level);
+ memcpy (dst, src, t->texelBytes);
+ src += t->texelBytes;
}
}
}
@@ -573,9 +463,8 @@ static void savageSetTexWrapping(savageTextureObjectPtr tex, GLenum s, GLenum t)
tex->texParams.tWrapMode = t;
}
-static void savageSetTexFilter(savageContextPtr imesa,
- savageTextureObjectPtr t,
- GLenum minf, GLenum magf)
+static void savageSetTexFilter(savageTextureObjectPtr t,
+ GLenum minf, GLenum magf)
{
t->texParams.minFilter = minf;
t->texParams.magFilter = magf;
@@ -592,145 +481,160 @@ static void savageSetTexBorderColor(savageTextureObjectPtr t, GLubyte color[4])
-static void ReplicateMesaTexState(savageContextPtr imesa,
- savageTextureObjectPtr t,
- struct gl_texture_object *mesatex)
-{
- savageSetTexWrapping(t,mesatex->WrapS,mesatex->WrapT);
- savageSetTexFilter(imesa, t,mesatex->MinFilter,mesatex->MagFilter);
- savageSetTexBorderColor(t,mesatex->_BorderChan);
-}
-
-static savageTextureObjectPtr savageCreateTexObj(savageContextPtr imesa,
- struct gl_texture_object *tObj)
+static savageTextureObjectPtr
+savageAllocTexObj( struct gl_texture_object *texObj )
{
savageTextureObjectPtr t;
- GLuint offset, width, pitch, i, textureFormat, log_pitch, baseFormat;
- struct gl_texture_image *image;
- image = tObj->Image[ 0 ];
- if ( !image ) {
- fprintf(stderr, "no image at level zero - not creating texobj\n");
- return 0;
- }
-
t = (savageTextureObjectPtr) calloc(1,sizeof(*t));
- if (!t)
- return 0;
+ texObj->DriverData = t;
+ if ( t != NULL ) {
- switch( image->Format ) {
- case GL_R3_G3_B2:
- case GL_RGB4:
- t->texelBytes = 2;
- baseFormat = GL_RGB;
- textureFormat = TFT_ARGB4444;
- break;
+ /* Initialize non-image-dependent parts of the state:
+ */
+ t->globj = texObj;
- case GL_RGB5:
- t->texelBytes = 2;
- baseFormat = GL_RGB;
- textureFormat = TFT_ARGB1555;
- break;
+ /* FIXME Something here to set initial values for other parts of
+ * FIXME t->setup?
+ */
+
+ make_empty_list( t );
+
+ savageSetTexWrapping(t,texObj->WrapS,texObj->WrapT);
+ savageSetTexFilter(t,texObj->MinFilter,texObj->MagFilter);
+ savageSetTexBorderColor(t,texObj->_BorderChan);
+ }
+
+ return t;
+}
+
+/* Called by the _mesa_store_teximage[123]d() functions. */
+static const struct gl_texture_format *
+savageChooseTextureFormat( GLcontext *ctx, GLint internalFormat,
+ GLenum format, GLenum type )
+{
+ savageContextPtr imesa = SAVAGE_CONTEXT(ctx);
+ const GLboolean do32bpt = GL_FALSE;
+ const GLboolean force16bpt = GL_FALSE;
+ const GLboolean isSavage4 = (imesa->savageScreen->chipset >= S3_SAVAGE4);
+ (void) format;
+ (void) type;
+
+ switch ( internalFormat ) {
+ case 4:
+ case GL_RGBA:
+ case GL_COMPRESSED_RGBA:
+ switch ( type ) {
+ case GL_UNSIGNED_INT_10_10_10_2:
+ case GL_UNSIGNED_INT_2_10_10_10_REV:
+ return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ return &_mesa_texformat_argb4444;
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ return &_mesa_texformat_argb1555;
+ default:
+ return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444;
+ }
+
+ case 3:
case GL_RGB:
+ case GL_COMPRESSED_RGB:
+ switch ( type ) {
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+ return &_mesa_texformat_argb4444;
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ return &_mesa_texformat_argb1555;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ case GL_UNSIGNED_SHORT_5_6_5_REV:
+ return &_mesa_texformat_rgb565;
+ default:
+ return do32bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565;
+ }
+
+ case GL_RGBA8:
+ case GL_RGBA12:
+ case GL_RGBA16:
+ return !force16bpt ?
+ &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444;
+
+ case GL_RGB10_A2:
+ return !force16bpt ?
+ &_mesa_texformat_rgba8888 : &_mesa_texformat_argb1555;
+
+ case GL_RGBA4:
+ case GL_RGBA2:
+ return &_mesa_texformat_argb4444;
+
+ case GL_RGB5_A1:
+ return &_mesa_texformat_argb1555;
+
case GL_RGB8:
case GL_RGB10:
case GL_RGB12:
case GL_RGB16:
- t->texelBytes = 4;
- baseFormat = GL_RGB;
- textureFormat = TFT_ARGB8888;
- break;
+ return !force16bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_rgb565;
+
+ case GL_RGB5:
+ case GL_RGB4:
+ case GL_R3_G3_B2:
+ return &_mesa_texformat_rgb565;
- case GL_LUMINANCE:
- case GL_LUMINANCE4:
- case GL_LUMINANCE8:
- case GL_LUMINANCE12:
- case GL_LUMINANCE16:
- baseFormat = GL_LUMINANCE;
- if (imesa->savageScreen->chipset >= S3_SAVAGE4) {
- t->texelBytes = 1;
- textureFormat = TFT_L8;
- } else {
- t->texelBytes = 2;
- textureFormat = TFT_ARGB1555;
- }
- break;
case GL_ALPHA:
+ case GL_COMPRESSED_ALPHA:
+ return isSavage4 ? &_mesa_texformat_a8 : (
+ do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444);
case GL_ALPHA4:
+ return isSavage4 ? &_mesa_texformat_a8 : &_mesa_texformat_argb4444;
case GL_ALPHA8:
case GL_ALPHA12:
case GL_ALPHA16:
- baseFormat = GL_ALPHA;
- if (imesa->savageScreen->chipset >= S3_SAVAGE4) {
- t->texelBytes = 1;
- textureFormat = TFT_A8;
- } else {
- t->texelBytes = 4;
- textureFormat = TFT_ARGB8888;
- }
- break;
+ return isSavage4 ? &_mesa_texformat_a8 : (
+ !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444);
+
+ case 1:
+ case GL_LUMINANCE:
+ case GL_COMPRESSED_LUMINANCE:
+ /* no alpha, but use argb1555 in 16bit case to get pure grey values */
+ return isSavage4 ? &_mesa_texformat_l8 : (
+ do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555);
+ case GL_LUMINANCE4:
+ return isSavage4 ? &_mesa_texformat_l8 : &_mesa_texformat_argb1555;
+ case GL_LUMINANCE8:
+ case GL_LUMINANCE12:
+ case GL_LUMINANCE16:
+ return isSavage4 ? &_mesa_texformat_l8 : (
+ !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb1555);
+ case 2:
case GL_LUMINANCE_ALPHA:
+ case GL_COMPRESSED_LUMINANCE_ALPHA:
+ /* Savage4 has a al44 texture format. But it's not supported by Mesa. */
+ return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444;
case GL_LUMINANCE4_ALPHA4:
case GL_LUMINANCE6_ALPHA2:
+ return &_mesa_texformat_argb4444;
case GL_LUMINANCE8_ALPHA8:
case GL_LUMINANCE12_ALPHA4:
case GL_LUMINANCE12_ALPHA12:
case GL_LUMINANCE16_ALPHA16:
- baseFormat = GL_LUMINANCE_ALPHA;
- if(image->Format == GL_LUMINANCE4_ALPHA4 &&
- imesa->savageScreen->chipset >= S3_SAVAGE4)
- {
- t->texelBytes = 1;
- textureFormat = TFT_A4L4;
- }
- else
- {
- t->texelBytes = 4;
- textureFormat = TFT_ARGB8888;
- }
- break;
+ return !force16bpt ? &_mesa_texformat_rgba8888 : &_mesa_texformat_argb4444;
case GL_INTENSITY:
+ case GL_COMPRESSED_INTENSITY:
+ return isSavage4 ? &_mesa_texformat_i8 : (
+ do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444);
case GL_INTENSITY4:
+ return isSavage4 ? &_mesa_texformat_i8 : &_mesa_texformat_argb4444;
case GL_INTENSITY8:
case GL_INTENSITY12:
case GL_INTENSITY16:
- baseFormat = GL_INTENSITY;
- if(image->Format == GL_INTENSITY4)
- {
- t->texelBytes = 2;
- textureFormat = TFT_ARGB4444;
- }
- else
- {
- t->texelBytes = 4;
- textureFormat = TFT_ARGB8888;
- }
- break;
-
- /* case GL_RGBA:*/
- case GL_RGBA2:
- case GL_RGBA4:
- t->texelBytes = 2;
- baseFormat = GL_RGBA;
- textureFormat = TFT_ARGB4444;
- break;
- case GL_RGB5_A1:
- t->texelBytes = 2;
- baseFormat = GL_RGBA;
- textureFormat = TFT_ARGB1555;
- break;
- case GL_RGBA:
- case GL_RGBA8:
- case GL_RGBA12:
- case GL_RGBA16:
- case GL_RGB10_A2:
- t->texelBytes = 4;
- baseFormat = GL_RGBA;
- textureFormat = TFT_ARGB8888;
- break;
-
+ return isSavage4 ? &_mesa_texformat_a8 : (
+ !force16bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444);
+/*
case GL_COLOR_INDEX:
case GL_COLOR_INDEX1_EXT:
case GL_COLOR_INDEX2_EXT:
@@ -738,16 +642,57 @@ static savageTextureObjectPtr savageCreateTexObj(savageContextPtr imesa,
case GL_COLOR_INDEX8_EXT:
case GL_COLOR_INDEX12_EXT:
case GL_COLOR_INDEX16_EXT:
- baseFormat = GL_COLOR_INDEX;
- textureFormat = GL_COLOR_INDEX;
+ return &_mesa_texformat_ci8;
+*/
+ default:
+ _mesa_problem(ctx, "unexpected texture format in %s", __FUNCTION__);
+ return NULL;
+ }
+}
+
+static void savageSetTexImages( savageContextPtr imesa,
+ const struct gl_texture_object *tObj )
+{
+ savageTextureObjectPtr t = (savageTextureObjectPtr) tObj->DriverData;
+ struct gl_texture_image *image = tObj->Image[tObj->BaseLevel];
+ GLuint offset, width, pitch, i, textureFormat, log_pitch;
+
+ assert(t);
+ assert(image);
+
+ switch (image->TexFormat->MesaFormat) {
+ case MESA_FORMAT_ARGB8888:
+ textureFormat = TFT_ARGB8888;
+ t->texelBytes = 4;
+ break;
+ case MESA_FORMAT_ARGB1555:
+ textureFormat = TFT_ARGB1555;
+ t->texelBytes = 2;
+ break;
+ case MESA_FORMAT_ARGB4444:
+ textureFormat = TFT_ARGB4444;
+ t->texelBytes = 2;
+ break;
+ case MESA_FORMAT_RGB565:
+ textureFormat = TFT_RGB565;
+ t->texelBytes = 2;
+ break;
+ case MESA_FORMAT_L8:
+ textureFormat = TFT_L8;
+ t->texelBytes = 1;
+ break;
+ case MESA_FORMAT_I8:
+ textureFormat = TFT_I8;
+ t->texelBytes = 1;
+ break;
+ case MESA_FORMAT_A8:
+ textureFormat = TFT_A8;
t->texelBytes = 1;
break;
default:
- free( t );
- return 0;
+ _mesa_problem(imesa->glCtx, "Bad texture format in %s", __FUNCTION__);
}
-
/* Figure out the size now (and count the levels). Upload won't be done
* until later.
*/
@@ -757,15 +702,12 @@ static savageTextureObjectPtr savageCreateTexObj(savageContextPtr imesa,
t->dirty_images = 0;
t->bound = 0;
-
- t->Pitch = pitch;
- offset = 0;
+ offset = 0;
for ( i = 0 ; i < SAVAGE_TEX_MAXLEVELS && tObj->Image[i] ; i++ ) {
t->image[i].image = tObj->Image[i];
t->image[i].offset = offset;
t->image[i].internalFormat = textureFormat;
- t->image[i].baseFormat = baseFormat;
t->dirty_images |= (1<<i);
offset += t->image[i].image->Height * pitch;
pitch = pitch >> 1;
@@ -774,17 +716,6 @@ static savageTextureObjectPtr savageCreateTexObj(savageContextPtr imesa,
t->totalSize = offset;
t->max_level = i-1;
t->min_level = 0;
- t->globj = tObj;
- t->age = 0;
-
-
- t->current_unit = 0;
-
- ReplicateMesaTexState(imesa, t,tObj);
- tObj->DriverData = t;
- imesa->dirty |= SAVAGE_UPLOAD_CTX;
- make_empty_list( t );
- return t;
}
void savageDestroyTexObj(savageContextPtr imesa, savageTextureObjectPtr t)
@@ -846,23 +777,8 @@ static void savageUploadTexLevel( savageTextureObjectPtr t, int level )
if(image->Border != 0)
fprintf (stderr, "Not supported texture border %d.\n",
(int) image->Border);
-
-
- switch(t->image[level].baseFormat)
- {
- case GL_RGB:
- case GL_RGBA:
- case GL_LUMINANCE:
- case GL_INTENSITY:
- case GL_LUMINANCE_ALPHA:
- case GL_ALPHA:
- case GL_COLOR_INDEX:
- savageTileTex(t, level);
- break;
- default:
- fprintf (stderr, "Not supported texture format %d.\n",
- (GLint) t->image[level].baseFormat);
- }
+
+ savageTileTex(t, level);
}
@@ -1137,10 +1053,9 @@ static void savageUpdateTex0State_s4( GLcontext *ctx )
/* Do 2D texture setup */
-
t = tObj->DriverData;
if (!t) {
- t = savageCreateTexObj( imesa, tObj );
+ t = savageAllocTexObj( tObj );
if (!t)
return;
}
@@ -1151,8 +1066,10 @@ static void savageUpdateTex0State_s4( GLcontext *ctx )
imesa->CurrentTexObj[0] = t;
t->bound = 1;
- if (t->dirty_images)
+ if (t->dirty_images) {
+ savageSetTexImages(imesa, tObj);
savageUploadTexImages(imesa, imesa->CurrentTexObj[0]);
+ }
if (t->MemBlock)
savageUpdateTexLRU( imesa, t );
@@ -1161,8 +1078,7 @@ static void savageUpdateTex0State_s4( GLcontext *ctx )
TexCtrl.ui = imesa->Registers.TexCtrl[0].ui;
TexBlendCtrl.ui = imesa->Registers.TexBlendCtrl[0].ui;
-
- format = t->image[0].baseFormat;
+ format = tObj->Image[tObj->BaseLevel]->Format;
switch (ctx->Texture.Unit[0].EnvMode) {
case GL_REPLACE:
@@ -1476,7 +1392,7 @@ static void savageUpdateTex1State_s4( GLcontext *ctx )
t = tObj->DriverData;
if (!t) {
- t = savageCreateTexObj( imesa, tObj );
+ t = savageAllocTexObj( tObj );
if (!t)
return;
}
@@ -1488,8 +1404,10 @@ static void savageUpdateTex1State_s4( GLcontext *ctx )
t->bound = 2;
- if (t->dirty_images)
+ if (t->dirty_images) {
+ savageSetTexImages(imesa, tObj);
savageUploadTexImages(imesa, imesa->CurrentTexObj[1]);
+ }
if (t->MemBlock)
savageUpdateTexLRU( imesa, t );
@@ -1498,9 +1416,7 @@ static void savageUpdateTex1State_s4( GLcontext *ctx )
TexCtrl.ui = imesa->Registers.TexCtrl[1].ui;
TexBlendCtrl.ui = imesa->Registers.TexBlendCtrl[1].ui;
- format = t->image[0].baseFormat;
- TexDescr.s4.tex1Fmt = t->image[0].internalFormat;
-
+ format = tObj->Image[tObj->BaseLevel]->Format;
switch (ctx->Texture.Unit[1].EnvMode) {
case GL_REPLACE:
@@ -1723,7 +1639,7 @@ static void savageUpdateTexState_s3d( GLcontext *ctx )
/* Do 2D texture setup */
t = tObj->DriverData;
if (!t) {
- t = savageCreateTexObj( imesa, tObj );
+ t = savageAllocTexObj( tObj );
if (!t)
return;
}
@@ -1735,7 +1651,7 @@ static void savageUpdateTexState_s3d( GLcontext *ctx )
t->bound = 1;
if (t->dirty_images) {
- FLUSH_BATCH(imesa);
+ savageSetTexImages(imesa, tObj);
savageUploadTexImages(imesa, imesa->CurrentTexObj[0]);
}
@@ -1746,7 +1662,7 @@ static void savageUpdateTexState_s3d( GLcontext *ctx )
TexCtrl.ui = imesa->Registers.TexCtrl[0].ui;
DrawCtrl.ui = imesa->Registers.DrawCtrl.ui;
- format = t->image[0].baseFormat;
+ format = tObj->Image[tObj->BaseLevel]->Format;
/* FIXME: copied from utah-glx, probably needs some tuning */
switch (ctx->Texture.Unit[0].EnvMode) {
@@ -1939,12 +1855,18 @@ static void savageTexImage2D( GLcontext *ctx, GLenum target, GLint level,
{
savageTextureObjectPtr t = (savageTextureObjectPtr) texObj->DriverData;
if (t) {
- savageDestroyTexObj( SAVAGE_CONTEXT(ctx), t );
- texObj->DriverData = 0;
+ savageSwapOutTexObj( SAVAGE_CONTEXT(ctx), t );
+ } else {
+ t = savageAllocTexObj(texObj);
+ if (!t) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
+ return;
+ }
}
_mesa_store_teximage2d( ctx, target, level, internalFormat,
width, height, border, format, type,
pixels, packing, texObj, texImage );
+ t->dirty_images |= (1 << level);
}
static void savageTexSubImage2D( GLcontext *ctx,
@@ -1959,67 +1881,22 @@ static void savageTexSubImage2D( GLcontext *ctx,
struct gl_texture_image *texImage )
{
savageTextureObjectPtr t = (savageTextureObjectPtr) texObj->DriverData;
+ assert( t ); /* this _should_ be true */
if (t) {
- savageDestroyTexObj( SAVAGE_CONTEXT(ctx), t );
- texObj->DriverData = 0;
+ savageSwapOutTexObj( SAVAGE_CONTEXT(ctx), t );
+ } else {
+ t = savageAllocTexObj(texObj);
+ if (!t) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
+ return;
+ }
}
_mesa_store_texsubimage2d(ctx, target, level, xoffset, yoffset, width,
height, format, type, pixels, packing, texObj,
texImage);
-
-}
-
-#if 0
-static void savageTexImage( GLcontext *ctx,
- GLenum target,
- struct gl_texture_object *tObj,
- GLint level,
- GLint internalFormat,
- const struct gl_texture_image *image )
-{
- savageContextPtr imesa = SAVAGE_CONTEXT( ctx );
- savageTextureObjectPtr t;
-
-
- if (target != GL_TEXTURE_2D)
- return;
-
- if (level >= SAVAGE_TEX_MAXLEVELS)
- return;
-
- t = (savageTextureObjectPtr) tObj->DriverData;
- if (t) {
- /* if this is the current object, it will force an update */
-
- savageDestroyTexObj( imesa, t );
- tObj->DriverData = 0;
- imesa->new_state |= SAVAGE_NEW_TEXTURE;
- }
+ t->dirty_images |= (1 << level);
}
-static void savageTexSubImage( GLcontext *ctx, GLenum target,
- struct gl_texture_object *tObj, GLint level,
- GLint xoffset, GLint yoffset,
- GLsizei width, GLsizei height,
- GLint internalFormat,
- const struct gl_texture_image *image )
-{
- savageContextPtr imesa = SAVAGE_CONTEXT( ctx );
- savageTextureObjectPtr t;
-
- if ( target != GL_TEXTURE_2D )
- return;
-
- t = (savageTextureObjectPtr) tObj->DriverData;
- if (t) {
-
- savageDestroyTexObj( imesa, t );
- tObj->DriverData = 0;
- imesa->new_state |= SAVAGE_NEW_TEXTURE;
- }
-}
-#endif
-
static void savageTexParameter( GLcontext *ctx, GLenum target,
struct gl_texture_object *tObj,
GLenum pname, const GLfloat *params )
@@ -2033,7 +1910,7 @@ static void savageTexParameter( GLcontext *ctx, GLenum target,
switch (pname) {
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
- savageSetTexFilter(imesa, t,tObj->MinFilter,tObj->MagFilter);
+ savageSetTexFilter(t,tObj->MinFilter,tObj->MagFilter);
break;
case GL_TEXTURE_WRAP_S:
@@ -2053,7 +1930,7 @@ static void savageTexParameter( GLcontext *ctx, GLenum target,
}
static void savageBindTexture( GLcontext *ctx, GLenum target,
- struct gl_texture_object *tObj )
+ struct gl_texture_object *tObj )
{
savageContextPtr imesa = SAVAGE_CONTEXT( ctx );
@@ -2117,7 +1994,7 @@ void savageDDInitTextureFuncs( GLcontext *ctx )
ctx->Driver.TexSubImage = savageTexSubImage;
#endif
- ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
+ ctx->Driver.ChooseTextureFormat = savageChooseTextureFormat;
ctx->Driver.TexImage1D = _mesa_store_teximage1d;
ctx->Driver.TexImage2D = savageTexImage2D;
ctx->Driver.TexImage3D = _mesa_store_teximage3d;
diff --git a/xc/lib/GL/mesa/src/drv/savage/savagetex.h b/xc/lib/GL/mesa/src/drv/savage/savagetex.h
index 3af756481..d2925d088 100755
--- a/xc/lib/GL/mesa/src/drv/savage/savagetex.h
+++ b/xc/lib/GL/mesa/src/drv/savage/savagetex.h
@@ -68,8 +68,6 @@ struct savage_texture_object_t {
GLuint age;
- GLuint Pitch;
- GLuint Height;
GLuint texelBytes;
GLuint totalSize;
GLuint bound;
@@ -87,7 +85,6 @@ struct savage_texture_object_t {
GLuint offset; /* into BufAddr */
GLuint height;
GLuint internalFormat;
- GLuint baseFormat;
} image[SAVAGE_TEX_MAXLEVELS];
/* Support for multitexture.