diff options
author | Brian Paul <brianp@vmware.com> | 2010-02-25 20:10:37 -0700 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2010-02-25 20:10:37 -0700 |
commit | a61d0b7406adab1efe946873ee5a8762e6c6406a (patch) | |
tree | 5231850d29c4e750bf9ba022f77f70b7d6901e9f | |
parent | 6f494186f6f85aeaa291e37cac50342668005957 (diff) |
array-texture: new test for GL_EXT_texture_array
-rw-r--r-- | tests/all.tests | 1 | ||||
-rw-r--r-- | tests/texturing/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/texturing/array-texture.c | 348 |
3 files changed, 350 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests index 0ef36208..b3480526 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -245,6 +245,7 @@ add_plain_test(glx, 'glx-multithread') add_plain_test(glx, 'glx-swap-exchange') texturing = Group() +add_plain_test(texturing, 'array-texture') add_plain_test(texturing, 'copytexsubimage') add_plain_test(texturing, 'cubemap') add_plain_test(texturing, 'gen-teximage') diff --git a/tests/texturing/CMakeLists.txt b/tests/texturing/CMakeLists.txt index 023564e7..f6919a6a 100644 --- a/tests/texturing/CMakeLists.txt +++ b/tests/texturing/CMakeLists.txt @@ -19,6 +19,7 @@ link_libraries ( ${GLEW_glew_LIBRARY} ) +add_executable (array-texture array-texture.c) add_executable (copytexsubimage copytexsubimage.c) add_executable (cubemap cubemap.c) add_executable (gen-compressed-teximage gen-compressed-teximage.c) diff --git a/tests/texturing/array-texture.c b/tests/texturing/array-texture.c new file mode 100644 index 00000000..d8988125 --- /dev/null +++ b/tests/texturing/array-texture.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2010 VMWare, Inc. + * + * Permission is hereby , 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. + * + * + * Test GL_EXT_texture_array and GL_MESA_texture_array. + * Note that the Mesa extension works with fixed-function fragment + * processing whereas the EXT version only works with shaders. + * + * Author: Brian Paul + */ + + +#include "piglit-util.h" + +int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB; +int piglit_width = 100; +int piglit_height = 100; + +static const char *prog = "array-texture"; + +static GLboolean have_MESA_texture_array; + +static GLuint array_tex_1d; +static GLuint array_tex_2d; + +/* + * We'll set each texture slice to a different solid color. + * XXX a better test would vary the color within each slice too. + */ +#define NUM_COLORS 7 + +static GLfloat colors[NUM_COLORS][3] = { + {1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {0.0, 0.0, 1.0}, + {0.0, 0.0, 1.0}, + {0.0, 1.0, 0.0}, + {1.0, 1.0, 0.0}, + {1.0, 1.0, 1.0} +}; + + +static const char *frag_shader_2d_array_text = + "uniform sampler2DArray tex; \n" + "void main() \n" + "{ \n" + " gl_FragColor = texture2DArray(tex, gl_TexCoord[0].xyz); \n" + "} \n"; + +static GLuint frag_shader_2d_array; +static GLuint program_2d_array; + + +static const char *frag_shader_1d_array_text = + "uniform sampler1DArray tex; \n" + "void main() \n" + "{ \n" + " gl_FragColor = texture1DArray(tex, gl_TexCoord[0].xy); \n" + "} \n"; + +static GLuint frag_shader_1d_array; +static GLuint program_1d_array; + + + +/* debug aid */ +static void +check_error(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("%s: GL error 0x%x at line %d\n", prog, err, line); + } +} + + +static GLuint +make_2d_array_texture(void) +{ + GLfloat img[NUM_COLORS][64][32][4]; + GLuint tex; + int i, j, k; + + for (i = 0; i < NUM_COLORS; i++) { + for (j = 0; j < 64; j++) { + for (k = 0; k < 32; k++) { + img[i][j][k][0] = colors[i][0]; + img[i][j][k][1] = colors[i][1]; + img[i][j][k][2] = colors[i][2]; + img[i][j][k][3] = colors[i][3]; + } + } + } + + glGenTextures(1, &tex); + + glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, tex); + check_error(__LINE__); + + glTexImage3D(GL_TEXTURE_2D_ARRAY_EXT, 0, GL_RGBA, + 32, 64, NUM_COLORS, /* w, h, d */ + 0, /* border */ + GL_RGBA, GL_FLOAT, img); + + glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + check_error(__LINE__); + + return tex; +} + + +static GLuint +make_1d_array_texture(void) +{ + GLfloat img[NUM_COLORS][16][4]; + GLuint tex; + int i, j; + + for (i = 0; i < NUM_COLORS; i++) { + for (j = 0; j < 16; j++) { + img[i][j][0] = colors[i][0]; + img[i][j][1] = colors[i][1]; + img[i][j][2] = colors[i][2]; + img[i][j][3] = colors[i][3]; + } + } + + glGenTextures(1, &tex); + + glBindTexture(GL_TEXTURE_1D_ARRAY_EXT, tex); + check_error(__LINE__); + + glTexImage2D(GL_TEXTURE_1D_ARRAY_EXT, 0, GL_RGBA, + 16, NUM_COLORS, /* w, depth */ + 0, /* border */ + GL_RGBA, GL_FLOAT, img); + + glTexParameteri(GL_TEXTURE_1D_ARRAY_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_1D_ARRAY_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + check_error(__LINE__); + + return tex; +} + + +static GLboolean +test_2d_array_texture(GLuint tex) +{ + GLboolean pass; + int i; + + glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, tex); + + /* render each image in the array, check its color */ + for (i = 0; i < NUM_COLORS; i++) { + GLfloat r = (GLfloat) i; + + glBegin(GL_POLYGON); + glTexCoord3f(0, 0, r); glVertex2f(0, 0); + glTexCoord3f(1, 0, r); glVertex2f(piglit_width, 0); + glTexCoord3f(1, 1, r); glVertex2f(piglit_width, piglit_height); + glTexCoord3f(0, 1, r); glVertex2f(0, piglit_height); + glEnd(); + + pass = piglit_probe_pixel_rgb(piglit_width / 2, piglit_height / 2, + colors[i]); + + if (!pass) { + printf("%s: failed for 2D image/slice %d\n", prog, i); + break; + } + } + + glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, 0); + + return pass; +} + + +static GLboolean +test_1d_array_texture(GLuint tex) +{ + GLboolean pass; + int i; + + glBindTexture(GL_TEXTURE_1D_ARRAY_EXT, tex); + + /* render each image in the array, check its color */ + for (i = 0; i < NUM_COLORS; i++) { + GLfloat r = (GLfloat) i; + + glBegin(GL_POLYGON); + glTexCoord2f(0, r); glVertex2f(0, 0); + glTexCoord2f(1, r); glVertex2f(piglit_width, 0); + glTexCoord2f(1, r); glVertex2f(piglit_width, piglit_height); + glTexCoord2f(0, r); glVertex2f(0, piglit_height); + glEnd(); + + glFinish(); + + pass = piglit_probe_pixel_rgb(piglit_width / 2, piglit_height / 2, + colors[i]); + + if (!pass) { + printf("%s: failed for 1D image/slice %d\n", prog, i); + break; + } + } + + glBindTexture(GL_TEXTURE_1D_ARRAY_EXT, 0); + + return pass; +} + + +enum piglit_result +piglit_display(void) +{ + GLboolean pass = GL_TRUE; + GLint loc; + + if (!frag_shader_2d_array) { + printf("%s: failed to compile 2D fragment shader.\n", prog); + return PIGLIT_FAILURE; + } + + if (!program_2d_array) { + printf("%s: failed to link 2D shader program.\n", prog); + return PIGLIT_FAILURE; + } + + if (!frag_shader_1d_array) { + printf("%s: failed to compile 1D fragment shader.\n", prog); + return PIGLIT_FAILURE; + } + + if (!program_1d_array) { + printf("%s: failed to link 1D shader program.\n", prog); + return PIGLIT_FAILURE; + } + + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + /* + * Test 2d array texture with fragment shader + */ + { + glClear(GL_COLOR_BUFFER_BIT); + glUseProgram(program_2d_array); + loc = glGetUniformLocation(program_2d_array, "tex"); + glUniform1i(loc, 0); /* texture unit p */ + pass = pass && test_2d_array_texture(array_tex_2d); + glUseProgram(0); + glutSwapBuffers(); + } + + /* + * Test 2d array texture with fixed function + */ + if (have_MESA_texture_array) { + glClear(GL_COLOR_BUFFER_BIT); + glEnable(GL_TEXTURE_2D_ARRAY_EXT); + check_error(__LINE__); + pass = pass && test_2d_array_texture(array_tex_2d); + glDisable(GL_TEXTURE_2D_ARRAY_EXT); + check_error(__LINE__); + glutSwapBuffers(); + } + + /* + * Test 1d array texture with fragment shader + */ + { + glClear(GL_COLOR_BUFFER_BIT); + glUseProgram(program_1d_array); + loc = glGetUniformLocation(program_1d_array, "tex"); + glUniform1i(loc, 0); /* texture unit p */ + pass = pass && test_1d_array_texture(array_tex_1d); + glUseProgram(0); + glutSwapBuffers(); + } + + /* + * Test 1d array texture with fixed function + */ + if (have_MESA_texture_array) { + glClear(GL_COLOR_BUFFER_BIT); + glEnable(GL_TEXTURE_1D_ARRAY_EXT); + check_error(__LINE__); + pass = pass && test_1d_array_texture(array_tex_1d); + glDisable(GL_TEXTURE_1D_ARRAY_EXT); + check_error(__LINE__); + glutSwapBuffers(); + } + + return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE; +} + + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_EXT_texture_array"); + + have_MESA_texture_array = glutExtensionSupported("GL_MESA_texture_array"); + + /* Make shader programs */ + frag_shader_2d_array = + piglit_compile_shader_text(GL_FRAGMENT_SHADER, + frag_shader_2d_array_text); + check_error(__LINE__); + + program_2d_array = piglit_link_simple_program(0, frag_shader_2d_array); + check_error(__LINE__); + + frag_shader_1d_array = + piglit_compile_shader_text(GL_FRAGMENT_SHADER, + frag_shader_1d_array_text); + check_error(__LINE__); + + program_1d_array = piglit_link_simple_program(0, frag_shader_1d_array); + check_error(__LINE__); + + /* make array textures */ + array_tex_2d = make_2d_array_texture(); + array_tex_1d = make_1d_array_texture(); +} |