[Piglit] [PATCH 1/8] shader_runner: support integer textures

Nicolai Hähnle nhaehnle at gmail.com
Thu Apr 7 01:10:45 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 tests/shaders/shader_runner.c | 17 +++++++++++++++++
 tests/util/piglit-util-gl.c   | 35 +++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl.h   |  1 +
 3 files changed, 53 insertions(+)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 8d2a9bd..206258c 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -3102,6 +3102,23 @@ piglit_display(void)
 					    GL_UNSIGNED_NORMALIZED);
 			if (!piglit_is_core_profile)
 				glEnable(GL_TEXTURE_2D);
+		} else if (sscanf(line, "texture integer %d ( %d", &tex, &w) == 2) {
+			GLenum int_fmt;
+			int b, a;
+			int num_scanned =
+				sscanf(line,
+				       "texture integer %d ( %d , %d ) ( %d, %d ) %31s",
+				       &tex, &w, &h, &b, &a, s);
+			if (num_scanned < 6) {
+				fprintf(stderr,
+					"invalid texture integer command!\n");
+				piglit_report_result(PIGLIT_FAIL);
+			}
+
+			int_fmt = piglit_get_gl_enum_from_name(s);
+
+			glActiveTexture(GL_TEXTURE0 + tex);
+			piglit_integer_texture(int_fmt, w, h, b, a);
 		} else if (sscanf(line, "texture miptree %d", &tex) == 1) {
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_miptree_texture();
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index dbdfb13..e8a47c5 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -2494,6 +2494,41 @@ piglit_rgbw_texture(GLenum internalFormat, int w, int h, GLboolean mip,
 }
 
 /**
+ * Generates a texture with the given integer internal format.
+ * Pixel data will be filled as R = x, G = y, B = b, A = a.
+ */
+GLuint piglit_integer_texture(GLenum internalFormat, int w, int h, int b, int a)
+{
+	int *img = malloc(w * h * 4 * sizeof(unsigned));
+	int *p;
+	int x, y;
+	GLuint tex;
+
+	for (y = 0, p = img; y < h; ++y) {
+		for (x = 0; x < w; ++x, p += 4) {
+			p[0] = x;
+			p[1] = y;
+			p[2] = b;
+			p[3] = a;
+		}
+	}
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+			GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+			GL_NEAREST);
+
+	glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0,
+		     GL_RGBA_INTEGER, GL_INT, img);
+
+	free(img);
+}
+
+/**
  * Create a depth texture.  The depth texture will be a gradient which varies
  * from 0.0 at the left side to 1.0 at the right side.  For a 2D array texture,
  * all the texture layers will have the same gradient.
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 00c106b..956804b 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -262,6 +262,7 @@ GLfloat *piglit_rgbw_image(GLenum internalFormat, int w, int h,
 GLubyte *piglit_rgbw_image_ubyte(int w, int h, GLboolean alpha);
 GLuint piglit_rgbw_texture(GLenum internalFormat, int w, int h, GLboolean mip,
 		    GLboolean alpha, GLenum basetype);
+GLuint piglit_integer_texture(GLenum internalFormat, int w, int h, int b, int a);
 GLuint piglit_depth_texture(GLenum target, GLenum format, int w, int h, int d, GLboolean mip);
 GLuint piglit_array_texture(GLenum target, GLenum format, int w, int h, int d, GLboolean mip);
 GLuint piglit_multisample_texture(GLenum target, GLenum tex,
-- 
2.5.0



More information about the Piglit mailing list