summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2001-06-13 14:56:14 +0000
committerBrian Paul <[email protected]>2001-06-13 14:56:14 +0000
commitcd1cefae9146fc14b35ee93a04bdb1b1590fba7b (patch)
tree01f74b0349d478ed65822a3271ce7cdf8384a304
parentcc22179cd855dad85a28c40416873a07e8b7cc0c (diff)
Allow different max texture sizes for 1/2D, 3D and cube maps.
-rw-r--r--src/mesa/drivers/glide/fxdd.c1
-rw-r--r--src/mesa/main/config.h10
-rw-r--r--src/mesa/main/context.c9
-rw-r--r--src/mesa/main/get.c26
-rw-r--r--src/mesa/main/mtypes.h6
-rw-r--r--src/mesa/main/teximage.c138
-rw-r--r--src/mesa/main/texobj.c24
-rw-r--r--src/mesa/main/texstate.c29
-rw-r--r--src/mesa/main/texstore.c9
9 files changed, 186 insertions, 66 deletions
diff --git a/src/mesa/drivers/glide/fxdd.c b/src/mesa/drivers/glide/fxdd.c
index 70f8e639b15..117e9d7dead 100644
--- a/src/mesa/drivers/glide/fxdd.c
+++ b/src/mesa/drivers/glide/fxdd.c
@@ -754,7 +754,6 @@ fxDDInitFxMesaContext(fxMesaContext fxMesa)
fxMesa->textureAlign = FX_grGetInteger(FX_TEXTURE_ALIGN);
fxMesa->glCtx->Const.MaxTextureLevels = 9;
- fxMesa->glCtx->Const.MaxTextureSize = 256;
fxMesa->glCtx->Const.MaxTextureUnits = fxMesa->emulateTwoTMUs ? 2 : 1;
fxMesa->new_state = _NEW_ALL;
diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h
index cf57106a330..805da1e7b7f 100644
--- a/src/mesa/main/config.h
+++ b/src/mesa/main/config.h
@@ -1,4 +1,4 @@
-/* $Id: config.h,v 1.31 2001/05/14 23:11:12 brianp Exp $ */
+/* $Id: config.h,v 1.32 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -99,9 +99,15 @@
/* Max texture palette / color table size */
#define MAX_COLOR_TABLE_SIZE 256
-/* Number of texture levels */
+/* Number of 1D/2D texture mipmap levels */
#define MAX_TEXTURE_LEVELS 12
+/* Number of 3D texture mipmap levels */
+#define MAX_3D_TEXTURE_LEVELS 8
+
+/* Number of cube texture mipmap levels */
+#define MAX_CUBE_TEXTURE_LEVELS 12
+
/* Number of texture units - GL_ARB_multitexture */
#define MAX_TEXTURE_UNITS 8
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 9da1526535e..63c30f2ee5d 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1,4 +1,4 @@
-/* $Id: context.c,v 1.142 2001/06/12 22:08:41 brianp Exp $ */
+/* $Id: context.c,v 1.143 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -728,10 +728,13 @@ init_attrib_groups( GLcontext *ctx )
assert(ctx);
+ assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
+ assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
+
/* Constants, may be overriden by device drivers */
ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
- ctx->Const.MaxTextureSize = 1 << (MAX_TEXTURE_LEVELS - 1);
- ctx->Const.MaxCubeTextureSize = ctx->Const.MaxTextureSize;
+ ctx->Const.Max3DTextureLevels = MAX_3D_TEXTURE_LEVELS;
+ ctx->Const.MaxCubeTextureLevels = MAX_CUBE_TEXTURE_LEVELS;
ctx->Const.MaxTextureUnits = MAX_TEXTURE_UNITS;
ctx->Const.MaxTextureMaxAnisotropy = MAX_TEXTURE_MAX_ANISOTROPY;
ctx->Const.MaxArrayLockSize = MAX_ARRAY_LOCK_SIZE;
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 36487df9121..987234a0a4d 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1,4 +1,4 @@
-/* $Id: get.c,v 1.62 2001/06/12 22:08:41 brianp Exp $ */
+/* $Id: get.c,v 1.63 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -583,8 +583,10 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
*params = INT_TO_BOOL(MAX_PROJECTION_STACK_DEPTH);
break;
case GL_MAX_TEXTURE_SIZE:
+ *params = INT_TO_BOOL(1 << (ctx->Const.MaxTextureLevels - 1));
+ break;
case GL_MAX_3D_TEXTURE_SIZE:
- *params = INT_TO_BOOL(ctx->Const.MaxTextureSize);
+ *params = INT_TO_BOOL(1 << (ctx->Const.Max3DTextureLevels - 1));
break;
case GL_MAX_TEXTURE_STACK_DEPTH:
*params = INT_TO_BOOL(MAX_TEXTURE_STACK_DEPTH);
@@ -994,7 +996,7 @@ _mesa_GetBooleanv( GLenum pname, GLboolean *params )
return;
case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
if (ctx->Extensions.ARB_texture_cube_map)
- *params = INT_TO_BOOL(ctx->Const.MaxCubeTextureSize);
+ *params = INT_TO_BOOL(1 << (ctx->Const.MaxCubeTextureLevels - 1));
else
_mesa_error(ctx, GL_INVALID_ENUM, "glGetBooleanv");
break;
@@ -1861,8 +1863,10 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
*params = (GLdouble) MAX_PROJECTION_STACK_DEPTH;
break;
case GL_MAX_TEXTURE_SIZE:
+ *params = (GLdouble) (1 << (ctx->Const.MaxTextureLevels - 1));
+ break;
case GL_MAX_3D_TEXTURE_SIZE:
- *params = (GLdouble) ctx->Const.MaxTextureSize;
+ *params = (GLdouble) (1 << (ctx->Const.Max3DTextureLevels - 1));
break;
case GL_MAX_TEXTURE_STACK_DEPTH:
*params = (GLdouble) MAX_TEXTURE_STACK_DEPTH;
@@ -2272,7 +2276,7 @@ _mesa_GetDoublev( GLenum pname, GLdouble *params )
return;
case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
if (ctx->Extensions.ARB_texture_cube_map)
- *params = (GLdouble) ctx->Const.MaxCubeTextureSize;
+ *params = (GLdouble) (1 << (ctx->Const.MaxCubeTextureLevels - 1));
else
_mesa_error(ctx, GL_INVALID_ENUM, "glGetDoublev");
return;
@@ -3139,8 +3143,10 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
*params = (GLfloat) MAX_PROJECTION_STACK_DEPTH;
break;
case GL_MAX_TEXTURE_SIZE:
+ *params = (GLfloat) (1 << (ctx->Const.MaxTextureLevels - 1));
+ break;
case GL_MAX_3D_TEXTURE_SIZE:
- *params = (GLfloat) ctx->Const.MaxTextureSize;
+ *params = (GLfloat) (1 << (ctx->Const.Max3DTextureLevels - 1));
break;
case GL_MAX_TEXTURE_STACK_DEPTH:
*params = (GLfloat) MAX_TEXTURE_STACK_DEPTH;
@@ -3552,7 +3558,7 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params )
return;
case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
if (ctx->Extensions.ARB_texture_cube_map)
- *params = (GLfloat) ctx->Const.MaxCubeTextureSize;
+ *params = (GLfloat) (1 << (ctx->Const.MaxCubeTextureLevels - 1));
else
_mesa_error(ctx, GL_INVALID_ENUM, "glGetFloatv");
return;
@@ -4393,8 +4399,10 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
*params = (GLint) MAX_PROJECTION_STACK_DEPTH;
break;
case GL_MAX_TEXTURE_SIZE:
+ *params = (1 << (ctx->Const.MaxTextureLevels - 1));
+ break;
case GL_MAX_3D_TEXTURE_SIZE:
- *params = ctx->Const.MaxTextureSize;
+ *params = (1 << (ctx->Const.Max3DTextureLevels - 1));
break;
case GL_MAX_TEXTURE_STACK_DEPTH:
*params = (GLint) MAX_TEXTURE_STACK_DEPTH;
@@ -4804,7 +4812,7 @@ _mesa_GetIntegerv( GLenum pname, GLint *params )
return;
case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
if (ctx->Extensions.ARB_texture_cube_map)
- *params = ctx->Const.MaxCubeTextureSize;
+ *params = (1 << (ctx->Const.MaxCubeTextureLevels - 1));
else
_mesa_error(ctx, GL_INVALID_ENUM, "glGetIntegerv");
return;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index fce26161126..80a8022f120 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1,4 +1,4 @@
-/* $Id: mtypes.h,v 1.45 2001/06/12 22:08:41 brianp Exp $ */
+/* $Id: mtypes.h,v 1.46 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -1156,9 +1156,9 @@ struct gl_frame_buffer {
* but are never changed after that.
*/
struct gl_constants {
- GLint MaxTextureSize;
- GLint MaxCubeTextureSize;
GLint MaxTextureLevels;
+ GLint Max3DTextureLevels;
+ GLint MaxCubeTextureLevels;
GLuint MaxTextureUnits;
GLfloat MaxTextureMaxAnisotropy; /* GL_EXT_texture_filter_anisotropic */
GLuint MaxArrayLockSize;
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 0dbbb187c67..0b535d1ecbd 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1,4 +1,4 @@
-/* $Id: teximage.c,v 1.96 2001/06/12 22:05:34 brianp Exp $ */
+/* $Id: teximage.c,v 1.97 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -443,6 +443,7 @@ _mesa_select_tex_image(GLcontext *ctx, const struct gl_texture_unit *texUnit,
GLenum target, GLint level)
{
ASSERT(texUnit);
+ ASSERT(level < MAX_TEXTURE_LEVELS);
switch (target) {
case GL_TEXTURE_1D:
return texUnit->Current1D->Image[level];
@@ -631,6 +632,7 @@ texture_error_check( GLcontext *ctx, GLenum target,
{
GLboolean isProxy;
GLint iformat;
+ GLint maxLevels = 0, maxTextureSize;
if (dimensions == 1) {
isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_1D);
@@ -638,6 +640,7 @@ texture_error_check( GLcontext *ctx, GLenum target,
_mesa_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.MaxTextureLevels;
}
else if (dimensions == 2) {
isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_2D ||
@@ -649,6 +652,10 @@ texture_error_check( GLcontext *ctx, GLenum target,
_mesa_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
return GL_TRUE;
}
+ if (target == GL_PROXY_TEXTURE_2D && target == GL_TEXTURE_2D)
+ maxLevels = ctx->Const.MaxTextureLevels;
+ else
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
}
else if (dimensions == 3) {
isProxy = (GLboolean) (target == GL_PROXY_TEXTURE_3D);
@@ -656,12 +663,16 @@ texture_error_check( GLcontext *ctx, GLenum target,
_mesa_error( ctx, GL_INVALID_ENUM, "glTexImage3D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.Max3DTextureLevels;
}
else {
_mesa_problem( ctx, "bad dims in texture_error_check" );
return GL_TRUE;
}
+ ASSERT(maxLevels > 0);
+ maxTextureSize = 1 << (maxLevels - 1);
+
/* Border */
if (border != 0 && border != 1) {
if (!isProxy) {
@@ -673,7 +684,7 @@ texture_error_check( GLcontext *ctx, GLenum target,
}
/* Width */
- if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize
+ if (width < 2 * border || width > 2 + maxTextureSize
|| logbase2( width - 2 * border ) < 0) {
if (!isProxy) {
char message[100];
@@ -685,7 +696,7 @@ texture_error_check( GLcontext *ctx, GLenum target,
/* Height */
if (dimensions >= 2) {
- if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize
+ if (height < 2 * border || height > 2 + maxTextureSize
|| logbase2( height - 2 * border ) < 0) {
if (!isProxy) {
char message[100];
@@ -709,7 +720,7 @@ texture_error_check( GLcontext *ctx, GLenum target,
/* Depth */
if (dimensions >= 3) {
- if (depth < 2 * border || depth > 2 + ctx->Const.MaxTextureSize
+ if (depth < 2 * border || depth > 2 + maxTextureSize
|| logbase2( depth - 2 * border ) < 0) {
if (!isProxy) {
char message[100];
@@ -721,7 +732,7 @@ texture_error_check( GLcontext *ctx, GLenum target,
}
/* Level */
- if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
+ if (level < 0 || level >= maxLevels) {
if (!isProxy) {
char message[100];
sprintf(message, "glTexImage%dD(level=%d)", dimensions, level);
@@ -784,12 +795,14 @@ subtexture_error_check( GLcontext *ctx, GLuint dimensions,
{
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
struct gl_texture_image *destTex;
+ GLint maxLevels = 0;
if (dimensions == 1) {
if (target != GL_TEXTURE_1D) {
_mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.MaxTextureLevels;
}
else if (dimensions == 2) {
if (ctx->Extensions.ARB_texture_cube_map) {
@@ -804,19 +817,26 @@ subtexture_error_check( GLcontext *ctx, GLuint dimensions,
_mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
return GL_TRUE;
}
+ if (target == GL_PROXY_TEXTURE_2D && target == GL_TEXTURE_2D)
+ maxLevels = ctx->Const.MaxTextureLevels;
+ else
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
}
else if (dimensions == 3) {
if (target != GL_TEXTURE_3D) {
_mesa_error( ctx, GL_INVALID_ENUM, "glTexSubImage3D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.Max3DTextureLevels;
}
else {
_mesa_problem( ctx, "bad dims in texture_error_check" );
return GL_TRUE;
}
- if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
+ ASSERT(maxLevels > 0);
+
+ if (level < 0 || level >= maxLevels) {
char message[100];
sprintf(message, "glTexSubImage2D(level=%d)", level);
_mesa_error(ctx, GL_INVALID_ENUM, message);
@@ -901,12 +921,14 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
GLint width, GLint height, GLint border )
{
GLint iformat;
+ GLint maxLevels = 0, maxTextureSize;
if (dimensions == 1) {
if (target != GL_TEXTURE_1D) {
_mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.MaxTextureLevels;
}
else if (dimensions == 2) {
if (ctx->Extensions.ARB_texture_cube_map) {
@@ -921,8 +943,15 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
_mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
return GL_TRUE;
}
+ if (target == GL_PROXY_TEXTURE_2D && target == GL_TEXTURE_2D)
+ maxLevels = ctx->Const.MaxTextureLevels;
+ else
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
}
+ ASSERT(maxLevels > 0);
+ maxTextureSize = 1 << (maxLevels - 1);
+
/* Border */
if (border != 0 && border != 1) {
char message[100];
@@ -932,7 +961,7 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
}
/* Width */
- if (width < 2 * border || width > 2 + ctx->Const.MaxTextureSize
+ if (width < 2 * border || width > 2 + maxTextureSize
|| logbase2( width - 2 * border ) < 0) {
char message[100];
sprintf(message, "glCopyTexImage%dD(width=%d)", dimensions, width);
@@ -942,7 +971,7 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
/* Height */
if (dimensions >= 2) {
- if (height < 2 * border || height > 2 + ctx->Const.MaxTextureSize
+ if (height < 2 * border || height > 2 + maxTextureSize
|| logbase2( height - 2 * border ) < 0) {
char message[100];
sprintf(message, "glCopyTexImage%dD(height=%d)", dimensions, height);
@@ -961,14 +990,14 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
}
/* Level */
- if (level < 0 || level>=ctx->Const.MaxTextureLevels) {
+ if (level < 0 || level >= maxLevels) {
char message[100];
sprintf(message, "glCopyTexImage%dD(level=%d)", dimensions, level);
_mesa_error(ctx, GL_INVALID_VALUE, message);
return GL_TRUE;
}
- iformat = _mesa_base_tex_format( ctx, internalFormat );
+ iformat = _mesa_base_tex_format(ctx, internalFormat);
if (iformat < 0) {
char message[100];
sprintf(message, "glCopyTexImage%dD(internalFormat)", dimensions);
@@ -989,12 +1018,14 @@ copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
{
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
struct gl_texture_image *teximage;
+ GLint maxLevels = 0;
if (dimensions == 1) {
if (target != GL_TEXTURE_1D) {
_mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.MaxTextureLevels;
}
else if (dimensions == 2) {
if (ctx->Extensions.ARB_texture_cube_map) {
@@ -1009,15 +1040,22 @@ copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
_mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
return GL_TRUE;
}
+ if (target == GL_PROXY_TEXTURE_2D && target == GL_TEXTURE_2D)
+ maxLevels = ctx->Const.MaxTextureLevels;
+ else
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
}
else if (dimensions == 3) {
if (target != GL_TEXTURE_3D) {
_mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage3D(target)" );
return GL_TRUE;
}
+ maxLevels = ctx->Const.Max3DTextureLevels;
}
- if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
+ ASSERT(maxLevels > 0);
+
+ if (level < 0 || level >= maxLevels) {
char message[100];
sprintf(message, "glCopyTexSubImage%dD(level=%d)", dimensions, level);
_mesa_error(ctx, GL_INVALID_VALUE, message);
@@ -1101,10 +1139,30 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
const struct gl_texture_unit *texUnit;
const struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
+ GLint maxLevels = 0;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
+ texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]);
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ if (!texObj || is_proxy_target(target)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
+ return;
+ }
+
+ if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D) {
+ maxLevels = ctx->Const.MaxTextureLevels;
+ }
+ else if (target == GL_TEXTURE_3D) {
+ maxLevels = ctx->Const.Max3DTextureLevels;
+ }
+ else {
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
+ }
+
+ ASSERT(maxLevels > 0);
+
+ if (level < 0 || level >= maxLevels) {
_mesa_error( ctx, GL_INVALID_VALUE, "glGetTexImage(level)" );
return;
}
@@ -1133,13 +1191,6 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
if (!pixels)
return;
- texUnit = &(ctx->Texture.Unit[ctx->Texture.CurrentUnit]);
- texObj = _mesa_select_tex_object(ctx, texUnit, target);
- if (!texObj || is_proxy_target(target)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(target)");
- return;
- }
-
texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
if (!texImage) {
/* invalid mipmap level, not an error */
@@ -1173,7 +1224,7 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
}
_mesa_pack_index_span(ctx, width, type, dest,
indexRow, &ctx->Pack,
- ctx->_ImageTransferState);
+ 0 /* no image transfer */);
}
else if (format == GL_DEPTH_COMPONENT) {
GLfloat depthRow[MAX_WIDTH];
@@ -1195,7 +1246,7 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
}
_mesa_pack_rgba_span(ctx, width, (const GLchan (*)[4])rgba,
format, type, dest, &ctx->Pack,
- ctx->_ImageTransferState);
+ 0 /* no image transfer */);
} /* format */
} /* row */
} /* img */
@@ -1414,7 +1465,9 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
}
if (error) {
/* if error, clear all proxy texture image parameters */
- if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
+ const GLint maxLevels = (target == GL_PROXY_TEXTURE_2D) ?
+ ctx->Const.MaxTextureLevels : ctx->Const.MaxCubeTextureLevels;
+ if (level >= 0 && level < maxLevels) {
clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]);
}
}
@@ -1520,7 +1573,7 @@ _mesa_TexImage3D( GLenum target, GLint level, GLenum internalFormat,
}
if (error) {
/* if error, clear all proxy texture image parameters */
- if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
+ if (level >= 0 && level < ctx->Const.Max3DTextureLevels) {
clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]);
}
}
@@ -2013,7 +2066,7 @@ _mesa_CompressedTexImage1DARB(GLenum target, GLint level,
}
}
else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)" );
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage1DARB(target)");
return;
}
}
@@ -2106,13 +2159,15 @@ _mesa_CompressedTexImage2DARB(GLenum target, GLint level,
}
if (error) {
/* if error, clear all proxy texture image parameters */
- if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
+ const GLint maxLevels = (target == GL_PROXY_TEXTURE_2D) ?
+ ctx->Const.MaxTextureLevels : ctx->Const.MaxCubeTextureLevels;
+ if (level >= 0 && level < maxLevels) {
clear_teximage_fields(ctx->Texture.Proxy2D->Image[level]);
}
}
}
else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)" );
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage2DARB(target)");
return;
}
}
@@ -2203,13 +2258,13 @@ _mesa_CompressedTexImage3DARB(GLenum target, GLint level,
}
if (error) {
/* if error, clear all proxy texture image parameters */
- if (level >= 0 && level < ctx->Const.MaxTextureLevels) {
+ if (level >= 0 && level < ctx->Const.Max3DTextureLevels) {
clear_teximage_fields(ctx->Texture.Proxy3D->Image[level]);
}
}
}
else {
- _mesa_error( ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)" );
+ _mesa_error(ctx, GL_INVALID_ENUM, "glCompressedTexImage3DARB(target)");
return;
}
}
@@ -2326,11 +2381,31 @@ _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
const struct gl_texture_unit *texUnit;
const struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
+ GLint maxLevels;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)" );
+ texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ if (!texObj) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImageARB");
+ return;
+ }
+
+ if (target == GL_TEXTURE_1D || target == GL_TEXTURE_2D) {
+ maxLevels = ctx->Const.MaxTextureLevels;
+ }
+ else if (target == GL_TEXTURE_3D) {
+ maxLevels = ctx->Const.Max3DTextureLevels;
+ }
+ else {
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
+ }
+
+ ASSERT(maxLevels > 0);
+
+ if (level < 0 || level >= maxLevels) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)");
return;
}
@@ -2339,10 +2414,7 @@ _mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img)
return;
}
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- texObj = _mesa_select_tex_object(ctx, texUnit, target);
texImage = _mesa_select_tex_image(ctx, texUnit, target, level);
-
if (!texImage) {
/* invalid mipmap level */
_mesa_error(ctx, GL_INVALID_VALUE, "glGetCompressedTexImageARB(level)");
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 644d99a9e78..7f46619203e 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1,4 +1,4 @@
-/* $Id: texobj.c,v 1.48 2001/04/25 18:21:05 brianp Exp $ */
+/* $Id: texobj.c,v 1.49 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -181,7 +181,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
struct gl_texture_object *t )
{
const GLint baseLevel = t->BaseLevel;
- GLint maxLog2 = 0;
+ GLint maxLog2 = 0, maxLevels = 0;
t->Complete = GL_TRUE; /* be optimistic */
@@ -195,20 +195,30 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
/* Compute _MaxLevel */
if (t->Dimensions == 1) {
maxLog2 = t->Image[baseLevel]->WidthLog2;
+ maxLevels = ctx->Const.MaxTextureLevels;
}
else if (t->Dimensions == 2 || t->Dimensions == 6) {
maxLog2 = MAX2(t->Image[baseLevel]->WidthLog2,
t->Image[baseLevel]->HeightLog2);
+ maxLevels = (t->Dimensions == 2) ?
+ ctx->Const.MaxTextureLevels : ctx->Const.MaxCubeTextureLevels;
}
else if (t->Dimensions == 3) {
GLint max = MAX2(t->Image[baseLevel]->WidthLog2,
t->Image[baseLevel]->HeightLog2);
maxLog2 = MAX2(max, (GLint)(t->Image[baseLevel]->DepthLog2));
+ maxLevels = ctx->Const.Max3DTextureLevels;
}
+ else {
+ _mesa_problem(ctx, "Bad t->Dimension in _mesa_test_texobj_completeness");
+ return;
+ }
+
+ ASSERT(maxLevels > 0);
t->_MaxLevel = baseLevel + maxLog2;
t->_MaxLevel = MIN2(t->_MaxLevel, t->MaxLevel);
- t->_MaxLevel = MIN2(t->_MaxLevel, ctx->Const.MaxTextureLevels - 1);
+ t->_MaxLevel = MIN2(t->_MaxLevel, maxLevels - 1);
/* Compute _MaxLambda = q - b (see the 1.2 spec) used during mipmapping */
t->_MaxLambda = (GLfloat) (t->_MaxLevel - t->BaseLevel);
@@ -272,7 +282,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
if (t->Dimensions == 1) {
/* Test 1-D mipmaps */
GLuint width = t->Image[baseLevel]->Width2;
- for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
+ for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
@@ -297,7 +307,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
/* Test 2-D mipmaps */
GLuint width = t->Image[baseLevel]->Width2;
GLuint height = t->Image[baseLevel]->Height2;
- for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
+ for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
@@ -331,7 +341,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
GLuint width = t->Image[baseLevel]->Width2;
GLuint height = t->Image[baseLevel]->Height2;
GLuint depth = t->Image[baseLevel]->Depth2;
- for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
+ for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
@@ -372,7 +382,7 @@ _mesa_test_texobj_completeness( const GLcontext *ctx,
/* make sure 6 cube faces are consistant */
GLuint width = t->Image[baseLevel]->Width2;
GLuint height = t->Image[baseLevel]->Height2;
- for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
+ for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 9615684a013..09bf872fe48 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -1,4 +1,4 @@
-/* $Id: texstate.c,v 1.52 2001/06/12 22:08:41 brianp Exp $ */
+/* $Id: texstate.c,v 1.53 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -1133,19 +1133,36 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
const struct gl_texture_image *img = NULL;
GLuint dimensions;
GLboolean isProxy;
+ GLint maxLevels;
ASSERT_OUTSIDE_BEGIN_END(ctx);
- if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
- _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
- return;
- }
-
dimensions = tex_image_dimensions(ctx, target); /* 1, 2 or 3 */
if (dimensions == 0) {
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
return;
}
+ switch (target) {
+ case GL_TEXTURE_1D:
+ case GL_PROXY_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_PROXY_TEXTURE_2D:
+ maxLevels = ctx->Const.MaxTextureLevels;
+ break;
+ case GL_TEXTURE_3D:
+ case GL_PROXY_TEXTURE_3D:
+ maxLevels = ctx->Const.Max3DTextureLevels;
+ break;
+ default:
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
+ break;
+ }
+
+ if (level < 0 || level >= maxLevels) {
+ _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
+ return;
+ }
+
img = _mesa_select_tex_image(ctx, texUnit, target, level);
if (!img || !img->TexFormat) {
/* undefined texture image */
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index 0947e116226..792f58bb975 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -1,4 +1,4 @@
-/* $Id: texstore.c,v 1.27 2001/05/24 14:47:56 brianp Exp $ */
+/* $Id: texstore.c,v 1.28 2001/06/13 14:56:14 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -1544,6 +1544,7 @@ _mesa_generate_mipmap(GLcontext *ctx,
0 };
const GLenum *targets;
GLuint level;
+ GLint maxLevels = 0;
ASSERT(texObj);
ASSERT(texObj->Image[texObj->BaseLevel]);
@@ -1551,15 +1552,19 @@ _mesa_generate_mipmap(GLcontext *ctx,
switch (texObj->Dimensions) {
case 1:
targets = targets1D;
+ maxLevels = ctx->Const.MaxTextureLevels;
break;
case 2:
targets = targets2D;
+ maxLevels = ctx->Const.MaxTextureLevels;
break;
case 3:
targets = targets3D;
+ maxLevels = ctx->Const.Max3DTextureLevels;
break;
case 6:
targets = targetsCube;
+ maxLevels = ctx->Const.MaxCubeTextureLevels;
break;
default:
_mesa_problem(ctx,
@@ -1568,7 +1573,7 @@ _mesa_generate_mipmap(GLcontext *ctx,
}
for (level = texObj->BaseLevel; level < texObj->MaxLevel
- && level < ctx->Const.MaxTextureLevels - 1; level++) {
+ && level < maxLevels - 1; level++) {
/* generate image[level+1] from image[level] */
const struct gl_texture_image *srcImage;
struct gl_texture_image *dstImage;