This patch adds functions piglit_gen_ortho_uniform() and
piglit_ortho_uniform(), which can be used to set up an orthographic
projection when the legacy function glOrtho() is not available.

The functions work exactly like piglit_gen_ortho_projection() and
piglit_ortho_projection(), except that instead of programming the
legacy projection matrix, they program an arbitrary uniform matrix.
---
 tests/util/piglit-util-gl-common.c | 34 ++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl-common.h |  4 ++++
 2 files changed, 38 insertions(+)

diff --git a/tests/util/piglit-util-gl-common.c 
b/tests/util/piglit-util-gl-common.c
index b431815..92a0a4d 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -527,3 +527,37 @@ piglit_compressed_pixel_offset(GLenum format, unsigned 
width,
 
        return offset;
 }
+
+
+#ifndef PIGLIT_USE_OPENGL_ES1
+/**
+ * Convenience function to configure a shader uniform variable as an
+ * arbitrary orthogonal projection matrix.
+ */
+void
+piglit_gen_ortho_uniform(GLint location, double l, double r, double b,
+                        double t, double n, double f)
+{
+       float values[4][4] = {
+               { 2/(r-l),    0,        0,    -(r+l)/(r-l) },
+               {    0,    2/(t-b),     0,    -(t+b)/(t-b) },
+               {    0,       0,    -2/(f-n), -(f+n)/(f-n) },
+               {    0,       0,        0,          1      }
+       };
+       glUniformMatrix4fv(location, 1, GL_TRUE, values);
+}
+
+
+/**
+ * Convenience function to configure a shader uniform variable as a
+ * projection matrix for window coordinates.
+ */
+void
+piglit_ortho_uniform(GLint location, int w, int h)
+{
+        /* Set up projection matrix so we can just draw using window
+         * coordinates.
+         */
+       piglit_gen_ortho_uniform(location, 0, w, 0, h, -1, 1);
+}
+#endif
diff --git a/tests/util/piglit-util-gl-common.h 
b/tests/util/piglit-util-gl-common.h
index 2d6bb1a..336953d 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -159,6 +159,10 @@ void piglit_gen_ortho_projection(double left, double 
right, double bottom,
 void piglit_ortho_projection(int w, int h, GLboolean push);
 void piglit_frustum_projection(GLboolean push, double l, double r, double b,
                               double t, double n, double f);
+void piglit_gen_ortho_uniform(GLint location, double left, double right,
+                             double bottom, double top, double near_val,
+                             double far_val);
+void piglit_ortho_uniform(GLint location, int w, int h);
 
 GLuint piglit_checkerboard_texture(GLuint tex, unsigned level,
     unsigned width, unsigned height,
-- 
1.8.0.3

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to