[Mesa-dev] [PATCH 18/37] mesa: Set all scissor rects

Ian Romanick idr at freedesktop.org
Fri Jan 17 17:03:38 PST 2014


From: Ian Romanick <ian.d.romanick at intel.com>

In _mesa_Scissor, make sure that ctx->Driver.Scissor is only called once
instead of once per scissor rectangle.

v2: Use MAX_VIEWPORTS instead of ctx->Const.MaxViewports because the
driver may not set ctx->Const.MaxViewports yet.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/main/context.c |  2 +-
 src/mesa/main/scissor.c | 30 +++++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 1cd0064..8078129 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1448,8 +1448,8 @@ _mesa_check_init_viewport(struct gl_context *ctx, GLuint width, GLuint height)
        */
       for (i = 0; i < MAX_VIEWPORTS; i++) {
          _mesa_set_viewport(ctx, i, 0, 0, width, height);
+         _mesa_set_scissor(ctx, i, 0, 0, width, height);
       }
-      _mesa_set_scissor(ctx, 0, 0, 0, width, height);
    }
 }
 
diff --git a/src/mesa/main/scissor.c b/src/mesa/main/scissor.c
index 9266f1e..9caac2e 100644
--- a/src/mesa/main/scissor.c
+++ b/src/mesa/main/scissor.c
@@ -60,6 +60,7 @@ set_scissor_no_notify(struct gl_context *ctx, unsigned idx,
 void GLAPIENTRY
 _mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
 {
+   unsigned i;
    GET_CURRENT_CONTEXT(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
@@ -70,7 +71,23 @@ _mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
       return;
    }
 
-   _mesa_set_scissor(ctx, 0, x, y, width, height);
+   /* The GL_ARB_viewport_array spec says:
+    *
+    *     "Scissor sets the scissor rectangle for all viewports to the same
+    *     values and is equivalent (assuming no errors are generated) to:
+    *
+    *     for (uint i = 0; i < MAX_VIEWPORTS; i++) {
+    *         ScissorIndexed(i, left, bottom, width, height);
+    *     }"
+    *
+    * Set the scissor rectangle for all of the viewports supported by the
+    * implementation, but only signal the driver once at the end.
+    */
+   for (i = 0; i < ctx->Const.MaxViewports; i++)
+      set_scissor_no_notify(ctx, i, x, y, width, height);
+
+   if (ctx->Driver.Scissor)
+      ctx->Driver.Scissor(ctx);
 }
 
 
@@ -105,7 +122,14 @@ _mesa_set_scissor(struct gl_context *ctx, unsigned idx,
 void
 _mesa_init_scissor(struct gl_context *ctx)
 {
+   unsigned i;
+
    /* Scissor group */
-   ctx->Scissor.EnableFlags = GL_FALSE;
-   set_scissor_no_notify(ctx, 0, 0, 0, 0, 0);
+   ctx->Scissor.EnableFlags = 0;
+
+   /* Note: ctx->Const.MaxViewports may not have been set by the driver yet,
+    * so just initialize all of them.
+    */
+   for (i = 0; i < MAX_VIEWPORTS; i++)
+      set_scissor_no_notify(ctx, i, 0, 0, 0, 0);
 }
-- 
1.8.1.4



More information about the mesa-dev mailing list