aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/teximage.c
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/teximage.c')
-rw-r--r--mesalib/src/mesa/main/teximage.c211
1 files changed, 166 insertions, 45 deletions
diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c
index 29c325bf2..611d664b6 100644
--- a/mesalib/src/mesa/main/teximage.c
+++ b/mesalib/src/mesa/main/teximage.c
@@ -224,7 +224,10 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
if (ctx->Extensions.ARB_stencil_texturing) {
switch (internalFormat) {
case GL_STENCIL_INDEX:
+ case GL_STENCIL_INDEX1:
+ case GL_STENCIL_INDEX4:
case GL_STENCIL_INDEX8:
+ case GL_STENCIL_INDEX16:
return GL_STENCIL_INDEX;
default:
; /* fallthrough */
@@ -650,8 +653,8 @@ set_tex_image(struct gl_texture_object *tObj,
{
const GLuint face = _mesa_tex_target_to_face(target);
- ASSERT(tObj);
- ASSERT(texImage);
+ assert(tObj);
+ assert(texImage);
if (target == GL_TEXTURE_RECTANGLE_NV || target == GL_TEXTURE_EXTERNAL_OES)
assert(level == 0);
@@ -696,7 +699,7 @@ _mesa_delete_texture_image(struct gl_context *ctx,
/* Free texImage->Data and/or any other driver-specific texture
* image storage.
*/
- ASSERT(ctx->Driver.FreeTextureImageBuffer);
+ assert(ctx->Driver.FreeTextureImageBuffer);
ctx->Driver.FreeTextureImageBuffer( ctx, texImage );
free(texImage);
}
@@ -729,9 +732,9 @@ _mesa_is_proxy_texture(GLenum target)
* NUM_TEXTURE_TARGETS should match number of terms above, except there's no
* proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
*/
- STATIC_ASSERT(NUM_TEXTURE_TARGETS == Elements(targets) + 2);
+ STATIC_ASSERT(NUM_TEXTURE_TARGETS == ARRAY_SIZE(targets) + 2);
- for (i = 0; i < Elements(targets); ++i)
+ for (i = 0; i < ARRAY_SIZE(targets); ++i)
if (target == targets[i])
return GL_TRUE;
return GL_FALSE;
@@ -739,6 +742,28 @@ _mesa_is_proxy_texture(GLenum target)
/**
+ * Test if a target is an array target.
+ *
+ * \param target texture target.
+ *
+ * \return true if the target is an array target, false otherwise.
+ */
+bool
+_mesa_is_array_texture(GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D_ARRAY:
+ case GL_TEXTURE_2D_ARRAY:
+ case GL_TEXTURE_CUBE_MAP_ARRAY:
+ case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+ return true;
+ default:
+ return false;
+ };
+}
+
+
+/**
* Return the proxy target which corresponds to the given texture target
*/
static GLenum
@@ -807,9 +832,9 @@ _mesa_select_tex_image(const struct gl_texture_object *texObj,
{
const GLuint face = _mesa_tex_target_to_face(target);
- ASSERT(texObj);
- ASSERT(level >= 0);
- ASSERT(level < MAX_TEXTURE_LEVELS);
+ assert(texObj);
+ assert(level >= 0);
+ assert(level < MAX_TEXTURE_LEVELS);
return texObj->Image[face][level];
}
@@ -1239,7 +1264,7 @@ make_null_texture(GLint width, GLint height, GLint depth, GLenum format)
static void
clear_teximage_fields(struct gl_texture_image *img)
{
- ASSERT(img);
+ assert(img);
img->_BaseFormat = 0;
img->InternalFormat = 0;
img->Border = 0;
@@ -1284,14 +1309,14 @@ init_teximage_fields_ms(struct gl_context *ctx,
GLuint numSamples, GLboolean fixedSampleLocations)
{
GLenum target;
- ASSERT(img);
- ASSERT(width >= 0);
- ASSERT(height >= 0);
- ASSERT(depth >= 0);
+ assert(img);
+ assert(width >= 0);
+ assert(height >= 0);
+ assert(depth >= 0);
target = img->TexObject->Target;
img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
- ASSERT(img->_BaseFormat != -1);
+ assert(img->_BaseFormat != -1);
img->InternalFormat = internalFormat;
img->Border = border;
img->Width = width;
@@ -2184,7 +2209,7 @@ texture_error_check( struct gl_context *ctx,
/* additional checks for ycbcr textures */
if (internalFormat == GL_YCBCR_MESA) {
- ASSERT(ctx->Extensions.MESA_ycbcr_texture);
+ assert(ctx->Extensions.MESA_ycbcr_texture);
if (type != GL_UNSIGNED_SHORT_8_8_MESA &&
type != GL_UNSIGNED_SHORT_8_8_REV_MESA) {
char message[100];
@@ -2491,8 +2516,8 @@ texsubimage_error_check(struct gl_context *ctx, GLuint dimensions,
}
if (error_check_subtexture_dimensions(ctx, dimensions,
- texImage, xoffset, yoffset, 0,
- width, height, 1,
+ texImage, xoffset, yoffset, zoffset,
+ width, height, depth,
dsa ? "glTextureSubImage" :
"glTexSubImage")) {
return GL_TRUE;
@@ -2815,14 +2840,6 @@ copytexsubimage_error_check(struct gl_context *ctx, GLuint dimensions,
}
}
- /* check target (proxies not allowed) */
- if (!legal_texsubimage_target(ctx, dimensions, target, dsa)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glCopyTex%sSubImage%uD(target=%s)",
- suffix, dimensions,
- _mesa_lookup_enum_by_nr(target));
- return GL_TRUE;
- }
-
/* Check level */
if (level < 0 || level >= _mesa_max_texture_levels(ctx, target)) {
_mesa_error(ctx, GL_INVALID_VALUE,
@@ -2933,7 +2950,7 @@ check_rtt_cb(GLuint key, void *data, void *userData)
att->TextureLevel == level &&
att->CubeMapFace == face) {
_mesa_update_texture_renderbuffer(ctx, ctx->DrawBuffer, att);
- ASSERT(att->Renderbuffer->TexImage);
+ assert(att->Renderbuffer->TexImage);
/* Mark fb status as indeterminate to force re-validation */
fb->_Status = 0;
}
@@ -2977,7 +2994,7 @@ check_gen_mipmap(struct gl_context *ctx, GLenum target,
if (texObj->GenerateMipmap &&
level == texObj->BaseLevel &&
level < texObj->MaxLevel) {
- ASSERT(ctx->Driver.GenerateMipmap);
+ assert(ctx->Driver.GenerateMipmap);
ctx->Driver.GenerateMipmap(ctx, target, texObj);
}
}
@@ -3054,7 +3071,7 @@ _mesa_choose_texture_format(struct gl_context *ctx,
prevImage->Width > 0 &&
prevImage->InternalFormat == internalFormat) {
/* use the same format */
- ASSERT(prevImage->TexFormat != MESA_FORMAT_NONE);
+ assert(prevImage->TexFormat != MESA_FORMAT_NONE);
return prevImage->TexFormat;
}
}
@@ -3093,7 +3110,7 @@ _mesa_choose_texture_format(struct gl_context *ctx,
/* choose format from scratch */
f = ctx->Driver.ChooseTextureFormat(ctx, target, internalFormat,
format, type);
- ASSERT(f != MESA_FORMAT_NONE);
+ assert(f != MESA_FORMAT_NONE);
return f;
}
@@ -4088,6 +4105,16 @@ _mesa_CopyTexSubImage1D( GLenum target, GLint level,
struct gl_texture_object* texObj;
GET_CURRENT_CONTEXT(ctx);
+ /* Check target (proxies not allowed). Target must be checked prior to
+ * calling _mesa_get_current_tex_object.
+ */
+ if (!legal_texsubimage_target(ctx, 1, target, false)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTexSubImage1D(invalid target %s)",
+ _mesa_lookup_enum_by_nr(target));
+ return;
+ }
+
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@@ -4106,6 +4133,16 @@ _mesa_CopyTexSubImage2D( GLenum target, GLint level,
struct gl_texture_object* texObj;
GET_CURRENT_CONTEXT(ctx);
+ /* Check target (proxies not allowed). Target must be checked prior to
+ * calling _mesa_get_current_tex_object.
+ */
+ if (!legal_texsubimage_target(ctx, 2, target, false)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTexSubImage2D(invalid target %s)",
+ _mesa_lookup_enum_by_nr(target));
+ return;
+ }
+
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@@ -4125,6 +4162,16 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level,
struct gl_texture_object* texObj;
GET_CURRENT_CONTEXT(ctx);
+ /* Check target (proxies not allowed). Target must be checked prior to
+ * calling _mesa_get_current_tex_object.
+ */
+ if (!legal_texsubimage_target(ctx, 3, target, false)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTexSubImage3D(invalid target %s)",
+ _mesa_lookup_enum_by_nr(target));
+ return;
+ }
+
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@@ -4145,6 +4192,14 @@ _mesa_CopyTextureSubImage1D(GLuint texture, GLint level,
if (!texObj)
return;
+ /* Check target (proxies not allowed). */
+ if (!legal_texsubimage_target(ctx, 1, texObj->Target, true)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTextureSubImage1D(invalid target %s)",
+ _mesa_lookup_enum_by_nr(texObj->Target));
+ return;
+ }
+
_mesa_copy_texture_sub_image(ctx, 1, texObj, texObj->Target, level,
xoffset, 0, 0, x, y, width, 1, true);
}
@@ -4161,6 +4216,14 @@ _mesa_CopyTextureSubImage2D(GLuint texture, GLint level,
if (!texObj)
return;
+ /* Check target (proxies not allowed). */
+ if (!legal_texsubimage_target(ctx, 2, texObj->Target, true)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTextureSubImage2D(invalid target %s)",
+ _mesa_lookup_enum_by_nr(texObj->Target));
+ return;
+ }
+
_mesa_copy_texture_sub_image(ctx, 2, texObj, texObj->Target, level,
xoffset, yoffset, 0,
x, y, width, height, true);
@@ -4180,6 +4243,14 @@ _mesa_CopyTextureSubImage3D(GLuint texture, GLint level,
if (!texObj)
return;
+ /* Check target (proxies not allowed). */
+ if (!legal_texsubimage_target(ctx, 3, texObj->Target, true)) {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glCopyTextureSubImage3D(invalid target %s)",
+ _mesa_lookup_enum_by_nr(texObj->Target));
+ return;
+ }
+
_mesa_copy_texture_sub_image(ctx, 3, texObj, texObj->Target, level,
xoffset, yoffset, zoffset,
x, y, width, height, true);
@@ -4454,25 +4525,21 @@ out:
/**
- * Error checking for glCompressedTexSubImage[123]D().
+ * Target checking for glCompressedTexSubImage[123]D().
* \return GL_TRUE if error, GL_FALSE if no error
+ * Must come before other error checking so that the texture object can
+ * be correctly retrieved using _mesa_get_current_tex_object.
*/
static GLboolean
-compressed_subtexture_error_check(struct gl_context *ctx, GLint dims,
- const struct gl_texture_object *texObj,
- GLenum target, GLint level,
- GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth,
- GLenum format, GLsizei imageSize, bool dsa)
+compressed_subtexture_target_check(struct gl_context *ctx, GLenum target,
+ GLint dims, GLenum format, bool dsa,
+ const char *caller)
{
- struct gl_texture_image *texImage;
- GLint expectedSize;
GLboolean targetOK;
- const char *suffix = dsa ? "ture" : "";
if (dsa && target == GL_TEXTURE_RECTANGLE) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glCompressedSubTexture%dD(target)", dims);
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid target %s)", caller,
+ _mesa_lookup_enum_by_nr(target));
return GL_TRUE;
}
@@ -4535,7 +4602,9 @@ compressed_subtexture_error_check(struct gl_context *ctx, GLint dims,
}
if (invalidformat) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glCompressedTex%sSubImage%uD(target)", suffix, dims);
+ "%s(invalid target %s for format %s)", caller,
+ _mesa_lookup_enum_by_nr(target),
+ _mesa_lookup_enum_by_nr(format));
return GL_TRUE;
}
}
@@ -4549,11 +4618,30 @@ compressed_subtexture_error_check(struct gl_context *ctx, GLint dims,
}
if (!targetOK) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glCompressedTex%sSubImage%uD(target)", suffix, dims);
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s(invalid target %s)", caller,
+ _mesa_lookup_enum_by_nr(target));
return GL_TRUE;
}
+ return GL_FALSE;
+}
+
+/**
+ * Error checking for glCompressedTexSubImage[123]D().
+ * \return GL_TRUE if error, GL_FALSE if no error
+ */
+static GLboolean
+compressed_subtexture_error_check(struct gl_context *ctx, GLint dims,
+ const struct gl_texture_object *texObj,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLsizei imageSize, bool dsa)
+{
+ struct gl_texture_image *texImage;
+ GLint expectedSize;
+ const char *suffix = dsa ? "ture" : "";
+
/* this will catch any invalid compressed format token */
if (!_mesa_is_compressed_format(ctx, format)) {
_mesa_error(ctx, GL_INVALID_ENUM,
@@ -4709,6 +4797,11 @@ _mesa_CompressedTexSubImage1D(GLenum target, GLint level, GLint xoffset,
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx);
+ if (compressed_subtexture_target_check(ctx, target, 1, format, false,
+ "glCompressedTexSubImage1D")) {
+ return;
+ }
+
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@@ -4731,6 +4824,12 @@ _mesa_CompressedTextureSubImage1D(GLuint texture, GLint level, GLint xoffset,
if (!texObj)
return;
+ if (compressed_subtexture_target_check(ctx, texObj->Target, 1, format,
+ true,
+ "glCompressedTextureSubImage1D")) {
+ return;
+ }
+
_mesa_compressed_texture_sub_image(ctx, 1, texObj, texObj->Target, level,
xoffset, 0, 0, width, 1, 1,
format, imageSize, data, true);
@@ -4746,6 +4845,11 @@ _mesa_CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset,
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx);
+ if (compressed_subtexture_target_check(ctx, target, 2, format, false,
+ "glCompressedTexSubImage2D")) {
+ return;
+ }
+
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@@ -4770,6 +4874,12 @@ _mesa_CompressedTextureSubImage2D(GLuint texture, GLint level, GLint xoffset,
if (!texObj)
return;
+ if (compressed_subtexture_target_check(ctx, texObj->Target, 2, format,
+ true,
+ "glCompressedTextureSubImage2D")) {
+ return;
+ }
+
_mesa_compressed_texture_sub_image(ctx, 2, texObj, texObj->Target, level,
xoffset, yoffset, 0, width, height, 1,
format, imageSize, data, true);
@@ -4784,6 +4894,11 @@ _mesa_CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset,
struct gl_texture_object *texObj;
GET_CURRENT_CONTEXT(ctx);
+ if (compressed_subtexture_target_check(ctx, target, 3, format, false,
+ "glCompressedTexSubImage3D")) {
+ return;
+ }
+
texObj = _mesa_get_current_tex_object(ctx, target);
if (!texObj)
return;
@@ -4809,6 +4924,12 @@ _mesa_CompressedTextureSubImage3D(GLuint texture, GLint level, GLint xoffset,
if (!texObj)
return;
+ if (compressed_subtexture_target_check(ctx, texObj->Target, 3, format,
+ true,
+ "glCompressedTextureSubImage3D")) {
+ return;
+ }
+
_mesa_compressed_texture_sub_image(ctx, 3, texObj, texObj->Target, level,
xoffset, yoffset, zoffset,
width, height, depth,
@@ -5031,7 +5152,7 @@ _mesa_validate_texbuffer_format(const struct gl_context *ctx,
void
_mesa_texture_buffer_range(struct gl_context *ctx,
- struct gl_texture_object *texObj, GLenum target,
+ struct gl_texture_object *texObj, GLenum target,
GLenum internalFormat,
struct gl_buffer_object *bufObj,
GLintptr offset, GLsizeiptr size, bool range,