Fix buffer mapping validation and refactor entry points
Checks for extension support are added to GetBufferPointervOES,
mapBufferOES, unmapBufferOES, mapBufferRangeEXT and
flushMappedBufferRangeEXT.
The GetBufferPointerv function now checks if state is queried from
buffer object zero.
The code is also refactored so that validation happens in separate
validation functions and the implementations are in Context functions.
BUG=angleproject:1101
TEST=dEQP-GLES3.functional.negative_api.state.get_buffer_pointerv
dEQP-GLES3.functional.*buffer*map* (no regression)
Change-Id: I0f439abd12c92c51324f2e5a31bf621f61534306
Reviewed-on: https://chromium-review.googlesource.com/336164
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/libANGLE/validationES2.cpp b/src/libANGLE/validationES2.cpp
index ee5ac41..2c7f83c 100644
--- a/src/libANGLE/validationES2.cpp
+++ b/src/libANGLE/validationES2.cpp
@@ -1882,4 +1882,94 @@
return true;
}
+bool ValidateGetBufferPointervOES(Context *context, GLenum target, GLenum pname, void **params)
+{
+ if (!context->getExtensions().mapBuffer)
+ {
+ context->recordError(Error(GL_INVALID_OPERATION, "Map buffer extension not available."));
+ return false;
+ }
+
+ return ValidateGetBufferPointervBase(context, target, pname, params);
+}
+
+bool ValidateMapBufferOES(Context *context, GLenum target, GLenum access)
+{
+ if (!context->getExtensions().mapBuffer)
+ {
+ context->recordError(Error(GL_INVALID_OPERATION, "Map buffer extension not available."));
+ return false;
+ }
+
+ if (!ValidBufferTarget(context, target))
+ {
+ context->recordError(Error(GL_INVALID_ENUM, "Invalid buffer target."));
+ return false;
+ }
+
+ Buffer *buffer = context->getState().getTargetBuffer(target);
+
+ if (buffer == nullptr)
+ {
+ context->recordError(Error(GL_INVALID_OPERATION, "Attempted to map buffer object zero."));
+ return false;
+ }
+
+ if (access != GL_WRITE_ONLY_OES)
+ {
+ context->recordError(Error(GL_INVALID_ENUM, "Non-write buffer mapping not supported."));
+ return false;
+ }
+
+ if (buffer->isMapped())
+ {
+ context->recordError(Error(GL_INVALID_OPERATION, "Buffer is already mapped."));
+ return false;
+ }
+
+ return true;
+}
+
+bool ValidateUnmapBufferOES(Context *context, GLenum target)
+{
+ if (!context->getExtensions().mapBuffer)
+ {
+ context->recordError(Error(GL_INVALID_OPERATION, "Map buffer extension not available."));
+ return false;
+ }
+
+ return ValidateUnmapBufferBase(context, target);
+}
+
+bool ValidateMapBufferRangeEXT(Context *context,
+ GLenum target,
+ GLintptr offset,
+ GLsizeiptr length,
+ GLbitfield access)
+{
+ if (!context->getExtensions().mapBufferRange)
+ {
+ context->recordError(
+ Error(GL_INVALID_OPERATION, "Map buffer range extension not available."));
+ return false;
+ }
+
+ return ValidateMapBufferRangeBase(context, target, offset, length, access);
+}
+
+bool ValidateFlushMappedBufferRangeEXT(Context *context,
+ GLenum target,
+ GLintptr offset,
+ GLsizeiptr length)
+{
+ if (!context->getExtensions().mapBufferRange)
+ {
+ context->recordError(
+ Error(GL_INVALID_OPERATION, "Map buffer range extension not available."));
+ return false;
+ }
+
+ return ValidateFlushMappedBufferRangeBase(context, target, offset, length);
+}
+
} // namespace gl