[Mesa-dev] [PATCH v3] swr: calculate viewport width/height based on the scale

Rowley, Timothy O timothy.o.rowley at intel.com
Tue Nov 22 00:20:59 UTC 2016


Reviewed-by: Tim Rowley <timothy.o.rowley at intel.com<mailto:timothy.o.rowley at intel.com>>

On Nov 20, 2016, at 10:32 AM, Ilia Mirkin <imirkin at alum.mit.edu<mailto:imirkin at alum.mit.edu>> wrote:

The former calculations were for min/max y. The width/height don't take
translate into account.

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu<mailto:imirkin at alum.mit.edu>>
---

v2 -> v3:
- reduce viewport width when clamping the x/y offsets to 0
- subtract vp->y from height, not vp->x

Let's hope I don't need to write a v4 of this trivial patch.

src/gallium/drivers/swr/swr_state.cpp | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp
index 520faea..0302439 100644
--- a/src/gallium/drivers/swr/swr_state.cpp
+++ b/src/gallium/drivers/swr/swr_state.cpp
@@ -1018,9 +1018,9 @@ swr_update_derived(struct pipe_context *pipe,
      SWR_VIEWPORT_MATRICES *vpm = &ctx->derived.vpm;

      vp->x = state->translate[0] - state->scale[0];
-      vp->width = state->translate[0] + state->scale[0];
+      vp->width = 2 * state->scale[0];
      vp->y = state->translate[1] - fabs(state->scale[1]);
-      vp->height = state->translate[1] + fabs(state->scale[1]);
+      vp->height = 2 * fabs(state->scale[1]);
      util_viewport_zmin_zmax(state, rasterizer->clip_halfz,
                              &vp->minZ, &vp->maxZ);

@@ -1033,10 +1033,16 @@ swr_update_derived(struct pipe_context *pipe,

      /* Now that the matrix is calculated, clip the view coords to screen
       * size.  OpenGL allows for -ve x,y in the viewport. */
-      vp->x = std::max(vp->x, 0.0f);
-      vp->y = std::max(vp->y, 0.0f);
-      vp->width = std::min(vp->width, (float)fb->width);
-      vp->height = std::min(vp->height, (float)fb->height);
+      if (vp->x < 0.0f) {
+         vp->width += vp->x;
+         vp->x = 0.0f;
+      }
+      if (vp->y < 0.0f) {
+         vp->height += vp->y;
+         vp->y = 0.0f;
+      }
+      vp->width = std::min(vp->width, (float)fb->width - vp->x);
+      vp->height = std::min(vp->height, (float)fb->height - vp->y);

      SwrSetViewports(ctx->swrContext, 1, vp, vpm);
   }
--
2.7.3


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161122/b4e0eb80/attachment.html>


More information about the mesa-dev mailing list