mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / multisample.c
index 8e5a969e3a8c3019e15afdb6e971dc72a5f9eec3..599cdee74075431071821b2a6ca50f6a6e8d89cf 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
@@ -30,6 +30,7 @@
 #include "main/mtypes.h"
 #include "main/fbobject.h"
 #include "main/glformats.h"
+#include "main/state.h"
 
 
 /**
@@ -73,9 +74,13 @@ _mesa_GetMultisamplefv(GLenum pname, GLuint index, GLfloat * val)
 {
    GET_CURRENT_CONTEXT(ctx);
 
+   if (ctx->NewState & _NEW_BUFFERS) {
+      _mesa_update_state(ctx);
+   }
+
    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;
       }
@@ -114,8 +119,27 @@ _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.0, 1.0);
+   ctx->NewState |= _NEW_MULTISAMPLE;
+}
 
-/* Helper for checking a requested sample count against the limit
+/**
+ * Helper for checking a requested sample count against the limit
  * for a particular (target, internalFormat) pair. The limit imposed,
  * and the error generated, both depend on which extensions are supported.
  *
@@ -126,8 +150,9 @@ GLenum
 _mesa_check_sample_count(struct gl_context *ctx, GLenum target,
                          GLenum internalFormat, GLsizei samples)
 {
-   /* 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.
+   /* 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.
     *
     * From the ARB_internalformat_query spec:
     *
@@ -136,25 +161,51 @@ _mesa_check_sample_count(struct gl_context *ctx, GLenum target,
     */
    if (ctx->Extensions.ARB_internalformat_query) {
       GLint buffer[16];
-      int count = ctx->Driver.QuerySamplesForFormat(ctx, target, internalFormat, buffer);
+      int count = ctx->Driver.QuerySamplesForFormat(ctx, target,
+                                                    internalFormat, buffer);
       int limit = count ? buffer[0] : -1;
 
       return samples > limit ? GL_INVALID_OPERATION : GL_NO_ERROR;
    }
 
-   /* If ARB_texture_multisample is supported, we have separate limits for
-    * integer formats.
+   /* If ARB_texture_multisample is supported, we have separate limits,
+    * which may be lower than MAX_SAMPLES:
     *
-    * From the ARB_texture_multisample spec:
+    * From the ARB_texture_multisample spec, when describing the operation
+    * of RenderbufferStorageMultisample:
     *
     * "If <internalformat> is a signed or unsigned integer format and
     * <samples> is greater than the value of MAX_INTEGER_SAMPLES, then the
     * error INVALID_OPERATION is generated"
+    *
+    * And when describing the operation of TexImage*Multisample:
+    *
+    * "The error INVALID_OPERATION may be generated if any of the following
+    * are true:
+    *
+    * * <internalformat> is a depth/stencil-renderable format and <samples>
+    *   is greater than the value of MAX_DEPTH_TEXTURE_SAMPLES
+    * * <internalformat> is a color-renderable format and <samples> is
+    *   grater than the value of MAX_COLOR_TEXTURE_SAMPLES
+    * * <internalformat> is a signed or unsigned integer format and
+    *   <samples> is greater than the value of MAX_INTEGER_SAMPLES
     */
 
    if (ctx->Extensions.ARB_texture_multisample) {
       if (_mesa_is_enum_format_integer(internalFormat))
-         return samples > ctx->Const.MaxIntegerSamples ? GL_INVALID_OPERATION : GL_NO_ERROR;
+         return samples > ctx->Const.MaxIntegerSamples
+            ? GL_INVALID_OPERATION : GL_NO_ERROR;
+
+      if (target == GL_TEXTURE_2D_MULTISAMPLE ||
+          target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
+
+         if (_mesa_is_depth_or_stencil_format(internalFormat))
+            return samples > ctx->Const.MaxDepthTextureSamples
+               ? GL_INVALID_OPERATION : GL_NO_ERROR;
+         else
+            return samples > ctx->Const.MaxColorTextureSamples
+               ? GL_INVALID_OPERATION : GL_NO_ERROR;
+      }
    }
 
    /* No more specific limit is available, so just use MAX_SAMPLES:
@@ -164,5 +215,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;
 }