summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2015-09-21 16:48:07 -0700
committerIan Romanick <ian.d.romanick@intel.com>2015-09-29 14:33:56 -0700
commit8811ccb3d6a908fc63e6b2d2bc0f4a961769579d (patch)
treeda6cf169a4f3328f5a4a6ef80a7c0d123e27843c
parent2d5448ac274ef42f7f1c52e968c14dfd759f2b76 (diff)
polygon-offset: Replace gluProject to remove the dependency on libGLU
I verified correctness by calling gluProject inside project and comparing the results. My initial implementation forgot to do the perspective divide, so this helped catch that bug. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Thanked-by: Kristian Høgsberg <krh@bitplanet.net>
-rw-r--r--tests/spec/gl-1.4/CMakeLists.gl.txt1
-rw-r--r--tests/spec/gl-1.4/polygon-offset.c77
2 files changed, 62 insertions, 16 deletions
diff --git a/tests/spec/gl-1.4/CMakeLists.gl.txt b/tests/spec/gl-1.4/CMakeLists.gl.txt
index 601c1e117..a6888f310 100644
--- a/tests/spec/gl-1.4/CMakeLists.gl.txt
+++ b/tests/spec/gl-1.4/CMakeLists.gl.txt
@@ -6,7 +6,6 @@ include_directories(
link_libraries (
piglitutil_${piglit_target_api}
${OPENGL_gl_LIBRARY}
- ${OPENGL_glu_LIBRARY}
)
piglit_add_executable (gl-1.4-dlist-multidrawarrays dlist-multidrawarrays.c)
diff --git a/tests/spec/gl-1.4/polygon-offset.c b/tests/spec/gl-1.4/polygon-offset.c
index 9d639f7cc..b1b826236 100644
--- a/tests/spec/gl-1.4/polygon-offset.c
+++ b/tests/spec/gl-1.4/polygon-offset.c
@@ -70,13 +70,6 @@
*/
#include "piglit-util-gl.h"
-
-#if defined(__APPLE__)
-# include <OpenGL/glu.h>
-#else
-# include <GL/glu.h>
-#endif
-
#include <math.h>
PIGLIT_GL_TEST_CONFIG_BEGIN
@@ -95,6 +88,61 @@ struct angle_axis {
};
static void
+multiply_matrix_with_vector(const double *matrix, double *vector)
+{
+ double tmp[4];
+ unsigned i;
+
+ /* The matrix is stored in the natural OpenGL order: column-major. In
+ * GLSL, this would be:
+ *
+ * vp.x = m[0] * v.xxxx;
+ * vp.y = m[1] * v.yyyy;
+ * vp.z = m[2] * v.zzzz;
+ * vp.w = m[3] * v.wwww;
+ * v = vp;
+ */
+ for (i = 0; i < 4; i++)
+ tmp[i] = matrix[i] * vector[0];
+
+ for (i = 0; i < 4; i++)
+ tmp[i] += matrix[i + 4] * vector[1];
+
+ for (i = 0; i < 4; i++)
+ tmp[i] += matrix[i + 8] * vector[2];
+
+ for (i = 0; i < 4; i++)
+ tmp[i] += matrix[i + 12] * vector[3];
+
+ memcpy(vector, tmp, sizeof(tmp));
+}
+
+static void
+project(double x, double y, double z, const double *modelview,
+ const double *projection, const int *viewport, double *result)
+{
+ double vp[4] = { x, y, z, 1.0 };
+
+ /* Calculate v' as P * M * v. */
+ multiply_matrix_with_vector(modelview, vp);
+ multiply_matrix_with_vector(projection, vp);
+
+ if (vp[3] == 0.0) {
+ fprintf(stderr, "Cannot perspective divide by zero.\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ vp[0] /= vp[3];
+ vp[1] /= vp[3];
+ vp[2] /= vp[3];
+
+ /* Calculate the screen position using the same formula a gluProject. */
+ result[0] = viewport[0] + (viewport[2] * ((vp[0] + 1.0) / 2.0));
+ result[1] = viewport[1] + (viewport[3] * ((vp[1] + 1.0) / 2.0));
+ result[2] = (vp[2] + 1.0) / 2.0;
+}
+
+static void
draw_quad_at_distance(GLdouble dist)
{
glBegin(GL_QUADS);
@@ -405,18 +453,17 @@ check_slope_offset(const struct angle_axis *aa, GLdouble *ideal_mrd_near)
piglit_draw_rect(-1.0, -1.0, 2.0, 2.0);
- gluProject(0.0, 0.0, 0.0, modelview_mat, projection_mat, viewport,
- centerw + 0, centerw + 1, centerw + 2);
+ project(0.0, 0.0, 0.0, modelview_mat, projection_mat, viewport,
+ centerw);
base_depth = read_depth(centerw[0], centerw[1]);
- gluProject(-0.9, -0.9, 0.0, modelview_mat, projection_mat, viewport,
- p0 + 0, p0 + 1, p0 + 2);
+ project(-0.9, -0.9, 0.0, modelview_mat, projection_mat, viewport, p0);
p0[2] = read_depth(p0[0], p0[1]);
- gluProject( 0.9, -0.9, 0.0, modelview_mat, projection_mat, viewport,
- p1 + 0, p1 + 1, p1 + 2);
+
+ project( 0.9, -0.9, 0.0, modelview_mat, projection_mat, viewport, p1);
p1[2] = read_depth(p1[0], p1[1]);
- gluProject( 0.9, 0.9, 0.0, modelview_mat, projection_mat, viewport,
- p2 + 0, p2 + 1, p2 + 2);
+
+ project( 0.9, 0.9, 0.0, modelview_mat, projection_mat, viewport, p2);
p2[2] = read_depth(p2[0], p2[1]);
det = (p0[0] - p1[0]) * (p0[1] - p2[1])