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
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
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
46 GLint vertex_location
;
48 #define TBO_WIDTH 1024
49 #define TBO_SIZE TBO_WIDTH
51 /* NOTE: must adjust shader when changing WIN_WIDTH */
53 #define WIN_HEIGHT (TBO_WIDTH / WIN_WIDTH)
56 test_range(GLuint offset
, GLuint size
, bool ext_dsa
)
58 const float green
[4] = { 0, 1, 0, 0 };
62 glBindTexture(GL_TEXTURE_BUFFER
, tex
[0]);
64 glTextureBufferRangeEXT(tex
[1], GL_TEXTURE_BUFFER
, GL_R8UI
, tbo
, offset
, size
);
65 glBindTexture(GL_TEXTURE_BUFFER
, tex
[1]);
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
))
84 enum piglit_result result
= PIGLIT_SKIP
;
88 bool has_ext_dsa
= piglit_is_extension_supported("GL_EXT_direct_state_access");
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
);
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
;
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 */
130 glDeleteBuffers(1, &vbo
);
131 if (piglit_get_gl_version() >= 31)
132 glDeleteVertexArrays(1, &vao
);
134 piglit_present_results();
139 static char *vs_source
=
144 " gl_Position = vertex;\n"
147 static char *fs_source
=
149 "#define WIN_WIDTH 32u\n"
150 "uniform usamplerBuffer buf;\n"
151 "uniform uint offset;\n"
152 "uniform uint size;\n"
156 " uint pos = uint(gl_FragCoord.x) + uint(gl_FragCoord.y) * WIN_WIDTH;\n"
157 " uint expected = ((pos + offset) | 1u) & 0xffu;\n"
160 " ok = float(texelFetch(buf, int(pos)).r == expected);\n"
161 " gl_FragColor = vec4(1.0 - ok, ok, 0.0, 0.0);\n"
167 prog
= piglit_build_simple_program(vs_source
, fs_source
);
169 vertex_location
= glGetAttribLocation(prog
, "vertex");
177 data
= malloc(TBO_SIZE
);
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
);
197 piglit_init(int argc
, char **argv
)
199 piglit_require_GLSL_version(140);
200 piglit_require_extension("GL_ARB_texture_buffer_range");