[Piglit] [PATCH] arb_texture_buffer_range: add initial tests (dlist, errors, ranges)

christoph.bumiller at speed.at christoph.bumiller at speed.at
Sat Jan 12 05:45:57 PST 2013


From: Christoph Bumiller <e0425955 at student.tuwien.ac.at>

---
 tests/all.tests                                    |    7 +
 tests/spec/CMakeLists.txt                          |    1 +
 .../arb_texture_buffer_range/CMakeLists.gl.txt     |   16 ++
 tests/spec/arb_texture_buffer_range/CMakeLists.txt |    1 +
 tests/spec/arb_texture_buffer_range/dlist.c        |   99 +++++++++
 tests/spec/arb_texture_buffer_range/errors.c       |  136 ++++++++++++
 .../spec/arb_texture_buffer_range/not-supported.c  |   71 +++++++
 tests/spec/arb_texture_buffer_range/ranges.c       |  221 ++++++++++++++++++++
 8 files changed, 552 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/arb_texture_buffer_range/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_texture_buffer_range/CMakeLists.txt
 create mode 100644 tests/spec/arb_texture_buffer_range/dlist.c
 create mode 100644 tests/spec/arb_texture_buffer_range/errors.c
 create mode 100644 tests/spec/arb_texture_buffer_range/not-supported.c
 create mode 100644 tests/spec/arb_texture_buffer_range/ranges.c

diff --git a/tests/all.tests b/tests/all.tests
index 145312c..1bb660e 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1101,6 +1101,13 @@ arb_texture_buffer_object['negative-bad-format'] = concurrent_test('arb_texture_
 arb_texture_buffer_object['negative-bad-target'] = concurrent_test('arb_texture_buffer_object-negative-bad-target')
 arb_texture_buffer_object['unused-name'] = concurrent_test('arb_texture_buffer_object-unused-name')
 
+arb_texture_buffer_range = Group()
+spec['ARB_texture_buffer_range'] = arb_texture_buffer_range
+arb_texture_buffer_range['dlist'] = concurrent_test('arb_texture_buffer_range-dlist')
+arb_texture_buffer_range['errors'] = concurrent_test('arb_texture_buffer_range-errors')
+arb_texture_buffer_range['ranges'] = concurrent_test('arb_texture_buffer_range-ranges')
+arb_texture_buffer_range['not-supported'] = concurrent_test('arb_texture_buffer_range-not-supported')
+
 arb_texture_rectangle = Group()
 spec['ARB_texture_rectangle'] = arb_texture_rectangle
 add_texwrap_target_tests(arb_texture_rectangle, 'RECT')
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 9ec37fa..650ffbf 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -20,6 +20,7 @@ add_subdirectory (arb_sync)
 add_subdirectory (arb_uniform_buffer_object)
 add_subdirectory (ati_draw_buffers)
 add_subdirectory (arb_texture_buffer_object)
+add_subdirectory (arb_texture_buffer_range)
 add_subdirectory (arb_texture_compression)
 add_subdirectory (arb_texture_cube_map_array)
 add_subdirectory (arb_texture_float)
diff --git a/tests/spec/arb_texture_buffer_range/CMakeLists.gl.txt b/tests/spec/arb_texture_buffer_range/CMakeLists.gl.txt
new file mode 100644
index 0000000..cd2892f
--- /dev/null
+++ b/tests/spec/arb_texture_buffer_range/CMakeLists.gl.txt
@@ -0,0 +1,16 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+	${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+)
+
+piglit_add_executable (arb_texture_buffer_range-dlist dlist.c)
+piglit_add_executable (arb_texture_buffer_range-errors errors.c)
+piglit_add_executable (arb_texture_buffer_range-ranges ranges.c)
+piglit_add_executable (arb_texture_buffer_range-not-supported not-supported.c)
diff --git a/tests/spec/arb_texture_buffer_range/CMakeLists.txt b/tests/spec/arb_texture_buffer_range/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_texture_buffer_range/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_texture_buffer_range/dlist.c b/tests/spec/arb_texture_buffer_range/dlist.c
new file mode 100644
index 0000000..6b8888f
--- /dev/null
+++ b/tests/spec/arb_texture_buffer_range/dlist.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+#include "piglit-util-gl-common.h"
+
+/**
+ * @file dlist.c
+ *
+ * Tests display list behavior for GL_ARB_texture_buffer_range.
+ *
+ * The new entrypoint was added to the list of buffer-object related
+ * commands that are executed immediately and not added to the display
+ * list.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_width = 32;
+	config.window_height = 32;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	bool pass = true;
+	GLuint list, tex, bo;
+	GLint ret;
+
+	piglit_require_gl_version(20);
+	piglit_require_extension("GL_ARB_texture_buffer_range");
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_BUFFER, tex);
+
+	glGenBuffers(1, &bo);
+	glBindBuffer(GL_TEXTURE_BUFFER, bo);
+	glBufferData(GL_TEXTURE_BUFFER, 128, NULL, GL_STATIC_DRAW);
+
+	list = glGenLists(1);
+	glNewList(list, GL_COMPILE);
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, bo, 0, 128);
+	glEndList();
+
+	ret = 0xd0d0d0d0;
+	glGetIntegerv(GL_TEXTURE_BUFFER_DATA_STORE_BINDING, &ret);
+	if (ret != bo) {
+		fprintf(stderr,
+			"GL_TEXTURE_BUFFER_DATA_STORE after display list "
+			"compile was %d, expected %d\n", ret, bo);
+		pass = false;
+	}
+
+	/* Make sure the list is empty. */
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, 0, 0, 0);
+	glCallList(list);
+	if (!piglit_check_gl_error(0))
+		pass = false;
+
+	glGetIntegerv(GL_TEXTURE_BUFFER_DATA_STORE_BINDING, &ret);
+	if (ret != 0) {
+		fprintf(stderr,
+			"GL_TEXTURE_BUFFER_DATA_STORE after display list "
+			"compile was %d, expected %d\n", ret, 0);
+		pass = false;
+	}
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
diff --git a/tests/spec/arb_texture_buffer_range/errors.c b/tests/spec/arb_texture_buffer_range/errors.c
new file mode 100644
index 0000000..2c0d5ce
--- /dev/null
+++ b/tests/spec/arb_texture_buffer_range/errors.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+#include "piglit-util-gl-common.h"
+
+/**
+ * @file errors.c
+ *
+ * Tests error conditions and queries for glTexBufferRange.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.supports_gl_core_version = 31;
+
+	config.window_width = 32;
+	config.window_height = 32;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+/* use min of MAX_TEXTURE_BUFFER_SIZE */
+#define TBO_SIZE (1 << 16)
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLint align, value[2];
+	GLuint tex, bo;
+
+	piglit_require_gl_version(20);
+	piglit_require_extension("GL_ARB_texture_buffer_range");
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_BUFFER, tex);
+	glGenBuffers(1, &bo);
+	glBindBuffer(GL_TEXTURE_BUFFER, bo);
+
+	glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &align);
+	if (align < 1) {
+		fprintf(stderr, "GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT == %i, "
+		        "should be >= 1\n", align);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* If <offset> is negative or if <size> is
+	 * less than or equal to zero or if <offset> + <size> is greater than
+	 * the value of BUFFER_SIZE for the buffer bound to <target>, of if
+	 * <offset> is not an integer multiple of
+	 * TEXTURE_BUFFER_OFFSET_ALIGNMENT, then the error INVALID_VALUE
+	 * is generated.
+	 */
+
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, bo, 0, 4);
+	if (!piglit_check_gl_error(GL_INVALID_VALUE))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glBufferData(GL_TEXTURE_BUFFER, TBO_SIZE, NULL, GL_STATIC_DRAW);
+
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, bo, -align, 4);
+	if (!piglit_check_gl_error(GL_INVALID_VALUE))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, bo, 0, 0);
+	if (!piglit_check_gl_error(GL_INVALID_VALUE))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, bo,
+	                 align, TBO_SIZE - align);
+	if (!piglit_check_gl_error(GL_NO_ERROR)) {
+		fprintf(stderr, "glTexBufferRange failed\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+	glGetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_OFFSET,
+	                         &value[0]);
+	glGetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_SIZE,
+	                         &value[1]);
+	if (value[0] != align || value[1] != TBO_SIZE - align) {
+		fprintf(stderr, "GL_TEXTURE_BUFFER_OFFSET/SIZE returned %i/%i, "
+		        "expected %i/%i\n",
+		        value[0], value[1], align, TBO_SIZE - align);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	/* If <buffer> is zero, then any buffer object attached to the
+	 * buffer texture is detached, the values <offset> and <size> are
+	 * ignored and the state for <offset> and <size> for the
+	 * buffer texture are reset to zero.
+	 */
+
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, 0, -align, TBO_SIZE * 2);
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		piglit_report_result(PIGLIT_FAIL);
+
+	glGetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_OFFSET,
+	                         &value[0]);
+	glGetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_SIZE,
+	                         &value[1]);
+	if (value[0] || value[1]) {
+		fprintf(stderr, "buffer detached but "
+		        "GL_TEXTURE_BUFFER_OFFSET/SIZE "
+		        "not reset to 0\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	piglit_report_result(PIGLIT_PASS);
+}
+
diff --git a/tests/spec/arb_texture_buffer_range/not-supported.c b/tests/spec/arb_texture_buffer_range/not-supported.c
new file mode 100644
index 0000000..9ad0b1f
--- /dev/null
+++ b/tests/spec/arb_texture_buffer_range/not-supported.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+#include "piglit-util-gl-common.h"
+
+/**
+ * @file not-supported.c
+ *
+ * Check that glTexBufferRange generates GL_INVALID_OPERATION if the extension
+ * is not supported.
+ */
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.supports_gl_core_version = 31;
+
+	config.window_width = 32;
+	config.window_height = 32;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	/* UNREACHED */
+	return PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	GLuint tex, bo;
+
+	piglit_require_extension("GL_ARB_texture_buffer_object");
+	piglit_require_not_extension("GL_ARB_texture_buffer_range");
+
+	glGenBuffers(1, &bo);
+	glBindBuffer(GL_TEXTURE_BUFFER, bo);
+	glBufferData(GL_TEXTURE_BUFFER, 4096, NULL, GL_STATIC_DRAW);
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_BUFFER, tex);
+
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_RGBA8, bo, 0, 4096);
+	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+		piglit_report_result(PIGLIT_FAIL);
+
+	piglit_report_result(PIGLIT_PASS);
+}
+
diff --git a/tests/spec/arb_texture_buffer_range/ranges.c b/tests/spec/arb_texture_buffer_range/ranges.c
new file mode 100644
index 0000000..e982efd
--- /dev/null
+++ b/tests/spec/arb_texture_buffer_range/ranges.c
@@ -0,0 +1,221 @@
+/* Copyright © 2012 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 ranges.c
+ *
+ * Test drawing with various ranges and sizes for glTexBufferRange.
+ */
+
+#define _GNU_SOURCE
+#include "piglit-util-gl-common.h"
+
+GLuint prog;
+GLuint tbo;
+GLuint tex;
+
+uint8_t *data;
+
+GLint vertex_location;
+
+#define TBO_WIDTH 1024
+#define TBO_SIZE  TBO_WIDTH
+
+#define WIN_HEIGHT 32
+#define WIN_WIDTH (TBO_WIDTH / WIN_HEIGHT)
+
+enum piglit_result
+test_range(GLint offset, GLint size)
+{
+	const float green[4] = { 0, 1, 0, 0 };
+
+	glUseProgram(prog);
+
+	glBindTexture(GL_TEXTURE_BUFFER, tex);
+	glTexBufferRange(GL_TEXTURE_BUFFER, GL_R8UI, tbo, offset, size);
+
+	glUniform1i(glGetUniformLocation(prog, "buf"), 0);
+	glUniform1i(glGetUniformLocation(prog, "offset"), offset);
+	glUniform1i(glGetUniformLocation(prog, "size"), size);
+
+	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+	if (!piglit_probe_rect_rgba(0, 0, WIN_WIDTH, WIN_HEIGHT, green))
+		return PIGLIT_FAIL;
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	enum piglit_result result = PIGLIT_SKIP;
+	GLint i, j, n;
+	GLuint vao, vbo;
+	GLint incr;
+	const float verts[] =
+		{ -1.0f, -1.0f,  -1.0f, 1.0f,  1.0f, 1.0f,  1.0f, -1.0f };
+
+	glClearColor(0.5, 0.5, 0.5, 0.5);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* For GL core, we need to have a vertex array object bound.
+	 * Otherwise, we don't particularly have to.  Always use a
+	 * vertex buffer object, though.
+	 */
+	glGenBuffers(1, &vbo);
+	glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo);
+	if (piglit_get_gl_version() >= 31) {
+		GLuint vao;
+		glGenVertexArrays(1, &vao);
+		glBindVertexArray(vao);
+	}
+	glVertexAttribPointer(vertex_location, 2, GL_FLOAT, GL_FALSE, 0, NULL);
+	glEnableVertexAttribArray(vertex_location);
+
+	glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
+
+	glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &incr);
+	if (!incr)
+		return PIGLIT_FAIL;
+	for (n = 0, i = 0; i < TBO_SIZE && result != PIGLIT_FAIL; i += incr) {
+		for (j = 1; j <= 4 && result != PIGLIT_FAIL; ++j, ++n) {
+			GLint size = (TBO_SIZE - i) / j;
+			if (!size)
+				break;
+			result = test_range(i, (TBO_SIZE - i) / j);
+		}
+		if (n > 128) { /* takes too long otherwise */
+			n = 0;
+			incr *= 2;
+		}
+	}
+
+	glDeleteBuffers(1, &vbo);
+	glDeleteVertexArrays(1, &vao);
+
+	piglit_present_results();
+
+	return result;
+}
+
+static char *vs_source =
+	"#version 140\n"
+	"in vec4 vertex;\n"
+	"void main()\n"
+	"{\n"
+	"	gl_Position = vertex;\n"
+	"}\n";
+
+static char *fs_source =
+	"#version 140\n"
+	"uniform isamplerBuffer buf;\n"
+	"uniform int offset;\n"
+	"uniform int size;\n"
+	"\n"
+	"void main()\n"
+	"{\n"
+	"  int pos = int(gl_FragCoord.x) + int(gl_FragCoord.y) * 64;\n"
+	"  int expected = ((pos + offset) | 1) & 0xff;\n"
+	"  if (pos >= size)\n"
+	"    expected = 0;\n"
+	"  bool ok = texelFetch(buf, pos).r == expected;\n"
+	"  gl_FragColor = ok ?\n"
+	"     vec4(0.0, 1.0, 0.0, 0.0) : vec4(1.0, 0.0, 0.0, 0.0);\n"
+	"}\n";
+
+static void
+init_program()
+{
+	GLuint vs, fs;
+
+	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
+	if (!vs) {
+		printf("VS source:\n%s\n", vs_source);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
+	if (!fs) {
+		printf("FS source:\n%s\n", fs_source);
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	prog = piglit_link_simple_program(vs, fs);
+	if (!prog)
+		piglit_report_result(PIGLIT_FAIL);
+
+	vertex_location = glGetAttribLocation(prog, "vertex");
+}
+
+static void
+init_tbo()
+{
+	int i;
+
+	data = malloc(TBO_SIZE);
+	if (!data) {
+		fprintf(stderr, "malloc failed\n");
+		piglit_report_result(PIGLIT_SKIP);
+	}
+
+	/* always non-zero to distinguish from out-of-bounds access */
+	for (i = 0; i < TBO_WIDTH; ++i)
+		data[i] = (i | 1) & 0xff;
+
+	glGenBuffers(1, &tbo);
+	glBindBuffer(GL_TEXTURE_BUFFER, tbo);
+	glBufferData(GL_TEXTURE_BUFFER, TBO_SIZE, data, GL_STATIC_DRAW);
+
+	glGenTextures(1, &tex);
+
+	free(data);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_GLSL_version(140);
+	piglit_require_extension("GL_ARB_texture_buffer_range");
+
+	init_program();
+	init_tbo();
+}
+
+int
+main(int argc, char *argv[])
+{
+	struct piglit_gl_test_config config;
+
+	piglit_gl_test_config_init(&config);
+
+	config.init = piglit_init;
+	config.display = piglit_display;
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_width = WIN_WIDTH;
+	config.window_height = WIN_HEIGHT;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;
+
+	piglit_gl_test_run(argc, argv, &config);
+
+	assert(0);
+	return 0;
+}
-- 
1.7.3.4



More information about the Piglit mailing list