summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/spec/arb_direct_state_access/generatetexturemipmap.c198
1 files changed, 198 insertions, 0 deletions
diff --git a/tests/spec/arb_direct_state_access/generatetexturemipmap.c b/tests/spec/arb_direct_state_access/generatetexturemipmap.c
index 9a73911e7..adabbebe1 100644
--- a/tests/spec/arb_direct_state_access/generatetexturemipmap.c
+++ b/tests/spec/arb_direct_state_access/generatetexturemipmap.c
@@ -80,6 +80,200 @@ static const float blue[4 * 4 * 4] = {
0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0
};
+struct tex_parameter {
+ GLenum pname;
+ bool is_float;
+ unsigned size;
+ float f[4];
+ int i[4];
+};
+
+#define FLOAT1(pname, param) \
+ { pname, true, 1, { param, 0.0f, 0.0f, 0.0f }, { 0, 0, 0, 0 } }
+#define FLOAT4(pname, p1, p2, p3, p4) \
+ { pname, true, 4, { p1, p2, p3, p4 }, { 0, 0, 0, 0 } }
+#define INT1(pname, param) \
+ { pname, false, 1, { 0.0f, 0.0f, 0.0f, 0.0f }, { param, 0, 0, 0 } }
+#define INT4(pname, p1, p2, p3, p4) \
+ { pname, false, 4, { 0.0f, 0.0f, 0.0f, 0.0f }, { p1, p2, p3, p4 } }
+
+/**
+ * Parameter values for the two textures
+ *
+ * It is most important that none of the parameter settings for the two
+ * textures match. The parameters for texture 0 should also differ from the
+ * default values. It is also better if the parameters for texture 1 differ
+ * from the default values, but this is not always possible because some
+ * parameters (e.g., GL_TEXTURE_MAG_FILTER) only have two possible values.
+ */
+static const struct tex_parameter parameters[2][17] = {
+ {
+ INT1(GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX),
+ INT1(GL_GENERATE_MIPMAP, GL_TRUE),
+ INT1(GL_TEXTURE_BASE_LEVEL, 2),
+ FLOAT4(GL_TEXTURE_BORDER_COLOR, 1.0, 0.6, 0.3, 0.1),
+ INT1(GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL),
+ INT1(GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE),
+ FLOAT1(GL_TEXTURE_LOD_BIAS, 0.5),
+ INT1(GL_TEXTURE_MIN_FILTER, GL_LINEAR),
+ INT1(GL_TEXTURE_MAG_FILTER, GL_NEAREST),
+ INT1(GL_TEXTURE_MIN_LOD, -2),
+ INT1(GL_TEXTURE_MAX_LOD, 42),
+ INT1(GL_TEXTURE_MAX_LEVEL, 18),
+ INT4(GL_TEXTURE_SWIZZLE_RGBA,
+ GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED),
+ INT1(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE),
+ INT1(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE),
+ INT1(GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE),
+ { 0 },
+ },
+ {
+ INT1(GL_DEPTH_STENCIL_TEXTURE_MODE, GL_DEPTH_COMPONENT),
+ INT1(GL_GENERATE_MIPMAP, GL_FALSE),
+ INT1(GL_TEXTURE_BASE_LEVEL, 0),
+ FLOAT4(GL_TEXTURE_BORDER_COLOR, 0.1, 0.3, 0.6, 1.0),
+ INT1(GL_TEXTURE_COMPARE_FUNC, GL_GEQUAL),
+ INT1(GL_TEXTURE_COMPARE_MODE, GL_NONE),
+ FLOAT1(GL_TEXTURE_LOD_BIAS, 0.1),
+ INT1(GL_TEXTURE_MIN_FILTER, GL_NEAREST),
+ INT1(GL_TEXTURE_MAG_FILTER, GL_LINEAR),
+ INT1(GL_TEXTURE_MIN_LOD, -10),
+ INT1(GL_TEXTURE_MAX_LOD, 100),
+ INT1(GL_TEXTURE_MAX_LEVEL, 99),
+ INT4(GL_TEXTURE_SWIZZLE_RGBA, GL_BLUE, GL_ONE, GL_RED, GL_ZERO),
+
+ /* In OpenGL 1.2, the only possible values are GL_REPEAT,
+ * GL_CLAMP, and GL_CLAMP_TO_EDGE. In OpenGL Core Profile,
+ * GL_CLAMP is removed. Since GL_CLAMP_TO_EDGE was already
+ * used for texture 0, GL_REPEAT must be used here. This is
+ * unfortunate because GL_REPEAT is the default value.
+ */
+ INT1(GL_TEXTURE_WRAP_S, GL_REPEAT),
+ INT1(GL_TEXTURE_WRAP_T, GL_REPEAT),
+ INT1(GL_TEXTURE_WRAP_R, GL_REPEAT),
+ { 0 },
+ }
+};
+
+static bool
+supported_pname(GLenum pname)
+{
+ const unsigned version = piglit_get_gl_version();
+
+ switch (pname) {
+ case GL_DEPTH_STENCIL_TEXTURE_MODE:
+ return version >= 43 ||
+ piglit_is_extension_supported("GL_ARB_stencil_texturing");
+ case GL_GENERATE_MIPMAP:
+ /* If the implementation advertises GL_SGIS_generat_mipmap in
+ * a core profile context, it deserves to fail the test.
+ */
+ return (version >= 14 && !piglit_is_core_profile) ||
+ piglit_is_extension_supported("GL_SGIS_generate_mipmap");
+ case GL_TEXTURE_COMPARE_FUNC:
+ case GL_TEXTURE_COMPARE_MODE:
+ return version >= 14 ||
+ piglit_is_extension_supported("GL_ARB_shadow");
+ case GL_TEXTURE_SWIZZLE_RGBA:
+ return version >= 33 ||
+ piglit_is_extension_supported("GL_ARB_texture_swizzle") ||
+ piglit_is_extension_supported("GL_EXT_texture_swizzle");
+ case GL_TEXTURE_BASE_LEVEL:
+ case GL_TEXTURE_BORDER_COLOR:
+ case GL_TEXTURE_LOD_BIAS:
+ case GL_TEXTURE_MIN_FILTER:
+ case GL_TEXTURE_MAG_FILTER:
+ case GL_TEXTURE_MIN_LOD:
+ case GL_TEXTURE_MAX_LOD:
+ case GL_TEXTURE_MAX_LEVEL:
+ case GL_TEXTURE_WRAP_S:
+ case GL_TEXTURE_WRAP_T:
+ case GL_TEXTURE_WRAP_R:
+ return true;
+ default:
+ printf("Unknown pname enum value 0x%04x\n", pname);
+ piglit_report_result(PIGLIT_FAIL);
+ }
+}
+
+static void
+initialize_texture_parameters(GLenum target, const struct tex_parameter *p)
+{
+ for (unsigned i = 0; p[i].pname != 0; i++) {
+ if (!supported_pname(p[i].pname))
+ continue;
+
+ if (p[i].is_float)
+ glTexParameterfv(target, p[i].pname, p[i].f);
+ else
+ glTexParameteriv(target, p[i].pname, p[i].i);
+ }
+}
+
+static bool
+verify_texture_parameters(GLenum target, const struct tex_parameter *p)
+{
+ GLint int_buf[4];
+ GLfloat float_buf[4];
+ bool pass = true;
+
+ for (unsigned i = 0; p[i].pname != 0; i++) {
+ assert(p[i].size <= ARRAY_SIZE(int_buf));
+ assert(p[i].size <= ARRAY_SIZE(float_buf));
+
+ if (!supported_pname(p[i].pname))
+ continue;
+
+ if (p[i].is_float) {
+ memset(float_buf, 0, sizeof(float_buf));
+
+ glGetTexParameterfv(target, p[i].pname, float_buf);
+ if (memcmp(float_buf,
+ p[i].f,
+ p[i].size * sizeof(float_buf[0])) != 0) {
+ pass = false;
+ printf("Bad value for %s (0x%04x).\n"
+ " Got: %f %f %f %f\n"
+ " Expected: %f %f %f %f\n",
+ piglit_get_gl_enum_name(p[i].pname),
+ p[i].pname,
+ float_buf[0],
+ float_buf[1],
+ float_buf[2],
+ float_buf[3],
+ p[i].f[0],
+ p[i].f[1],
+ p[i].f[2],
+ p[i].f[3]);
+ }
+ } else {
+ memset(int_buf, 0, sizeof(int_buf));
+
+ glGetTexParameteriv(target, p[i].pname, int_buf);
+ if (memcmp(int_buf,
+ p[i].i,
+ p[i].size * sizeof(int_buf[0])) != 0) {
+ pass = false;
+ printf("Bad value for %s (0x%04x).\n"
+ " Got: %d %d %d %d\n"
+ " Expected: %d %d %d %d\n",
+ piglit_get_gl_enum_name(p[i].pname),
+ p[i].pname,
+ int_buf[0],
+ int_buf[1],
+ int_buf[2],
+ int_buf[3],
+ p[i].i[0],
+ p[i].i[1],
+ p[i].i[2],
+ p[i].i[3]);
+ }
+ }
+ }
+
+ return pass;
+}
+
void
piglit_init(int argc, char **argv)
{
@@ -107,6 +301,7 @@ piglit_init(int argc, char **argv)
GL_FLOAT, red);
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 1, 1, 0, GL_RGBA,
GL_FLOAT, red);
+ initialize_texture_parameters(GL_TEXTURE_2D, parameters[i]);
pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
}
@@ -155,6 +350,9 @@ piglit_init(int argc, char **argv)
pass = piglit_probe_texel_rect_rgba(GL_TEXTURE_2D, 2,
0, 0, 1, 1,
level_color) && pass;
+ printf("Check parameters of texture %u...\n", i);
+ pass = verify_texture_parameters(GL_TEXTURE_2D, parameters[i])
+ && pass;
}
piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);