"glCopyNamedBufferSubData");
}
-
-static void *
-map_buffer_range(struct gl_context *ctx, struct gl_buffer_object *bufObj,
- GLintptr offset, GLsizeiptr length, GLbitfield access,
- const char *func)
+static bool
+validate_map_buffer_range(struct gl_context *ctx,
+ struct gl_buffer_object *bufObj, GLintptr offset,
+ GLsizeiptr length, GLbitfield access,
+ const char *func)
{
- void *map;
GLbitfield allowed_access;
- ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, NULL);
+ ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, false);
if (offset < 0) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(offset %ld < 0)", func, (long) offset);
- return NULL;
+ return false;
}
if (length < 0) {
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(length %ld < 0)", func, (long) length);
- return NULL;
+ return false;
}
/* Page 38 of the PDF of the OpenGL ES 3.0 spec says:
*/
if (length == 0) {
_mesa_error(ctx, GL_INVALID_OPERATION, "%s(length = 0)", func);
- return NULL;
+ return false;
}
allowed_access = GL_MAP_READ_BIT |
/* generate an error if any bits other than those allowed are set */
_mesa_error(ctx, GL_INVALID_VALUE,
"%s(access has undefined bits set)", func);
- return NULL;
+ return false;
}
if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(access indicates neither read or write)", func);
- return NULL;
+ return false;
}
if ((access & GL_MAP_READ_BIT) &&
GL_MAP_UNSYNCHRONIZED_BIT))) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(read access with disallowed bits)", func);
- return NULL;
+ return false;
}
if ((access & GL_MAP_FLUSH_EXPLICIT_BIT) &&
((access & GL_MAP_WRITE_BIT) == 0)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(access has flush explicit without write)", func);
- return NULL;
+ return false;
}
if (access & GL_MAP_READ_BIT &&
!(bufObj->StorageFlags & GL_MAP_READ_BIT)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(buffer does not allow read access)", func);
- return NULL;
+ return false;
}
if (access & GL_MAP_WRITE_BIT &&
!(bufObj->StorageFlags & GL_MAP_WRITE_BIT)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(buffer does not allow write access)", func);
- return NULL;
+ return false;
}
if (access & GL_MAP_COHERENT_BIT &&
!(bufObj->StorageFlags & GL_MAP_COHERENT_BIT)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(buffer does not allow coherent access)", func);
- return NULL;
+ return false;
}
if (access & GL_MAP_PERSISTENT_BIT &&
!(bufObj->StorageFlags & GL_MAP_PERSISTENT_BIT)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(buffer does not allow persistent access)", func);
- return NULL;
+ return false;
}
if (offset + length > bufObj->Size) {
"%s(offset %lu + length %lu > buffer_size %lu)", func,
(unsigned long) offset, (unsigned long) length,
(unsigned long) bufObj->Size);
- return NULL;
+ return false;
}
if (_mesa_bufferobj_mapped(bufObj, MAP_USER)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"%s(buffer already mapped)", func);
- return NULL;
- }
-
- if (!bufObj->Size) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(buffer size = 0)", func);
- return NULL;
+ return false;
}
if (access & GL_MAP_WRITE_BIT) {
}
}
+ return true;
+}
+
+static void *
+map_buffer_range(struct gl_context *ctx, struct gl_buffer_object *bufObj,
+ GLintptr offset, GLsizeiptr length, GLbitfield access,
+ const char *func)
+{
+ if (!bufObj->Size) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(buffer size = 0)", func);
+ return NULL;
+ }
+
assert(ctx->Driver.MapBufferRange);
- map = ctx->Driver.MapBufferRange(ctx, offset, length, access, bufObj,
- MAP_USER);
+ void *map = ctx->Driver.MapBufferRange(ctx, offset, length, access, bufObj,
+ MAP_USER);
if (!map) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(map failed)", func);
}
if (!bufObj)
return NULL;
+ if (!validate_map_buffer_range(ctx, bufObj, offset, length, access,
+ "glMapBufferRange"))
+ return NULL;
+
return map_buffer_range(ctx, bufObj, offset, length, access,
"glMapBufferRange");
}
if (!bufObj)
return NULL;
+ if (!validate_map_buffer_range(ctx, bufObj, offset, length, access,
+ "glMapNamedBufferRange"))
+ return NULL;
+
return map_buffer_range(ctx, bufObj, offset, length, access,
"glMapNamedBufferRange");
}
if (!bufObj)
return NULL;
+ if (!validate_map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
+ "glMapBuffer"))
+ return NULL;
+
return map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
"glMapBuffer");
}
if (!bufObj)
return NULL;
+ if (!validate_map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
+ "glMapNamedBuffer"))
+ return NULL;
+
return map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
"glMapNamedBuffer");
}