Move draw call early-outs until after validation.
Drawing without a current program is not an error and we can early-out,
but not until after other validation which could generate an error has
completed. Validation happening on a valid program happens afterwards
though. Likewise, providing insufficient vertices for even one
primitive results in drawing nothing, but validation still needs to
happen.
Change-Id: I5385ffe352fc38343caa41eb99f5549472da3b4f
Reviewed-on: https://swiftshader-review.googlesource.com/14489
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp
index b32e792..8dec865 100644
--- a/src/OpenGL/libGLESv2/Context.cpp
+++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -3481,21 +3481,13 @@
void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
{
- if(!mState.currentProgram)
- {
- return;
- }
-
sw::DrawType primitiveType;
int primitiveCount;
int verticesPerPrimitive;
if(!es2sw::ConvertPrimitiveType(mode, count, GL_NONE, primitiveType, primitiveCount, verticesPerPrimitive))
- return error(GL_INVALID_ENUM);
-
- if(primitiveCount <= 0)
{
- return;
+ return error(GL_INVALID_ENUM);
}
if(!applyRenderTarget())
@@ -3515,6 +3507,11 @@
return error(err);
}
+ if(!mState.currentProgram)
+ {
+ return;
+ }
+
applyShaders();
applyTextures();
@@ -3523,6 +3520,11 @@
return error(GL_INVALID_OPERATION);
}
+ if(primitiveCount <= 0)
+ {
+ return;
+ }
+
TransformFeedback* transformFeedback = getTransformFeedback();
if(!cullSkipsDraw(mode) || (transformFeedback->isActive() && !transformFeedback->isPaused()))
{
@@ -3537,11 +3539,6 @@
void Context::drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount)
{
- if(!mState.currentProgram)
- {
- return;
- }
-
if(!indices && !getCurrentVertexArray()->getElementArrayBuffer())
{
return error(GL_INVALID_OPERATION);
@@ -3570,11 +3567,8 @@
int verticesPerPrimitive;
if(!es2sw::ConvertPrimitiveType(internalMode, count, type, primitiveType, primitiveCount, verticesPerPrimitive))
- return error(GL_INVALID_ENUM);
-
- if(primitiveCount <= 0)
{
- return;
+ return error(GL_INVALID_ENUM);
}
if(!applyRenderTarget())
@@ -3602,6 +3596,11 @@
return error(err);
}
+ if(!mState.currentProgram)
+ {
+ return;
+ }
+
applyShaders();
applyTextures();
@@ -3610,6 +3609,11 @@
return error(GL_INVALID_OPERATION);
}
+ if(primitiveCount <= 0)
+ {
+ return;
+ }
+
TransformFeedback* transformFeedback = getTransformFeedback();
if(!cullSkipsDraw(internalMode) || (transformFeedback->isActive() && !transformFeedback->isPaused()))
{