fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / arb_shader_storage_buffer_object / getintegeri_v.c
blobe30439766fbce4763e20261fdf5d1041730c0e4d
1 /*
2 * Copyright © 2015 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
21 * DEALINGS IN THE SOFTWARE.
24 /** @file getintegeri_v.c
26 * From the GL_ARB_shader_storage_buffer_object spec:
28 * "To query the starting offset or size of the range of each buffer object
29 * binding used for shader storage buffers, call GetInteger64i_v with <param>
30 * set to SHADER_STORAGE_BUFFER_START or SHADER_STORAGE_BUFFER_SIZE
31 * respectively. <index> must be in the range zero to the value of
32 * MAX_SHADER_STORAGE_BUFFER_BINDINGS-1. If the parameter (starting offset
33 * or size) was not specified when the buffer object was bound (e.g. if
34 * bound with BindBufferBase), or if no buffer object is bound to index, zero
35 * is returned."
37 * Based on ARB_uniform_buffer_object's getintegeri_v.c
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config.supports_gl_compat_version = 32;
45 config.supports_gl_core_version = 32;
46 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
47 config.khr_no_error_support = PIGLIT_NO_ERRORS;
49 PIGLIT_GL_TEST_CONFIG_END
51 static bool pass = true;
53 static void
54 test_index(int line, GLenum e, int index, int expected)
56 GLint val;
58 glGetIntegeri_v(e, index, &val);
59 if (val != expected) {
60 printf("%s:%d: %s[%d] was %d, expected %d\n",
61 __FILE__, line, piglit_get_gl_enum_name(e), index,
62 val, expected);
63 pass = false;
67 void
68 test_range(int line, int index, int bo, int offset, int size)
70 test_index(line, GL_SHADER_STORAGE_BUFFER_BINDING, index, bo);
71 test_index(line, GL_SHADER_STORAGE_BUFFER_START, index, offset);
72 test_index(line, GL_SHADER_STORAGE_BUFFER_SIZE, index, size);
75 void
76 piglit_init(int argc, char **argv)
78 GLuint bo[2];
79 int size = 1024;
80 GLint max_bindings;
81 GLint junk;
82 GLint alignment;
84 piglit_require_extension("GL_ARB_shader_storage_buffer_object");
86 /* If no buffer object is bound to index, zero is returned. */
87 test_range(__LINE__, 1, 0, 0, 0);
89 glGetIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &alignment);
91 glGenBuffers(2, bo);
92 glBindBuffer(GL_SHADER_STORAGE_BUFFER, bo[0]);
93 glBufferData(GL_SHADER_STORAGE_BUFFER, size, NULL, GL_STATIC_READ);
94 glBindBuffer(GL_SHADER_STORAGE_BUFFER, bo[1]);
95 glBufferData(GL_SHADER_STORAGE_BUFFER, size, NULL, GL_STATIC_READ);
97 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, bo[0], 0, 1);
98 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 1, bo[1], 2 * alignment, 3);
99 test_range(__LINE__, 0, bo[0], 0, 1);
100 test_range(__LINE__, 1, bo[1], 2 * alignment, 3);
102 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, bo[1]);
103 test_range(__LINE__, 1, bo[1], 0, 0);
105 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0);
106 test_range(__LINE__, 0, 0, 0, 0);
108 /* Test the error condition. */
109 if (!piglit_khr_no_error) {
110 glGetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS,
111 &max_bindings);
112 glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_BINDING,
113 max_bindings, &junk);
114 if (!piglit_check_gl_error(GL_INVALID_VALUE))
115 pass = false;
118 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
121 enum piglit_result piglit_display(void)
123 /* UNREACHED */
124 return PIGLIT_FAIL;