Am 01.08.2014 17:07, schrieb Brian Paul:
> For creating 1D/2D array textures.  Each slice of the array is a
> solid color (red, green, blue, white, etc.)
> ---
>  tests/util/piglit-util-gl.c |   97 
> ++++++++++++++++++++++++++++++++++++++++---
>  tests/util/piglit-util-gl.h |    1 +
>  2 files changed, 92 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
> index 1a8ee18..bbea519 100644
> --- a/tests/util/piglit-util-gl.c
> +++ b/tests/util/piglit-util-gl.c
> @@ -35,6 +35,13 @@
>   */
>  static const char **gl_extensions = NULL;
>  
> +static 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 */
> +};
> +
>  bool piglit_is_core_profile;
>  
>  bool piglit_is_gles(void)
> @@ -2012,12 +2019,6 @@ 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);
> @@ -2376,6 +2377,90 @@ piglit_depth_texture(GLenum target, GLenum 
> internalformat, int w, int h, int d,
>  }
>  
>  /**
> + * Create 1D or 2D array texture in which each slice is a different color.
> + * the color pattern is red, green, blue, white, red, green, ...
> + */
> +GLuint
> +piglit_array_texture(GLenum target, GLenum internalformat,
> +                  int w, int h, int d, GLboolean mip)
> +{
> +     float *data;
> +     int size, i, level, layer;
> +     GLuint tex;
> +     GLenum type = GL_FLOAT, format = GL_RGBA;
> +
> +     if (target == GL_TEXTURE_1D_ARRAY) {
> +             assert(h == 1);
> +     }
> +     else {
> +             assert(target == GL_TEXTURE_2D_ARRAY);
> +     }
> +
> +     glGenTextures(1, &tex);
> +     glBindTexture(target, tex);
> +     glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> +     glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> +     if (mip) {
> +             glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
> +                             GL_LINEAR);
> +             glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
> +                             GL_LINEAR_MIPMAP_NEAREST);
> +     } else {
> +             glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
> +                             GL_NEAREST);
> +             glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
> +                             GL_NEAREST);
> +     }
Is that on purpose that the mip case does linear filtering but the no
mip case does nearest filtering? Since it is a solid color though it
really shouldn't matter anyway.

> +     data = malloc(w * h * 4 * sizeof(GLfloat));
> +
> +     size = w > h ? w : h;
> +
> +     for (level = 0; size > 0; level++, size >>= 1) {
> +
> +             /* Create mipmap level */
> +             if (target == GL_TEXTURE_1D_ARRAY) {
> +                     glTexImage2D(target, level, internalformat,
> +                                  w, d, 0, format, type, NULL);
> +             }
> +             else {
> +                     glTexImage3D(target, level, internalformat,
> +                                  w, h, d, 0, format, type, NULL);
> +             }
> +
> +             for (layer = 0; layer < d; layer++) {
> +                     /* Set whole layer to one color */
> +                     for (i = 0; i < w * h; i++) {
> +                             memcpy(data + 4 * i,
> +                                    color_wheel[layer %
> +                                                ARRAY_SIZE(color_wheel)],
> +                                    sizeof(color_wheel[0]));
> +                     }
> +
> +                     if (target == GL_TEXTURE_1D_ARRAY) {
> +                             glTexSubImage2D(target, level,
> +                                             0, layer, w, 1,
> +                                             format, type, data);
> +                     }
> +                     else {
> +                             glTexSubImage3D(target, level,
> +                                             0, 0, layer, w, h, 1,
> +                                             format, type, data);
> +                     }
> +             }
> +
> +             if (!mip)
> +                     break;
> +
> +             if (w > 1)
> +                     w >>= 1;
> +             if (h > 1)
> +                     h >>= 1;
> +     }
> +     free(data);
> +     return tex;
> +}
> +
> +/**
>   * Require transform feedback.
>   *
>   * Transform feedback may either be provided by GL 3.0 or
> diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
> index 73b658e..fcd8988 100644
> --- a/tests/util/piglit-util-gl.h
> +++ b/tests/util/piglit-util-gl.h
> @@ -203,6 +203,7 @@ GLfloat *piglit_rgbw_image(GLenum internalFormat, int w, 
> int h,
>  GLuint piglit_rgbw_texture(GLenum internalFormat, 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);
> +GLuint piglit_array_texture(GLenum target, GLenum format, int w, int h, int 
> d, GLboolean mip);
>  extern float piglit_tolerance[4];
>  void piglit_set_tolerance_for_bits(int rbits, int gbits, int bbits, int 
> abits);
>  extern void piglit_require_transform_feedback(void);
> 

For the series:
Reviewed-by: Roland Scheidegger <[email protected]>

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to