framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_texture_buffer_range / ranges.c
blob16aef461a07b51d03d2e44565d0882099819676e
1 /* Copyright © 2012 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
23 /** @file ranges.c
25 * Test drawing with various ranges and sizes for glTexBufferRange.
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config.supports_gl_compat_version = 10;
33 config.supports_gl_core_version = 31;
35 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
38 PIGLIT_GL_TEST_CONFIG_END
40 GLuint prog;
41 GLuint tbo;
42 GLuint tex[2];
44 uint8_t *data;
46 GLint vertex_location;
48 #define TBO_WIDTH 1024
49 #define TBO_SIZE TBO_WIDTH
51 /* NOTE: must adjust shader when changing WIN_WIDTH */
52 #define WIN_WIDTH 32
53 #define WIN_HEIGHT (TBO_WIDTH / WIN_WIDTH)
55 enum piglit_result
56 test_range(GLuint offset, GLuint size, bool ext_dsa)
58 const float green[4] = { 0, 1, 0, 0 };
60 glUseProgram(prog);
62 glBindTexture(GL_TEXTURE_BUFFER, tex[0]);
63 if (ext_dsa) {
64 glTextureBufferRangeEXT(tex[1], GL_TEXTURE_BUFFER, GL_R8UI, tbo, offset, size);
65 glBindTexture(GL_TEXTURE_BUFFER, tex[1]);
66 } else {
67 glTexBufferRange(GL_TEXTURE_BUFFER, GL_R8UI, tbo, offset, size);
70 glUniform1i(glGetUniformLocation(prog, "buf"), 0);
71 glUniform1ui(glGetUniformLocation(prog, "offset"), offset);
72 glUniform1ui(glGetUniformLocation(prog, "size"), size);
74 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
76 if (!piglit_probe_rect_rgba(0, 0, WIN_WIDTH, WIN_HEIGHT, green))
77 return PIGLIT_FAIL;
78 return PIGLIT_PASS;
81 enum piglit_result
82 piglit_display(void)
84 enum piglit_result result = PIGLIT_SKIP;
85 GLint i, j, n;
86 GLuint vao, vbo;
87 GLint incr;
88 bool has_ext_dsa = piglit_is_extension_supported("GL_EXT_direct_state_access");
90 const float verts[] =
91 { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f };
93 glClearColor(0.5, 0.5, 0.5, 0.5);
94 glClear(GL_COLOR_BUFFER_BIT);
96 /* For GL core, we need to have a vertex array object bound.
97 * Otherwise, we don't particularly have to. Always use a
98 * vertex buffer object, though.
100 glGenBuffers(1, &vbo);
101 glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo);
102 if (piglit_get_gl_version() >= 31) {
103 glGenVertexArrays(1, &vao);
104 glBindVertexArray(vao);
106 glVertexAttribPointer(vertex_location, 2, GL_FLOAT, GL_FALSE, 0, NULL);
107 glEnableVertexAttribArray(vertex_location);
109 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
111 glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &incr);
112 if (!incr)
113 return PIGLIT_FAIL;
114 for (n = 0, i = 0; i < TBO_SIZE && result != PIGLIT_FAIL; i += incr) {
115 for (j = 1; j <= 4 && result != PIGLIT_FAIL; ++j, ++n) {
116 GLint size = (TBO_SIZE - i) / j;
117 if (!size)
118 break;
119 result = test_range(i, (TBO_SIZE - i) / j, false);
121 if (result == PIGLIT_PASS && has_ext_dsa)
122 result = test_range(i, (TBO_SIZE - i) / j, true);
124 if (n > 128) { /* takes too long otherwise */
125 n = 0;
126 incr *= 2;
130 glDeleteBuffers(1, &vbo);
131 if (piglit_get_gl_version() >= 31)
132 glDeleteVertexArrays(1, &vao);
134 piglit_present_results();
136 return result;
139 static char *vs_source =
140 "#version 140\n"
141 "in vec4 vertex;\n"
142 "void main()\n"
143 "{\n"
144 " gl_Position = vertex;\n"
145 "}\n";
147 static char *fs_source =
148 "#version 140\n"
149 "#define WIN_WIDTH 32u\n"
150 "uniform usamplerBuffer buf;\n"
151 "uniform uint offset;\n"
152 "uniform uint size;\n"
153 "\n"
154 "void main()\n"
155 "{\n"
156 " uint pos = uint(gl_FragCoord.x) + uint(gl_FragCoord.y) * WIN_WIDTH;\n"
157 " uint expected = ((pos + offset) | 1u) & 0xffu;\n"
158 " float ok = 1.0;\n"
159 " if (pos < size)\n"
160 " ok = float(texelFetch(buf, int(pos)).r == expected);\n"
161 " gl_FragColor = vec4(1.0 - ok, ok, 0.0, 0.0);\n"
162 "}\n";
164 static void
165 init_program()
167 prog = piglit_build_simple_program(vs_source, fs_source);
169 vertex_location = glGetAttribLocation(prog, "vertex");
172 static void
173 init_tbo()
175 int i;
177 data = malloc(TBO_SIZE);
178 if (!data) {
179 fprintf(stderr, "malloc failed\n");
180 piglit_report_result(PIGLIT_SKIP);
183 /* always non-zero to distinguish from out-of-bounds access */
184 for (i = 0; i < TBO_WIDTH; ++i)
185 data[i] = (i | 1) & 0xff;
187 glGenBuffers(1, &tbo);
188 glBindBuffer(GL_TEXTURE_BUFFER, tbo);
189 glBufferData(GL_TEXTURE_BUFFER, TBO_SIZE, data, GL_STATIC_DRAW);
191 glGenTextures(ARRAY_SIZE(tex), tex);
193 free(data);
196 void
197 piglit_init(int argc, char **argv)
199 piglit_require_GLSL_version(140);
200 piglit_require_extension("GL_ARB_texture_buffer_range");
202 init_program();
203 init_tbo();