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
23 /** @file render-no-bo.c
25 * Tests that we can sample from the default texture buffer or a
26 * texture buffer with no buffer bound, and not crash.
28 * From the GL_ARB_texture_buffer_object spec:
30 * "If no buffer object is bound to the buffer texture, the
31 * results of the texel access are undefined."
33 * we interpret this as allowing any result to come back, but not
34 * terminate the program. To test that, we glReadPixels the result
35 * but don't test the values returned.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
41 config
.supports_gl_compat_version
= 10;
42 config
.supports_gl_core_version
= 31;
43 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
44 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
45 PIGLIT_GL_TEST_CONFIG_END
50 static const char *vs_source
=
55 " gl_Position = vertex;\n"
58 static const char *fs_source
=
60 "uniform samplerBuffer s;\n"
63 " gl_FragColor = texelFetch(s, 4096);\n"
68 static const GLfloat verts
[8] = {
77 prog
= piglit_build_simple_program(vs_source
, fs_source
);
80 vertex_location
= glGetAttribLocation(prog
, "vertex");
82 if (piglit_get_gl_version() >= 31) {
84 glGenVertexArrays(1, &vao
);
85 glBindVertexArray(vao
);
87 glGenBuffers(1, &vbo
);
88 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
89 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_READ
);
90 glVertexAttribPointer(vertex_location
, 2, GL_FLOAT
,
92 glEnableVertexAttribArray(vertex_location
);
94 /* First, draw with no texture buffer bound (so using the
95 * default texture buffer object)
97 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
98 glReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, &junk
);
100 /* Now, do it again with a texture buffer that doesn't have
101 * any buffer bound yet.
103 glGenTextures(1, &tex
);
104 glBindTexture(GL_TEXTURE_BUFFER
, tex
);
106 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
107 glReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, &junk
);
109 glDeleteTextures(1, &tex
);
111 piglit_present_results();
117 piglit_init(int argc
, char **argv
)
119 piglit_require_GLSL_version(140);
120 if (piglit_get_gl_version() < 31)
121 piglit_require_extension("GL_ARB_texture_buffer_object");