cso: add new cso_set_viewport_dims() helper
authorBrian Paul <brianp@vmware.com>
Tue, 16 Feb 2016 17:22:32 +0000 (10:22 -0700)
committerBrian Paul <brianp@vmware.com>
Tue, 16 Feb 2016 17:22:32 +0000 (10:22 -0700)
To simplify some viewport setting code in the state tracker.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/cso_cache/cso_context.c
src/gallium/auxiliary/cso_cache/cso_context.h

index 79ae75306bf5faad1ace524fb2d5400fe61aca75..2d6540d470d07b9f10c2b7e595ed9e019ac9f065 100644 (file)
@@ -674,6 +674,24 @@ void cso_set_viewport(struct cso_context *ctx,
    }
 }
 
+/**
+ * Setup viewport state for given width and height (position is always (0,0)).
+ * Invert the Y axis if 'invert' is true.
+ */
+void
+cso_set_viewport_dims(struct cso_context *ctx,
+                      float width, float height, boolean invert)
+{
+   struct pipe_viewport_state vp;
+   vp.scale[0] = width * 0.5f;
+   vp.scale[1] = height * (invert ? -0.5f : 0.5f);
+   vp.scale[2] = 0.5f;
+   vp.translate[0] = 0.5f * width;
+   vp.translate[1] = 0.5f * height;
+   vp.translate[2] = 0.5f;
+   cso_set_viewport(ctx, &vp);
+}
+
 void cso_save_viewport(struct cso_context *ctx)
 {
    ctx->vp_saved = ctx->vp;
index ec9112b493aa1939c6e0d95e94ec25cafb53d49d..83ce60e69fb768c32f3ede00af3093c5de7ef382 100644 (file)
@@ -163,6 +163,8 @@ void cso_restore_framebuffer(struct cso_context *cso);
 
 void cso_set_viewport(struct cso_context *cso,
                       const struct pipe_viewport_state *vp);
+void cso_set_viewport_dims(struct cso_context *ctx,
+                           float width, float height, boolean invert);
 void cso_save_viewport(struct cso_context *cso);
 void cso_restore_viewport(struct cso_context *cso);