[Mesa-dev] [PATCH 5/6] cso: add new cso_set_viewport_dims() helper
Brian Paul
brianp at vmware.com
Fri Feb 12 15:43:52 UTC 2016
To simplify some viewport setting code in the state tracker.
---
src/gallium/auxiliary/cso_cache/cso_context.c | 18 ++++++++++++++++++
src/gallium/auxiliary/cso_cache/cso_context.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 6b29b20..a05c1c7 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -664,6 +664,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;
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
index f0a2739..39afc15 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.h
+++ b/src/gallium/auxiliary/cso_cache/cso_context.h
@@ -159,6 +159,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);
--
1.9.1
More information about the mesa-dev
mailing list