Merge branch 'lp-offset-twoside'
[mesa.git] / src / mesa / main / drawpix.c
index 5d4b53af4cbec89a8b0fa0def63e1444b0ada3a6..757aae6e70306437cb5d1e8bd2a3807fd5d7f96e 100644 (file)
 #include "enums.h"
 #include "feedback.h"
 #include "framebuffer.h"
-#include "image.h"
 #include "readpix.h"
 #include "state.h"
-#include "glapi/dispatch.h"
+#include "dispatch.h"
 
 
 #if FEATURE_drawpix
 
 
-/**
- * If a fragment program is enabled, check that it's valid.
- * \return GL_TRUE if valid, GL_FALSE otherwise
- */
-static GLboolean
-valid_fragment_program(GLcontext *ctx)
-{
-   return !(ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled);
-}
-
-
 /*
  * Execute glDrawPixels
  */
@@ -66,33 +54,21 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
    }
 
    /* We're not using the current vertex program, and the driver may install
-    * it's own.
+    * its own.  Note: this may dirty some state.
     */
    _mesa_set_vp_override(ctx, GL_TRUE);
 
-   if (ctx->NewState) {
-      _mesa_update_state(ctx);
-   }
-
-   if (!valid_fragment_program(ctx)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glDrawPixels (invalid fragment program)");
-      goto end;
+   /* Note: this call does state validation */
+   if (!_mesa_valid_to_render(ctx, "glDrawPixels")) {
+      goto end;      /* the error code was recorded */
    }
 
    if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
-      /* the error was already recorded */
-      goto end;
-   }
-
-   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
-      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
-                  "glDrawPixels(incomplete framebuffer)" );
-      goto end;
+      goto end;      /* the error code was recorded */
    }
 
    if (!ctx->Current.RasterPosValid) {
-      goto end; /* no-op, not an error */
+      goto end;  /* no-op, not an error */
    }
 
    if (ctx->RenderMode == GL_RENDER) {
@@ -128,7 +104,6 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
       _mesa_feedback_vertex( ctx,
                              ctx->Current.RasterPos,
                              ctx->Current.RasterColor,
-                             ctx->Current.RasterIndex,
                              ctx->Current.RasterTexCoords[0] );
    }
    else {
@@ -167,22 +142,17 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
    }
 
    /* We're not using the current vertex program, and the driver may install
-    * it's own.
+    * it's own.  Note: this may dirty some state.
     */
    _mesa_set_vp_override(ctx, GL_TRUE);
 
-   if (ctx->NewState) {
-      _mesa_update_state(ctx);
+   /* Note: this call does state validation */
+   if (!_mesa_valid_to_render(ctx, "glCopyPixels")) {
+      goto end;      /* the error code was recorded */
    }
 
-   if (!valid_fragment_program(ctx)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glCopyPixels (invalid fragment program)");
-      goto end;
-   }
-
-   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
-       ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+   /* Check read buffer's status (draw buffer was already checked) */
+   if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
       _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
                   "glCopyPixels(incomplete framebuffer)" );
       goto end;
@@ -214,7 +184,6 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
       _mesa_feedback_vertex( ctx, 
                              ctx->Current.RasterPos,
                              ctx->Current.RasterColor,
-                             ctx->Current.RasterIndex,
                              ctx->Current.RasterTexCoords[0] );
    }
    else {
@@ -244,19 +213,9 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
       return;    /* do nothing */
    }
 
-   if (ctx->NewState) {
-      _mesa_update_state(ctx);
-   }
-
-   if (!valid_fragment_program(ctx)) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBitmap (invalid fragment program)");
-      return;
-   }
-
-   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
-      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
-                  "glBitmap(incomplete framebuffer)");
+   /* Note: this call does state validation */
+   if (!_mesa_valid_to_render(ctx, "glBitmap")) {
+      /* the error code was recorded */
       return;
    }
 
@@ -294,7 +253,6 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
       _mesa_feedback_vertex( ctx,
                              ctx->Current.RasterPos,
                              ctx->Current.RasterColor,
-                             ctx->Current.RasterIndex, 
                              ctx->Current.RasterTexCoords[0] );
    }
    else {