mesa/es3.1: Pass sample count check for multisampled textures
[mesa.git] / src / mesa / main / multisample.c
index 8b974c1b707932e174873602fa467d58d515a9fe..09e6154f7ec389298bc154f46cbdad9e078221bf 100644 (file)
@@ -43,7 +43,7 @@ _mesa_SampleCoverage(GLclampf value, GLboolean invert)
 
    FLUSH_VERTICES(ctx, 0);
 
-   ctx->Multisample.SampleCoverageValue = (GLfloat) CLAMP(value, 0.0, 1.0);
+   ctx->Multisample.SampleCoverageValue = CLAMP(value, 0.0f, 1.0f);
    ctx->Multisample.SampleCoverageInvert = invert;
    ctx->NewState |= _NEW_MULTISAMPLE;
 }
@@ -80,7 +80,7 @@ _mesa_GetMultisamplefv(GLenum pname, GLuint index, GLfloat * val)
 
    switch (pname) {
    case GL_SAMPLE_POSITION: {
-      if (index >= ctx->DrawBuffer->Visual.samples) {
+      if ((int) index >= ctx->DrawBuffer->Visual.samples) {
          _mesa_error( ctx, GL_INVALID_VALUE, "glGetMultisamplefv(index)" );
          return;
       }
@@ -89,7 +89,7 @@ _mesa_GetMultisamplefv(GLenum pname, GLuint index, GLfloat * val)
 
       /* winsys FBOs are upside down */
       if (_mesa_is_winsys_fbo(ctx->DrawBuffer))
-         val[1] = 1 - val[1];
+         val[1] = 1.0f - val[1];
 
       return;
    }
@@ -119,6 +119,24 @@ _mesa_SampleMaski(GLuint index, GLbitfield mask)
    ctx->Multisample.SampleMaskValue = mask;
 }
 
+/**
+ * Called via glMinSampleShadingARB
+ */
+void GLAPIENTRY
+_mesa_MinSampleShading(GLclampf value)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!ctx->Extensions.ARB_sample_shading || !_mesa_is_desktop_gl(ctx)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glMinSampleShading");
+      return;
+   }
+
+   FLUSH_VERTICES(ctx, 0);
+
+   ctx->Multisample.MinSampleShadingValue = CLAMP(value, 0.0f, 1.0f);
+   ctx->NewState |= _NEW_MULTISAMPLE;
+}
 
 /**
  * Helper for checking a requested sample count against the limit
@@ -132,6 +150,29 @@ GLenum
 _mesa_check_sample_count(struct gl_context *ctx, GLenum target,
                          GLenum internalFormat, GLsizei samples)
 {
+   /* Section 2.5 (GL Errors) of OpenGL 3.0 specification, page 16:
+    *
+    * "If a negative number is provided where an argument of type sizei or
+    * sizeiptr is specified, the error INVALID VALUE is generated."
+    */
+   if (samples < 0) {
+      return GL_INVALID_VALUE;
+   }
+
+   /* Section 4.4 (Framebuffer objects), page 198 of the OpenGL ES 3.0.0
+    * specification says:
+    *
+    *     "If internalformat is a signed or unsigned integer format and samples
+    *     is greater than zero, then the error INVALID_OPERATION is generated."
+    *
+    * This restriction is relaxed for OpenGL ES 3.1.
+    */
+   if ((ctx->API == API_OPENGLES2 && ctx->Version == 30) &&
+       _mesa_is_enum_format_integer(internalFormat)
+       && samples > 0) {
+      return GL_INVALID_OPERATION;
+   }
+
    /* If ARB_internalformat_query is supported, then treat its highest
     * returned sample count as the absolute maximum for this format; it is
     * allowed to exceed MAX_SAMPLES.
@@ -197,5 +238,6 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target,
     * "... or if samples is greater than MAX_SAMPLES, then the error
     * INVALID_VALUE is generated"
     */
-   return samples > ctx->Const.MaxSamples ? GL_INVALID_VALUE : GL_NO_ERROR;
+   return (GLuint) samples > ctx->Const.MaxSamples
+      ? GL_INVALID_VALUE : GL_NO_ERROR;
 }