[Piglit] [PATCH] add test for initial texture state
Ian Romanick
idr at freedesktop.org
Fri May 4 14:13:22 PDT 2012
On 05/01/2012 04:04 PM, nobled wrote:
> Current Mesa fails to produce GL_INVALID_ENUM in glGetTexLevelParameteriv
> and segfaults when passed NULL.
> ---
> It's kind of pointless to pass null to a glGet* function like this,
> but I couldn't find
> any language in the spec about ignoring NULL pointers, which seems like the
> sane thing to do.
>
> tests/all.tests | 1 +
> tests/general/CMakeLists.gl.txt | 1 +
> tests/general/initial-texture-state.c | 173 +++++++++++++++++++++++++++++++++
> 3 files changed, 175 insertions(+), 0 deletions(-)
> create mode 100644 tests/general/initial-texture-state.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index d3c1868..4acfc37 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -259,6 +259,7 @@ add_plain_test(general, 'geterror-invalid-enum')
> add_plain_test(general, 'geterror-inside-begin')
> add_plain_test(general, 'gl30basic')
> add_plain_test(general, 'hiz')
> +add_concurrent_test(general, 'initial-texture-state')
> add_plain_test(general, 'infinite-spot-light')
> add_plain_test(general, 'isbufferobj')
> add_plain_test(general, 'line-aa-width')
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index f9f2b09..c72fd5b 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -64,6 +64,7 @@ if (UNIX)
> target_link_libraries (hiz m)
> endif (UNIX)
> piglit_add_executable (early-z early-z.c)
> +piglit_add_executable (initial-texture-state initial-texture-state.c)
> piglit_add_executable (infinite-spot-light infinite-spot-light.c)
> piglit_add_executable (isbufferobj isbufferobj.c)
> piglit_add_executable (linestipple linestipple.c)
> diff --git a/tests/general/initial-texture-state.c
> b/tests/general/initial-texture-state.c
> new file mode 100644
> index 0000000..c8591d9
> --- /dev/null
> +++ b/tests/general/initial-texture-state.c
> @@ -0,0 +1,173 @@
> +/*
> + * 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 initial-texture-state.c
> + * Verify the state of a texture object before the client sets any
> state itself.
> + */
> +
> +#include "piglit-util.h"
> +
> +int piglit_width = 0, piglit_height = 0;
> +int piglit_window_mode = GLUT_RGB;
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + /* unreachable */
> + return PIGLIT_FAIL;
> +}
> +
> +struct paramtest {
> +GLenum pname;
> +GLint expected;
> +const char *required_extension;
> +};
> +
> +static const struct paramtest texstate[] = {
> +{ GL_TEXTURE_WRAP_S, GL_REPEAT, NULL },
> +{ GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE, "GL_ARB_depth_texture"},
> +{ GL_TEXTURE_COMPARE_MODE, GL_NONE, "GL_ARB_shadow"},
> +{ GL_GENERATE_MIPMAP, GL_FALSE, "GL_SGIS_generate_mipmap"}
> +};
> +
> +/**
> + * From the GL 3.0 spec, page 215 (page 231 of the PDF):
> + * "Each initial texel array is null (zero width, height, and depth,
> + * zero border width, internal format 1, with the compressed flag set to
> + * FALSE, a zero compressed size, and zero-sized components)."
> + *
> + * See also the state table on page 361/377.
> + */
> +static const struct paramtest levelstate[] = {
> +/* GL 1.0 state */
> +{ GL_TEXTURE_WIDTH, 0, NULL },
> +{ GL_TEXTURE_HEIGHT, 0, NULL },
> +{ GL_TEXTURE_DEPTH, 0, NULL },
> +{ GL_TEXTURE_BORDER, 0, NULL },
> +{ GL_TEXTURE_INTERNAL_FORMAT /* aka GL_TEXTURE_COMPONENTS */,
> + 1 /* GL 1.0 way of specifying luminance */, NULL },
> +
> +{ GL_TEXTURE_RED_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_GREEN_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_BLUE_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_ALPHA_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_LUMINANCE_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_INTENSITY_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_DEPTH_SIZE, 0, "GL_EXT_texture" },
> +{ GL_TEXTURE_STENCIL_SIZE, 0, "GL_EXT_texture" },
Yikes! GL_EXT_texture has been part of core since OpenGL 1.1. Windows,
Linux, and Mac all have a minimum version of 1.2. You can safely drop
these checks.
> +
> +{ GL_TEXTURE_SHARED_SIZE, 0, "GL_EXT_texture_shared_exponent" },
> +
> +{ GL_TEXTURE_RED_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +{ GL_TEXTURE_GREEN_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +{ GL_TEXTURE_BLUE_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +{ GL_TEXTURE_ALPHA_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +{ GL_TEXTURE_LUMINANCE_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +{ GL_TEXTURE_INTENSITY_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +{ GL_TEXTURE_DEPTH_TYPE, GL_NONE, "GL_ARB_texture_float" },
> +
> +{ GL_TEXTURE_COMPRESSED, GL_FALSE, "GL_ARB_texture_compression" },
> +{ GL_TEXTURE_COMPRESSED_IMAGE_SIZE, 0, "GL_ARB_texture_compression" },
> +
> +};
> +
> +#define INVALID_PNAME GL_RED
> +
> +static GLboolean test_target(GLenum target) {
> + unsigned i;
> + GLint value;
> + GLboolean pass = GL_TRUE;
> +
> + for (i = 0; i< ARRAY_SIZE(texstate); ++i) {
> + const GLenum pname = texstate[i].pname;
> + const GLint expected = texstate[i].expected;
> + const char *const ext = texstate[i].required_extension;
> + if (ext&& !piglit_is_extension_supported(ext))
> + continue;
> +
> + glGetTexParameteriv(target, pname,&value);
> + if (!piglit_check_gl_error(GL_NO_ERROR))
> + pass = GL_FALSE;
> + if (value != texstate[i].expected) {
> + fprintf(stderr, "Expected initial value of %s to be %x,"
> + " but got %x\n", piglit_get_gl_enum_name(pname),
> + expected, value);
> + pass = GL_FALSE;
> + }
> + }
> +
> + glGetTexParameteriv(target, INVALID_PNAME,&value);
> + pass = piglit_check_gl_error(GL_INVALID_ENUM)&& pass;
> + glGetTexParameteriv(target, INVALID_PNAME, NULL);
> + pass = piglit_check_gl_error(GL_INVALID_ENUM)&& pass;
> +
> + for (i = 0; i< ARRAY_SIZE(levelstate); ++i) {
> + const GLenum pname = levelstate[i].pname;
> + const GLint expected = levelstate[i].expected;
> + const char *const ext = levelstate[i].required_extension;
> + if (ext&& !piglit_is_extension_supported(ext))
> + continue;
> +
> + glGetTexLevelParam-eteriv(target, 0, pname,&value);
> + if (!piglit_check_gl_error(GL_NO_ERROR))
> + pass = GL_FALSE;
> + if (value != levelstate[i].expected) {
> + fprintf(stderr, "Expected initial value of %s to be %x,"
> + " but got %x\n", piglit_get_gl_enum_name(pname),
> + expected, value);
> + pass = GL_FALSE;
> + }
> + }
> +
> + glGetTexLevelParameteriv(target, 0, INVALID_PNAME,&value);
> + pass = piglit_check_gl_error(GL_INVALID_ENUM)&& pass;
> + glGetTexLevelParameteriv(target, 0, INVALID_PNAME, NULL);
> + pass = piglit_check_gl_error(GL_INVALID_ENUM)&& pass;
> +
> + return pass;
> +}
> +
> +static const GLenum targets[] =
> +{ GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D };
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + unsigned i, count = ARRAY_SIZE(targets);
> + GLboolean pass = GL_TRUE;
> + GLboolean bind = piglit_is_extension_supported("GL_EXT_texture_object");
Texture objects have also been part of OpenGL since 1.1. You can drop
this check and the EXT from the texture functions.
> +
> + for (i = 0; i< count*2; ++i) {
> + GLenum target = targets[i%count];
> + if (i>= count&& bind) {
> + GLuint tex;
> + glGenTexturesEXT(1,&tex);
> + glBindTextureEXT(target, tex);
> + glDeleteTexturesEXT(1,&tex);
> + }
> + pass = test_target(target)&& pass;
> + }
> +
> + pass = piglit_check_gl_error(GL_NO_ERROR)&& pass;
> +
> + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
More information about the Piglit
mailing list