[Piglit] [RFC PATCH] KHR image from texture test

Abdiel Janulgue abdiel.janulgue at linux.intel.com
Mon Dec 17 06:00:40 PST 2012


Initial piglit test for image from texture extension. This patch-set currently
tests KHR_gl_texture_2D_image functionality. I plan to incrementally
add tests for cubemaps and 3D textures at some point. The test basically
makes sure that we create correct multiple EGL targets from a source texture.

Comments are suggestions welcome!

Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
---
 tests/spec/CMakeLists.txt                          |    1 +
 .../spec/khr_gl_texture_image/CMakeLists.gles2.txt |   17 ++
 tests/spec/khr_gl_texture_image/CMakeLists.txt     |    1 +
 .../khr_gl_texture_image/khr_gl_texture_image.c    |  205 ++++++++++++++++++++
 4 files changed, 224 insertions(+)
 create mode 100644 tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
 create mode 100644 tests/spec/khr_gl_texture_image/CMakeLists.txt
 create mode 100644 tests/spec/khr_gl_texture_image/khr_gl_texture_image.c

diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 46a91bd..0168d00 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -62,3 +62,4 @@ add_subdirectory (arb_draw_buffers)
 add_subdirectory (oes_draw_texture)
 add_subdirectory (arb_blend_func_extended)
 add_subdirectory (ext_unpack_subimage)
+add_subdirectory (khr_gl_texture_image)
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt b/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
new file mode 100644
index 0000000..d1887a1
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
@@ -0,0 +1,17 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+	${OPENGL_INCLUDE_PATH}
+	)
+
+link_libraries(
+	${OPENGL_gles2_LIBRARY}
+	${OPENGL_egl_LIBRARY}
+	piglitutil_gles2
+	)
+
+piglit_add_executable(khr_gl_texture_image_gles2
+	khr_gl_texture_image.c
+	)
+
+# vim: ft=cmake:
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.txt b/tests/spec/khr_gl_texture_image/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c b/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c
new file mode 100644
index 0000000..9250a81
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c
@@ -0,0 +1,205 @@
+
+#define EGL_EGLEXT_PROTOTYPES 1
+#define GL_GLEXT_PROTOTYPES 1
+
+#include "piglit-util-gl-common.h"
+#include "piglit-util-egl.h"
+
+#include <EGL/eglext.h>
+
+#define WIDTH  512
+#define HEIGHT 512
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+
+	config.window_width = WIDTH;
+	config.window_height = HEIGHT;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char
+vertex_shader[] =
+	"attribute vec4 pos_attrib;\n"
+	"attribute vec2 tex_attrib;\n"
+	"varying vec2 tex_coord;\n"
+	"void main () {\n"
+	"gl_Position = pos_attrib;\n"
+	"tex_coord = tex_attrib;\n"
+	"}\n";
+
+static const char
+fragment_shader[] =
+	"uniform sampler2D tex;\n"
+	"varying vec2 tex_coord;\n"
+	"void main () {\n"
+	"gl_FragColor = texture2D(tex, tex_coord);\n"
+	"}\n";
+
+static GLuint
+make_shader(GLenum type,
+	    const char *source)
+{
+	GLuint shader;
+	GLint length = strlen (source);
+	GLint status;
+
+	shader = glCreateShader(type);
+	glShaderSource(shader, 1, &source, &length);
+	glCompileShader(shader);
+	glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
+
+	if (!status)
+		fprintf(stderr, "Shader compilation failed\n");
+
+	return shader;
+}
+
+static void
+make_program(const char *vertex_source,
+	     const char *fragment_source)
+{
+	GLuint program, shader;
+	GLuint uniform;
+	GLint status;
+	GLchar glerr[256] = "";
+	int len;
+
+	program = glCreateProgram();
+	shader = make_shader(GL_VERTEX_SHADER, vertex_source);
+	glAttachShader(program, shader);
+	shader = make_shader(GL_FRAGMENT_SHADER, fragment_source);
+	glAttachShader(program, shader);
+
+	glBindAttribLocation(program, PIGLIT_ATTRIB_POS, "pos_attrib");
+	glBindAttribLocation(program, PIGLIT_ATTRIB_TEX, "tex_attrib");
+
+	glLinkProgram(program);
+
+	glGetProgramiv(program, GL_LINK_STATUS, &status);
+	if (!status) {
+	    glGetProgramInfoLog(program, 255, &len, glerr);
+	    fprintf(stderr, "Program linking failed, len: %d, error: %s\n",
+		    len, glerr);
+	}
+	
+	uniform = glGetUniformLocation(program, "tex");
+	glUseProgram(program);
+	glUniform1i(uniform, 0);
+}
+
+GLuint 
+create_egl_image_target(GLuint texture, GLuint level)
+{
+    GLuint target_texture;
+    EGLint attribs[] = {
+	EGL_GL_TEXTURE_LEVEL_KHR, level,
+	EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
+	EGL_NONE };
+
+    EGLDisplay dpy = eglGetCurrentDisplay();
+    EGLContext ctx = eglGetCurrentContext();
+    EGLImageKHR image = eglCreateImageKHR(dpy, ctx, EGL_GL_TEXTURE_2D_KHR,
+					  (EGLClientBuffer)(uintptr_t)texture,
+					  attribs);
+    if (image == EGL_NO_IMAGE_KHR) {
+	printf("Warning EGL_NO_IMAGE_KHR  0x%x\n",
+	       eglGetError());
+    }
+    
+    glGenTextures(1, &target_texture);
+    glBindTexture(GL_TEXTURE_2D, target_texture);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
+		    GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
+		    GL_LINEAR);
+    glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
+
+    return target_texture;
+}
+
+int miplevel_rendered_correctly(int level)
+{
+    static float blue[]    = {0.0,  0.0,  1.0};
+    /* approximate 5th mip level minification  */
+    static float interp[]  = {0.23, 0.19, 0.94};
+    /* smallest mip level interpolates to a single gray pixel */
+    static float gray[]    = {0.5,  0.5,  0.5};
+    
+    switch(level) {
+    case 6:
+	return piglit_probe_pixel_rgb(WIDTH  - (WIDTH  * 0.25), 
+				      HEIGHT - (HEIGHT * 0.25), gray);
+    case 5:
+	return piglit_probe_pixel_rgb(WIDTH  - (WIDTH  * 0.35), 
+				      HEIGHT - (HEIGHT * 0.60), interp);
+    case 3:
+	return piglit_probe_pixel_rgb(WIDTH  - (WIDTH  * 0.95), 
+				      HEIGHT - (HEIGHT * 0.60), blue);
+    }
+    
+    return 0;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+    EGLDisplay dpy = eglGetCurrentDisplay();
+    EGLSurface draw = eglGetCurrentSurface(EGL_DRAW);
+    GLboolean pass = GL_TRUE;
+    GLuint texture;
+    
+    glClearColor(0,0, 0, 0);
+    glClear(GL_COLOR_BUFFER_BIT);
+    
+    /* Set up a source texture object with mipmap generation */
+    texture = piglit_rgbw_texture(GL_RGBA, 120, 120, GL_FALSE, GL_FALSE, 0);
+    glGenerateMipmap(GL_TEXTURE_2D);
+   
+    glActiveTexture(GL_TEXTURE0);
+    glBindTexture(GL_TEXTURE_2D, texture);
+    
+    make_program(vertex_shader, fragment_shader);
+    piglit_draw_rect_tex(-1, 0, 1.0, 1.0,  0, 0, 1, 1);
+
+    if (!piglit_check_gl_error(GL_NO_ERROR))
+	    pass = GL_FALSE;
+
+    /* Generate EGLImage target textures for some levels */
+    glBindTexture(GL_TEXTURE_2D, create_egl_image_target(texture, 3));
+    piglit_draw_rect_tex(-1, -1, 1.0, 1.0,  0, 0, 1, 1);
+    
+    glBindTexture(GL_TEXTURE_2D, create_egl_image_target(texture, 5));
+    piglit_draw_rect_tex(0, -1, 1.0, 1.0,  0, 0, 1, 1);
+
+    glBindTexture(GL_TEXTURE_2D, create_egl_image_target(texture, 6));
+    piglit_draw_rect_tex(0, 0, 1.0, 1.0,  0, 0, 1, 1);
+
+    if (!piglit_check_gl_error(GL_NO_ERROR))
+	    pass = GL_FALSE;
+
+    eglSwapBuffers(dpy, draw);	
+           
+    /* Check for correctness */
+    if (miplevel_rendered_correctly(6) &&
+	miplevel_rendered_correctly(5) &&
+	miplevel_rendered_correctly(3))
+	pass &= GL_TRUE;
+
+    return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+    const char *s;
+
+    EGLDisplay dpy = eglGetCurrentDisplay();
+    s = (const char *) eglQueryString(dpy, EGL_EXTENSIONS);
+    if (!piglit_is_extension_in_string(s, "EGL_KHR_gl_texture_2D_image")) {
+	piglit_report_result(PIGLIT_SKIP);
+	exit(1);
+    }
+}
-- 
1.7.9.5



More information about the Piglit mailing list