Fix pow <small> and a very stypid bug with dummy srcs(0 equals to tmp0.x)</small...
[mesa.git] / src / mesa / main / drawpix.c
index 3ced2072478fd98d32b54dc293139a9a3f98bdc6..638679e8455c96bb0fac2c451a7afd7fa121ce46 100644 (file)
@@ -43,6 +43,15 @@ error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
                         GLboolean drawing)
 {
    const char *readDraw = drawing ? "Draw" : "Read";
+   struct gl_framebuffer *fb = drawing ? ctx->DrawBuffer : ctx->ReadBuffer;
+
+   if (ctx->Extensions.EXT_packed_depth_stencil
+       && type == GL_UNSIGNED_INT_24_8_EXT
+       && format != GL_DEPTH_STENCIL_EXT) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "gl%sPixels(format is not GL_DEPTH_STENCIL_EXT)", readDraw);
+      return GL_TRUE;
+   }
 
    /* basic combinations test */
    if (!_mesa_is_legal_format_and_type(ctx, format, type)) {
@@ -78,19 +87,33 @@ error_check_format_type(GLcontext *ctx, GLenum format, GLenum type,
       }
       break;
    case GL_STENCIL_INDEX:
-      if (ctx->DrawBuffer->Visual.stencilBits == 0) {
+      if (fb->Visual.stencilBits == 0) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "gl%sPixels(no stencil buffer)", readDraw);
          return GL_TRUE;
       }
       break;
    case GL_DEPTH_COMPONENT:
-      if (ctx->DrawBuffer->Visual.depthBits == 0) {
+      if (fb->Visual.depthBits == 0) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "gl%sPixels(no depth buffer)", readDraw);
          return GL_TRUE;
       }
       break;
+   case GL_DEPTH_STENCIL_EXT:
+      if (!ctx->Extensions.EXT_packed_depth_stencil ||
+          type != GL_UNSIGNED_INT_24_8_EXT) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "gl%sPixels(type)", readDraw);
+         return GL_TRUE;
+      }
+      if (fb->Visual.depthBits == 0 || fb->Visual.stencilBits == 0) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "gl%sPixels(no depth or stencil buffer)", readDraw);
+         return GL_TRUE;
+      }
+      ASSERT(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
+      ASSERT(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
+      break;
    default:
       /* this should have been caught in _mesa_is_legal_format_type() */
       _mesa_problem(ctx, "unexpected format in _mesa_%sPixels", readDraw);
@@ -126,17 +149,23 @@ _mesa_DrawPixels( GLsizei width, GLsizei height,
       return;
    }
 
+   if (ctx->NewState) {
+      _mesa_update_state(ctx);
+   }
+
    if (error_check_format_type(ctx, format, type, GL_TRUE)) {
       /* found an error */
       return;
    }
 
-   if (!ctx->Current.RasterPosValid) {
-      return; /* not an error */
+   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glDrawPixels(incomplete framebuffer)" );
+      return;
    }
 
-   if (ctx->NewState) {
-      _mesa_update_state(ctx);
+   if (!ctx->Current.RasterPosValid) {
+      return;
    }
 
    if (ctx->RenderMode == GL_RENDER) {
@@ -170,6 +199,10 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
+   if (ctx->NewState) {
+      _mesa_update_state(ctx);
+   }
+
    if (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glCopyPixels (invalid fragment program)");
@@ -201,13 +234,30 @@ _mesa_CopyPixels( GLint srcx, GLint srcy, GLsizei width, GLsizei height,
          return;
       }
       break;
+   case GL_DEPTH_STENCIL_EXT:
+      if (!ctx->Extensions.EXT_packed_depth_stencil) {
+         _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels");
+         return;
+      }
+      if (ctx->DrawBuffer->Visual.depthBits == 0 ||
+          ctx->ReadBuffer->Visual.depthBits == 0 ||
+          ctx->DrawBuffer->Visual.stencilBits == 0 ||
+          ctx->ReadBuffer->Visual.stencilBits == 0) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "glCopyPixels(no depth or stencil buffer)");
+         return;
+      }
+      break;
    default:
       _mesa_error(ctx, GL_INVALID_ENUM, "glCopyPixels");
       return;
    }
 
-   if (ctx->NewState) {
-      _mesa_update_state(ctx);
+   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT ||
+       ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glCopyPixels(incomplete framebuffer)" );
+      return;
    }
 
    if (!ctx->Current.RasterPosValid) {
@@ -245,6 +295,7 @@ _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
                  GLenum format, GLenum type, GLvoid *pixels )
 {
    GET_CURRENT_CONTEXT(ctx);
+   const struct gl_renderbuffer *rb = ctx->ReadBuffer->_ColorReadBuffer;
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
 
    if (width < 0 || height < 0) {
@@ -253,13 +304,24 @@ _mesa_ReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
       return;
    }
 
+   if (ctx->NewState)
+      _mesa_update_state(ctx);
+
    if (error_check_format_type(ctx, format, type, GL_FALSE)) {
       /* found an error */
       return;
    }
 
-   if (ctx->NewState)
-      _mesa_update_state(ctx);
+   if (ctx->ReadBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glReadPixels(incomplete framebuffer)" );
+      return;
+   }
+
+   if (!rb) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glReadPixels(no readbuffer)");
+      return;
+   }
 
    ctx->Driver.ReadPixels(ctx, x, y, width, height,
                          format, type, &ctx->Pack, pixels);
@@ -294,6 +356,12 @@ _mesa_Bitmap( GLsizei width, GLsizei height,
       _mesa_update_state(ctx);
    }
 
+   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glBitmap(incomplete framebuffer)");
+      return;
+   }
+
    if (ctx->RenderMode == GL_RENDER) {
       /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */
       GLint x = IFLOOR(ctx->Current.RasterPos[0] - xorig);
@@ -354,6 +422,12 @@ _mesa_DrawDepthPixelsMESA( GLsizei width, GLsizei height,
       _mesa_update_state(ctx);
    }
 
+   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glDrawDepthPixelsMESA(incomplete framebuffer)");
+      return;
+   }
+
    if (ctx->RenderMode == GL_RENDER) {
       /* Round, to satisfy conformance tests (matches SGI's OpenGL) */
       GLint x = IROUND(ctx->Current.RasterPos[0]);