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 fetch-outside-bounds.c
25 * Tests that we can sample from outside of a texture buffer object
28 * From the GL_ARB_texture_buffer_object spec:
30 * "When a buffer texture is accessed in a shader, the results of
31 * a texel fetch are undefined if the specified texel number is
32 * greater than or equal to the clamped number of texels in the
35 * we interpret this as allowing any result to come back, but not
36 * terminate the program. To test that, we glReadPixels the result
37 * but don't test the values returned.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 10;
44 config
.supports_gl_core_version
= 31;
45 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
52 static const char *vs_source
=
57 " gl_Position = vertex;\n"
60 static const char *fs_source
=
62 "uniform samplerBuffer s;\n"
65 " gl_FragColor = texelFetch(s, 4096);\n"
69 /* data stored in our TBO, not actually read by the shader. */
70 static const uint8_t data
[4] = {0x0, 0xff, 0x0, 0x0};
72 static const GLfloat verts
[8] = {
81 prog
= piglit_build_simple_program(vs_source
, fs_source
);
84 vertex_location
= glGetAttribLocation(prog
, "vertex");
86 glGenBuffers(1, &tbo
);
87 glBindBuffer(GL_TEXTURE_BUFFER
, tbo
);
89 glGenTextures(1, &tex
);
90 glBindTexture(GL_TEXTURE_BUFFER
, tex
);
92 glTexBuffer(GL_TEXTURE_BUFFER
, GL_RGBA8
, tbo
);
93 glBufferData(GL_TEXTURE_BUFFER
, sizeof(data
), data
, GL_STATIC_READ
);
95 if (piglit_get_gl_version() >= 31) {
97 glGenVertexArrays(1, &vao
);
98 glBindVertexArray(vao
);
100 glGenBuffers(1, &vbo
);
101 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
102 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_READ
);
103 glVertexAttribPointer(vertex_location
, 2, GL_FLOAT
,
105 glEnableVertexAttribArray(vertex_location
);
106 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
108 glReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, &junk
);
109 /* We don't verify the junk read, since it's undefined. */
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");