mesa: add ASTC 2D LDR decoder
[mesa.git] / src / mesa / main / viewport.c
index e1ab03dec39f499041574886822b4439d70e4f79..97d328541b2c029c3b8a812f556871170ad80f58 100644 (file)
@@ -51,9 +51,8 @@ clamp_viewport(struct gl_context *ctx, GLfloat *x, GLfloat *y,
     *     determined by calling GetFloatv with the symbolic constant
     *     VIEWPORT_BOUNDS_RANGE (see section 6.1)."
     */
-   if (ctx->Extensions.ARB_viewport_array ||
-       (ctx->Extensions.OES_viewport_array &&
-        _mesa_is_gles31(ctx))) {
+   if (_mesa_has_ARB_viewport_array(ctx) ||
+       _mesa_has_OES_viewport_array(ctx)) {
       *x = CLAMP(*x,
                  ctx->Const.ViewportBounds.Min, ctx->Const.ViewportBounds.Max);
       *y = CLAMP(*y,
@@ -94,9 +93,10 @@ static void
 viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei width,
          GLsizei height)
 {
+   struct gl_viewport_inputs input = { x, y, width, height };
+
    /* Clamp the viewport to the implementation dependent values. */
-   clamp_viewport(ctx, (GLfloat *)&x, (GLfloat *)&y,
-                  (GLfloat *)&width, (GLfloat *)&height);
+   clamp_viewport(ctx, &input.X, &input.Y, &input.Width, &input.Height);
 
    /* The GL_ARB_viewport_array spec says:
     *
@@ -110,7 +110,7 @@ viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei width,
     * signal the driver once at the end.
     */
    for (unsigned i = 0; i < ctx->Const.MaxViewports; i++)
-      set_viewport_no_notify(ctx, i, x, y, width, height);
+      set_viewport_no_notify(ctx, i, input.X, input.Y, input.Width, input.Height);
 
    if (ctx->Driver.Viewport)
       ctx->Driver.Viewport(ctx);
@@ -370,6 +370,16 @@ depth_range_arrayv(struct gl_context *ctx, GLuint first, GLsizei count,
       ctx->Driver.DepthRange(ctx);
 }
 
+void GLAPIENTRY
+_mesa_DepthRangeArrayv_no_error(GLuint first, GLsizei count, const GLclampd *v)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   const struct gl_depthrange_inputs *const p =
+      (struct gl_depthrange_inputs *)v;
+   depth_range_arrayv(ctx, first, count, p);
+}
+
 void GLAPIENTRY
 _mesa_DepthRangeArrayv(GLuint first, GLsizei count, const GLclampd *v)
 {
@@ -479,16 +489,31 @@ void _mesa_init_viewport(struct gl_context *ctx)
       ctx->ViewportArray[i].Near = 0.0;
       ctx->ViewportArray[i].Far = 1.0;
    }
+
+   ctx->SubpixelPrecisionBias[0] = 0;
+   ctx->SubpixelPrecisionBias[1] = 0;
 }
 
 
-static void
-clip_control(struct gl_context *ctx, GLenum origin, GLenum depth)
+static ALWAYS_INLINE void
+clip_control(struct gl_context *ctx, GLenum origin, GLenum depth, bool no_error)
 {
    if (ctx->Transform.ClipOrigin == origin &&
        ctx->Transform.ClipDepthMode == depth)
       return;
 
+   if (!no_error &&
+       origin != GL_LOWER_LEFT && origin != GL_UPPER_LEFT) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glClipControl");
+      return;
+   }
+
+   if (!no_error &&
+       depth != GL_NEGATIVE_ONE_TO_ONE && depth != GL_ZERO_TO_ONE) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glClipControl");
+      return;
+   }
+
    /* Affects transform state and the viewport transform */
    FLUSH_VERTICES(ctx, ctx->DriverFlags.NewClipControl ? 0 :
                   _NEW_TRANSFORM | _NEW_VIEWPORT);
@@ -520,7 +545,7 @@ void GLAPIENTRY
 _mesa_ClipControl_no_error(GLenum origin, GLenum depth)
 {
    GET_CURRENT_CONTEXT(ctx);
-   clip_control(ctx, origin, depth);
+   clip_control(ctx, origin, depth, true);
 }
 
 
@@ -541,17 +566,7 @@ _mesa_ClipControl(GLenum origin, GLenum depth)
       return;
    }
 
-   if (origin != GL_LOWER_LEFT && origin != GL_UPPER_LEFT) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glClipControl");
-      return;
-   }
-
-   if (depth != GL_NEGATIVE_ONE_TO_ONE && depth != GL_ZERO_TO_ONE) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "glClipControl");
-      return;
-   }
-
-   clip_control(ctx, origin, depth);
+   clip_control(ctx, origin, depth, false);
 }
 
 /**
@@ -587,3 +602,58 @@ _mesa_get_viewport_xform(struct gl_context *ctx, unsigned i,
       translate[2] = n;
    }
 }
+
+
+static void
+subpixel_precision_bias(struct gl_context *ctx, GLuint xbits, GLuint ybits)
+{
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glSubpixelPrecisionBiasNV(%u, %u)\n", xbits, ybits);
+
+   ctx->SubpixelPrecisionBias[0] = xbits;
+   ctx->SubpixelPrecisionBias[1] = ybits;
+
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |=
+      ctx->DriverFlags.NewNvConservativeRasterizationParams;
+}
+
+void GLAPIENTRY
+_mesa_SubpixelPrecisionBiasNV_no_error(GLuint xbits, GLuint ybits)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glSubpixelPrecisionBiasNV(%u, %u)\n", xbits, ybits);
+
+   subpixel_precision_bias(ctx, xbits, ybits);
+}
+
+void GLAPIENTRY
+_mesa_SubpixelPrecisionBiasNV(GLuint xbits, GLuint ybits)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glSubpixelPrecisionBiasNV(%u, %u)\n", xbits, ybits);
+
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (!ctx->Extensions.NV_conservative_raster) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glSubpixelPrecisionBiasNV not supported");
+      return;
+   }
+
+   if (xbits > ctx->Const.MaxSubpixelPrecisionBiasBits) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glSubpixelPrecisionBiasNV");
+      return;
+   }
+
+   if (ybits > ctx->Const.MaxSubpixelPrecisionBiasBits) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glSubpixelPrecisionBiasNV");
+      return;
+   }
+
+   subpixel_precision_bias(ctx, xbits, ybits);
+}