[Piglit] [PATCH] copyteximage: test 3D, 1D_ARRAY, 2D_ARRAY and RECT textures and check all layers
Marek Olšák
maraeo at gmail.com
Sun Jul 8 11:17:23 PDT 2012
it now tests all texture targets and thoroughly checks all texture layers,
faces and slices by rendering a different color into each one of them.
---
tests/all.tests | 12 +-
tests/texturing/copyteximage.c | 471 ++++++++++++++++++++++++++++++++++------
2 files changed, 414 insertions(+), 69 deletions(-)
diff --git a/tests/all.tests b/tests/all.tests
index 5408e00..a619083 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -706,7 +706,6 @@ texturing = Group()
add_concurrent_test(texturing, '1-1-linear-texture')
add_plain_test(texturing, 'array-texture')
add_plain_test(texturing, 'copytexsubimage')
-add_plain_test(texturing, 'copyteximage')
add_plain_test(texturing, 'copyteximage-border')
add_plain_test(texturing, 'copyteximage-clipping')
add_plain_test(texturing, 'cubemap')
@@ -849,11 +848,14 @@ add_texwrap_test2(gl11, '2D', 'GL_INTENSITY4')
add_texwrap_test2(gl11, '2D', 'GL_INTENSITY8')
add_texwrap_test2(gl11, '2D', 'GL_INTENSITY12')
add_texwrap_test2(gl11, '2D', 'GL_INTENSITY16')
+gl11['copyteximage 1D'] = PlainExecTest(['copyteximage', '-auto', '1D'])
+gl11['copyteximage 2D'] = PlainExecTest(['copyteximage', '-auto', '2D'])
gl12 = Group()
spec['!OpenGL 1.2'] = gl12
add_texwrap_test1(gl12, '3D')
add_texwrap_test2(gl12, '3D', 'proj')
+gl12['copyteximage 3D'] = PlainExecTest(['copyteximage', '-auto', '3D'])
gl20 = Group()
spec['!OpenGL 2.0'] = gl20
@@ -1216,6 +1218,7 @@ add_texwrap_test2(arb_texture_rectangle, 'RECT', 'proj')
add_shader_test_dir(arb_texture_rectangle,
testsDir + '/spec/arb_texture_rectangle',
recursive=True)
+arb_texture_rectangle['copyteximage RECT'] = PlainExecTest(['copyteximage', '-auto', 'RECT'])
arb_texture_storage = Group()
spec['ARB_texture_storage'] = arb_texture_storage
@@ -1498,6 +1501,13 @@ spec['EXT_texture_array']['maxlayers'] = concurrent_test('ext_texture_array-maxl
add_shader_test_dir(ext_texture_array,
testsDir + '/spec/ext_texture_array',
recursive=True)
+ext_texture_array['copyteximage 1D_ARRAY'] = PlainExecTest(['copyteximage', '-auto', '1D_ARRAY'])
+ext_texture_array['copyteximage 2D_ARRAY'] = PlainExecTest(['copyteximage', '-auto', '2D_ARRAY'])
+
+arb_texture_cube_map = Group()
+spec['ARB_texture_cube_map'] = arb_texture_cube_map
+arb_texture_cube_map['copyteximage CUBE'] = PlainExecTest(['copyteximage', '-auto', 'CUBE'])
+
ext_texture_compression_latc = Group()
spec['EXT_texture_compression_latc'] = ext_texture_compression_latc
diff --git a/tests/texturing/copyteximage.c b/tests/texturing/copyteximage.c
index 8a35703..a0bf228 100644
--- a/tests/texturing/copyteximage.c
+++ b/tests/texturing/copyteximage.c
@@ -89,10 +89,22 @@ static const struct {
{ GL_DEPTH_COMPONENT32F, fcolor[7] },
};
-static const GLenum target[] = {
- GL_TEXTURE_1D,
- GL_TEXTURE_2D,
- GL_TEXTURE_CUBE_MAP };
+static const struct {
+ GLenum target;
+ const char *name;
+ unsigned gl_version;
+ const char *extension;
+} target[] = {
+ {GL_TEXTURE_1D, "1D", 11, NULL},
+ {GL_TEXTURE_2D, "2D", 11, NULL},
+ {GL_TEXTURE_3D, "3D", 12, NULL},
+ {GL_TEXTURE_CUBE_MAP, "CUBE", 13, "GL_ARB_texture_cube_map"},
+ {GL_TEXTURE_1D_ARRAY, "1D_ARRAY", 30, "GL_EXT_texture_array"},
+ {GL_TEXTURE_2D_ARRAY, "2D_ARRAY", 30, "GL_EXT_texture_array"},
+ {GL_TEXTURE_RECTANGLE, "RECT", 31, "GL_ARB_texture_rectangle"}
+};
+
+static int test_target = -1;
PIGLIT_GL_TEST_MAIN(
IMAGE_SIZE * (ARRAY_SIZE(test_vectors) + 1) /*window_width*/,
@@ -106,7 +118,166 @@ static const float texCoords_2d[4][2] = {
{ 1.0, 1.0 },
{ 0.0, 1.0 } };
-GLboolean
+static const float texCoords_3d[4][4][3] = {
+ {
+ { 0.0, 0.0, 0.0 },
+ { 1.0, 0.0, 0.0 },
+ { 1.0, 1.0, 0.0 },
+ { 0.0, 1.0, 0.0 }
+ },
+ {
+ { 0.0, 0.0, 0.25 },
+ { 1.0, 0.0, 0.25 },
+ { 1.0, 1.0, 0.25 },
+ { 0.0, 1.0, 0.25 }
+ },
+ {
+ { 0.0, 0.0, 0.5 },
+ { 1.0, 0.0, 0.5 },
+ { 1.0, 1.0, 0.5 },
+ { 0.0, 1.0, 0.5 }
+ },
+ {
+ { 0.0, 0.0, 0.75 },
+ { 1.0, 0.0, 0.75 },
+ { 1.0, 1.0, 0.75 },
+ { 0.0, 1.0, 0.75 }
+ }
+};
+
+static const float texCoords_1d_array[16][4][2] = {
+ {
+ { 0.0, 0 },
+ { 1.0, 0 },
+ { 1.0, 0 },
+ { 0.0, 0 }
+ },
+ {
+ { 0.0, 1 },
+ { 1.0, 1 },
+ { 1.0, 1 },
+ { 0.0, 1 }
+ },
+ {
+ { 0.0, 2 },
+ { 1.0, 2 },
+ { 1.0, 2 },
+ { 0.0, 2 }
+ },
+ {
+ { 0.0, 3 },
+ { 1.0, 3 },
+ { 1.0, 3 },
+ { 0.0, 3 }
+ },
+ {
+ { 0.0, 4 },
+ { 1.0, 4 },
+ { 1.0, 4 },
+ { 0.0, 4 }
+ },
+ {
+ { 0.0, 5 },
+ { 1.0, 5 },
+ { 1.0, 5 },
+ { 0.0, 5 }
+ },
+ {
+ { 0.0, 6 },
+ { 1.0, 6 },
+ { 1.0, 6 },
+ { 0.0, 6 }
+ },
+ {
+ { 0.0, 7 },
+ { 1.0, 7 },
+ { 1.0, 7 },
+ { 0.0, 7 }
+ },
+ {
+ { 0.0, 8 },
+ { 1.0, 8 },
+ { 1.0, 8 },
+ { 0.0, 8 }
+ },
+ {
+ { 0.0, 9 },
+ { 1.0, 9 },
+ { 1.0, 9 },
+ { 0.0, 9 }
+ },
+ {
+ { 0.0, 10 },
+ { 1.0, 10 },
+ { 1.0, 10 },
+ { 0.0, 10 }
+ },
+ {
+ { 0.0, 11 },
+ { 1.0, 11 },
+ { 1.0, 11 },
+ { 0.0, 11 }
+ },
+ {
+ { 0.0, 12 },
+ { 1.0, 12 },
+ { 1.0, 12 },
+ { 0.0, 12 }
+ },
+ {
+ { 0.0, 13 },
+ { 1.0, 13 },
+ { 1.0, 13 },
+ { 0.0, 13 }
+ },
+ {
+ { 0.0, 14 },
+ { 1.0, 14 },
+ { 1.0, 14 },
+ { 0.0, 14 }
+ },
+ {
+ { 0.0, 15 },
+ { 1.0, 15 },
+ { 1.0, 15 },
+ { 0.0, 15 }
+ }
+};
+
+static const float texCoords_2d_array[4][4][3] = {
+ {
+ { 0.0, 0.0, 0 },
+ { 1.0, 0.0, 0 },
+ { 1.0, 1.0, 0 },
+ { 0.0, 1.0, 0 }
+ },
+ {
+ { 0.0, 0.0, 1 },
+ { 1.0, 0.0, 1 },
+ { 1.0, 1.0, 1 },
+ { 0.0, 1.0, 1 }
+ },
+ {
+ { 0.0, 0.0, 2 },
+ { 1.0, 0.0, 2 },
+ { 1.0, 1.0, 2 },
+ { 0.0, 1.0, 2 }
+ },
+ {
+ { 0.0, 0.0, 3 },
+ { 1.0, 0.0, 3 },
+ { 1.0, 1.0, 3 },
+ { 0.0, 1.0, 3 }
+ }
+};
+
+static const float texCoords_rect[4][2] = {
+ { 0.0, 0.0 },
+ { IMAGE_SIZE-1, 0.0 },
+ { IMAGE_SIZE-1, IMAGE_SIZE-1 },
+ { 0.0, IMAGE_SIZE-1 } };
+
+static GLboolean
is_compressed_format(GLenum format)
{
switch (format) {
@@ -120,6 +291,20 @@ is_compressed_format(GLenum format)
}
}
+static bool
+is_depth_format(GLenum format)
+{
+ switch (format) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32F:
+ return true;
+ default:
+ return false;
+ }
+}
+
/** is the given texture internal format supported? */
static bool
supported_format(GLenum format)
@@ -144,54 +329,119 @@ static bool
supported_target_format(GLenum target, GLenum format)
{
/* all the compressed formats we test (so far) are 2D only */
- if (is_compressed_format(format) && target == GL_TEXTURE_1D) {
+ if (is_compressed_format(format) &&
+ (target == GL_TEXTURE_1D ||
+ target == GL_TEXTURE_1D_ARRAY ||
+ target == GL_TEXTURE_3D ||
+ target == GL_TEXTURE_RECTANGLE)) {
+ return false;
+ }
+ if (is_depth_format(format) && target == GL_TEXTURE_3D) {
return false;
}
return true;
}
-enum piglit_result
-piglit_display(void)
+static bool
+supported_target(unsigned i)
+{
+ return piglit_get_gl_version() >= target[i].gl_version ||
+ (target[i].extension &&
+ piglit_is_extension_supported(target[i].extension));
+}
+
+static GLenum get_format(GLenum format)
+{
+ if (is_depth_format(format))
+ return GL_DEPTH_COMPONENT;
+ else
+ return GL_RGBA;
+}
+
+static void draw_pixels(float scale)
{
GLfloat buf_fcolor[IMAGE_SIZE][IMAGE_SIZE][4];
- GLuint tex;
- GLboolean pass = GL_TRUE;
- GLenum format;
- const GLfloat *expected;
int i, j;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Image data setup */
for (i = 0; i < IMAGE_SIZE; i++) {
for (j = 0; j < IMAGE_SIZE; j++) {
- buf_fcolor[i][j][0] = 0.5;
- buf_fcolor[i][j][1] = 0.2;
- buf_fcolor[i][j][2] = 0.8;
- buf_fcolor[i][j][3] = 0.4;
+ buf_fcolor[i][j][0] = 0.5 * scale;
+ buf_fcolor[i][j][1] = 0.2 * scale;
+ buf_fcolor[i][j][2] = 0.8 * scale;
+ buf_fcolor[i][j][3] = 0.4 * scale;
}
}
+ glDrawPixels(IMAGE_SIZE, IMAGE_SIZE, GL_RGBA,
+ GL_FLOAT, buf_fcolor);
+}
+
+static void draw_depth(float scale)
+{
+ glClearDepth(0.75 * scale);
+ glClear(GL_DEPTH_BUFFER_BIT);
+}
+
+static void draw(GLenum format, float scale)
+{
+ if (is_depth_format(format))
+ draw_depth(scale);
+ else
+ draw_pixels(scale);
+}
+
+static GLboolean probe_rect(int x, int y, int w, int h,
+ const float *expected, float scale)
+{
+ float expected_scaled[4];
+ unsigned i;
+
+ for (i = 0; i < 4; i++) {
+ if (expected[i] == 1.0 || expected[i] == 0.0)
+ expected_scaled[i] = expected[i];
+ else
+ expected_scaled[i] = expected[i] * scale;
+ }
+ return piglit_probe_rect_rgba(x, y, w, h, expected_scaled);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ GLuint tex;
+ GLboolean pass = GL_TRUE;
+ GLenum format;
+ const GLfloat *expected;
+ int i, j, k;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
/* Do glCopyPixels and draw a textured rectangle for each format
* and each texture target
*/
for (j = 0; j < ARRAY_SIZE(target); j++) {
+ if (test_target != -1 && test_target != j)
+ continue;
+ if (!supported_target(j))
+ continue;
+
+ printf("Testing %s\n", piglit_get_gl_enum_name(target[j].target));
- /* Draw a pixel rectangle with float color data. As per OpenGL 3.0
- * specification integer formats are not allowed in glDrawPixels
- */
- glDrawPixels(IMAGE_SIZE, IMAGE_SIZE, GL_RGBA,
- GL_FLOAT, buf_fcolor);
+ if (target[j].target == GL_TEXTURE_1D_ARRAY) {
+ printf("NOTE: We use glCopyTexSubImage2D to set 4 texture layers at once.\n");
+ }
/* Texture setup */
glGenTextures(1, &tex);
- glBindTexture(target[j], tex);
- glTexParameteri(target[j],
+ glBindTexture(target[j].target, tex);
+ glTexParameteri(target[j].target,
GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
- glTexParameteri(target[j],
+ glTexParameteri(target[j].target,
GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
- glTexParameteri(target[j],
+ glTexParameteri(target[j].target,
GL_GENERATE_MIPMAP,
GL_FALSE);
@@ -206,20 +456,23 @@ piglit_display(void)
format = test_vectors[i].format;
expected = (const float*)test_vectors[i].expected;
- if(!piglit_automatic)
+ if (!piglit_automatic)
printf("Texture target = %s, Internal"
- " format = %s\n",
- piglit_get_gl_enum_name(target[j]),
+ " format = %s",
+ piglit_get_gl_enum_name(target[j].target),
piglit_get_gl_enum_name(format));
if (!supported_format(format) ||
- !supported_target_format(target[j], format)) {
+ !supported_target_format(target[j].target, format)) {
if (!piglit_automatic)
- printf("Internal format = %s skipped\n",
- piglit_get_gl_enum_name(format));
+ printf(" - skipped\n");
continue;
+ } else {
+ if (!piglit_automatic)
+ printf("\n");
}
+
/* To avoid failures not related to this test case,
* loosen up the tolerence for compressed texture
* formats
@@ -229,16 +482,17 @@ piglit_display(void)
else
piglit_set_tolerance_for_bits(8, 8, 8, 8);
- switch(target[j]) {
+ switch(target[j].target) {
case GL_TEXTURE_1D:
+ draw(format, 1.0);
glCopyTexImage1D(GL_TEXTURE_1D, 0,
format,
0, 0, IMAGE_SIZE, 0);
pass = piglit_check_gl_error(GL_NO_ERROR)
&& pass;
- glEnable(target[j]);
+ glEnable(target[j].target);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(1, GL_FLOAT, 0, texCoords_1d);
glVertexPointer(2, GL_FLOAT, 0, vertices_1d);
@@ -252,11 +506,12 @@ piglit_display(void)
break;
case GL_TEXTURE_2D:
+ draw(format, 1.0);
glCopyTexImage2D(GL_TEXTURE_2D, 0, format, 0, 0,
IMAGE_SIZE, IMAGE_SIZE, 0);
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
- glEnable(target[j]);
+ glEnable(target[j].target);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords_2d);
piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
@@ -266,47 +521,110 @@ piglit_display(void)
&& pass;
break;
+ case GL_TEXTURE_3D:
+ glTexImage3D(GL_TEXTURE_3D, 0, format, IMAGE_SIZE, IMAGE_SIZE, 4,
+ 0, GL_RGBA, GL_FLOAT, NULL);
+
+ for (k = 0; k < 4; k++) {
+ draw(format, 1.0 - k*0.2);
+ glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, k,
+ 0, 0, IMAGE_SIZE, IMAGE_SIZE);
+ }
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glEnable(target[j].target);
+
+ for (k = 0; k < 4; k++) {
+ glTexCoordPointer(3, GL_FLOAT, 0, texCoords_3d[k]);
+ piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
+ pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
+ expected, 1.0 - k*0.2) && pass;
+ }
+ break;
+
case GL_TEXTURE_CUBE_MAP:
- glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,
- 0, format, 0, 0,
- IMAGE_SIZE, IMAGE_SIZE, 0);
- glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
- 0, format, 0, 0,
- IMAGE_SIZE, IMAGE_SIZE, 0);
- glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
- 0, format, 0, 0,
- IMAGE_SIZE, IMAGE_SIZE, 0);
- glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
- 0, format, 0, 0,
- IMAGE_SIZE, IMAGE_SIZE, 0);
- glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
- 0, format, 0, 0,
- IMAGE_SIZE, IMAGE_SIZE, 0);
- glCopyTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
- 0, format, 0, 0,
- IMAGE_SIZE, IMAGE_SIZE, 0);
+ for (k = 0; k < 6; k++) {
+ draw(format, 1.0 - k*0.15);
+ glCopyTexImage2D(cube_face_targets[k],
+ 0, format, 0, 0,
+ IMAGE_SIZE, IMAGE_SIZE, 0);
+ }
+
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
- glEnable(target[j]);
+ glEnable(target[j].target);
- /* Draw a rect with +X cubemap face as texture */
- glTexCoordPointer(3, GL_FLOAT, 0,
- cube_face_texcoords[0]);
- piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
- pass = piglit_probe_rect_rgba(x, y,
- IMAGE_SIZE, IMAGE_SIZE, expected)
- && pass;
+ for (k = 0; k < 6; k++) {
+ glTexCoordPointer(3, GL_FLOAT, 0,
+ cube_face_texcoords[k]);
+ piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
+ pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
+ expected, 1.0 - k*0.15) && pass;
+ }
+ break;
+
+ case GL_TEXTURE_1D_ARRAY:
+ glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, format, IMAGE_SIZE, 16,
+ 0, get_format(format), GL_FLOAT, NULL);
+
+ for (k = 0; k < 4; k++) {
+ draw(format, 1.0 - 0.2*k);
+ glCopyTexSubImage2D(GL_TEXTURE_1D_ARRAY, 0, 0, 4*k,
+ 0, 0, IMAGE_SIZE, 4);
+ }
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glEnable(target[j].target);
+
+ for (k = 0; k < 16; k++) {
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords_1d_array[k]);
+ piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
+ pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
+ expected, 1.0 - 0.2*(k/4)) && pass;
+ }
+ break;
+
+ case GL_TEXTURE_2D_ARRAY:
+ glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, format, IMAGE_SIZE, IMAGE_SIZE, 4,
+ 0, get_format(format), GL_FLOAT, NULL);
+
+ for (k = 0; k < 4; k++) {
+ draw(format, 1.0 - k*0.2);
+ glCopyTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, k,
+ 0, 0, IMAGE_SIZE, IMAGE_SIZE);
+ }
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glEnable(target[j].target);
+
+ for (k = 0; k < 4; k++) {
+ glTexCoordPointer(3, GL_FLOAT, 0, texCoords_2d_array[k]);
+ piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
+ pass = probe_rect(x, y, IMAGE_SIZE, IMAGE_SIZE,
+ expected, 1.0 - k*0.2) && pass;
+ }
+ break;
+
+ case GL_TEXTURE_RECTANGLE:
+ draw(format, 1.0);
+ glCopyTexImage2D(GL_TEXTURE_RECTANGLE, 0, format, 0, 0,
+ IMAGE_SIZE, IMAGE_SIZE, 0);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glEnable(target[j].target);
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords_rect);
- /* Draw a rect with +Z cubemap face as texture */
- glTexCoordPointer(3, GL_FLOAT, 0,
- cube_face_texcoords[2]);
piglit_draw_rect(x, y, IMAGE_SIZE, IMAGE_SIZE);
- pass = piglit_probe_rect_rgba(x, y,
- IMAGE_SIZE, IMAGE_SIZE, expected)
+ pass = piglit_probe_rect_rgba(x, y, IMAGE_SIZE,
+ IMAGE_SIZE,
+ expected)
&& pass;
break;
}
- glDisable(target[j]);
+ glDisable(target[j].target);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDeleteTextures(1, &tex);
@@ -319,7 +637,24 @@ piglit_display(void)
void
piglit_init(int argc, char **argv)
{
+ if (argc == 2) {
+ unsigned i;
+ for (i = 0; i < ARRAY_SIZE(target); i++) {
+ if (strcmp(target[i].name, argv[1]) == 0) {
+ test_target = i;
+
+ if (!supported_target(i)) {
+ printf("Test requires OpenGL %1.1f", target[i].gl_version * 0.1);
+ if (target[i].extension)
+ printf(" or %s", target[i].extension);
+ printf(".\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+ break;
+ }
+ }
+ }
+
glClearColor(0.0, 0.0, 0.0, 1.0);
- glClearDepth(0.75);
piglit_ortho_projection(piglit_width, piglit_height, GL_TRUE);
}
--
1.7.9.5
More information about the Piglit
mailing list