summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2014-11-11 09:44:46 +0000
committerIan Romanick <[email protected]>2014-12-02 12:16:28 -0800
commit5e72886db0a170d8862f3fc5d8f546fa75b20b2b (patch)
tree8a8554540160452999b9f1dff6724fe55e3cd6af /src/mesa/main
parentb93dcb0e718a0a177370f2c7851223350d3b7bc7 (diff)
mesa: Refactor common validation code to validate_DrawElements_common
Most of the code in _mesa_validate_DrawElements, _mesa_validate_DrawRangeElements, and _mesa_validate_DrawElementsInstanced was the same. Refactor this out to common code. As a side-effect, a bug in _mesa_validate_DrawElementsInstanced was fixed. Previously this function would not generate an error when check_valid_to_render failed if numInstances was 0. Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/api_validate.c168
1 files changed, 43 insertions, 125 deletions
diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c
index 006fca45e14..276aab74e92 100644
--- a/src/mesa/main/api_validate.c
+++ b/src/mesa/main/api_validate.c
@@ -318,18 +318,12 @@ valid_elements_type(struct gl_context *ctx, GLenum type, const char *name)
}
}
-/**
- * Error checking for glDrawElements(). Includes parameter checking
- * and VBO bounds checking.
- * \return GL_TRUE if OK to render, GL_FALSE if error found
- */
-GLboolean
-_mesa_validate_DrawElements(struct gl_context *ctx,
- GLenum mode, GLsizei count, GLenum type,
- const GLvoid *indices, GLint basevertex)
+static bool
+validate_DrawElements_common(struct gl_context *ctx,
+ GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices,
+ const char *caller)
{
- FLUSH_CURRENT(ctx, 0);
-
/* From the GLES3 specification, section 2.14.2 (Transform Feedback
* Primitive Capture):
*
@@ -339,44 +333,60 @@ _mesa_validate_DrawElements(struct gl_context *ctx,
*/
if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawElements(transform feedback active)");
- return GL_FALSE;
+ "%s(transform feedback active)", caller);
+ return false;
}
if (count < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDrawElements(count)" );
- return GL_FALSE;
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(count)", caller);
+ return false;
}
- if (!_mesa_valid_prim_mode(ctx, mode, "glDrawElements")) {
- return GL_FALSE;
+ if (!_mesa_valid_prim_mode(ctx, mode, caller)) {
+ return false;
}
- if (!valid_elements_type(ctx, type, "glDrawElements"))
- return GL_FALSE;
+ if (!valid_elements_type(ctx, type, caller))
+ return false;
- if (!check_valid_to_render(ctx, "glDrawElements"))
- return GL_FALSE;
+ if (!check_valid_to_render(ctx, caller))
+ return false;
/* Vertex buffer object tests */
if (_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj)) {
/* use indices in the buffer object */
/* make sure count doesn't go outside buffer bounds */
if (index_bytes(type, count) > ctx->Array.VAO->IndexBufferObj->Size) {
- _mesa_warning(ctx, "glDrawElements index out of buffer bounds");
- return GL_FALSE;
+ _mesa_warning(ctx, "%s index out of buffer bounds", caller);
+ return false;
}
}
else {
/* not using a VBO */
if (!indices)
- return GL_FALSE;
+ return false;
}
if (count == 0)
- return GL_FALSE;
+ return false;
- return GL_TRUE;
+ return true;
+}
+
+/**
+ * Error checking for glDrawElements(). Includes parameter checking
+ * and VBO bounds checking.
+ * \return GL_TRUE if OK to render, GL_FALSE if error found
+ */
+GLboolean
+_mesa_validate_DrawElements(struct gl_context *ctx,
+ GLenum mode, GLsizei count, GLenum type,
+ const GLvoid *indices, GLint basevertex)
+{
+ FLUSH_CURRENT(ctx, 0);
+
+ return validate_DrawElements_common(ctx, mode, count, type, indices,
+ "glDrawElements");
}
@@ -451,58 +461,13 @@ _mesa_validate_DrawRangeElements(struct gl_context *ctx, GLenum mode,
{
FLUSH_CURRENT(ctx, 0);
- /* From the GLES3 specification, section 2.14.2 (Transform Feedback
- * Primitive Capture):
- *
- * The error INVALID_OPERATION is also generated by DrawElements,
- * DrawElementsInstanced, and DrawRangeElements while transform feedback
- * is active and not paused, regardless of mode.
- */
- if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawElements(transform feedback active)");
- return GL_FALSE;
- }
-
- if (count < 0) {
- _mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(count)" );
- return GL_FALSE;
- }
-
- if (!_mesa_valid_prim_mode(ctx, mode, "glDrawRangeElements")) {
- return GL_FALSE;
- }
-
if (end < start) {
_mesa_error(ctx, GL_INVALID_VALUE, "glDrawRangeElements(end<start)");
return GL_FALSE;
}
- if (!valid_elements_type(ctx, type, "glDrawRangeElements"))
- return GL_FALSE;
-
- if (!check_valid_to_render(ctx, "glDrawRangeElements"))
- return GL_FALSE;
-
- /* Vertex buffer object tests */
- if (_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj)) {
- /* use indices in the buffer object */
- /* make sure count doesn't go outside buffer bounds */
- if (index_bytes(type, count) > ctx->Array.VAO->IndexBufferObj->Size) {
- _mesa_warning(ctx, "glDrawRangeElements index out of buffer bounds");
- return GL_FALSE;
- }
- }
- else {
- /* not using a VBO */
- if (!indices)
- return GL_FALSE;
- }
-
- if (count == 0)
- return GL_FALSE;
-
- return GL_TRUE;
+ return validate_DrawElements_common(ctx, mode, count, type, indices,
+ "glDrawRangeElements");
}
@@ -634,62 +599,15 @@ _mesa_validate_DrawElementsInstanced(struct gl_context *ctx,
{
FLUSH_CURRENT(ctx, 0);
- /* From the GLES3 specification, section 2.14.2 (Transform Feedback
- * Primitive Capture):
- *
- * The error INVALID_OPERATION is also generated by DrawElements,
- * DrawElementsInstanced, and DrawRangeElements while transform feedback
- * is active and not paused, regardless of mode.
- */
- if (_mesa_is_gles3(ctx) && _mesa_is_xfb_active_and_unpaused(ctx)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glDrawElements(transform feedback active)");
- return GL_FALSE;
- }
-
- if (count < 0) {
+ if (numInstances < 0) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "glDrawElementsInstanced(count=%d)", count);
+ "glDrawElementsInstanced(numInstances=%d)", numInstances);
return GL_FALSE;
}
- if (!_mesa_valid_prim_mode(ctx, mode, "glDrawElementsInstanced")) {
- return GL_FALSE;
- }
-
- if (!valid_elements_type(ctx, type, "glDrawElementsInstanced"))
- return GL_FALSE;
-
- if (numInstances <= 0) {
- if (numInstances < 0)
- _mesa_error(ctx, GL_INVALID_VALUE,
- "glDrawElementsInstanced(numInstances=%d)", numInstances);
- return GL_FALSE;
- }
-
- if (!check_valid_to_render(ctx, "glDrawElementsInstanced"))
- return GL_FALSE;
-
- /* Vertex buffer object tests */
- if (_mesa_is_bufferobj(ctx->Array.VAO->IndexBufferObj)) {
- /* use indices in the buffer object */
- /* make sure count doesn't go outside buffer bounds */
- if (index_bytes(type, count) > ctx->Array.VAO->IndexBufferObj->Size) {
- _mesa_warning(ctx,
- "glDrawElementsInstanced index out of buffer bounds");
- return GL_FALSE;
- }
- }
- else {
- /* not using a VBO */
- if (!indices)
- return GL_FALSE;
- }
-
- if (count == 0)
- return GL_FALSE;
-
- return GL_TRUE;
+ return validate_DrawElements_common(ctx, mode, count, type, indices,
+ "glDrawElementsInstanced")
+ && (numInstances > 0);
}