X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fteximage.c;h=5e13025ed1ba2df730eb40fa7e28a361129634ed;hb=1ebe4305fd0e4b4f023eb50ca0b8229bdd7c1a5e;hp=b262e75b9d6000f68d79aec200e209868fc1246e;hpb=3e34fc0363dfbb634ad2c36c2df66d4e6f77b23b;p=mesa.git diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index b262e75b9d6..5e13025ed1b 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -1578,7 +1578,7 @@ legal_texsubimage_target(struct gl_context *ctx, GLuint dims, GLenum target, /** * Helper function to determine if a texture object is mutable (in terms - * of GL_ARB_texture_storage). + * of GL_ARB_texture_storage/GL_ARB_bindless_texture). */ static GLboolean mutable_tex_object(struct gl_context *ctx, GLenum target) @@ -1587,6 +1587,17 @@ mutable_tex_object(struct gl_context *ctx, GLenum target) if (!texObj) return GL_FALSE; + if (texObj->HandleAllocated) { + /* The ARB_bindless_texture spec says: + * + * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*, + * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other + * functions defined in terms of these, if the texture object to be + * modified is referenced by one or more texture or image handles." + */ + return GL_FALSE; + } + return !texObj->Immutable; } @@ -2493,6 +2504,8 @@ copytexsubimage_error_check(struct gl_context *ctx, GLuint dimensions, GLint xoffset, GLint yoffset, GLint zoffset, GLint width, GLint height, const char *caller) { + assert(texObj); + struct gl_texture_image *texImage; /* Check that the source buffer is complete */ @@ -2519,12 +2532,6 @@ copytexsubimage_error_check(struct gl_context *ctx, GLuint dimensions, return GL_TRUE; } - /* Get dest image pointers */ - if (!texObj) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s()", caller); - return GL_TRUE; - } - texImage = _mesa_select_tex_image(texObj, target, level); if (!texImage) { /* destination image does not exist */ @@ -2854,19 +2861,19 @@ strip_texture_border(GLenum target, * \param type the user's image type (only used if !compressed) * \param imageSize only used for glCompressedTexImage1D/2D/3D calls. */ -static void +static ALWAYS_INLINE void teximage(struct gl_context *ctx, GLboolean compressed, GLuint dims, GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, - GLsizei imageSize, const GLvoid *pixels) + GLsizei imageSize, const GLvoid *pixels, bool no_error) { const char *func = compressed ? "glCompressedTexImage" : "glTexImage"; struct gl_pixelstore_attrib unpack_no_border; const struct gl_pixelstore_attrib *unpack = &ctx->Unpack; struct gl_texture_object *texObj; mesa_format texFormat; - GLboolean dimensionsOK, sizeOK; + bool dimensionsOK = true, sizeOK = true; FLUSH_VERTICES(ctx, 0); @@ -2891,26 +2898,27 @@ teximage(struct gl_context *ctx, GLboolean compressed, GLuint dims, internalFormat = override_internal_format(internalFormat, width, height); - /* target error checking */ - if (!legal_teximage_target(ctx, dims, target)) { - _mesa_error(ctx, GL_INVALID_ENUM, "%s%uD(target=%s)", - func, dims, _mesa_enum_to_string(target)); - return; - } - - /* general error checking */ - if (compressed) { - if (compressed_texture_error_check(ctx, dims, target, level, - internalFormat, - width, height, depth, - border, imageSize, pixels)) - return; - } - else { - if (texture_error_check(ctx, dims, target, level, internalFormat, - format, type, width, height, depth, border, - pixels)) + if (!no_error) { + /* target error checking */ + if (!legal_teximage_target(ctx, dims, target)) { + _mesa_error(ctx, GL_INVALID_ENUM, "%s%uD(target=%s)", + func, dims, _mesa_enum_to_string(target)); return; + } + + /* general error checking */ + if (compressed) { + if (compressed_texture_error_check(ctx, dims, target, level, + internalFormat, + width, height, depth, + border, imageSize, pixels)) + return; + } else { + if (texture_error_check(ctx, dims, target, level, internalFormat, + format, type, width, height, depth, border, + pixels)) + return; + } } /* Here we convert a cpal compressed image into a regular glTexImage2D @@ -2965,14 +2973,16 @@ teximage(struct gl_context *ctx, GLboolean compressed, GLuint dims, assert(texFormat != MESA_FORMAT_NONE); - /* check that width, height, depth are legal for the mipmap level */ - dimensionsOK = _mesa_legal_texture_dimensions(ctx, target, level, width, - height, depth, border); + if (!no_error) { + /* check that width, height, depth are legal for the mipmap level */ + dimensionsOK = _mesa_legal_texture_dimensions(ctx, target, level, width, + height, depth, border); - /* check that the texture won't take too much memory, etc */ - sizeOK = ctx->Driver.TestProxyTexImage(ctx, proxy_target(target), - 0, level, texFormat, 1, - width, height, depth); + /* check that the texture won't take too much memory, etc */ + sizeOK = ctx->Driver.TestProxyTexImage(ctx, proxy_target(target), + 0, level, texFormat, 1, + width, height, depth); + } if (_mesa_is_proxy_texture(target)) { /* Proxy texture: just clear or set state depending on error checking */ @@ -3061,6 +3071,31 @@ teximage(struct gl_context *ctx, GLboolean compressed, GLuint dims, } } +/* This is a wrapper around teximage() so that we can force the KHR_no_error + * logic to be inlined without inlining the function into all the callers. + */ +static void +teximage_err(struct gl_context *ctx, GLboolean compressed, GLuint dims, + GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLint border, GLenum format, GLenum type, + GLsizei imageSize, const GLvoid *pixels) +{ + teximage(ctx, compressed, dims, target, level, internalFormat, width, height, + depth, border, format, type, imageSize, pixels, false); +} + + +static void +teximage_no_error(struct gl_context *ctx, GLboolean compressed, GLuint dims, + GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLint border, GLenum format, GLenum type, + GLsizei imageSize, const GLvoid *pixels) +{ + teximage(ctx, compressed, dims, target, level, internalFormat, width, height, + depth, border, format, type, imageSize, pixels, true); +} /* @@ -3072,8 +3107,8 @@ _mesa_TexImage1D( GLenum target, GLint level, GLint internalFormat, GLenum type, const GLvoid *pixels ) { GET_CURRENT_CONTEXT(ctx); - teximage(ctx, GL_FALSE, 1, target, level, internalFormat, width, 1, 1, - border, format, type, 0, pixels); + teximage_err(ctx, GL_FALSE, 1, target, level, internalFormat, width, 1, 1, + border, format, type, 0, pixels); } @@ -3084,8 +3119,8 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat, const GLvoid *pixels ) { GET_CURRENT_CONTEXT(ctx); - teximage(ctx, GL_FALSE, 2, target, level, internalFormat, width, height, 1, - border, format, type, 0, pixels); + teximage_err(ctx, GL_FALSE, 2, target, level, internalFormat, width, height, 1, + border, format, type, 0, pixels); } @@ -3100,9 +3135,8 @@ _mesa_TexImage3D( GLenum target, GLint level, GLint internalFormat, const GLvoid *pixels ) { GET_CURRENT_CONTEXT(ctx); - teximage(ctx, GL_FALSE, 3, target, level, internalFormat, - width, height, depth, - border, format, type, 0, pixels); + teximage_err(ctx, GL_FALSE, 3, target, level, internalFormat, + width, height, depth, border, format, type, 0, pixels); } @@ -3117,6 +3151,40 @@ _mesa_TexImage3DEXT( GLenum target, GLint level, GLenum internalFormat, } +void GLAPIENTRY +_mesa_TexImage1D_no_error(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLint border, GLenum format, + GLenum type, const GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + teximage_no_error(ctx, GL_FALSE, 1, target, level, internalFormat, width, 1, + 1, border, format, type, 0, pixels); +} + + +void GLAPIENTRY +_mesa_TexImage2D_no_error(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLint border, + GLenum format, GLenum type, const GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + teximage_no_error(ctx, GL_FALSE, 2, target, level, internalFormat, width, + height, 1, border, format, type, 0, pixels); +} + + +void GLAPIENTRY +_mesa_TexImage3D_no_error(GLenum target, GLint level, GLint internalFormat, + GLsizei width, GLsizei height, GLsizei depth, + GLint border, GLenum format, GLenum type, + const GLvoid *pixels ) +{ + GET_CURRENT_CONTEXT(ctx); + teximage_no_error(ctx, GL_FALSE, 3, target, level, internalFormat, + width, height, depth, border, format, type, 0, pixels); +} + + void GLAPIENTRY _mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image) { @@ -3282,6 +3350,24 @@ texsubimage_err(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, } +static void +texsubimage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, const GLvoid *pixels) +{ + struct gl_texture_object *texObj; + struct gl_texture_image *texImage; + + texObj = _mesa_get_current_tex_object(ctx, target); + texImage = _mesa_select_tex_image(texObj, target, level); + + texture_sub_image(ctx, dims, texObj, texImage, target, level, + xoffset, yoffset, zoffset, width, height, depth, + format, type, pixels, false); +} + + /** * Implement all the glTextureSubImage1/2/3D() functions. * Must split this out this way because of GL_TEXTURE_CUBE_MAP. @@ -3307,12 +3393,9 @@ texturesubimage(struct gl_context *ctx, GLuint dims, _mesa_enum_to_string(type), pixels); /* Get the texture object by Name. */ - texObj = _mesa_lookup_texture(ctx, texture); - if (!texObj) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glTextureSubImage%uD(texture)", - dims); + texObj = _mesa_lookup_texture_err(ctx, texture, callerName); + if (!texObj) return; - } /* check target (proxies not allowed) */ if (!legal_texsubimage_target(ctx, dims, texObj->Target, true)) { @@ -3395,6 +3478,20 @@ texturesubimage(struct gl_context *ctx, GLuint dims, } +void GLAPIENTRY +_mesa_TexSubImage1D_no_error(GLenum target, GLint level, + GLint xoffset, GLsizei width, + GLenum format, GLenum type, + const GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + texsubimage(ctx, 1, target, level, + xoffset, 0, 0, + width, 1, 1, + format, type, pixels); +} + + void GLAPIENTRY _mesa_TexSubImage1D( GLenum target, GLint level, GLint xoffset, GLsizei width, @@ -3409,6 +3506,21 @@ _mesa_TexSubImage1D( GLenum target, GLint level, } +void GLAPIENTRY +_mesa_TexSubImage2D_no_error(GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLsizei width, GLsizei height, + GLenum format, GLenum type, + const GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + texsubimage(ctx, 2, target, level, + xoffset, yoffset, 0, + width, height, 1, + format, type, pixels); +} + + void GLAPIENTRY _mesa_TexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, @@ -3424,6 +3536,20 @@ _mesa_TexSubImage2D( GLenum target, GLint level, } +void GLAPIENTRY +_mesa_TexSubImage3D_no_error(GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, + const GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + texsubimage(ctx, 3, target, level, + xoffset, yoffset, zoffset, + width, height, depth, + format, type, pixels); +} + void GLAPIENTRY _mesa_TexSubImage3D( GLenum target, GLint level, @@ -3578,19 +3704,114 @@ can_avoid_reallocation(const struct gl_texture_image *texImage, return true; } + /** - * Implement the glCopyTexImage1/2D() functions. + * Implementation for glCopyTex(ture)SubImage1/2/3D() functions. */ static void +copy_texture_sub_image(struct gl_context *ctx, GLuint dims, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, GLsizei width, GLsizei height) +{ + struct gl_texture_image *texImage; + + _mesa_lock_texture(ctx, texObj); + + texImage = _mesa_select_tex_image(texObj, target, level); + + /* If we have a border, offset=-1 is legal. Bias by border width. */ + switch (dims) { + case 3: + if (target != GL_TEXTURE_2D_ARRAY) + zoffset += texImage->Border; + /* fall-through */ + case 2: + if (target != GL_TEXTURE_1D_ARRAY) + yoffset += texImage->Border; + /* fall-through */ + case 1: + xoffset += texImage->Border; + } + + if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, + &width, &height)) { + struct gl_renderbuffer *srcRb = + get_copy_tex_image_source(ctx, texImage->TexFormat); + + copytexsubimage_by_slice(ctx, texImage, dims, xoffset, yoffset, zoffset, + srcRb, x, y, width, height); + + check_gen_mipmap(ctx, target, texObj, level); + + /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed + * the texel data, not the texture format, size, etc. + */ + } + + _mesa_unlock_texture(ctx, texObj); +} + + +static void +copy_texture_sub_image_err(struct gl_context *ctx, GLuint dims, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, GLsizei width, GLsizei height, + const char *caller) +{ + FLUSH_VERTICES(ctx, 0); + + if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) + _mesa_debug(ctx, "%s %s %d %d %d %d %d %d %d %d\n", caller, + _mesa_enum_to_string(target), + level, xoffset, yoffset, zoffset, x, y, width, height); + + if (ctx->NewState & NEW_COPY_TEX_STATE) + _mesa_update_state(ctx); + + if (copytexsubimage_error_check(ctx, dims, texObj, target, level, + xoffset, yoffset, zoffset, + width, height, caller)) { + return; + } + + copy_texture_sub_image(ctx, dims, texObj, target, level, xoffset, yoffset, + zoffset, x, y, width, height); +} + + +static void +copy_texture_sub_image_no_error(struct gl_context *ctx, GLuint dims, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, GLsizei width, GLsizei height) +{ + FLUSH_VERTICES(ctx, 0); + + if (ctx->NewState & NEW_COPY_TEX_STATE) + _mesa_update_state(ctx); + + copy_texture_sub_image(ctx, dims, texObj, target, level, xoffset, yoffset, + zoffset, x, y, width, height); +} + + +/** + * Implement the glCopyTexImage1/2D() functions. + */ +static ALWAYS_INLINE void copyteximage(struct gl_context *ctx, GLuint dims, GLenum target, GLint level, GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLsizei height, GLint border ) + GLint x, GLint y, GLsizei width, GLsizei height, GLint border, + bool no_error) { - struct gl_texture_object *texObj; struct gl_texture_image *texImage; - const GLuint face = _mesa_tex_target_to_face(target); + struct gl_texture_object *texObj; mesa_format texFormat; - struct gl_renderbuffer *rb; FLUSH_VERTICES(ctx, 0); @@ -3604,15 +3825,17 @@ copyteximage(struct gl_context *ctx, GLuint dims, if (ctx->NewState & NEW_COPY_TEX_STATE) _mesa_update_state(ctx); - if (copytexture_error_check(ctx, dims, target, level, internalFormat, - width, height, border)) - return; + if (!no_error) { + if (copytexture_error_check(ctx, dims, target, level, internalFormat, + width, height, border)) + return; - if (!_mesa_legal_texture_dimensions(ctx, target, level, width, height, - 1, border)) { - _mesa_error(ctx, GL_INVALID_VALUE, - "glCopyTexImage%uD(invalid width or height)", dims); - return; + if (!_mesa_legal_texture_dimensions(ctx, target, level, width, height, + 1, border)) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glCopyTexImage%uD(invalid width or height)", dims); + return; + } } texObj = _mesa_get_current_tex_object(ctx, target); @@ -3630,9 +3853,13 @@ copyteximage(struct gl_context *ctx, GLuint dims, if (texImage && can_avoid_reallocation(texImage, internalFormat, texFormat, x, y, width, height, border)) { _mesa_unlock_texture(ctx, texObj); - _mesa_copy_texture_sub_image(ctx, dims, texObj, target, level, - 0, 0, 0, x, y, width, height, - "CopyTexImage"); + if (no_error) { + copy_texture_sub_image_no_error(ctx, dims, texObj, target, level, 0, + 0, 0, x, y, width, height); + } else { + copy_texture_sub_image_err(ctx, dims, texObj, target, level, 0, 0, + 0, x, y, width, height,"CopyTexImage"); + } return; } } @@ -3640,9 +3867,10 @@ copyteximage(struct gl_context *ctx, GLuint dims, _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_LOW, "glCopyTexImage " "can't avoid reallocating texture storage\n"); - rb = _mesa_get_read_renderbuffer_for_format(ctx, internalFormat); + if (!no_error && _mesa_is_gles3(ctx)) { + struct gl_renderbuffer *rb = + _mesa_get_read_renderbuffer_for_format(ctx, internalFormat); - if (_mesa_is_gles3(ctx)) { if (_mesa_is_enum_format_unsized(internalFormat)) { /* Conversion from GL_RGB10_A2 source buffer format is not allowed in * OpenGL ES 3.0. Khronos bug# 9807. @@ -3702,6 +3930,7 @@ copyteximage(struct gl_context *ctx, GLuint dims, } else { GLint srcX = x, srcY = y, dstX = 0, dstY = 0, dstZ = 0; + const GLuint face = _mesa_tex_target_to_face(target); /* Free old texture image */ ctx->Driver.FreeTextureImageBuffer(ctx, texImage); @@ -3735,6 +3964,24 @@ copyteximage(struct gl_context *ctx, GLuint dims, } +static void +copyteximage_err(struct gl_context *ctx, GLuint dims, GLenum target, + GLint level, GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border) +{ + copyteximage(ctx, dims, target, level, internalFormat, x, y, width, height, + border, false); +} + +static void +copyteximage_no_error(struct gl_context *ctx, GLuint dims, GLenum target, + GLint level, GLenum internalFormat, GLint x, GLint y, + GLsizei width, GLsizei height, GLint border) +{ + copyteximage(ctx, dims, target, level, internalFormat, x, y, width, height, + border, true); +} + void GLAPIENTRY _mesa_CopyTexImage1D( GLenum target, GLint level, @@ -3743,7 +3990,8 @@ _mesa_CopyTexImage1D( GLenum target, GLint level, GLsizei width, GLint border ) { GET_CURRENT_CONTEXT(ctx); - copyteximage(ctx, 1, target, level, internalFormat, x, y, width, 1, border); + copyteximage_err(ctx, 1, target, level, internalFormat, x, y, width, 1, + border); } @@ -3754,77 +4002,32 @@ _mesa_CopyTexImage2D( GLenum target, GLint level, GLenum internalFormat, GLint border ) { GET_CURRENT_CONTEXT(ctx); - copyteximage(ctx, 2, target, level, internalFormat, - x, y, width, height, border); + copyteximage_err(ctx, 2, target, level, internalFormat, + x, y, width, height, border); } -/** - * Implementation for glCopyTex(ture)SubImage1/2/3D() functions. - */ -void -_mesa_copy_texture_sub_image(struct gl_context *ctx, GLuint dims, - struct gl_texture_object *texObj, - GLenum target, GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLint x, GLint y, - GLsizei width, GLsizei height, - const char *caller) -{ - struct gl_texture_image *texImage; - - FLUSH_VERTICES(ctx, 0); - - if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE)) - _mesa_debug(ctx, "%s %s %d %d %d %d %d %d %d %d\n", caller, - _mesa_enum_to_string(target), - level, xoffset, yoffset, zoffset, x, y, width, height); - - if (ctx->NewState & NEW_COPY_TEX_STATE) - _mesa_update_state(ctx); - - if (copytexsubimage_error_check(ctx, dims, texObj, target, level, - xoffset, yoffset, zoffset, - width, height, caller)) { - return; - } - - _mesa_lock_texture(ctx, texObj); - { - texImage = _mesa_select_tex_image(texObj, target, level); - - /* If we have a border, offset=-1 is legal. Bias by border width. */ - switch (dims) { - case 3: - if (target != GL_TEXTURE_2D_ARRAY) - zoffset += texImage->Border; - /* fall-through */ - case 2: - if (target != GL_TEXTURE_1D_ARRAY) - yoffset += texImage->Border; - /* fall-through */ - case 1: - xoffset += texImage->Border; - } - - if (_mesa_clip_copytexsubimage(ctx, &xoffset, &yoffset, &x, &y, - &width, &height)) { - struct gl_renderbuffer *srcRb = - get_copy_tex_image_source(ctx, texImage->TexFormat); - copytexsubimage_by_slice(ctx, texImage, dims, - xoffset, yoffset, zoffset, - srcRb, x, y, width, height); +void GLAPIENTRY +_mesa_CopyTexImage1D_no_error(GLenum target, GLint level, GLenum internalFormat, + GLint x, GLint y, GLsizei width, GLint border) +{ + GET_CURRENT_CONTEXT(ctx); + copyteximage_no_error(ctx, 1, target, level, internalFormat, x, y, width, 1, + border); +} - check_gen_mipmap(ctx, target, texObj, level); - /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed - * the texel data, not the texture format, size, etc. - */ - } - } - _mesa_unlock_texture(ctx, texObj); +void GLAPIENTRY +_mesa_CopyTexImage2D_no_error(GLenum target, GLint level, GLenum internalFormat, + GLint x, GLint y, GLsizei width, GLsizei height, + GLint border) +{ + GET_CURRENT_CONTEXT(ctx); + copyteximage_no_error(ctx, 2, target, level, internalFormat, + x, y, width, height, border); } + void GLAPIENTRY _mesa_CopyTexSubImage1D( GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width ) @@ -3846,12 +4049,10 @@ _mesa_CopyTexSubImage1D( GLenum target, GLint level, if (!texObj) return; - _mesa_copy_texture_sub_image(ctx, 1, texObj, target, level, xoffset, 0, 0, - x, y, width, 1, self); + copy_texture_sub_image_err(ctx, 1, texObj, target, level, xoffset, 0, 0, + x, y, width, 1, self); } - - void GLAPIENTRY _mesa_CopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, @@ -3874,9 +4075,8 @@ _mesa_CopyTexSubImage2D( GLenum target, GLint level, if (!texObj) return; - _mesa_copy_texture_sub_image(ctx, 2, texObj, target, level, - xoffset, yoffset, 0, - x, y, width, height, self); + copy_texture_sub_image_err(ctx, 2, texObj, target, level, xoffset, yoffset, + 0, x, y, width, height, self); } @@ -3903,9 +4103,8 @@ _mesa_CopyTexSubImage3D( GLenum target, GLint level, if (!texObj) return; - _mesa_copy_texture_sub_image(ctx, 3, texObj, target, level, - xoffset, yoffset, zoffset, - x, y, width, height, self); + copy_texture_sub_image_err(ctx, 3, texObj, target, level, xoffset, yoffset, + zoffset, x, y, width, height, self); } void GLAPIENTRY @@ -3927,8 +4126,8 @@ _mesa_CopyTextureSubImage1D(GLuint texture, GLint level, return; } - _mesa_copy_texture_sub_image(ctx, 1, texObj, texObj->Target, level, - xoffset, 0, 0, x, y, width, 1, self); + copy_texture_sub_image_err(ctx, 1, texObj, texObj->Target, level, xoffset, 0, + 0, x, y, width, 1, self); } void GLAPIENTRY @@ -3951,9 +4150,8 @@ _mesa_CopyTextureSubImage2D(GLuint texture, GLint level, return; } - _mesa_copy_texture_sub_image(ctx, 2, texObj, texObj->Target, level, - xoffset, yoffset, 0, - x, y, width, height, self); + copy_texture_sub_image_err(ctx, 2, texObj, texObj->Target, level, xoffset, + yoffset, 0, x, y, width, height, self); } @@ -3980,17 +4178,97 @@ _mesa_CopyTextureSubImage3D(GLuint texture, GLint level, if (texObj->Target == GL_TEXTURE_CUBE_MAP) { /* Act like CopyTexSubImage2D */ - _mesa_copy_texture_sub_image(ctx, 2, texObj, - GL_TEXTURE_CUBE_MAP_POSITIVE_X + zoffset, - level, xoffset, yoffset, 0, - x, y, width, height, self); + copy_texture_sub_image_err(ctx, 2, texObj, + GL_TEXTURE_CUBE_MAP_POSITIVE_X + zoffset, + level, xoffset, yoffset, 0, x, y, width, height, + self); } else - _mesa_copy_texture_sub_image(ctx, 3, texObj, texObj->Target, level, - xoffset, yoffset, zoffset, - x, y, width, height, self); + copy_texture_sub_image_err(ctx, 3, texObj, texObj->Target, level, xoffset, + yoffset, zoffset, x, y, width, height, self); +} + + +void GLAPIENTRY +_mesa_CopyTexSubImage1D_no_error(GLenum target, GLint level, GLint xoffset, + GLint x, GLint y, GLsizei width) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_texture_object* texObj = _mesa_get_current_tex_object(ctx, target); + copy_texture_sub_image_no_error(ctx, 1, texObj, target, level, xoffset, 0, 0, + x, y, width, 1); } +void GLAPIENTRY +_mesa_CopyTexSubImage2D_no_error(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint x, GLint y, GLsizei width, + GLsizei height) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_texture_object* texObj = _mesa_get_current_tex_object(ctx, target); + copy_texture_sub_image_no_error(ctx, 2, texObj, target, level, xoffset, + yoffset, 0, x, y, width, height); +} + +void GLAPIENTRY +_mesa_CopyTexSubImage3D_no_error(GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint zoffset, GLint x, GLint y, + GLsizei width, GLsizei height) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_texture_object* texObj = _mesa_get_current_tex_object(ctx, target); + copy_texture_sub_image_no_error(ctx, 3, texObj, target, level, xoffset, + yoffset, zoffset, x, y, width, height); +} + +void GLAPIENTRY +_mesa_CopyTextureSubImage1D_no_error(GLuint texture, GLint level, GLint xoffset, + GLint x, GLint y, GLsizei width) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_texture_object* texObj = _mesa_lookup_texture(ctx, texture); + copy_texture_sub_image_no_error(ctx, 1, texObj, texObj->Target, level, + xoffset, 0, 0, x, y, width, 1); +} + +void GLAPIENTRY +_mesa_CopyTextureSubImage2D_no_error(GLuint texture, GLint level, GLint xoffset, + GLint yoffset, GLint x, GLint y, + GLsizei width, GLsizei height) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_texture_object* texObj = _mesa_lookup_texture(ctx, texture); + copy_texture_sub_image_no_error(ctx, 2, texObj, texObj->Target, level, + xoffset, yoffset, 0, x, y, width, height); +} + +void GLAPIENTRY +_mesa_CopyTextureSubImage3D_no_error(GLuint texture, GLint level, GLint xoffset, + GLint yoffset, GLint zoffset, GLint x, + GLint y, GLsizei width, GLsizei height) +{ + GET_CURRENT_CONTEXT(ctx); + + struct gl_texture_object* texObj = _mesa_lookup_texture(ctx, texture); + if (texObj->Target == GL_TEXTURE_CUBE_MAP) { + /* Act like CopyTexSubImage2D */ + copy_texture_sub_image_no_error(ctx, 2, texObj, + GL_TEXTURE_CUBE_MAP_POSITIVE_X + zoffset, + level, xoffset, yoffset, 0, x, y, width, + height); + } + else + copy_texture_sub_image_no_error(ctx, 3, texObj, texObj->Target, level, + xoffset, yoffset, zoffset, x, y, width, + height); +} + + static bool check_clear_tex_image(struct gl_context *ctx, const char *function, @@ -4071,17 +4349,9 @@ get_tex_obj_for_clear(struct gl_context *ctx, { struct gl_texture_object *texObj; - if (texture == 0) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(zero texture)", function); - return NULL; - } - - texObj = _mesa_lookup_texture(ctx, texture); - - if (texObj == NULL) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", function); + texObj = _mesa_lookup_texture_err(ctx, texture, function); + if (!texObj) return NULL; - } if (texObj->Target == 0) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unbound tex)", function); @@ -4091,6 +4361,15 @@ get_tex_obj_for_clear(struct gl_context *ctx, return texObj; } + +/** + * For clearing cube textures, the zoffset and depth parameters indicate + * which cube map faces are to be cleared. This is the one case where we + * need to be concerned with multiple gl_texture_images. This function + * returns the array of texture images to clear for cube maps, or one + * texture image otherwise. + * \return number of texture images, 0 for error, 6 for cube, 1 otherwise. + */ static int get_tex_images_for_clear(struct gl_context *ctx, const char *function, @@ -4099,7 +4378,7 @@ get_tex_images_for_clear(struct gl_context *ctx, struct gl_texture_image **texImages) { GLenum target; - int i; + int numFaces, i; if (level < 0 || level >= MAX_TEXTURE_LEVELS) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid level)", function); @@ -4107,28 +4386,23 @@ get_tex_images_for_clear(struct gl_context *ctx, } if (texObj->Target == GL_TEXTURE_CUBE_MAP) { - for (i = 0; i < MAX_FACES; i++) { - target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; - - texImages[i] = _mesa_select_tex_image(texObj, target, level); - if (texImages[i] == NULL) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "%s(invalid level)", function); - return 0; - } - } - - return MAX_FACES; + target = GL_TEXTURE_CUBE_MAP_POSITIVE_X; + numFaces = MAX_FACES; + } + else { + target = texObj->Target; + numFaces = 1; } - texImages[0] = _mesa_select_tex_image(texObj, texObj->Target, level); - - if (texImages[0] == NULL) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid level)", function); - return 0; + for (i = 0; i < numFaces; i++) { + texImages[i] = _mesa_select_tex_image(texObj, target + i, level); + if (texImages[i] == NULL) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid level)", function); + return 0; + } } - return 1; + return numFaces; } void GLAPIENTRY @@ -4160,6 +4434,7 @@ _mesa_ClearTexSubImage( GLuint texture, GLint level, minDepth = -(int) texImages[0]->Border; maxDepth = texImages[0]->Depth; } else { + assert(numImages == MAX_FACES); minDepth = 0; maxDepth = numImages; } @@ -4189,7 +4464,9 @@ _mesa_ClearTexSubImage( GLuint texture, GLint level, data ? clearValue[0] : NULL); } } else { + /* loop over cube face images */ for (i = zoffset; i < zoffset + depth; i++) { + assert(i < MAX_FACES); if (!check_clear_tex_image(ctx, "glClearTexSubImage", texImages[i], format, type, data, clearValue[i])) @@ -4466,8 +4743,8 @@ _mesa_CompressedTexImage1D(GLenum target, GLint level, const GLvoid *data) { GET_CURRENT_CONTEXT(ctx); - teximage(ctx, GL_TRUE, 1, target, level, internalFormat, - width, 1, 1, border, GL_NONE, GL_NONE, imageSize, data); + teximage_err(ctx, GL_TRUE, 1, target, level, internalFormat, + width, 1, 1, border, GL_NONE, GL_NONE, imageSize, data); } @@ -4478,8 +4755,8 @@ _mesa_CompressedTexImage2D(GLenum target, GLint level, const GLvoid *data) { GET_CURRENT_CONTEXT(ctx); - teximage(ctx, GL_TRUE, 2, target, level, internalFormat, - width, height, 1, border, GL_NONE, GL_NONE, imageSize, data); + teximage_err(ctx, GL_TRUE, 2, target, level, internalFormat, + width, height, 1, border, GL_NONE, GL_NONE, imageSize, data); } @@ -4490,8 +4767,44 @@ _mesa_CompressedTexImage3D(GLenum target, GLint level, GLsizei imageSize, const GLvoid *data) { GET_CURRENT_CONTEXT(ctx); - teximage(ctx, GL_TRUE, 3, target, level, internalFormat, - width, height, depth, border, GL_NONE, GL_NONE, imageSize, data); + teximage_err(ctx, GL_TRUE, 3, target, level, internalFormat, width, height, + depth, border, GL_NONE, GL_NONE, imageSize, data); +} + + +void GLAPIENTRY +_mesa_CompressedTexImage1D_no_error(GLenum target, GLint level, + GLenum internalFormat, GLsizei width, + GLint border, GLsizei imageSize, + const GLvoid *data) +{ + GET_CURRENT_CONTEXT(ctx); + teximage_no_error(ctx, GL_TRUE, 1, target, level, internalFormat, width, 1, + 1, border, GL_NONE, GL_NONE, imageSize, data); +} + + +void GLAPIENTRY +_mesa_CompressedTexImage2D_no_error(GLenum target, GLint level, + GLenum internalFormat, GLsizei width, + GLsizei height, GLint border, + GLsizei imageSize, const GLvoid *data) +{ + GET_CURRENT_CONTEXT(ctx); + teximage_no_error(ctx, GL_TRUE, 2, target, level, internalFormat, width, + height, 1, border, GL_NONE, GL_NONE, imageSize, data); +} + + +void GLAPIENTRY +_mesa_CompressedTexImage3D_no_error(GLenum target, GLint level, + GLenum internalFormat, GLsizei width, + GLsizei height, GLsizei depth, GLint border, + GLsizei imageSize, const GLvoid *data) +{ + GET_CURRENT_CONTEXT(ctx); + teximage_no_error(ctx, GL_TRUE, 3, target, level, internalFormat, width, + height, depth, border, GL_NONE, GL_NONE, imageSize, data); } @@ -5009,6 +5322,18 @@ texture_buffer_range(struct gl_context *ctx, return; } + if (texObj->HandleAllocated) { + /* The ARB_bindless_texture spec says: + * + * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*, + * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other + * functions defined in terms of these, if the texture object to be + * modified is referenced by one or more texture or image handles." + */ + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(immutable texture)", caller); + return; + } + format = _mesa_validate_texbuffer_format(ctx, internalFormat); if (format == MESA_FORMAT_NONE) { _mesa_error(ctx, GL_INVALID_ENUM, "%s(internalFormat %s)",