ARB_ubo/referenced-by-shader: pass if shader compiler moves UBOs between shaders
[piglit.git] / tests / spec / arb_clear_texture / texview.c
blobaeae2ef66e4353d928931832884e6a7b08a6a0aa
1 /*
2 * Copyright 2015 Ilia Mirkin
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.
24 /** @file texview.c
26 * A test to make sure that ARB_copy_image respects texture views on
27 * both the source and destination ends.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config.supports_gl_compat_version = 13;
33 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
34 config.khr_no_error_support = PIGLIT_NO_ERRORS;
35 PIGLIT_GL_TEST_CONFIG_END
37 static const float green[4] = {0.0, 1.0, 0.0, 1.0};
38 static const float red[4] = {1.0, 0.0, 0.0, 1.0};
40 static bool
41 test_2d(void)
43 bool pass = true;
44 GLuint src;
45 float red4[16];
46 int i, j;
48 memcpy(&red4[0], red, sizeof(red));
49 memcpy(&red4[4], red, sizeof(red));
50 memcpy(&red4[8], red, sizeof(red));
51 memcpy(&red4[12], red, sizeof(red));
53 glGenTextures(1, &src);
55 glBindTexture(GL_TEXTURE_2D, src);
56 glTexStorage2D(GL_TEXTURE_2D, 2, GL_RGBA8, 2, 2);
58 for (i = 0; i < 2; i++) {
59 GLuint view;
61 /* reset src to red */
62 glBindTexture(GL_TEXTURE_2D, src);
63 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2,
64 GL_RGBA, GL_FLOAT, red4);
65 glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 1, 1,
66 GL_RGBA, GL_FLOAT, red);
68 /* create a single-level view */
69 glGenTextures(1, &view);
70 glTextureView(view, GL_TEXTURE_2D, src,
71 GL_RGBA8, i, 1, 0, 1);
73 glClearTexImage(view, 0, GL_RGBA, GL_FLOAT, green);
75 /* check that the i'th level is cleared while others aren't */
76 for (j = 0; j < 2; j++) {
77 pass &= piglit_probe_texel_rect_rgba(
78 GL_TEXTURE_2D, j,
79 0, 0, 2 >> j, 2 >> j,
80 j == i ? green : red);
82 glDeleteTextures(1, &view);
85 glDeleteTextures(1, &src);
86 return pass;
89 static bool
90 test_2d_array(void)
92 bool pass = true;
93 GLuint src;
94 float red2[8];
95 int i, j;
97 memcpy(&red2[0], red, sizeof(red));
98 memcpy(&red2[4], red, sizeof(red));
100 glGenTextures(1, &src);
102 glBindTexture(GL_TEXTURE_2D_ARRAY, src);
103 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 1, 1, 2);
105 for (i = 0; i < 2; i++) {
106 GLuint view;
108 /* reset src to red */
109 glBindTexture(GL_TEXTURE_2D_ARRAY, src);
110 glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
111 1, 1, 2,
112 GL_RGBA, GL_FLOAT, red2);
114 /* create view of the layer1 */
115 glGenTextures(1, &view);
116 glTextureView(view, GL_TEXTURE_2D_ARRAY, src,
117 GL_RGBA8, 0, 1, i, 1);
119 glClearTexImage(view, 0, GL_RGBA, GL_FLOAT, green);
121 /* check that the i'th layer is cleared while others aren't */
122 for (j = 0; j < 2; j++) {
123 pass &= piglit_probe_texel_volume_rgba(
124 GL_TEXTURE_2D_ARRAY, 0,
125 0, 0, j, 1, 1, 1,
126 j == i ? green : red);
128 glDeleteTextures(1, &view);
131 glDeleteTextures(1, &src);
132 return pass;
135 void
136 piglit_init(int argc, char **argv)
138 bool pass = true;
139 piglit_require_extension("GL_ARB_clear_texture");
140 piglit_require_extension("GL_ARB_texture_view");
141 piglit_require_extension("GL_ARB_texture_storage");
143 pass &= test_2d();
144 if (piglit_is_extension_supported("GL_EXT_texture_array"))
145 pass &= test_2d_array();
147 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
150 enum piglit_result
151 piglit_display(void)
153 return PIGLIT_FAIL;