[Piglit] [PATCH] arb_texture_view: add test for glCopyTexSubImage with MinLayer

Jon Ashburn jon at lunarg.com
Fri Mar 21 10:02:07 PDT 2014


On 03/14/2014 01:53 PM, Chris Forbes wrote:
> Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
> ---
>   tests/all.py                                       |   1 +
>   tests/spec/arb_texture_view/CMakeLists.gl.txt      |   1 +
>   .../spec/arb_texture_view/copytexsubimage-layers.c | 141 +++++++++++++++++++++
>   3 files changed, 143 insertions(+)
>   create mode 100644 tests/spec/arb_texture_view/copytexsubimage-layers.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 05dded0..0d8bc98 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -1998,6 +1998,7 @@ arb_texture_view['texsubimage-layers'] = concurrent_test('arb_texture_view-texsu
>   arb_texture_view['clear-into-view-2d'] = concurrent_test('arb_texture_view-clear-into-view-2d')
>   arb_texture_view['clear-into-view-2d-array'] = concurrent_test('arb_texture_view-clear-into-view-2d-array')
>   arb_texture_view['clear-into-view-layered'] = concurrent_test('arb_texture_view-clear-into-view-layered')
> +arb_texture_view['copytexsubimage-layers'] = concurrent_test('arb_texture_view-copytexsubimage-layers')
>   
>   tdfx_texture_compression_fxt1 = Group()
>   spec['3DFX_texture_compression_FXT1'] = tdfx_texture_compression_fxt1
> diff --git a/tests/spec/arb_texture_view/CMakeLists.gl.txt b/tests/spec/arb_texture_view/CMakeLists.gl.txt
> index 76a7e95..249713c 100644
> --- a/tests/spec/arb_texture_view/CMakeLists.gl.txt
> +++ b/tests/spec/arb_texture_view/CMakeLists.gl.txt
> @@ -26,5 +26,6 @@ piglit_add_executable(arb_texture_view-clear-into-view-2d-array clear-into-view-
>   piglit_add_executable(arb_texture_view-clear-into-view-layered clear-into-view-layered.c common.c)
>   piglit_add_executable(arb_texture_view-rendering-formats rendering-formats.c)
>   piglit_add_executable(arb_texture_view-rendering-formats2 rendering-formats2.c)
> +piglit_add_executable(arb_texture_view-copytexsubimage-layers copytexsubimage-layers.c common.c)
>   
>   # vim: ft=cmake:
> diff --git a/tests/spec/arb_texture_view/copytexsubimage-layers.c b/tests/spec/arb_texture_view/copytexsubimage-layers.c
> new file mode 100644
> index 0000000..4fbcc7e
> --- /dev/null
> +++ b/tests/spec/arb_texture_view/copytexsubimage-layers.c
> @@ -0,0 +1,141 @@
> +/*
> + * Copyright © 2014 Intel Corporation
> + *
> + * 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.
> + *
> + * Author: Chris Forbes <chrisf at ijw.co.nz>
> + */
> +
> +/**
> + * \file copytexsubimage-layers.c
> + * This tests that glCopyTexImage into a 2D texture view (with nonzero MinLayer)
> + * of a 2D texture array works.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +#include "common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 30;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	return PIGLIT_FAIL;
> +}
> +
> +#define NUM_LAYERS 7
> +#define VIEW_MIN_LAYER 2
> +#define VIEW_NUM_LAYERS 1
> +#define TEX_SIZE 64
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	GLuint tex, view, scratch;
> +	GLuint fbo;
> +	int i, j;
> +	bool pass = true;
> +
> +	piglit_require_extension("GL_ARB_texture_storage");
> +	piglit_require_extension("GL_ARB_texture_view");
> +
> +	/* build a 2d array texture; no mip levels */
> +	glGenTextures(1, &tex);
> +	glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
> +	glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1,
> +		GL_RGBA8, TEX_SIZE, TEX_SIZE, NUM_LAYERS);
> +
> +	for (i=0; i < NUM_LAYERS; i++) {
> +		GLubyte *pixels = create_solid_image(TEX_SIZE, TEX_SIZE,
> +						     1, 4, i);
Handle case of pixels == NULL.
> +		glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
> +				0, 0, i, TEX_SIZE, TEX_SIZE, 1,
> +				GL_RGBA, GL_UNSIGNED_BYTE, pixels);
> +		free(pixels);
> +	}
> +
> +	/* create a view of just one layer, as a non-array 2d texture */
> +	glGenTextures(1, &view);
> +	glTextureView(view, GL_TEXTURE_2D, tex, GL_RGBA8,
> +		      0, 1, VIEW_MIN_LAYER, VIEW_NUM_LAYERS);
> +
> +	if (!piglit_check_gl_error(GL_NO_ERROR))
> +		piglit_report_result(PIGLIT_FAIL);
> +
> +	/* create a scratch fbo which we will clear into, and then
> +	 * glCopyTexSubImage out of */
format multi-line comments  with /*  on separate line
> +	glGenFramebuffers(1, &fbo);
> +	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
> +	glGenTextures(1, &scratch);
> +	glBindTexture(GL_TEXTURE_2D, scratch);
> +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEX_SIZE,
> +		     TEX_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
> +	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> +			       GL_TEXTURE_2D, scratch, 0);
> +	if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
> +		piglit_report_result(PIGLIT_FAIL);
> +	glViewport(0, 0, TEX_SIZE, TEX_SIZE);
> +
> +	glClearColor(
> +		Colors[NUM_LAYERS][0] / 255.0f,
> +		Colors[NUM_LAYERS][1] / 255.0f,
> +		Colors[NUM_LAYERS][2] / 255.0f,
> +		Colors[NUM_LAYERS][3] / 255.0f);
> +	glClear(GL_COLOR_BUFFER_BIT);
> +
> +	/* glCopyTexSubImage2D out of the scratch fbo */
> +	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
> +	glReadBuffer(GL_COLOR_ATTACHMENT0);
> +	glBindTexture(GL_TEXTURE_2D, view);
> +	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
> +			    0, 0, TEX_SIZE, TEX_SIZE);
> +
> +	if (!piglit_check_gl_error(GL_NO_ERROR))
> +		piglit_report_result(PIGLIT_FAIL);
> +
> +	/* bind the underlying texture and readback */
> +	glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
> +	for (i = 0; i < NUM_LAYERS; i++) {
> +		/* the single layer inside the view should have been replaced.
> +		 * everything else should be untouched.
> +		 */
format of multi-line comment
> +
> +		int color_index = i;
> +		if (i >= VIEW_MIN_LAYER && i < VIEW_MIN_LAYER + VIEW_NUM_LAYERS)
> +			color_index = i + NUM_LAYERS - VIEW_MIN_LAYER;
> +		float expected_color[4];
> +
> +		printf("Testing layer %d\n", i);
> +
> +		for (j = 0; j < 4; j++)
> +			expected_color[j] = Colors[color_index][j] / 255.0f;
> +
> +		pass = piglit_probe_texel_volume_rgba(GL_TEXTURE_2D_ARRAY, 0,
> +						      0, 0, i, TEX_SIZE, TEX_SIZE, 1,
> +						      expected_color) && pass;
> +	}
> +
> +	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
With these changes
Reviewed-by: Jon Ashburn <jon at lunarg.com>


More information about the Piglit mailing list