glsl: test loop unroll with uint overflow
[piglit.git] / tests / spec / arb_texture_view / clear-into-view-2d-array.c
blob1628bbf7bf828e45b46bc6e6ccdfa3f456915e79
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
23 * Author: Chris Forbes <chrisf@ijw.co.nz>
26 /**
27 * \file clear-into-view-2d-array.c
28 * This tests that glClear() into a layer of a 2D array view (with nonzero MinLayer)
29 * works.
32 #include "piglit-util-gl.h"
33 #include "common.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 30;
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
44 enum piglit_result
45 piglit_display(void)
47 return PIGLIT_FAIL;
50 #define NUM_LAYERS 7
51 #define VIEW_MIN_LAYER 2
52 #define VIEW_NUM_LAYERS 3
53 #define CLEAR_LAYER 1
54 #define TEX_SIZE 64
56 void
57 piglit_init(int argc, char **argv)
59 GLuint tex, view;
60 GLuint fbo;
61 int i, j;
62 bool pass = true;
64 #ifdef PIGLIT_USE_OPENGL
65 piglit_require_extension("GL_ARB_texture_view");
66 #else
67 piglit_require_extension("GL_OES_texture_view");
68 #endif
70 /* build a 2d array texture; no mip levels */
71 glGenTextures(1, &tex);
72 glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
73 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1,
74 GL_RGBA8, TEX_SIZE, TEX_SIZE, NUM_LAYERS);
76 for (i=0; i < NUM_LAYERS; i++) {
77 GLubyte *pixels = create_solid_image(TEX_SIZE, TEX_SIZE, 1, 4, i);
78 if (!pixels) {
79 printf("Allocation failure for layer %d\n", i);
80 piglit_report_result(PIGLIT_FAIL);
82 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0,
83 0, 0, i, TEX_SIZE, TEX_SIZE, 1,
84 GL_RGBA, GL_UNSIGNED_BYTE, pixels);
85 free(pixels);
88 /* create a view to a subset of the layers */
89 glGenTextures(1, &view);
90 glTextureView(view, GL_TEXTURE_2D_ARRAY, tex, GL_RGBA8,
91 0, 1, VIEW_MIN_LAYER, VIEW_NUM_LAYERS);
93 if (!piglit_check_gl_error(GL_NO_ERROR))
94 piglit_report_result(PIGLIT_FAIL);
96 /* set up for rendering into the view.
97 * we attach just the middle layer of the view, to exercise both minlayer
98 * and the attachment's layer index.
100 glGenFramebuffers(1, &fbo);
101 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
102 glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
103 view, 0, CLEAR_LAYER);
104 if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
105 piglit_report_result(PIGLIT_FAIL);
106 glViewport(0, 0, TEX_SIZE, TEX_SIZE);
108 /* clear through the view */
109 glClearColor(Colors[NUM_LAYERS][0] / 255.0f,
110 Colors[NUM_LAYERS][1] / 255.0f,
111 Colors[NUM_LAYERS][2] / 255.0f,
112 Colors[NUM_LAYERS][3] / 255.0f);
113 glClear(GL_COLOR_BUFFER_BIT);
115 if (!piglit_check_gl_error(GL_NO_ERROR))
116 piglit_report_result(PIGLIT_FAIL);
118 /* bind the underlying texture and readback */
119 glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
120 for (i = 0; i < NUM_LAYERS; i++) {
121 /* the layer we cleared should have been replaced;
122 * everything else should be untouched.
125 int color_index = (i == VIEW_MIN_LAYER + CLEAR_LAYER) ? NUM_LAYERS : i;
126 float expected_color[4];
128 printf("Testing layer %d\n", i);
130 for (j = 0; j < 4; j++)
131 expected_color[j] = Colors[color_index][j] / 255.0f;
133 pass = piglit_probe_texel_volume_rgba(GL_TEXTURE_2D_ARRAY, 0,
134 0, 0, i,
135 TEX_SIZE, TEX_SIZE, 1,
136 expected_color) && pass;
139 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);