Prevent crashing when no current program is set.

This fixes a regression caused by
https://swiftshader-review.googlesource.com/14489

Context::applyVertexBuffer() expects a valid program, so we need to
check for it sooner. Not having a current program is not an error and
makes the draw call a no-op, but
dEQP-GLES3.functional.negative_api.vertex_array.* still expects
validation to happen before leaving the function. In particular,
the framebuffer completeness check has to be performed. Note that
ConvertPrimitiveType() should never return an error because we already
check the primitive type in the entry function, sampler validation
can only be done when we have a valid program, and likewise
applyVertexBuffer() requires a program, so these validations can still
happen after the early-out.

Change-Id: I7036ca59d37ea0385f79bf87afd1eeeb9728f7af
Reviewed-on: https://swiftshader-review.googlesource.com/17228
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Lingfeng Yang <lfy@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Common/Version.h b/src/Common/Version.h
index 627366d..f73a7e9 100644
--- a/src/Common/Version.h
+++ b/src/Common/Version.h
@@ -15,7 +15,7 @@
 #define MAJOR_VERSION 4
 #define MINOR_VERSION 0
 #define BUILD_VERSION 0
-#define BUILD_REVISION 0
+#define BUILD_REVISION 1
 
 #define STRINGIFY(x) #x
 #define MACRO_STRINGIFY(x) STRINGIFY(x)
diff --git a/src/OpenGL/libGLESv2/Context.cpp b/src/OpenGL/libGLESv2/Context.cpp
index 92b9a0a..fa081c5 100644
--- a/src/OpenGL/libGLESv2/Context.cpp
+++ b/src/OpenGL/libGLESv2/Context.cpp
@@ -3465,6 +3465,16 @@
 
 void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
 {
+	if(!applyRenderTarget())
+	{
+		return;
+	}
+
+	if(mState.currentProgram == 0)
+	{
+		return;   // Nothing to process.
+	}
+
 	sw::DrawType primitiveType;
 	int primitiveCount;
 	int verticesPerPrimitive;
@@ -3474,11 +3484,6 @@
 		return error(GL_INVALID_ENUM);
 	}
 
-	if(!applyRenderTarget())
-	{
-		return;
-	}
-
 	applyState(mode);
 
 	for(int i = 0; i < instanceCount; ++i)
@@ -3491,11 +3496,6 @@
 			return error(err);
 		}
 
-		if(!mState.currentProgram)
-		{
-			return;
-		}
-
 		applyShaders();
 		applyTextures();
 
@@ -3523,6 +3523,16 @@
 
 void Context::drawElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLsizei instanceCount)
 {
+	if(!applyRenderTarget())
+	{
+		return;
+	}
+
+	if(mState.currentProgram == 0)
+	{
+		return;   // Nothing to process.
+	}
+
 	if(!indices && !getCurrentVertexArray()->getElementArrayBuffer())
 	{
 		return error(GL_INVALID_OPERATION);
@@ -3555,11 +3565,6 @@
 		return error(GL_INVALID_ENUM);
 	}
 
-	if(!applyRenderTarget())
-	{
-		return;
-	}
-
 	TranslatedIndexData indexInfo(primitiveCount);
 	GLenum err = applyIndexBuffer(indices, start, end, count, mode, type, &indexInfo);
 	if(err != GL_NO_ERROR)
@@ -3580,11 +3585,6 @@
 			return error(err);
 		}
 
-		if(!mState.currentProgram)
-		{
-			return;
-		}
-
 		applyShaders();
 		applyTextures();