summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaura Ekstrand <[email protected]>2015-03-04 14:45:40 -0800
committerLaura Ekstrand <[email protected]>2015-03-09 13:33:54 -0700
commit5f8c6eabbeb698b6dc653eda9dcf01704e53ae58 (patch)
treea4b30ac6bf94a0f28e0ec8d3934fa69ed41ffb8b
parent0f6372946b8bf52658140508d6501fe1bfd180d0 (diff)
main: Add check_texture_buffer_range.
Creates a shared function that TexBufferRange and TextureBufferRange can use to check the buffer range. This cleans up TexBufferRange considerably. v2: Review from Anuj Phogat - Split rebase of Tex[ture]Buffer[Range] Reviewed-by: Anuj Phogat <[email protected]>
-rw-r--r--src/mesa/main/teximage.c73
1 files changed, 58 insertions, 15 deletions
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index b4b5ac56c0c..e8b5d2eb678 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -5289,6 +5289,56 @@ _mesa_texture_buffer_range(struct gl_context *ctx,
}
+/**
+ * Check for errors related to the texture buffer range.
+ * Return false if errors are found, true if none are found.
+ */
+static bool
+check_texture_buffer_range(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr size,
+ const char *caller)
+{
+ /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
+ * Textures (PDF page 245):
+ * "An INVALID_VALUE error is generated if offset is negative, if
+ * size is less than or equal to zero, or if offset + size is greater
+ * than the value of BUFFER_SIZE for the buffer bound to target."
+ */
+ if (offset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(offset=%d < 0)", caller,
+ (int) offset);
+ return false;
+ }
+
+ if (size <= 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(size=%d <= 0)", caller,
+ (int) size);
+ return false;
+ }
+
+ if (offset + size > bufObj->Size) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(offset=%d + size=%d > buffer_size=%d)", caller,
+ (int) offset, (int) size, (int) bufObj->Size);
+ return false;
+ }
+
+ /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
+ * Textures (PDF page 245):
+ * "An INVALID_VALUE error is generated if offset is not an integer
+ * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
+ */
+ if (offset % ctx->Const.TextureBufferOffsetAlignment) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(invalid offset alignment)", caller);
+ return false;
+ }
+
+ return true;
+}
+
+
/** GL_ARB_texture_buffer_object */
void GLAPIENTRY
_mesa_TexBuffer(GLenum target, GLenum internalFormat, GLuint buffer)
@@ -5336,23 +5386,15 @@ _mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
return;
}
- bufObj = _mesa_lookup_bufferobj(ctx, buffer);
- if (bufObj) {
- if (offset < 0 ||
- size <= 0 ||
- (offset + size) > bufObj->Size) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glTexBufferRange");
+ if (buffer) {
+ bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glTexBufferRange");
+ if (!bufObj)
return;
- }
- if (offset % ctx->Const.TextureBufferOffsetAlignment) {
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glTexBufferRange(invalid offset alignment)");
+
+ if (!check_texture_buffer_range(ctx, bufObj, offset, size,
+ "glTexBufferRange"))
return;
- }
- } else if (buffer) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glTexBufferRange(buffer %u)",
- buffer);
- return;
+
} else {
/* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
@@ -5364,6 +5406,7 @@ _mesa_TexBufferRange(GLenum target, GLenum internalFormat, GLuint buffer,
*/
offset = 0;
size = 0;
+ bufObj = NULL;
}
texObj = _mesa_get_current_tex_object(ctx, target);