2 * Copyright © 2014 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * Author: Chris Forbes <chrisf@ijw.co.nz>
27 * \file clear-into-view-layered.c
28 * This tests that glClear() into a 2D array view, bound as a layered attachment,
32 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_core_version
= 32; /* for layered rendering */
38 config
.supports_gl_es_version
= 31;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
40 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
51 #define VIEW_MIN_LAYER 2
52 #define VIEW_NUM_LAYERS 3
56 piglit_init(int argc
, char **argv
)
63 #ifdef PIGLIT_USE_OPENGL
64 piglit_require_extension("GL_ARB_texture_view");
66 piglit_require_extension("GL_OES_texture_view");
69 /* build a 2d array texture; no mip levels */
70 glGenTextures(1, &tex
);
71 glBindTexture(GL_TEXTURE_2D_ARRAY
, tex
);
72 glTexStorage3D(GL_TEXTURE_2D_ARRAY
, 1,
73 GL_RGBA8
, TEX_SIZE
, TEX_SIZE
, NUM_LAYERS
);
75 for (i
=0; i
< NUM_LAYERS
; i
++) {
76 GLubyte
*pixels
= create_solid_image(TEX_SIZE
, TEX_SIZE
, 1, 4, i
);
78 printf("Allocation failure for layer %d\n", i
);
79 piglit_report_result(PIGLIT_FAIL
);
81 glTexSubImage3D(GL_TEXTURE_2D_ARRAY
, 0,
82 0, 0, i
, TEX_SIZE
, TEX_SIZE
, 1,
83 GL_RGBA
, GL_UNSIGNED_BYTE
, pixels
);
87 /* create a view to a subset of the layers */
88 glGenTextures(1, &view
);
89 glTextureView(view
, GL_TEXTURE_2D_ARRAY
, tex
, GL_RGBA8
,
90 0, 1, VIEW_MIN_LAYER
, VIEW_NUM_LAYERS
);
92 if (!piglit_check_gl_error(GL_NO_ERROR
))
93 piglit_report_result(PIGLIT_FAIL
);
95 /* set up for rendering into the view */
96 glGenFramebuffers(1, &fbo
);
97 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fbo
);
98 glFramebufferTexture(GL_DRAW_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, view
, 0);
99 if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER
) != GL_FRAMEBUFFER_COMPLETE
)
100 piglit_report_result(PIGLIT_FAIL
);
101 glViewport(0, 0, TEX_SIZE
, TEX_SIZE
);
104 /* clear all the attached layers */
105 glClearColor(Colors
[NUM_LAYERS
][0] / 255.0f
,
106 Colors
[NUM_LAYERS
][1] / 255.0f
,
107 Colors
[NUM_LAYERS
][2] / 255.0f
,
108 Colors
[NUM_LAYERS
][3] / 255.0f
);
109 glClear(GL_COLOR_BUFFER_BIT
);
111 if (!piglit_check_gl_error(GL_NO_ERROR
))
112 piglit_report_result(PIGLIT_FAIL
);
114 /* bind the underlying texture and readback */
115 glBindTexture(GL_TEXTURE_2D_ARRAY
, tex
);
116 for (i
= 0; i
< NUM_LAYERS
; i
++) {
117 /* the layers inside the view should have been replaced.
118 * everything else should be untouched.
121 float expected_color
[4];
123 if (i
>= VIEW_MIN_LAYER
&& i
< VIEW_MIN_LAYER
+ VIEW_NUM_LAYERS
) {
124 color_index
= NUM_LAYERS
;
127 printf("Testing layer %d\n", i
);
129 for (j
= 0; j
< 4; j
++)
130 expected_color
[j
] = Colors
[color_index
][j
] / 255.0f
;
132 pass
= piglit_probe_texel_volume_rgba(GL_TEXTURE_2D_ARRAY
, 0,
134 TEX_SIZE
, TEX_SIZE
, 1,
135 expected_color
) && pass
;
138 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);