mesa: Use correct data for MAX_{VERTEX,GEOMETRY}_VARYING_COMPONENTS_ARB queries
[mesa.git] / src / mesa / main / fbobject.c
index 070fb8c535628aa92346d1d699478830a1fca652..1034c7a712c24b3497d9acd92cc6e4466f9b3ba1 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (C) 1999-2009  VMware, Inc.  All Rights Reserved.
@@ -327,7 +326,7 @@ _mesa_remove_attachment(struct gl_context *ctx,
 
    /* tell driver that we're done rendering to this texture. */
    if (rb && rb->NeedsFinishRenderTexture)
-      ctx->Driver.FinishRenderTexture(ctx, att);
+      ctx->Driver.FinishRenderTexture(ctx, rb);
 
    if (att->Type == GL_TEXTURE) {
       ASSERT(att->Texture);
@@ -343,6 +342,28 @@ _mesa_remove_attachment(struct gl_context *ctx,
    att->Complete = GL_TRUE;
 }
 
+/**
+ * Verify a couple error conditions that will lead to an incomplete FBO and
+ * may cause problems for the driver's RenderTexture path.
+ */
+static bool
+driver_RenderTexture_is_safe(const struct gl_renderbuffer_attachment *att)
+{
+   const struct gl_texture_image *const texImage =
+      att->Texture->Image[att->CubeMapFace][att->TextureLevel];
+
+   if (texImage->Width == 0 || texImage->Height == 0 || texImage->Depth == 0)
+      return false;
+
+   if ((texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY
+        && att->Zoffset >= texImage->Height)
+       || (texImage->TexObject->Target != GL_TEXTURE_1D_ARRAY
+           && att->Zoffset >= texImage->Depth))
+      return false;
+
+   return true;
+}
+
 /**
  * Create a renderbuffer which will be set up by the driver to wrap the
  * texture image slice.
@@ -364,8 +385,6 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
    struct gl_renderbuffer *rb;
 
    texImage = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
-   if (!texImage)
-      return;
 
    rb = att->Renderbuffer;
    if (!rb) {
@@ -384,6 +403,9 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
       rb->NeedsFinishRenderTexture = ctx->Driver.FinishRenderTexture != NULL;
    }
 
+   if (!texImage)
+      return;
+
    rb->_BaseFormat = texImage->_BaseFormat;
    rb->Format = texImage->TexFormat;
    rb->InternalFormat = texImage->InternalFormat;
@@ -392,7 +414,8 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
    rb->NumSamples = texImage->NumSamples;
    rb->TexImage = texImage;
 
-   ctx->Driver.RenderTexture(ctx, fb, att);
+   if (driver_RenderTexture_is_safe(att))
+      ctx->Driver.RenderTexture(ctx, fb, att);
 }
 
 /**
@@ -410,7 +433,7 @@ _mesa_set_texture_attachment(struct gl_context *ctx,
    struct gl_renderbuffer *rb = att->Renderbuffer;
 
    if (rb && rb->NeedsFinishRenderTexture)
-      ctx->Driver.FinishRenderTexture(ctx, att);
+      ctx->Driver.FinishRenderTexture(ctx, rb);
 
    if (att->Texture == texObj) {
       /* re-attaching same texture */
@@ -569,8 +592,15 @@ att_incomplete(const char *msg)
  * For debug only.
  */
 static void
-fbo_incomplete(const char *msg, int index)
+fbo_incomplete(struct gl_context *ctx, const char *msg, int index)
 {
+   static GLuint msg_id;
+
+   _mesa_gl_debug(ctx, &msg_id,
+                  MESA_DEBUG_TYPE_OTHER,
+                  MESA_DEBUG_SEVERITY_MEDIUM,
+                  "FBO incomplete: %s [%d]\n", msg, index);
+
    if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_FBO) {
       _mesa_debug(NULL, "FBO Incomplete: %s [%d]\n", msg, index);
    }
@@ -697,15 +727,39 @@ test_attachment_completeness(const struct gl_context *ctx, GLenum format,
       }
       if (texImage->Width < 1 || texImage->Height < 1) {
          att_incomplete("teximage width/height=0");
-         printf("texobj = %u\n", texObj->Name);
-         printf("level = %d\n", att->TextureLevel);
          att->Complete = GL_FALSE;
          return;
       }
-      if (texObj->Target == GL_TEXTURE_3D && att->Zoffset >= texImage->Depth) {
-         att_incomplete("bad z offset");
-         att->Complete = GL_FALSE;
-         return;
+
+      switch (texObj->Target) {
+      case GL_TEXTURE_3D:
+         if (att->Zoffset >= texImage->Depth) {
+            att_incomplete("bad z offset");
+            att->Complete = GL_FALSE;
+            return;
+         }
+         break;
+      case GL_TEXTURE_1D_ARRAY:
+         if (att->Zoffset >= texImage->Height) {
+            att_incomplete("bad 1D-array layer");
+            att->Complete = GL_FALSE;
+            return;
+         }
+         break;
+      case GL_TEXTURE_2D_ARRAY:
+         if (att->Zoffset >= texImage->Depth) {
+            att_incomplete("bad 2D-array layer");
+            att->Complete = GL_FALSE;
+            return;
+         }
+         break;
+      case GL_TEXTURE_CUBE_MAP_ARRAY:
+         if (att->Zoffset >= texImage->Depth) {
+            att_incomplete("bad cube-array layer");
+            att->Complete = GL_FALSE;
+            return;
+         }
+         break;
       }
 
       baseFormat = _mesa_get_format_base_format(texImage->TexFormat);
@@ -864,7 +918,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
          test_attachment_completeness(ctx, GL_DEPTH, att);
          if (!att->Complete) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
-            fbo_incomplete("depth attachment incomplete", -1);
+            fbo_incomplete(ctx, "depth attachment incomplete", -1);
             return;
          }
       }
@@ -873,7 +927,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
          test_attachment_completeness(ctx, GL_STENCIL, att);
          if (!att->Complete) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
-            fbo_incomplete("stencil attachment incomplete", -1);
+            fbo_incomplete(ctx, "stencil attachment incomplete", -1);
             return;
          }
       }
@@ -882,7 +936,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
          test_attachment_completeness(ctx, GL_COLOR, att);
          if (!att->Complete) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT;
-            fbo_incomplete("color attachment incomplete", i);
+            fbo_incomplete(ctx, "color attachment incomplete", i);
             return;
          }
       }
@@ -902,7 +956,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
          if (!is_format_color_renderable(ctx, attFormat, texImg->InternalFormat) &&
              !is_legal_depth_format(ctx, f)) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
-            fbo_incomplete("texture attachment incomplete", -1);
+            fbo_incomplete(ctx, "texture attachment incomplete", -1);
             return;
          }
 
@@ -910,7 +964,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
             numSamples = texImg->NumSamples;
          else if (numSamples != texImg->NumSamples) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
-            fbo_incomplete("inconsistent sample count", -1);
+            fbo_incomplete(ctx, "inconsistent sample count", -1);
             return;
          }
 
@@ -918,7 +972,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
             fixedSampleLocations = texImg->FixedSampleLocations;
          else if (fixedSampleLocations != texImg->FixedSampleLocations) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
-            fbo_incomplete("inconsistent fixed sample locations", -1);
+            fbo_incomplete(ctx, "inconsistent fixed sample locations", -1);
             return;
          }
       }
@@ -935,7 +989,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
             numSamples = att->Renderbuffer->NumSamples;
          else if (numSamples != att->Renderbuffer->NumSamples) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
-            fbo_incomplete("inconsistent sample count", -1);
+            fbo_incomplete(ctx, "inconsistent sample count", -1);
             return;
          }
 
@@ -944,7 +998,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
             fixedSampleLocations = GL_TRUE;
          else if (fixedSampleLocations != GL_TRUE) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE;
-            fbo_incomplete("inconsistent fixed sample locations", -1);
+            fbo_incomplete(ctx, "inconsistent fixed sample locations", -1);
             return;
          }
       }
@@ -981,13 +1035,13 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
             /* check that width, height, format are same */
             if (minWidth != maxWidth || minHeight != maxHeight) {
                fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT;
-               fbo_incomplete("width or height mismatch", -1);
+               fbo_incomplete(ctx, "width or height mismatch", -1);
                return;
             }
             /* check that all color buffers are the same format */
             if (intFormat != GL_NONE && f != intFormat) {
                fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT;
-               fbo_incomplete("format mismatch", -1);
+               fbo_incomplete(ctx, "format mismatch", -1);
                return;
             }
          }
@@ -998,7 +1052,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
       if (att->Type == GL_RENDERBUFFER &&
           att->Renderbuffer->Format == MESA_FORMAT_NONE) {
          fb->_Status = GL_FRAMEBUFFER_UNSUPPORTED;
-         fbo_incomplete("unsupported renderbuffer format", i);
+         fbo_incomplete(ctx, "unsupported renderbuffer format", i);
          return;
       }
 
@@ -1010,10 +1064,10 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
       } else if (layer_count != att_layer_count) {
          if (layer_count == 0 || att_layer_count == 0) {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS;
-            fbo_incomplete("framebuffer attachment layer mode is inconsistent", i);
+            fbo_incomplete(ctx, "framebuffer attachment layer mode is inconsistent", i);
          } else {
             fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB;
-            fbo_incomplete("framebuffer attachment layer count is inconsistent", i);
+            fbo_incomplete(ctx, "framebuffer attachment layer count is inconsistent", i);
          }
          return;
       }
@@ -1030,7 +1084,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
            assert(att);
            if (att->Type == GL_NONE) {
               fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT;
-              fbo_incomplete("missing drawbuffer", j);
+              fbo_incomplete(ctx, "missing drawbuffer", j);
               return;
            }
         }
@@ -1043,7 +1097,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
         assert(att);
         if (att->Type == GL_NONE) {
            fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT;
-            fbo_incomplete("missing readbuffer", -1);
+            fbo_incomplete(ctx, "missing readbuffer", -1);
            return;
         }
       }
@@ -1051,7 +1105,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
 
    if (numImages == 0) {
       fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT;
-      fbo_incomplete("no attachments", -1);
+      fbo_incomplete(ctx, "no attachments", -1);
       return;
    }
 
@@ -1065,7 +1119,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
    if (ctx->Driver.ValidateFramebuffer) {
       ctx->Driver.ValidateFramebuffer(ctx, fb);
       if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
-         fbo_incomplete("driver marked FBO as incomplete", -1);
+         fbo_incomplete(ctx, "driver marked FBO as incomplete", -1);
       }
    }
 
@@ -1098,8 +1152,8 @@ _mesa_IsRenderbuffer(GLuint renderbuffer)
 }
 
 
-void GLAPIENTRY
-_mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer)
+static void
+bind_renderbuffer(GLenum target, GLuint renderbuffer, bool allow_user_names)
 {
    struct gl_renderbuffer *newRb;
    GET_CURRENT_CONTEXT(ctx);
@@ -1119,9 +1173,7 @@ _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer)
          /* ID was reserved, but no real renderbuffer object made yet */
          newRb = NULL;
       }
-      else if (!newRb
-               && _mesa_is_desktop_gl(ctx)
-               && ctx->Extensions.ARB_framebuffer_object) {
+      else if (!newRb && !allow_user_names) {
          /* All RB IDs must be Gen'd */
          _mesa_error(ctx, GL_INVALID_OPERATION, "glBindRenderbuffer(buffer)");
          return;
@@ -1148,25 +1200,68 @@ _mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer)
    _mesa_reference_renderbuffer(&ctx->CurrentRenderbuffer, newRb);
 }
 
+void GLAPIENTRY
+_mesa_BindRenderbuffer(GLenum target, GLuint renderbuffer)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   /* OpenGL ES glBindRenderbuffer and glBindRenderbufferOES use this same
+    * entry point, but they allow the use of user-generated names.
+    */
+   bind_renderbuffer(target, renderbuffer, _mesa_is_gles(ctx));
+}
+
+void GLAPIENTRY
+_mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
+{
+   /* This function should not be in the dispatch table for core profile /
+    * OpenGL 3.1, so execution should never get here in those cases -- no
+    * need for an explicit test.
+    */
+   bind_renderbuffer(target, renderbuffer, true);
+}
+
 
 /**
- * If the given renderbuffer is anywhere attached to the framebuffer, detach
- * the renderbuffer.
- * This is used when a renderbuffer object is deleted.
- * The spec calls for unbinding.
+ * Remove the specified renderbuffer or texture from any attachment point in
+ * the framebuffer.
+ *
+ * \returns
+ * \c true if the renderbuffer was detached from an attachment point.  \c
+ * false otherwise.
  */
-static void
-detach_renderbuffer(struct gl_context *ctx,
-                    struct gl_framebuffer *fb,
-                    struct gl_renderbuffer *rb)
+bool
+_mesa_detach_renderbuffer(struct gl_context *ctx,
+                          struct gl_framebuffer *fb,
+                          const void *att)
 {
-   GLuint i;
+   unsigned i;
+   bool progress = false;
+
    for (i = 0; i < BUFFER_COUNT; i++) {
-      if (fb->Attachment[i].Renderbuffer == rb) {
+      if (fb->Attachment[i].Texture == att
+          || fb->Attachment[i].Renderbuffer == att) {
          _mesa_remove_attachment(ctx, &fb->Attachment[i]);
+         progress = true;
       }
    }
-   invalidate_framebuffer(fb);
+
+   /* Section 4.4.4 (Framebuffer Completeness), subsection "Whole Framebuffer
+    * Completeness," of the OpenGL 3.1 spec says:
+    *
+    *     "Performing any of the following actions may change whether the
+    *     framebuffer is considered complete or incomplete:
+    *
+    *     ...
+    *
+    *        - Deleting, with DeleteTextures or DeleteRenderbuffers, an object
+    *          containing an image that is attached to a framebuffer object
+    *          that is bound to the framebuffer."
+    */
+   if (progress)
+      invalidate_framebuffer(fb);
+
+   return progress;
 }
 
 
@@ -1190,12 +1285,29 @@ _mesa_DeleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
                _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT, 0);
             }
 
+            /* Section 4.4.2 (Attaching Images to Framebuffer Objects),
+             * subsection "Attaching Renderbuffer Images to a Framebuffer," of
+             * the OpenGL 3.1 spec says:
+             *
+             *     "If a renderbuffer object is deleted while its image is
+             *     attached to one or more attachment points in the currently
+             *     bound framebuffer, then it is as if FramebufferRenderbuffer
+             *     had been called, with a renderbuffer of 0, for each
+             *     attachment point to which this image was attached in the
+             *     currently bound framebuffer. In other words, this
+             *     renderbuffer image is first detached from all attachment
+             *     points in the currently bound framebuffer. Note that the
+             *     renderbuffer image is specifically not detached from any
+             *     non-bound framebuffers. Detaching the image from any
+             *     non-bound framebuffers is the responsibility of the
+             *     application.
+             */
             if (_mesa_is_user_fbo(ctx->DrawBuffer)) {
-               detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
+               _mesa_detach_renderbuffer(ctx, ctx->DrawBuffer, rb);
             }
             if (_mesa_is_user_fbo(ctx->ReadBuffer)
                 && ctx->ReadBuffer != ctx->DrawBuffer) {
-               detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
+               _mesa_detach_renderbuffer(ctx, ctx->ReadBuffer, rb);
             }
 
            /* Remove from hash table immediately, to free the ID.
@@ -1862,7 +1974,8 @@ check_begin_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
 
    for (i = 0; i < BUFFER_COUNT; i++) {
       struct gl_renderbuffer_attachment *att = fb->Attachment + i;
-      if (att->Texture && att->Renderbuffer->TexImage) {
+      if (att->Texture && att->Renderbuffer->TexImage
+          && driver_RenderTexture_is_safe(att)) {
          ctx->Driver.RenderTexture(ctx, fb, att);
       }
    }
@@ -1886,15 +1999,15 @@ check_end_texture_render(struct gl_context *ctx, struct gl_framebuffer *fb)
          struct gl_renderbuffer_attachment *att = fb->Attachment + i;
          struct gl_renderbuffer *rb = att->Renderbuffer;
          if (rb && rb->NeedsFinishRenderTexture) {
-            ctx->Driver.FinishRenderTexture(ctx, att);
+            ctx->Driver.FinishRenderTexture(ctx, rb);
          }
       }
    }
 }
 
 
-void GLAPIENTRY
-_mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
+static void
+bind_framebuffer(GLenum target, GLuint framebuffer, bool allow_user_names)
 {
    struct gl_framebuffer *newDrawFb, *newReadFb;
    struct gl_framebuffer *oldDrawFb, *oldReadFb;
@@ -1903,17 +2016,10 @@ _mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
 
 #ifdef DEBUG
    if (ctx->Extensions.ARB_framebuffer_object) {
-      ASSERT(ctx->Extensions.EXT_framebuffer_object);
       ASSERT(ctx->Extensions.EXT_framebuffer_blit);
    }
 #endif
 
-   if (!ctx->Extensions.EXT_framebuffer_object) {
-      _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glBindFramebufferEXT(unsupported)");
-      return;
-   }
-
    switch (target) {
    case GL_DRAW_FRAMEBUFFER_EXT:
       if (!ctx->Extensions.EXT_framebuffer_blit) {
@@ -1947,9 +2053,7 @@ _mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
          /* ID was reserved, but no real framebuffer object made yet */
          newDrawFb = NULL;
       }
-      else if (!newDrawFb
-               && _mesa_is_desktop_gl(ctx)
-               && ctx->Extensions.ARB_framebuffer_object) {
+      else if (!newDrawFb && !allow_user_names) {
          /* All FBO IDs must be Gen'd */
          _mesa_error(ctx, GL_INVALID_OPERATION, "glBindFramebuffer(buffer)");
          return;
@@ -2026,6 +2130,26 @@ _mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
    }
 }
 
+void GLAPIENTRY
+_mesa_BindFramebuffer(GLenum target, GLuint framebuffer)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   /* OpenGL ES glBindFramebuffer and glBindFramebufferOES use this same entry
+    * point, but they allow the use of user-generated names.
+    */
+   bind_framebuffer(target, framebuffer, _mesa_is_gles(ctx));
+}
+
+void GLAPIENTRY
+_mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
+{
+   /* This function should not be in the dispatch table for core profile /
+    * OpenGL 3.1, so execution should never get here in those cases -- no
+    * need for an explicit test.
+    */
+   bind_framebuffer(target, framebuffer, true);
+}
 
 void GLAPIENTRY
 _mesa_DeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
@@ -2128,8 +2252,12 @@ _mesa_CheckFramebufferStatus(GLenum target)
    }
 
    if (_mesa_is_winsys_fbo(buffer)) {
-      /* The window system / default framebuffer is always complete */
-      return GL_FRAMEBUFFER_COMPLETE_EXT;
+      /* EGL_KHR_surfaceless_context allows the winsys FBO to be incomplete. */
+      if (buffer != &IncompleteFramebuffer) {
+         return GL_FRAMEBUFFER_COMPLETE_EXT;
+      } else {
+         return GL_FRAMEBUFFER_UNDEFINED;
+      }
    }
 
    /* No need to flush here */
@@ -2459,7 +2587,7 @@ _mesa_FramebufferTexture(GLenum target, GLenum attachment,
 {
    GET_CURRENT_CONTEXT(ctx);
 
-   if (ctx->Version >= 32 || ctx->Extensions.ARB_geometry_shader4) {
+   if (_mesa_has_geometry_shaders(ctx)) {
       framebuffer_texture(ctx, "Layer", target, attachment, 0, texture,
                           level, 0, GL_TRUE);
    } else {
@@ -2980,6 +3108,20 @@ compatible_resolve_formats(const struct gl_renderbuffer *readRb,
    return GL_FALSE;
 }
 
+static GLboolean
+is_valid_blit_filter(const struct gl_context *ctx, GLenum filter)
+{
+   switch (filter) {
+   case GL_NEAREST:
+   case GL_LINEAR:
+      return true;
+   case GL_SCALED_RESOLVE_FASTEST_EXT:
+   case GL_SCALED_RESOLVE_NICEST_EXT:
+      return ctx->Extensions.EXT_framebuffer_multisample_blit_scaled;
+   default:
+      return false;
+   }
+}
 
 /**
  * Blit rectangular region, optionally from one framebuffer to another.
@@ -3029,8 +3171,17 @@ _mesa_BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
       return;
    }
 
-   if (filter != GL_NEAREST && filter != GL_LINEAR) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(filter)");
+   if (!is_valid_blit_filter(ctx, filter)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glBlitFramebufferEXT(%s)",
+                  _mesa_lookup_enum_by_nr(filter));
+      return;
+   }
+
+   if ((filter == GL_SCALED_RESOLVE_FASTEST_EXT ||
+        filter == GL_SCALED_RESOLVE_NICEST_EXT) &&
+        (readFb->Visual.samples == 0 || drawFb->Visual.samples > 0)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glBlitFramebufferEXT(%s)",
+                  _mesa_lookup_enum_by_nr(filter));
       return;
    }
 
@@ -3102,10 +3253,10 @@ _mesa_BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
                }
             }
          }
-         if (filter == GL_LINEAR) {
-            /* 3.1 spec, page 199:
+         if (filter != GL_NEAREST) {
+            /* From EXT_framebuffer_multisample_blit_scaled specification:
              * "Calling BlitFramebuffer will result in an INVALID_OPERATION error
-             * if filter is LINEAR and read buffer contains integer data."
+             * if filter is not NEAREST and read buffer contains integer data."
              */
             GLenum type = _mesa_get_format_datatype(colorReadRb->Format);
             if (type == GL_INT || type == GL_UNSIGNED_INT) {
@@ -3263,7 +3414,8 @@ _mesa_BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
       }
 
       /* extra checks for multisample copies... */
-      if (readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) {
+      if ((readFb->Visual.samples > 0 || drawFb->Visual.samples > 0) &&
+          (filter == GL_NEAREST || filter == GL_LINEAR)) {
          /* src and dest region sizes must be the same */
          if (abs(srcX1 - srcX0) != abs(dstX1 - dstX0) ||
              abs(srcY1 - srcY0) != abs(dstY1 - dstY0)) {