ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_view / clear-into-view-2d.c
blobd03323a5d52703b23f6516566522203dd04bf2e1
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.c
28 * This tests that glClear() into a 2D texture view (with nonzero MinLayer)
29 * of a 2D texture array 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 1
53 #define TEX_SIZE 64
55 void
56 piglit_init(int argc, char **argv)
58 GLuint tex, view;
59 GLuint fbo;
60 int i, j;
61 bool pass = true;
63 #ifdef PIGLIT_USE_OPENGL
64 piglit_require_extension("GL_ARB_texture_view");
65 #else
66 piglit_require_extension("GL_OES_texture_view");
67 #endif
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,
77 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 of just one layer, as a non-array 2d texture */
89 glGenTextures(1, &view);
90 glTextureView(view, GL_TEXTURE_2D, 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 glGenFramebuffers(1, &fbo);
98 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
99 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
100 GL_TEXTURE_2D, view, 0);
101 if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
102 piglit_report_result(PIGLIT_FAIL);
103 glViewport(0, 0, TEX_SIZE, TEX_SIZE);
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 single layer inside the view should have been replaced.
118 * everything else should be untouched.
121 float expected_color[4];
122 int color_index = i;
123 if (i >= VIEW_MIN_LAYER && i < VIEW_MIN_LAYER + VIEW_NUM_LAYERS) {
124 color_index = i + NUM_LAYERS - VIEW_MIN_LAYER;
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,
133 0, 0, i,
134 TEX_SIZE, TEX_SIZE, 1,
135 expected_color) && pass;
138 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);