[Piglit] [PATCH 4/4] fbo-drawbuffers: Port to ES2 w/NV_draw_buffers and NV_fbo_color_attachments

Ian Romanick idr at freedesktop.org
Mon Oct 3 11:40:24 PDT 2011


From: Ian Romanick <ian.d.romanick at intel.com>

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/fbo/CMakeLists.gles2.txt |   11 +++++
 tests/fbo/fbo-drawbuffers.c    |   83 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 93 insertions(+), 1 deletions(-)
 create mode 100644 tests/fbo/CMakeLists.gles2.txt

diff --git a/tests/fbo/CMakeLists.gles2.txt b/tests/fbo/CMakeLists.gles2.txt
new file mode 100644
index 0000000..b7e52d1
--- /dev/null
+++ b/tests/fbo/CMakeLists.gles2.txt
@@ -0,0 +1,11 @@
+include_directories(
+        ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries(
+        glut_egl
+        piglitutil_${piglit_target_api}
+        ${OPENGL_gles1_LIBRARY}
+        )
+
+add_executable (fbo-drawbuffers-gles2 fbo-drawbuffers.c)
diff --git a/tests/fbo/fbo-drawbuffers.c b/tests/fbo/fbo-drawbuffers.c
index 36e057c..f6c4306 100644
--- a/tests/fbo/fbo-drawbuffers.c
+++ b/tests/fbo/fbo-drawbuffers.c
@@ -38,6 +38,45 @@ int piglit_width = 128;
 int piglit_height = 128;
 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
 
+#ifndef GL_MAX_DRAW_BUFFERS_ARB
+#define GL_MAX_DRAW_BUFFERS_ARB 0x8824
+#endif
+
+#if defined (USE_OPENGL_ES2)
+#include <EGL/egl.h>
+
+const char *vs_text =
+	"#version 100\n"
+	"attribute vec4 vertex;\n"
+	"attribute vec2 texcoord;\n"
+	"varying vec2 tc;\n"
+	"void main() { gl_Position = vertex; tc = texcoord; }"
+	;
+
+const char *fs1_text =
+	"#version 100\n"
+	"void main()\n"
+	"{\n"
+	"    gl_FragData[0] = vec4(0.0, 1.0, 0.0, 1.0);\n"
+	"    gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
+	"}\n"
+	;
+
+const char *fs2_text =
+	"#version 100\n"
+	"uniform sampler2D tex;\n"
+	"varying vec2 tc;\n"
+	"void main() { gl_FragColor = texture2D(tex, tc); }"
+	;
+
+static GLint prog_mrt;
+static GLint prog;
+
+typedef void (*PFNGLDRAWBUFFERSPROC) (GLsizei n, const GLenum *bufs);
+#endif
+
+PFNGLDRAWBUFFERSPROC DrawBuffers = NULL;
+
 static GLuint
 attach_texture(int i)
 {
@@ -80,7 +119,7 @@ piglit_display(void)
 	tex0 = attach_texture(0);
 	tex1 = attach_texture(1);
 
-	glDrawBuffersARB(2, attachments);
+	DrawBuffers(2, attachments);
 
 	status = piglit_CheckFramebufferStatus(GL_FRAMEBUFFER);
 	if (status != GL_FRAMEBUFFER_COMPLETE) {
@@ -92,19 +131,29 @@ piglit_display(void)
 	glClearColor(1.0, 0.0, 0.0, 0.0);
 	glClear(GL_COLOR_BUFFER_BIT);
 
+#if defined(USE_OPENGL_ES2)
+	piglit_UseProgram(prog_mrt);
+#else
 	glColor4fv(green);
+#endif
 	piglit_draw_rect(-1, -1, 2, 2);
 
 	piglit_BindFramebuffer(GL_FRAMEBUFFER, 0);
 
 	/* Draw the two green textures to halves of the window. */
+#if defined(USE_OPENGL_ES2)
+	piglit_UseProgram(prog);
+#else
 	glEnable(GL_TEXTURE_2D);
 	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+#endif
 	glBindTexture(GL_TEXTURE_2D, tex0);
 	piglit_draw_rect_tex(-1, -1, 1, 2,  0, 0, 1, 1);
 	glBindTexture(GL_TEXTURE_2D, tex1);
 	piglit_draw_rect_tex(0, -1, 1, 2, 0, 0, 1, 1);
+#if !defined(USE_OPENGL_ES2)
 	glDisable(GL_TEXTURE_2D);
+#endif
 	glDeleteTextures(1, &tex0);
 	glDeleteTextures(1, &tex1);
 	piglit_DeleteFramebuffers(1, &fb);
@@ -121,10 +170,42 @@ void
 piglit_init(int argc, char **argv)
 {
 	GLint num;
+#if defined(USE_OPENGL_ES2)
+	GLuint vs;
+	GLuint fs;
+#endif
 
 	piglit_require_fbo();
+#if defined(USE_OPENGL)
 	piglit_require_extension("GL_ARB_draw_buffers");
 
+	DrawBuffers = glDrawBuffers;
+#elif defined(USE_OPENGL_ES2)
+	piglit_require_extension("GL_NV_draw_buffers");
+	piglit_require_extension("GL_NV_fbo_color_attachments");
+
+	DrawBuffers = (PFNGLDRAWBUFFERSPROC)
+		eglGetProcAddress("glDrawBuffersNV");
+#endif
+
+#if defined(USE_OPENGL_ES2)
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text);
+	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs2_text);
+	prog = piglit_link_simple_program(vs, fs);
+
+	piglit_BindAttribLocation(prog, PIGLIT_ATTRIB_POS, "vertex");
+	piglit_BindAttribLocation(prog, PIGLIT_ATTRIB_TEX, "texcoord");
+	piglit_LinkProgram(prog);
+	piglit_link_check_status(prog);
+
+	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs1_text);
+	prog_mrt = piglit_link_simple_program(vs, fs);
+
+	piglit_BindAttribLocation(prog_mrt, PIGLIT_ATTRIB_POS, "vertex");
+	piglit_LinkProgram(prog_mrt);
+	piglit_link_check_status(prog_mrt);
+#endif
+
 	glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &num);
 	if (num < 2)
 		piglit_report_result(PIGLIT_SKIP);
-- 
1.7.6



More information about the Piglit mailing list