[Piglit] [PATCH 5/8] shader_runner: Add ability to create textures with per-miplevel colors.

Ian Romanick idr at freedesktop.org
Wed Apr 11 16:09:08 PDT 2012


On 04/08/2012 11:25 AM, Kenneth Graunke wrote:
> On 04/05/2012 12:33 PM, Ian Romanick wrote:
>> On 04/04/2012 01:51 AM, Kenneth Graunke wrote:
>>> For basic mipmapped texture testing, it's often useful to create
>>> textures where each miplevel has a unique color.
>>>
>>> The next commit will use this to simplify an existing test case, and
>>> subsequent commits will introduce new tests based on this functionality.
>>>
>>> Signed-off-by: Kenneth Graunke<kenneth at whitecape.org>
>>> ---
>>> tests/shaders/shader_runner.c | 4 ++++
>>> tests/util/piglit-util-gl.c | 39 +++++++++++++++++++++++++++++++++++++++
>>> tests/util/piglit-util.h | 1 +
>>> 3 files changed, 44 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/tests/shaders/shader_runner.c
>>> b/tests/shaders/shader_runner.c
>>> index ee49e41..d5cc220 100644
>>> --- a/tests/shaders/shader_runner.c
>>> +++ b/tests/shaders/shader_runner.c
>>> @@ -1264,6 +1264,10 @@ piglit_display(void)
>>> glActiveTexture(GL_TEXTURE0 + tex);
>>> piglit_rgbw_texture(GL_RGBA, w, h, GL_FALSE, GL_FALSE,
>>> GL_UNSIGNED_NORMALIZED);
>>> glEnable(GL_TEXTURE_2D);
>>> + } else if (sscanf(line, "texture miptree %d",&tex) == 1) {
>>> + glActiveTexture(GL_TEXTURE0 + tex);
>>> + piglit_miptree_texture();
>>> + glEnable(GL_TEXTURE_2D);
>>> } else if (sscanf(line,
>>> "texture checkerboard %d %d ( %d , %d ) "
>>> "( %f , %f , %f , %f ) "
>>> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
>>> index 4270cd6..269ed4d 100644
>>> --- a/tests/util/piglit-util-gl.c
>>> +++ b/tests/util/piglit-util-gl.c
>>> @@ -959,6 +959,45 @@ piglit_checkerboard_texture(GLuint tex, unsigned
>>> level,
>>> }
>>>
>>> /**
>>> + * Generates a 8x8 mipmapped texture whose layers contain solid r, g,
>>> b, and w.
>>> + */
>>> +GLuint
>>> +piglit_miptree_texture()
>>> +{
>>> + GLfloat *data;
>>> + int size, i, level;
>>> + GLuint tex;
>>> + const float color_wheel[4][4] = {
>>> + {1, 0, 0, 1}, /* red */
>>> + {0, 1, 0, 1}, /* green */
>>> + {0, 0, 1, 1}, /* blue */
>>> + {1, 1, 1, 1}, /* white */
>>> + };
>>> +
>>> + glGenTextures(1,&tex);
>>> + glBindTexture(GL_TEXTURE_2D, tex);
>>> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
>>> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
>>> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
>>> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
>>> + GL_NEAREST_MIPMAP_NEAREST);
>>
>> This seems like a surprising default min filter.
>
> This is the one glsl-fs-texturelod-01 used. But it's a moot point now
> that shader_runner can set it to whatever you want.
>
> What would you prefer instead? GL_LINEAR_MIPMAP_NEAREST (used elsewhere
> in piglit-util-gl)? GL_LINEAR_MIPMAP_LINEAR (not used in piglit)?

GL_LINEAR_MIPMAP_LINEAR is the OpenGL default.  It seems odd that the 
infrastructure would use anything else.  This means that someone looking 
at a test that's familiar with OpenGL but not the framework will be 
confused when I tests expects (and gets) behavior other than 
GL_LINEAR_MIPMAP_LINEAR without asking for it.

Though it could be argued that, using the same reasoning, changing any 
of the texture parameters from the defaults is strange.  Hmm...

I guess I can withdraw that nit.

>>> +
>>> + for (level = 0; level< 4; ++level) {
>>> + size = 8>> level;
>>> +
>>> + data = malloc(size*size*4*sizeof(GLfloat));
>>> + for (i = 0; i< size * size; ++i) {
>>> + memcpy(data + 4 * i, color_wheel[level],
>>> + 4 * sizeof(GLfloat));
>>> + }
>>> + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA,
>>> + size, size, 0, GL_RGBA, GL_FLOAT, data);
>>> + free(data);
>>> + }
>>> + return tex;
>>> +}
>>> +
>>> +/**
>>> * Generates a texture with the given internalFormat, w, h with a
>>> * teximage of r, g, b w quadrants.
>>> *
>>> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
>>> index 775dfe2..66fdb2a 100755
>>> --- a/tests/util/piglit-util.h
>>> +++ b/tests/util/piglit-util.h
>>> @@ -253,6 +253,7 @@ GLuint piglit_checkerboard_texture(GLuint tex,
>>> unsigned level,
>>> unsigned width, unsigned height,
>>> unsigned horiz_square_size, unsigned vert_square_size,
>>> const float *black, const float *white);
>>> +GLuint piglit_miptree_texture();
>>
>> GLuint piglit_miptree_texture(void);
>>
>> The C vs. C++ rules are different, so you should actually say void in C.
>> In C++ an empty list is the same as void. In C an empty list means the
>> parameters aren't known, so you can pass anything.
>
> Argh. I always forget about that. Fixed, thanks.
>
>>> GLuint piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
>>> GLboolean alpha, GLenum basetype);
>>> GLuint piglit_depth_texture(GLenum target, GLenum format, int w, int
>>> h, int d, GLboolean mip);


More information about the Piglit mailing list