r600g: pad the DMA CS to a multiple of 8 dwords
[mesa.git] / src / mesa / main / drawpix.c
index 01983d945ca7a7f06321068cf10cf1e6616b5b87..d9f55d3af28fc23d6f73609a1b57739787be4981 100644 (file)
 #include "image.h"
 #include "mfeatures.h"
 #include "pbo.h"
-#include "readpix.h"
 #include "state.h"
 #include "dispatch.h"
-
-
-#if FEATURE_drawpix
+#include "glformats.h"
+#include "fbobject.h"
 
 
 /*
  * Execute glDrawPixels
  */
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_DrawPixels( GLsizei width, GLsizei height,
                   GLenum format, GLenum type, const GLvoid *pixels )
 {
+   GLenum err;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+   FLUSH_VERTICES(ctx, 0);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glDrawPixels(%d, %d, %s, %s, %p) // to %s at %d, %d\n",
@@ -89,13 +89,45 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
     * input), NVIDIA's implementation also just returns this error despite
     * exposing GL_EXT_texture_integer, just return an error regardless.
     */
-   if (_mesa_is_integer_format(format)) {
+   if (_mesa_is_enum_format_integer(format)) {
       _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawPixels(integer format)");
       goto end;
    }
 
-   if (_mesa_error_check_format_type(ctx, format, type, GL_TRUE)) {
-      goto end;      /* the error code was recorded */
+   err = _mesa_error_check_format_and_type(ctx, format, type);
+   if (err != GL_NO_ERROR) {
+      _mesa_error(ctx, err, "glDrawPixels(invalid format %s and/or type %s)",
+                  _mesa_lookup_enum_by_nr(format),
+                  _mesa_lookup_enum_by_nr(type));
+      goto end;
+   }
+
+   /* do special format-related checks */
+   switch (format) {
+   case GL_STENCIL_INDEX:
+   case GL_DEPTH_COMPONENT:
+   case GL_DEPTH_STENCIL_EXT:
+      /* these buffers must exist */
+      if (!_mesa_dest_buffer_exists(ctx, format)) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glDrawPixels(missing deest buffer)");
+         goto end;
+      }
+      break;
+   case GL_COLOR_INDEX:
+      if (ctx->PixelMaps.ItoR.Size == 0 ||
+          ctx->PixelMaps.ItoG.Size == 0 ||
+          ctx->PixelMaps.ItoB.Size == 0) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                "glDrawPixels(drawing color index pixels into RGB buffer)");
+         goto end;
+      }
+      break;
+   default:
+      /* for color formats it's not an error if the destination color
+       * buffer doesn't exist.
+       */
+      break;
    }
 
    if (ctx->RasterDiscard) {
@@ -148,15 +180,20 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
 
 end:
    _mesa_set_vp_override(ctx, GL_FALSE);
+
+   if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
+      _mesa_flush(ctx);
+   }
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
                   GLenum type )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+   FLUSH_VERTICES(ctx, 0);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx,
@@ -203,8 +240,9 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
       goto end;
    }
 
-   if (ctx->ReadBuffer->Name != 0 && ctx->ReadBuffer->Visual.samples > 0) {
-      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION,
+   if (_mesa_is_user_fbo(ctx->ReadBuffer) &&
+       ctx->ReadBuffer->Visual.samples > 0) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
                  "glCopyPixels(multisample FBO)");
       goto end;
    }
@@ -248,16 +286,21 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
 
 end:
    _mesa_set_vp_override(ctx, GL_FALSE);
+
+   if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
+      _mesa_flush(ctx);
+   }
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_Bitmap( GLsizei width, GLsizei height,
               GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove,
               const GLubyte *bitmap )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+   FLUSH_VERTICES(ctx, 0);
 
    if (width < 0 || height < 0) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glBitmap(width or height < 0)" );
@@ -304,7 +347,6 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
          ctx->Driver.Bitmap( ctx, x, y, width, height, &ctx->Unpack, bitmap );
       }
    }
-#if _HAVE_FULL_GL
    else if (ctx->RenderMode == GL_FEEDBACK) {
       FLUSH_CURRENT(ctx, 0);
       _mesa_feedback_token( ctx, (GLfloat) (GLint) GL_BITMAP_TOKEN );
@@ -317,21 +359,12 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
       ASSERT(ctx->RenderMode == GL_SELECT);
       /* Do nothing.  See OpenGL Spec, Appendix B, Corollary 6. */
    }
-#endif
 
    /* update raster position */
    ctx->Current.RasterPos[0] += xmove;
    ctx->Current.RasterPos[1] += ymove;
-}
-
 
-void
-_mesa_init_drawpix_dispatch(struct _glapi_table *disp)
-{
-   SET_Bitmap(disp, _mesa_Bitmap);
-   SET_CopyPixels(disp, _mesa_CopyPixels);
-   SET_DrawPixels(disp, _mesa_DrawPixels);
+   if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
+      _mesa_flush(ctx);
+   }
 }
-
-
-#endif /* FEATURE_drawpix */