[PATCH] sampler-objects: test for GL_ARB_sampler_objects
Brian Paul
brianp at vmware.com
Sun Apr 10 12:26:07 PDT 2011
---
tests/all.tests | 5 +
tests/spec/CMakeLists.txt | 1 +
tests/spec/arb_sampler_objects/CMakeLists.gl.txt | 18 ++
tests/spec/arb_sampler_objects/CMakeLists.txt | 1 +
tests/spec/arb_sampler_objects/sampler-objects.c | 252 ++++++++++++++++++++++
5 files changed, 277 insertions(+), 0 deletions(-)
create mode 100644 tests/spec/arb_sampler_objects/CMakeLists.gl.txt
create mode 100644 tests/spec/arb_sampler_objects/CMakeLists.txt
create mode 100644 tests/spec/arb_sampler_objects/sampler-objects.c
diff --git a/tests/all.tests b/tests/all.tests
index 17d1270..6c974fd 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -687,6 +687,11 @@ add_plain_test(arb_es2_compatibility, 'arb_es2_compatibility-maxvectors')
add_plain_test(arb_es2_compatibility, 'arb_es2_compatibility-shadercompiler')
add_plain_test(arb_es2_compatibility, 'arb_es2_compatibility-releaseshadercompiler')
+# Group ARB_sampler_objects
+arb_sampler_objects = Group()
+spec['ARB_sampler_objects'] = arb_sampler_objects
+add_plain_test(arb_sampler_objects, 'sampler-objects')
+
# Group ARB_shader_texture_lod
arb_shader_texture_lod = Group()
spec['ARB_shader_texture_lod'] = arb_shader_texture_lod
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 4287e5f..11476f2 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -2,6 +2,7 @@ add_subdirectory (arb_color_buffer_float)
add_subdirectory (arb_es2_compatibility)
add_subdirectory (arb_instanced_arrays)
add_subdirectory (arb_robustness)
+add_subdirectory (arb_sampler_objects)
add_subdirectory (arb_shader_texture_lod)
add_subdirectory (ati_envmap_bumpmap)
add_subdirectory (ext_fog_coord)
diff --git a/tests/spec/arb_sampler_objects/CMakeLists.gl.txt b/tests/spec/arb_sampler_objects/CMakeLists.gl.txt
new file mode 100644
index 0000000..5a3feac
--- /dev/null
+++ b/tests/spec/arb_sampler_objects/CMakeLists.gl.txt
@@ -0,0 +1,18 @@
+include_directories(
+ ${GLEXT_INCLUDE_DIR}
+ ${OPENGL_INCLUDE_PATH}
+ ${GLUT_INCLUDE_DIR}
+ ${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+ piglitutil
+ ${OPENGL_gl_LIBRARY}
+ ${OPENGL_glu_LIBRARY}
+ ${GLUT_glut_LIBRARY}
+ ${TIFF_LIBRARY}
+)
+
+add_executable (sampler-objects sampler-objects.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_sampler_objects/CMakeLists.txt b/tests/spec/arb_sampler_objects/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_sampler_objects/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_sampler_objects/sampler-objects.c b/tests/spec/arb_sampler_objects/sampler-objects.c
new file mode 100644
index 0000000..ab1cc1a
--- /dev/null
+++ b/tests/spec/arb_sampler_objects/sampler-objects.c
@@ -0,0 +1,252 @@
+/*
+ * Copyright (c) 2011 VMware, Inc.
+ *
+ * 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 sampler-objects.c
+ *
+ * Test GL_ARB_sampler_objects
+ * Brian Paul
+ * April 2011
+ */
+
+
+#include "piglit-util.h"
+#include "piglit-framework.h"
+
+int piglit_width = 100;
+int piglit_height = 100;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
+
+static const char *Prog = "sampler-objects";
+
+
+static GLboolean
+check_error(int line)
+{
+ GLenum err = glGetError();
+ if (err != GL_NO_ERROR) {
+ fprintf(stderr, "%s: unexpected error 0x%x at line %d\n", Prog, err, line);
+ return GL_TRUE;
+ }
+ return GL_FALSE;
+}
+
+
+/**
+ * Test the sampler object gen/bind/delete functions.
+ */
+static enum piglit_result
+test_objects(void)
+{
+ GLuint samplers[4], i;
+
+ glGenSamplers(4, samplers);
+ if (check_error(__LINE__))
+ return PIGLIT_FAILURE;
+
+ for (i = 0; i < 4; i++) {
+ if (samplers[i] == 0)
+ return PIGLIT_FAILURE;
+ if (i > 1 && samplers[i] == samplers[i-1])
+ return PIGLIT_FAILURE;
+ if (!glIsSampler(samplers[i]))
+ return PIGLIT_FAILURE;
+ }
+
+ for (i = 0; i < 4; i++) {
+ glBindSampler(i, samplers[i]);
+ if (check_error(__LINE__))
+ return PIGLIT_FAILURE;
+ }
+
+ glDeleteSamplers(4, samplers);
+ if (check_error(__LINE__))
+ return PIGLIT_FAILURE;
+
+ for (i = 0; i < 4; i++) {
+ if (glIsSampler(samplers[i]))
+ return PIGLIT_FAILURE;
+ }
+
+ return PIGLIT_SUCCESS;
+}
+
+
+static const GLubyte mipmap_colors[10][4] = {
+ { 255, 0, 0, 255 },
+ { 0, 255, 0, 255 },
+ { 0, 0, 255, 255 },
+ { 0, 255, 255, 255 },
+ { 255, 0, 255, 255 },
+ { 255, 255, 0, 255 },
+ { 255, 255, 255, 255 },
+ { 128, 128, 128, 255 },
+ { 255, 128, 0, 255 },
+ { 0, 255, 128, 255 }
+};
+
+
+/** XXX this could be a piglit util function */
+static GLuint
+generate_mipmap(GLuint numLevels)
+{
+ int l;
+ GLuint tex;
+ assert(numLevels <= 10);
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ for (l = 0; l < numLevels; l++) {
+ int w = 1 << (numLevels - l - 1);
+ int h = w;
+ GLubyte *buf = malloc(w * h * 4);
+ int i;
+ for (i = 0; i < w * h; i++) {
+ buf[i*4+0] = mipmap_colors[l][0];
+ buf[i*4+1] = mipmap_colors[l][1];
+ buf[i*4+2] = mipmap_colors[l][2];
+ buf[i*4+3] = mipmap_colors[l][3];
+ }
+ glTexImage2D(GL_TEXTURE_2D, l, GL_RGBA, w, h, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, buf);
+ free(buf);
+ if (l == numLevels - 1) {
+ assert(w == 1);
+ }
+ }
+ return tex;
+}
+
+
+#define NUM_SAMPLERS 8
+
+/**
+ * Test sampler object operation. Create a mipmap texture with each
+ * level a different color. Create a number of samplers with each
+ * one's GL_TEXTURE_MIN_LOD = GL_TEXTURE_MAX_LOD = i to force sampling
+ * from mipmap level i. Draw a textured rect with each sampler object
+ * and test that the rect's color matches the mipmap level.
+ * XXX we should also test texcoord wrap modes, lod bias, filters, etc.
+ */
+static enum piglit_result
+test_samplers(void)
+{
+ const GLenum minFilt = GL_NEAREST_MIPMAP_NEAREST, magFilt = GL_NEAREST;
+ GLuint tex = generate_mipmap(9);
+ GLuint samplers[NUM_SAMPLERS], i;
+
+ glGenSamplers(NUM_SAMPLERS, samplers);
+ if (check_error(__LINE__))
+ return PIGLIT_FAILURE;
+
+ /* Create samplers which clamp lod to a particular mipmap level) */
+ for (i = 0; i < NUM_SAMPLERS; i++) {
+ glSamplerParameteri(samplers[i], GL_TEXTURE_MIN_LOD, (float) i);
+ glSamplerParameteri(samplers[i], GL_TEXTURE_MAX_LOD, (float) i);
+ glSamplerParameteri(samplers[i], GL_TEXTURE_MIN_FILTER, minFilt);
+ glSamplerParameteri(samplers[i], GL_TEXTURE_MAG_FILTER, magFilt);
+ }
+
+ /* Test sampler queries */
+ for (i = 0; i < NUM_SAMPLERS; i++) {
+ GLint v;
+ glGetSamplerParameteriv(samplers[i], GL_TEXTURE_MIN_LOD, &v);
+ if (v != i) {
+ fprintf(stderr, "%s: GL_TEXTURE_MIN_LOD query failed\n", Prog);
+ return PIGLIT_FAIL;
+ }
+ glGetSamplerParameteriv(samplers[i], GL_TEXTURE_MAX_LOD, &v);
+ if (v != i) {
+ fprintf(stderr, "%s: GL_TEXTURE_MAX_LOD query failed\n", Prog);
+ return PIGLIT_FAIL;
+ }
+ glGetSamplerParameteriv(samplers[i], GL_TEXTURE_MIN_FILTER, &v);
+ if (v != minFilt) {
+ fprintf(stderr, "%s: GL_TEXTURE_MIN_LOD query failed\n", Prog);
+ return PIGLIT_FAIL;
+ }
+ glGetSamplerParameteriv(samplers[i], GL_TEXTURE_MAG_FILTER, &v);
+ if (v != magFilt) {
+ fprintf(stderr, "%s: GL_TEXTURE_MIN_LOD query failed\n", Prog);
+ return PIGLIT_FAIL;
+ }
+ }
+
+ /* draw test rects */
+ glEnable(GL_TEXTURE_2D);
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ for (i = 0; i < NUM_SAMPLERS; i++) {
+ GLint p;
+ GLfloat exp[4];
+
+ glBindSampler(0, samplers[i]);
+ glClear(GL_COLOR_BUFFER_BIT);
+ piglit_draw_rect_tex(0, 0, piglit_width, piglit_height,
+ 0.0, 0.0, 1.0, 1.0);
+
+ exp[0] = mipmap_colors[i][0] / 255.0;
+ exp[1] = mipmap_colors[i][1] / 255.0;
+ exp[2] = mipmap_colors[i][2] / 255.0;
+ exp[3] = mipmap_colors[i][3] / 255.0;
+
+ p = piglit_probe_pixel_rgba(10, 10, exp);
+
+ glutSwapBuffers();
+
+ if (!p) {
+ fprintf(stderr, "%s failed for sampler %d\n", Prog, i);
+ return PIGLIT_FAIL;
+ }
+ }
+ glDisable(GL_TEXTURE_2D);
+
+ return PIGLIT_PASS;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ enum piglit_result res;
+
+ res = test_objects();
+ if (res != PIGLIT_SUCCESS)
+ return res;
+
+ res = test_samplers();
+ if (res != PIGLIT_SUCCESS)
+ return res;
+
+ return res;
+}
+
+
+void
+piglit_init(int argc, char**argv)
+{
+ if (!piglit_is_extension_supported("GL_ARB_sampler_objects"))
+ piglit_report_result(PIGLIT_SKIP);
+
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+}
--
1.7.3.4
--------------080807060207040005080601--
More information about the Piglit
mailing list