mesa: new _mesa_valid_to_render() function
authorBrian Paul <brianp@vmware.com>
Fri, 14 Aug 2009 16:45:17 +0000 (10:45 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 14 Aug 2009 17:27:33 +0000 (11:27 -0600)
Tests if the current shader/program is valid and that the framebuffer is
complete.  To be called by glBegin, glDrawArrays, etc.

src/mesa/main/context.c
src/mesa/main/context.h

index 415e339..3547d0a 100644 (file)
@@ -1576,4 +1576,46 @@ _mesa_set_mvp_with_dp4( GLcontext *ctx,
 }
 
 
+
+/**
+ * Prior to drawing anything with glBegin, glDrawArrays, etc. this function
+ * is called to see if it's valid to render.  This involves checking that
+ * the current shader is valid and the framebuffer is complete.
+ * If an error is detected it'll be recorded here.
+ * \return GL_TRUE if OK to render, GL_FALSE if not
+ */
+GLboolean
+_mesa_valid_to_render(GLcontext *ctx, const char *where)
+{
+   if (ctx->Shader.CurrentProgram) {
+      /* using shaders */
+      if (!ctx->Shader.CurrentProgram->LinkStatus) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "%s(shader not linked), where");
+         return GL_FALSE;
+      }
+   }
+   else {
+      if (ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "%s(vertex program not valid)", where);
+         return GL_FALSE;
+      }
+      if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "%s(fragment program not valid)", where);
+         return GL_FALSE;
+      }
+   }
+
+   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "%s(incomplete framebuffer)", where);
+      return GL_FALSE;
+   }
+
+   return GL_TRUE;
+}
+
+
 /*@}*/
index 0531ae8..5587695 100644 (file)
@@ -159,6 +159,11 @@ _mesa_set_mvp_with_dp4( GLcontext *ctx,
                         GLboolean flag );
 
 
+extern GLboolean
+_mesa_valid_to_render(GLcontext *ctx, const char *where);
+
+
+
 /** \name Miscellaneous */
 /*@{*/
 
@@ -174,7 +179,6 @@ _mesa_Flush( void );
 /*@}*/
 
 
-
 /**
  * \name Macros for flushing buffered rendering commands before state changes,
  * checking if inside glBegin/glEnd, etc.