GL_MESA_framebuffer_flip_y: Testing using gl_FragCoord

Submitted by Fritz Koenig on Sept. 17, 2018, 6:36 p.m.

Details

Message ID 20180917183615.39875-1-frkoenig@google.com
State New
Headers show
Series "GL_MESA_framebuffer_flip_y: Testing using gl_FragCoord" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

Fritz Koenig Sept. 17, 2018, 6:36 p.m.
Checks that gl_FragCoord colors the correct area when
the framebuffer is flipped.
---
 tests/opengl.py                               |   1 +
 .../CMakeLists.gles2.txt                      |   1 +
 .../spec/mesa_framebuffer_flip_y/fragcoord.c  | 184 ++++++++++++++++++
 3 files changed, 186 insertions(+)
 create mode 100644 tests/spec/mesa_framebuffer_flip_y/fragcoord.c

Patch hide | download patch | download mbox

diff --git a/tests/opengl.py b/tests/opengl.py
index 6cfa56e01..52a355ff9 100644
--- a/tests/opengl.py
+++ b/tests/opengl.py
@@ -4950,6 +4950,7 @@  with profile.test_list.group_manager(
 with profile.test_list.group_manager(
         PiglitGLTest,
         grouptools.join('spec', 'mesa_framebuffer_flip_y')) as g:
+    g(['mesa_framebuffer_flip_y-fragcoord'])
     g(['mesa_framebuffer_flip_y-params'])
     g(['mesa_framebuffer_flip_y-scissor'])
 
diff --git a/tests/spec/mesa_framebuffer_flip_y/CMakeLists.gles2.txt b/tests/spec/mesa_framebuffer_flip_y/CMakeLists.gles2.txt
index f8a758fba..a2387f028 100644
--- a/tests/spec/mesa_framebuffer_flip_y/CMakeLists.gles2.txt
+++ b/tests/spec/mesa_framebuffer_flip_y/CMakeLists.gles2.txt
@@ -2,6 +2,7 @@  link_libraries (
         piglitutil_${piglit_target_api}
 )
 
+piglit_add_executable (mesa_framebuffer_flip_y-fragcoord fragcoord.c)
 piglit_add_executable (mesa_framebuffer_flip_y-params params.c)
 
 if(PIGLIT_BUILD_DMA_BUF_TESTS)
diff --git a/tests/spec/mesa_framebuffer_flip_y/fragcoord.c b/tests/spec/mesa_framebuffer_flip_y/fragcoord.c
new file mode 100644
index 000000000..d405dab2c
--- /dev/null
+++ b/tests/spec/mesa_framebuffer_flip_y/fragcoord.c
@@ -0,0 +1,184 @@ 
+/*
+ * Copyright © 2018 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/**
+ * @file fragcoord.c
+ *
+ * https://www.khronos.org/registry/OpenGL/extensions/MESA/MESA_framebuffer_flip_y.txt
+ *
+ * Checks that gl_FragCoord works correctly on a flipped fbo.  This is done
+ * by creating a shader that colors the top half of a rectangle green and the
+ * bottom half red.
+ */
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 30;
+	config.khr_no_error_support = PIGLIT_HAS_ERRORS;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float red[4] = {1.0, 0.0, 0.0, 1.0};
+static const float green[4] = {0.0, 1.0, 0.0, 1.0};
+static const int tex_width = 16;
+static const int tex_height = 8;
+static GLuint prog;
+
+static const char vs_text[] =
+	"#version 300 es\n"
+	"layout(location=0) in vec2 a_position;\n"
+	"void main() { \n"
+	"  gl_Position = vec4(a_position.xy, 0, 1);\n"
+	"}\n";
+
+static const char *fs_text =
+	"#version 300 es\n"
+	"precision highp float;\n"
+	"out highp vec4 f_color;\n"
+	"uniform float window_height;\n"
+	"uniform vec4 green;\n"
+	"uniform vec4 red;\n"
+	"void main() \n"
+	"{ \n"
+	"  if (gl_FragCoord.y > (window_height / 2.0)) { \n"
+	"    f_color = green; \n"
+	"  } else { \n"
+	"    f_color = red; \n"
+	"  } \n"
+	"} \n";
+
+static GLuint setup_shaders()
+{
+	GLuint vs, fs, prog;
+
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text);
+	prog = piglit_link_simple_program(vs, fs);
+
+	glDeleteShader(vs);
+	glDeleteShader(fs);
+
+	return prog;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_FAIL;
+}
+
+void piglit_init(int argc, char **argv)
+{
+	GLuint fbo_normal, fbo_flip, tex;
+	bool pass = true;
+	int uniform_window_height, uniform_green, uniform_red;
+
+	piglit_require_extension("GL_MESA_framebuffer_flip_y");
+
+	piglit_require_vertex_shader();
+	piglit_require_fragment_shader();
+
+	prog = setup_shaders();
+
+	/* Create flipped fbo */
+	glGenFramebuffers(1, &fbo_flip);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo_flip);
+	glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_FLIP_Y_MESA, 1);
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
+		     tex_width, tex_height,
+		     0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+			       GL_TEXTURE_2D, tex, 0);
+
+	glViewport(0, 0, tex_width, tex_height);
+
+	/* clear to black */
+	glClearColor(0.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	uniform_window_height = glGetUniformLocation(prog,"window_height");
+	uniform_green = glGetUniformLocation(prog,"green");
+	uniform_red = glGetUniformLocation(prog,"red");
+
+	glUseProgram(prog);
+	glUniform1f(uniform_window_height, tex_height);
+	glUniform4fv(uniform_green, 1, green);
+	glUniform4fv(uniform_red, 1, red);
+	piglit_draw_rect(-1, -1, 2, 2);
+	glUseProgram(0);
+
+	/* Check that reading back the through the framebuffer
+	 * that the flipped orientation is not shown */
+	/* Check top half is green */
+	pass &= piglit_probe_rect_rgb(0, 0, tex_width, tex_height / 2, green);
+
+	/* Check bottom half is red */
+	pass &= piglit_probe_rect_rgb(0, tex_height / 2,
+					   tex_width, tex_height / 2,
+					   red);
+
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
+					     "fbo access");
+
+	/* Create another fbo, this time not flipped */
+	glGenFramebuffers(1, &fbo_normal);
+	glBindFramebuffer(GL_FRAMEBUFFER, fbo_normal);
+
+	/* Bind the previously created texture to it */
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
+		     tex_width, tex_height,
+		     0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+			       GL_TEXTURE_2D, tex, 0);
+
+	/* Now when reading back from the fbo the texture should
+	 * be flipped */
+	/* Check top half is red */
+	pass &= piglit_probe_rect_rgb(0, 0, tex_width, tex_height / 2, red);
+
+	/* Check bottom half is green */
+	pass &= piglit_probe_rect_rgb(0, tex_height / 2,
+					     tex_width, tex_height / 2,
+					     green);
+
+	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
+					     "flipped fbo");
+
+	glUseProgram(0);
+	glDeleteProgram(prog);
+	glDeleteTextures(1, &tex);
+	glDeleteFramebuffers(1, &fbo_normal);
+	glDeleteFramebuffers(1, &fbo_flip);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		pass = false;
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}