Commit e6eaa85a authored by Brian Paul's avatar Brian Paul

mesa: rework texture size error checking

There are two aspects to texture image size checking:
1. Are the width, height, depth legal values (not negative, not larger
   than the max size for the mipmap level, etc)?
2. Is the texture just too large to handle?  For example, we might not be
   able to really allocate memory for a 3D texture of maxSize x maxSize x
   maxSize.

Previously, we did (1) via the ctx->Driver.TestProxyTextureImage() hook
but those tests are really device-independent.  Now we do (2) via that
hook since the max texture memory and texture shape are device-dependent.

Also, (1) is now done outside the general texture parameter error checking
functions because of the special interaction with proxy textures.  The
recently introduced PROXY_ERROR token is removed.

The teximage() and copyteximage() functions are bit simpler now (less
if-then nesting, etc.)
Reviewed-by: Jose Fonseca's avatarJose Fonseca <jfonseca@vmware.com>
parent ce2ae3c3
......@@ -251,14 +251,14 @@ struct dd_function_table {
struct gl_texture_object *texObj);
/**
* Called by glTexImage[123]D when user specifies a proxy texture
* target.
*
* \return GL_TRUE if the proxy test passes, or GL_FALSE if the test fails.
* Called by glTexImage, glCompressedTexImage, glCopyTexImage
* and glTexStorage to check if the dimensions of the texture image
* are too large.
* \param target any GL_PROXY_TEXTURE_x target
* \return GL_TRUE if the image is OK, GL_FALSE if too large
*/
GLboolean (*TestProxyTexImage)(struct gl_context *ctx, GLenum target,
GLint level, GLint internalFormat,
GLenum format, GLenum type,
GLint level, gl_format format,
GLint width, GLint height,
GLint depth, GLint border);
/*@}*/
......
This diff is collapsed.
......@@ -128,8 +128,8 @@ _mesa_max_texture_levels(struct gl_context *ctx, GLenum target);
extern GLboolean
_mesa_test_proxy_teximage(struct gl_context *ctx, GLenum target, GLint level,
GLint internalFormat, GLenum format, GLenum type,
GLint width, GLint height, GLint depth, GLint border);
gl_format format,
GLint width, GLint height, GLint depth, GLint border);
extern GLuint
......
......@@ -125,12 +125,12 @@ static void
setup_texstorage(struct gl_context *ctx,
struct gl_texture_object *texObj,
GLuint dims,
gl_format texFormat,
GLsizei levels, GLenum internalFormat,
GLsizei width, GLsizei height, GLsizei depth)
{
const GLenum target = texObj->Target;
const GLuint numFaces = _mesa_num_tex_faces(target);
gl_format texFormat;
GLint level, levelWidth = width, levelHeight = height, levelDepth = depth;
GLuint face;
......@@ -139,9 +139,6 @@ setup_texstorage(struct gl_context *ctx,
assert(height > 0);
assert(depth > 0);
texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0,
internalFormat, GL_NONE, GL_NONE);
/* Set up all the texture object's gl_texture_images */
for (level = 0; level < levels; level++) {
for (face = 0; face < numFaces; face++) {
......@@ -360,19 +357,23 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
{
struct gl_texture_object *texObj;
GLboolean sizeOK;
GLenum proxyTarget = _mesa_get_proxy_target(target);
gl_format texFormat;
GET_CURRENT_CONTEXT(ctx);
texObj = _mesa_get_current_tex_object(ctx, target);
if (tex_storage_error_check(ctx, dims, target, levels,
internalformat, width, height, depth)) {
return; /* error was recorded */
}
sizeOK = ctx->Driver.TestProxyTexImage(ctx, proxyTarget, 0,
internalformat, GL_NONE, GL_NONE,
texObj = _mesa_get_current_tex_object(ctx, target);
assert(texObj);
texFormat = _mesa_choose_texture_format(ctx, texObj, target, 0,
internalformat, GL_NONE, GL_NONE);
assert(texFormat != MESA_FORMAT_NONE);
sizeOK = ctx->Driver.TestProxyTexImage(ctx, target, 0, texFormat,
width, height, depth, 0);
if (!sizeOK) {
......@@ -388,7 +389,7 @@ texstorage(GLuint dims, GLenum target, GLsizei levels, GLenum internalformat,
}
}
else {
setup_texstorage(ctx, texObj, dims, levels, internalformat,
setup_texstorage(ctx, texObj, dims, texFormat, levels, internalformat,
width, height, depth);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment