Existing test values were also changed to provide nonzero expected result, otherwise it succeeds with glGenerateMipmap() doing nothing.
Signed-off-by: Paul Gofman <gofm...@gmail.com> --- v2: Also delete textures after the second test. tests/spec/arb_texture_view/mipgen.c | 80 ++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/tests/spec/arb_texture_view/mipgen.c b/tests/spec/arb_texture_view/mipgen.c index 3502aff00..01149e27d 100644 --- a/tests/spec/arb_texture_view/mipgen.c +++ b/tests/spec/arb_texture_view/mipgen.c @@ -45,21 +45,21 @@ PIGLIT_GL_TEST_CONFIG_END static bool test_mipgen(void) { - GLuint tex, new_tex; GLint width = 4, height = 4, levels = 2; - bool pass = true; + GLuint tex, new_tex; + bool pass, pass2; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexStorage2D(GL_TEXTURE_2D, levels, GL_R8, width, height); - /* averaging these as snorm values should give 0 */ + /* averaging these as snorm values should give 0x01 */ GLubyte buf[4][4] = - {{0xFF, 0x01, 0xFF, 0x01}, - {0xFF, 0x01, 0xFF, 0x01}, - {0xFF, 0x01, 0xFF, 0x01}, - {0xFF, 0x01, 0xFF, 0x01}}; + {{0xFF, 0x03, 0xFF, 0x03}, + {0xFF, 0x03, 0xFF, 0x03}, + {0xFF, 0x03, 0xFF, 0x03}, + {0xFF, 0x03, 0xFF, 0x03}}; GLbyte res[4]; glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, @@ -67,17 +67,75 @@ test_mipgen(void) glGenTextures(1, &new_tex); - glTextureView(new_tex, GL_TEXTURE_2D, tex, GL_R8_SNORM, 0, 2, 0, 1); + glTextureView(new_tex, GL_TEXTURE_2D, tex, GL_R8_SNORM, 0, levels, 0, 1); glBindTexture(GL_TEXTURE_2D, new_tex); glGenerateMipmap(GL_TEXTURE_2D); glPixelStorei(GL_PACK_ALIGNMENT, 1); glGetTexImage(GL_TEXTURE_2D, 1, GL_RED, GL_BYTE, &res); - pass = !res[0] && !res[1] && !res[2] && !res[3]; + pass = res[0] == 0x01 && res[1] == 0x01 && res[2] == 0x01 && res[3] == 0x01; if (!pass) { - printf("expected 0, got %d %d %d %d\n", - res[0], res[1], res[2], res[3]); + printf("expected 0x01, got %d %d %d %d\n", + res[0], res[1], res[2], res[3]); + } + + glDeleteTextures(1, &new_tex); + glDeleteTextures(1, &tex); + + /* Test views with nonzero minlevel */ + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + + glTexStorage2D(GL_TEXTURE_2D, levels + 1, GL_R8, width * 2, height * 2); + + glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, width, height, + GL_RED, GL_UNSIGNED_BYTE, buf); + + glGenTextures(1, &new_tex); + + glTextureView(new_tex, GL_TEXTURE_2D, tex, GL_R8_SNORM, 1, levels, 0, 1); + glBindTexture(GL_TEXTURE_2D, new_tex); + glGenerateMipmap(GL_TEXTURE_2D); + memset(res, 0, sizeof(res)); + glGetTexImage(GL_TEXTURE_2D, 1, GL_RED, GL_BYTE, &res); + pass2 = res[0] == 0x01 && res[1] == 0x01 && res[2] == 0x01 && res[3] == 0x01; + + if (!pass2) { + printf("view minlevel 1, expected 0x01, got %d %d %d %d\n", + res[0], res[1], res[2], res[3]); + } + pass = pass && pass2; + + glDeleteTextures(1, &new_tex); + glDeleteTextures(1, &tex); + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_3D, tex); + + glTexStorage3D(GL_TEXTURE_3D, levels + 1, GL_R8, width * 2, height * 2, 4); + + GLubyte buf_3d[4 * 4 * 2]; + + memcpy(buf_3d, buf, sizeof(buf)); + memcpy(buf_3d + 4 * 4, buf, sizeof(buf)); + + glTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, width, height, 2, + GL_RED, GL_UNSIGNED_BYTE, buf_3d); + + glGenTextures(1, &new_tex); + + glTextureView(new_tex, GL_TEXTURE_3D, tex, GL_R8_SNORM, 1, levels, 0, 1); + glBindTexture(GL_TEXTURE_3D, new_tex); + glGenerateMipmap(GL_TEXTURE_3D); + memset(res, 0, sizeof(res)); + glGetTexImage(GL_TEXTURE_3D, 1, GL_RED, GL_BYTE, res); + pass2 = res[0] == 0x01 && res[1] == 0x01 && res[2] == 0x01 && res[3] == 0x01; + + if (!pass2) { + printf("view minlevel 1, 3d texture. expected 0x01, got %d %d %d %d\n", + res[0], res[1], res[2], res[3]); } + pass = pass && pass2; glDeleteTextures(1, &new_tex); glDeleteTextures(1, &tex); -- 2.23.0 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/piglit