summaryrefslogtreecommitdiff
path: root/src/mesa/main/teximage.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/teximage.c')
-rw-r--r--src/mesa/main/teximage.c433
1 files changed, 209 insertions, 224 deletions
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 36557f19fd..e3d4404759 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -1,8 +1,9 @@
/*
- * Mesa 3-D graphics library
- * Version: 7.1
+ * mesa 3-D graphics library
+ * Version: 7.5
*
- * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -37,6 +38,7 @@
#endif
#include "fbobject.h"
#include "framebuffer.h"
+#include "hash.h"
#include "image.h"
#include "imports.h"
#include "macros.h"
@@ -241,36 +243,33 @@ _mesa_base_tex_format( GLcontext *ctx, GLint internalFormat )
}
}
- if (ctx->Extensions.SGIX_depth_texture ||
- ctx->Extensions.ARB_depth_texture) {
+ if (ctx->Extensions.ARB_depth_texture) {
switch (internalFormat) {
case GL_DEPTH_COMPONENT:
- case GL_DEPTH_COMPONENT16_SGIX:
- case GL_DEPTH_COMPONENT24_SGIX:
- case GL_DEPTH_COMPONENT32_SGIX:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
return GL_DEPTH_COMPONENT;
default:
; /* fallthrough */
}
}
- if (ctx->Extensions.ARB_texture_compression) {
- switch (internalFormat) {
- case GL_COMPRESSED_ALPHA:
- return GL_ALPHA;
- case GL_COMPRESSED_LUMINANCE:
- return GL_LUMINANCE;
- case GL_COMPRESSED_LUMINANCE_ALPHA:
- return GL_LUMINANCE_ALPHA;
- case GL_COMPRESSED_INTENSITY:
- return GL_INTENSITY;
- case GL_COMPRESSED_RGB:
- return GL_RGB;
- case GL_COMPRESSED_RGBA:
- return GL_RGBA;
- default:
- ; /* fallthrough */
- }
+ switch (internalFormat) {
+ case GL_COMPRESSED_ALPHA:
+ return GL_ALPHA;
+ case GL_COMPRESSED_LUMINANCE:
+ return GL_LUMINANCE;
+ case GL_COMPRESSED_LUMINANCE_ALPHA:
+ return GL_LUMINANCE_ALPHA;
+ case GL_COMPRESSED_INTENSITY:
+ return GL_INTENSITY;
+ case GL_COMPRESSED_RGB:
+ return GL_RGB;
+ case GL_COMPRESSED_RGBA:
+ return GL_RGBA;
+ default:
+ ; /* fallthrough */
}
if (ctx->Extensions.TDFX_texture_compression_FXT1) {
@@ -389,9 +388,10 @@ _mesa_base_tex_format( GLcontext *ctx, GLint internalFormat )
* index, depth, stencil, etc).
* \param format the image format value (may by an internal texture format)
* \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
+ * XXX maybe move this func to image.c
*/
-static GLboolean
-is_color_format(GLenum format)
+GLboolean
+_mesa_is_color_format(GLenum format)
{
switch (format) {
case GL_RED:
@@ -492,6 +492,7 @@ is_color_format(GLenum format)
#endif /* FEATURE_EXT_texture_sRGB */
return GL_TRUE;
case GL_YCBCR_MESA: /* not considered to be RGB */
+ /* fall-through */
default:
return GL_FALSE;
}
@@ -526,9 +527,9 @@ static GLboolean
is_depth_format(GLenum format)
{
switch (format) {
- case GL_DEPTH_COMPONENT16_ARB:
- case GL_DEPTH_COMPONENT24_ARB:
- case GL_DEPTH_COMPONENT32_ARB:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
case GL_DEPTH_COMPONENT:
return GL_TRUE;
default:
@@ -765,15 +766,15 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
{
switch (target) {
case GL_TEXTURE_1D:
- return texUnit->Current1D;
+ return texUnit->CurrentTex[TEXTURE_1D_INDEX];
case GL_PROXY_TEXTURE_1D:
return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
case GL_TEXTURE_2D:
- return texUnit->Current2D;
+ return texUnit->CurrentTex[TEXTURE_2D_INDEX];
case GL_PROXY_TEXTURE_2D:
return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
case GL_TEXTURE_3D:
- return texUnit->Current3D;
+ return texUnit->CurrentTex[TEXTURE_3D_INDEX];
case GL_PROXY_TEXTURE_3D:
return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
@@ -784,25 +785,25 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
case GL_TEXTURE_CUBE_MAP_ARB:
return ctx->Extensions.ARB_texture_cube_map
- ? texUnit->CurrentCubeMap : NULL;
+ ? texUnit->CurrentTex[TEXTURE_CUBE_INDEX] : NULL;
case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
return ctx->Extensions.ARB_texture_cube_map
? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
case GL_TEXTURE_RECTANGLE_NV:
return ctx->Extensions.NV_texture_rectangle
- ? texUnit->CurrentRect : NULL;
+ ? texUnit->CurrentTex[TEXTURE_RECT_INDEX] : NULL;
case GL_PROXY_TEXTURE_RECTANGLE_NV:
return ctx->Extensions.NV_texture_rectangle
? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
case GL_TEXTURE_1D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
- ? texUnit->Current1DArray : NULL;
+ ? texUnit->CurrentTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
case GL_TEXTURE_2D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
- ? texUnit->Current2DArray : NULL;
+ ? texUnit->CurrentTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
@@ -924,6 +925,7 @@ struct gl_texture_image *
_mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level)
{
struct gl_texture_image *texImage;
+ GLuint texIndex;
if (level < 0 )
return NULL;
@@ -932,111 +934,54 @@ _mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level)
case GL_PROXY_TEXTURE_1D:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_1D_INDEX;
+ break;
case GL_PROXY_TEXTURE_2D:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_2D_INDEX;
+ break;
case GL_PROXY_TEXTURE_3D:
if (level >= ctx->Const.Max3DTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_3D_INDEX;
+ break;
case GL_PROXY_TEXTURE_CUBE_MAP:
if (level >= ctx->Const.MaxCubeTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_CUBE_INDEX;
+ break;
case GL_PROXY_TEXTURE_RECTANGLE_NV:
if (level > 0)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_RECT_INDEX;
+ break;
case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_1D_ARRAY_INDEX;
+ break;
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level];
- if (!texImage) {
- texImage = ctx->Driver.NewTextureImage(ctx);
- if (!texImage) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
- return NULL;
- }
- ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level] = texImage;
- /* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX];
- }
- return texImage;
+ texIndex = TEXTURE_2D_ARRAY_INDEX;
+ break;
default:
return NULL;
}
+
+ texImage = ctx->Texture.ProxyTex[texIndex]->Image[0][level];
+ if (!texImage) {
+ texImage = ctx->Driver.NewTextureImage(ctx);
+ if (!texImage) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
+ return NULL;
+ }
+ ctx->Texture.ProxyTex[texIndex]->Image[0][level] = texImage;
+ /* Set the 'back' pointer */
+ texImage->TexObject = ctx->Texture.ProxyTex[texIndex];
+ }
+ return texImage;
}
@@ -1243,9 +1188,9 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
img->IsCompressed = GL_FALSE;
img->CompressedSize = 0;
- if ((width == 1 || _mesa_bitcount(img->Width2) == 1) &&
- (height == 1 || _mesa_bitcount(img->Height2) == 1) &&
- (depth == 1 || _mesa_bitcount(img->Depth2) == 1))
+ if ((width == 1 || _mesa_is_pow_two(img->Width2)) &&
+ (height == 1 || _mesa_is_pow_two(img->Height2)) &&
+ (depth == 1 || _mesa_is_pow_two(img->Depth2)))
img->_IsPowerOfTwo = GL_TRUE;
else
img->_IsPowerOfTwo = GL_FALSE;
@@ -1316,7 +1261,7 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
if (width < 2 * border || width > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- width >0 && _mesa_bitcount(width - 2 * border) != 1) ||
+ width >0 && !_mesa_is_pow_two(width - 2 * border)) ||
level >= ctx->Const.MaxTextureLevels) {
/* bad width or level */
return GL_FALSE;
@@ -1326,10 +1271,10 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
if (width < 2 * border || width > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- width > 0 && _mesa_bitcount(width - 2 * border) != 1) ||
+ width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
height < 2 * border || height > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- height > 0 && _mesa_bitcount(height - 2 * border) != 1) ||
+ height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
level >= ctx->Const.MaxTextureLevels) {
/* bad width or height or level */
return GL_FALSE;
@@ -1339,13 +1284,13 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
maxSize = 1 << (ctx->Const.Max3DTextureLevels - 1);
if (width < 2 * border || width > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- width > 0 && _mesa_bitcount(width - 2 * border) != 1) ||
+ width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
height < 2 * border || height > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- height > 0 && _mesa_bitcount(height - 2 * border) != 1) ||
+ height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
depth < 2 * border || depth > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- depth > 0 && _mesa_bitcount(depth - 2 * border) != 1) ||
+ depth > 0 && !_mesa_is_pow_two(depth - 2 * border)) ||
level >= ctx->Const.Max3DTextureLevels) {
/* bad width or height or depth or level */
return GL_FALSE;
@@ -1363,10 +1308,10 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
maxSize = 1 << (ctx->Const.MaxCubeTextureLevels - 1);
if (width < 2 * border || width > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- width > 0 && _mesa_bitcount(width - 2 * border) != 1) ||
+ width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
height < 2 * border || height > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- height > 0 && _mesa_bitcount(height - 2 * border) != 1) ||
+ height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
level >= ctx->Const.MaxCubeTextureLevels) {
/* bad width or height */
return GL_FALSE;
@@ -1376,7 +1321,7 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
if (width < 2 * border || width > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- width > 0 && _mesa_bitcount(width - 2 * border) != 1) ||
+ width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
level >= ctx->Const.MaxTextureLevels) {
/* bad width or level */
return GL_FALSE;
@@ -1390,10 +1335,10 @@ _mesa_test_proxy_teximage(GLcontext *ctx, GLenum target, GLint level,
maxSize = 1 << (ctx->Const.MaxTextureLevels - 1);
if (width < 2 * border || width > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- width > 0 && _mesa_bitcount(width - 2 * border) != 1) ||
+ width > 0 && !_mesa_is_pow_two(width - 2 * border)) ||
height < 2 * border || height > 2 + maxSize ||
(!ctx->Extensions.ARB_texture_non_power_of_two &&
- height > 0 && _mesa_bitcount(height - 2 * border) != 1) ||
+ height > 0 && !_mesa_is_pow_two(height - 2 * border)) ||
level >= ctx->Const.MaxTextureLevels) {
/* bad width or height or level */
return GL_FALSE;
@@ -1588,9 +1533,9 @@ texture_error_check( GLcontext *ctx, GLenum target,
}
/* make sure internal format and format basically agree */
- colorFormat = is_color_format(format);
+ colorFormat = _mesa_is_color_format(format);
indexFormat = is_index_format(format);
- if ((is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
+ if ((_mesa_is_color_format(internalFormat) && !colorFormat && !indexFormat) ||
(is_index_format(internalFormat) && !indexFormat) ||
(is_depth_format(internalFormat) != is_depth_format(format)) ||
(is_ycbcr_format(internalFormat) != is_ycbcr_format(format)) ||
@@ -2017,7 +1962,7 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
}
if (is_compressed_format(ctx, internalFormat)) {
- if (target != GL_TEXTURE_2D) {
+ if (!target_can_be_compressed(ctx, target)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glCopyTexImage%d(target)", dimensions);
return GL_TRUE;
@@ -2052,30 +1997,20 @@ copytexture_error_check( GLcontext *ctx, GLuint dimensions,
/**
* Test glCopyTexSubImage[12]D() parameters for errors.
+ * Note that this is the first part of error checking.
+ * See also copytexsubimage_error_check2() below for the second part.
*
* \param ctx GL context.
* \param dimensions texture image dimensions (must be 1, 2 or 3).
* \param target texture target given by the user.
* \param level image level given by the user.
- * \param xoffset sub-image x offset given by the user.
- * \param yoffset sub-image y offset given by the user.
- * \param zoffset sub-image z offset given by the user.
- * \param width image width given by the user.
- * \param height image height given by the user.
*
* \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
- *
- * Verifies each of the parameters against the constants specified in
- * __GLcontextRec::Const and the supported extensions, and according to the
- * OpenGL specification.
*/
static GLboolean
-copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height)
+copytexsubimage_error_check1( GLcontext *ctx, GLuint dimensions,
+ GLenum target, GLint level)
{
- /* Check target */
/* Check that the source buffer is complete */
if (ctx->ReadBuffer->Name) {
_mesa_test_framebuffer_completeness(ctx, ctx->ReadBuffer);
@@ -2086,6 +2021,7 @@ copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
}
}
+ /* Check target */
if (dimensions == 1) {
if (target != GL_TEXTURE_1D) {
_mesa_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" );
@@ -2133,21 +2069,18 @@ copytexsubimage_error_check( GLcontext *ctx, GLuint dimensions,
return GL_TRUE;
}
- /* Check size */
- if (width < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(width=%d)", dimensions, width);
- return GL_TRUE;
- }
- if (dimensions > 1 && height < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glCopyTexSubImage%dD(height=%d)", dimensions, height);
- return GL_TRUE;
- }
-
return GL_FALSE;
}
+
+/**
+ * Second part of error checking for glCopyTexSubImage[12]D().
+ * \param xoffset sub-image x offset given by the user.
+ * \param yoffset sub-image y offset given by the user.
+ * \param zoffset sub-image z offset given by the user.
+ * \param width image width given by the user.
+ * \param height image height given by the user.
+ */
static GLboolean
copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
GLenum target, GLint level,
@@ -2155,6 +2088,7 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
GLsizei width, GLsizei height,
const struct gl_texture_image *teximage )
{
+ /* check that dest tex image exists */
if (!teximage) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glCopyTexSubImage%dD(undefined texture level: %d)",
@@ -2162,6 +2096,19 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
return GL_TRUE;
}
+ /* Check size */
+ if (width < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(width=%d)", dimensions, width);
+ return GL_TRUE;
+ }
+ if (dimensions > 1 && height < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "glCopyTexSubImage%dD(height=%d)", dimensions, height);
+ return GL_TRUE;
+ }
+
+ /* check x/y offsets */
if (xoffset < -((GLint)teximage->Border)) {
_mesa_error(ctx, GL_INVALID_VALUE,
"glCopyTexSubImage%dD(xoffset=%d)", dimensions, xoffset);
@@ -2186,6 +2133,7 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
}
}
+ /* check z offset */
if (dimensions > 2) {
if (zoffset < -((GLint)teximage->Border)) {
_mesa_error(ctx, GL_INVALID_VALUE,
@@ -2200,7 +2148,7 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
}
if (teximage->IsCompressed) {
- if (target != GL_TEXTURE_2D) {
+ if (!target_can_be_compressed(ctx, target)) {
_mesa_error(ctx, GL_INVALID_ENUM,
"glCopyTexSubImage%d(target)", dimensions);
return GL_TRUE;
@@ -2231,7 +2179,8 @@ copytexsubimage_error_check2( GLcontext *ctx, GLuint dimensions,
if (!_mesa_source_buffer_exists(ctx, teximage->_BaseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glCopyTexSubImage%dD(missing readbuffer)", dimensions);
+ "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
+ dimensions, teximage->_BaseFormat);
return GL_TRUE;
}
@@ -2308,8 +2257,7 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
return;
}
- if (!ctx->Extensions.SGIX_depth_texture &&
- !ctx->Extensions.ARB_depth_texture && is_depth_format(format)) {
+ if (!ctx->Extensions.ARB_depth_texture && is_depth_format(format)) {
_mesa_error(ctx, GL_INVALID_ENUM, "glGetTexImage(format)");
return;
}
@@ -2338,8 +2286,8 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
* texture's format. Note that a color index texture can be converted
* to RGBA so that combo is allowed.
*/
- if (is_color_format(format)
- && !is_color_format(texImage->TexFormat->BaseFormat)
+ if (_mesa_is_color_format(format)
+ && !_mesa_is_color_format(texImage->TexFormat->BaseFormat)
&& !is_index_format(texImage->TexFormat->BaseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(format mismatch)");
goto out;
@@ -2388,23 +2336,33 @@ _mesa_GetTexImage( GLenum target, GLint level, GLenum format,
}
+/** Callback info for walking over FBO hash table */
+struct cb_info
+{
+ GLcontext *ctx;
+ struct gl_texture_object *texObj;
+ GLuint level, face;
+};
+
/**
- * Check if the given texture image is bound to any framebuffer objects
- * and update/invalidate them.
- * XXX We're only checking the currently bound framebuffer object for now.
- * In the future, perhaps struct gl_texture_image should have a pointer (or
- * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
+ * Check render to texture callback. Called from _mesa_HashWalk().
*/
static void
-update_fbo_texture(GLcontext *ctx, struct gl_texture_object *texObj,
- GLuint face, GLuint level)
+check_rtt_cb(GLuint key, void *data, void *userData)
{
- if (ctx->DrawBuffer->Name) {
+ struct gl_framebuffer *fb = (struct gl_framebuffer *) data;
+ const struct cb_info *info = (struct cb_info *) userData;
+ GLcontext *ctx = info->ctx;
+ const struct gl_texture_object *texObj = info->texObj;
+ const GLuint level = info->level, face = info->face;
+
+ /* If this is a user-created FBO */
+ if (fb->Name) {
GLuint i;
+ /* check if any of the FBO's attachments point to 'texObj' */
for (i = 0; i < BUFFER_COUNT; i++) {
- struct gl_renderbuffer_attachment *att =
- ctx->DrawBuffer->Attachment + i;
+ struct gl_renderbuffer_attachment *att = fb->Attachment + i;
if (att->Type == GL_TEXTURE &&
att->Texture == texObj &&
att->TextureLevel == level &&
@@ -2412,12 +2370,36 @@ update_fbo_texture(GLcontext *ctx, struct gl_texture_object *texObj,
ASSERT(att->Texture->Image[att->CubeMapFace][att->TextureLevel]);
/* Tell driver about the new renderbuffer texture */
ctx->Driver.RenderTexture(ctx, ctx->DrawBuffer, att);
+ /* Mark fb status as indeterminate to force re-validation */
+ fb->_Status = 0;
}
}
}
}
+/**
+ * When a texture image is specified we have to check if it's bound to
+ * any framebuffer objects (render to texture) in order to detect changes
+ * in size or format since that effects FBO completeness.
+ * Any FBOs rendering into the texture must be re-validated.
+ */
+static void
+update_fbo_texture(GLcontext *ctx, struct gl_texture_object *texObj,
+ GLuint face, GLuint level)
+{
+ /* Only check this texture if it's been marked as RenderToTexture */
+ if (texObj->_RenderToTexture) {
+ struct cb_info info;
+ info.ctx = ctx;
+ info.texObj = texObj;
+ info.level = level;
+ info.face = face;
+ _mesa_HashWalk(ctx->Shared->FrameBuffers, check_rtt_cb, &info);
+ }
+}
+
+
/*
* Called from the API. Note that width includes the border.
@@ -2432,7 +2414,7 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
#if FEATURE_convolve
- if (is_color_format(internalFormat)) {
+ if (_mesa_is_color_format(internalFormat)) {
_mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
}
#endif
@@ -2449,7 +2431,7 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat,
return; /* error was recorded */
}
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -2529,7 +2511,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
#if FEATURE_convolve
- if (is_color_format(internalFormat)) {
+ if (_mesa_is_color_format(internalFormat)) {
_mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
&postConvHeight);
}
@@ -2555,7 +2537,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
return; /* error was recorded */
}
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -2611,7 +2593,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
1, border)) {
/* when error, clear all proxy texture image parameters */
if (texImage)
- clear_teximage_fields(ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level]);
+ clear_teximage_fields(texImage);
}
else {
/* no error, set the tex image parameters */
@@ -2656,7 +2638,7 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
return; /* error was recorded */
}
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -2711,8 +2693,8 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat,
}
else {
/* no error, set the tex image parameters */
- _mesa_init_teximage_fields(ctx, target, texImage, width, height, 1,
- border, internalFormat);
+ _mesa_init_teximage_fields(ctx, target, texImage, width, height,
+ depth, border, internalFormat);
texImage->TexFormat = (*ctx->Driver.ChooseTextureFormat)(ctx,
internalFormat, format, type);
}
@@ -2749,12 +2731,12 @@ _mesa_TexSubImage1D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
#if FEATURE_convolve
/* XXX should test internal format */
- if (is_color_format(format)) {
+ if (_mesa_is_color_format(format)) {
_mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
}
#endif
@@ -2809,12 +2791,12 @@ _mesa_TexSubImage2D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
#if FEATURE_convolve
/* XXX should test internal format */
- if (is_color_format(format)) {
+ if (_mesa_is_color_format(format)) {
_mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
&postConvHeight);
}
@@ -2869,7 +2851,7 @@ _mesa_TexSubImage3D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
if (subtexture_error_check(ctx, 3, target, level, xoffset, yoffset, zoffset,
@@ -2925,11 +2907,11 @@ _mesa_CopyTexImage1D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
#if FEATURE_convolve
- if (is_color_format(internalFormat)) {
+ if (_mesa_is_color_format(internalFormat)) {
_mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
}
#endif
@@ -2990,15 +2972,16 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
#if FEATURE_convolve
- if (is_color_format(internalFormat)) {
+ if (_mesa_is_color_format(internalFormat)) {
_mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth,
&postConvHeight);
}
#endif
+
if (copytexture_error_check(ctx, 2, target, level, internalFormat,
postConvWidth, postConvHeight, border))
return;
@@ -3057,16 +3040,10 @@ _mesa_CopyTexSubImage1D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
-#if FEATURE_convolve
- /* XXX should test internal format */
- _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
-#endif
-
- if (copytexsubimage_error_check(ctx, 1, target, level,
- xoffset, 0, 0, postConvWidth, 1))
+ if (copytexsubimage_error_check1(ctx, 1, target, level))
return;
texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -3076,6 +3053,12 @@ _mesa_CopyTexSubImage1D( GLenum target, GLint level,
{
texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+#if FEATURE_convolve
+ if (texImage && _mesa_is_color_format(texImage->InternalFormat)) {
+ _mesa_adjust_image_for_convolution(ctx, 1, &postConvWidth, NULL);
+ }
+#endif
+
if (copytexsubimage_error_check2(ctx, 1, target, level,
xoffset, 0, 0, postConvWidth, 1,
texImage))
@@ -3112,16 +3095,10 @@ _mesa_CopyTexSubImage2D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
-#if FEATURE_convolve
- /* XXX should test internal format */
- _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight);
-#endif
-
- if (copytexsubimage_error_check(ctx, 2, target, level, xoffset, yoffset, 0,
- postConvWidth, postConvHeight))
+ if (copytexsubimage_error_check1(ctx, 2, target, level))
return;
texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -3131,6 +3108,13 @@ _mesa_CopyTexSubImage2D( GLenum target, GLint level,
{
texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+#if FEATURE_convolve
+ if (texImage && _mesa_is_color_format(texImage->InternalFormat)) {
+ _mesa_adjust_image_for_convolution(ctx, 2,
+ &postConvWidth, &postConvHeight);
+ }
+#endif
+
if (copytexsubimage_error_check2(ctx, 2, target, level, xoffset, yoffset, 0,
postConvWidth, postConvHeight, texImage))
goto out;
@@ -3166,16 +3150,10 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
- if (ctx->NewState & _IMAGE_NEW_TRANSFER_STATE)
+ if (ctx->NewState & _MESA_NEW_TRANSFER_STATE)
_mesa_update_state(ctx);
-#if FEATURE_convolve
- /* XXX should test internal format */
- _mesa_adjust_image_for_convolution(ctx, 2, &postConvWidth, &postConvHeight);
-#endif
-
- if (copytexsubimage_error_check(ctx, 3, target, level, xoffset, yoffset,
- zoffset, postConvWidth, postConvHeight))
+ if (copytexsubimage_error_check1(ctx, 3, target, level))
return;
texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
@@ -3185,6 +3163,13 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level,
{
texImage = _mesa_select_tex_image(ctx, texObj, target, level);
+#if FEATURE_convolve
+ if (texImage && _mesa_is_color_format(texImage->InternalFormat)) {
+ _mesa_adjust_image_for_convolution(ctx, 2,
+ &postConvWidth, &postConvHeight);
+ }
+#endif
+
if (copytexsubimage_error_check2(ctx, 3, target, level, xoffset, yoffset,
zoffset, postConvWidth, postConvHeight,
texImage))
@@ -3278,16 +3263,16 @@ compressed_texture_error_check(GLcontext *ctx, GLint dimensions,
* XXX We should probably use the proxy texture error check function here.
*/
if (width < 1 || width > maxTextureSize ||
- (!ctx->Extensions.ARB_texture_non_power_of_two && _mesa_bitcount(width) != 1))
+ (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(width)))
return GL_INVALID_VALUE;
if ((height < 1 || height > maxTextureSize ||
- (!ctx->Extensions.ARB_texture_non_power_of_two && _mesa_bitcount(height) != 1))
+ (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(height)))
&& dimensions > 1)
return GL_INVALID_VALUE;
if ((depth < 1 || depth > maxTextureSize ||
- (!ctx->Extensions.ARB_texture_non_power_of_two && _mesa_bitcount(depth) != 1))
+ (!ctx->Extensions.ARB_texture_non_power_of_two && !_mesa_is_pow_two(depth)))
&& dimensions > 2)
return GL_INVALID_VALUE;