2 * Copyright © 2011 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
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 DEALINGS
24 #include "piglit-util-gl.h"
29 * Tests error conditions and queries for glTexBufferRange.
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_compat_version
= 10;
35 config
.supports_gl_core_version
= 31;
37 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
38 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
40 PIGLIT_GL_TEST_CONFIG_END
49 /* use min of MAX_TEXTURE_BUFFER_SIZE */
50 #define TBO_SIZE (1 << 16)
53 piglit_init(int argc
, char **argv
)
55 GLint align
, value
[2];
58 piglit_require_gl_version(20);
59 piglit_require_extension("GL_ARB_texture_buffer_range");
61 glGenTextures(1, &tex
);
62 glBindTexture(GL_TEXTURE_BUFFER
, tex
);
64 glBindBuffer(GL_TEXTURE_BUFFER
, bo
);
66 glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT
, &align
);
68 fprintf(stderr
, "GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT == %i, "
69 "should be >= 1\n", align
);
70 piglit_report_result(PIGLIT_FAIL
);
73 /* From OpenGL 4.5 spec, section 8.9 Buffer Textures:
75 * "An INVALID_ENUM error is generated if the effective target is not
78 glTexBufferRange(GL_TEXTURE_2D
, GL_RGBA8
, bo
, 0, 4);
79 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
80 piglit_report_result(PIGLIT_FAIL
);
82 /* If <offset> is negative or if <size> is
83 * less than or equal to zero or if <offset> + <size> is greater than
84 * the value of BUFFER_SIZE for the buffer bound to <target>, of if
85 * <offset> is not an integer multiple of
86 * TEXTURE_BUFFER_OFFSET_ALIGNMENT, then the error INVALID_VALUE
90 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, bo
, 0, 4);
91 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
92 piglit_report_result(PIGLIT_FAIL
);
94 glBufferData(GL_TEXTURE_BUFFER
, TBO_SIZE
, NULL
, GL_STATIC_DRAW
);
96 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, bo
, -align
, 4);
97 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
98 piglit_report_result(PIGLIT_FAIL
);
100 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, bo
, 0, 0);
101 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
102 piglit_report_result(PIGLIT_FAIL
);
104 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, bo
, 0, -16);
105 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
106 piglit_report_result(PIGLIT_FAIL
);
109 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, bo
, align
/ 2, 16);
110 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
111 piglit_report_result(PIGLIT_FAIL
);
114 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, bo
,
115 align
, TBO_SIZE
- align
);
116 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
117 fprintf(stderr
, "glTexBufferRange failed\n");
118 piglit_report_result(PIGLIT_FAIL
);
120 glGetTexLevelParameteriv(GL_TEXTURE_BUFFER
, 0, GL_TEXTURE_BUFFER_OFFSET
,
122 glGetTexLevelParameteriv(GL_TEXTURE_BUFFER
, 0, GL_TEXTURE_BUFFER_SIZE
,
124 if (value
[0] != align
|| value
[1] != TBO_SIZE
- align
) {
125 fprintf(stderr
, "GL_TEXTURE_BUFFER_OFFSET/SIZE returned %i/%i, "
127 value
[0], value
[1], align
, TBO_SIZE
- align
);
128 piglit_report_result(PIGLIT_FAIL
);
131 /* If <buffer> is zero, then any buffer object attached to the
132 * buffer texture is detached, the values <offset> and <size> are
133 * ignored and the state for <offset> and <size> for the
134 * buffer texture are reset to zero.
137 glTexBufferRange(GL_TEXTURE_BUFFER
, GL_RGBA8
, 0, -align
, TBO_SIZE
* 2);
138 if (!piglit_check_gl_error(GL_NO_ERROR
))
139 piglit_report_result(PIGLIT_FAIL
);
141 glGetTexLevelParameteriv(GL_TEXTURE_BUFFER
, 0, GL_TEXTURE_BUFFER_OFFSET
,
143 glGetTexLevelParameteriv(GL_TEXTURE_BUFFER
, 0, GL_TEXTURE_BUFFER_SIZE
,
145 if (value
[0] || value
[1]) {
146 fprintf(stderr
, "buffer detached but "
147 "GL_TEXTURE_BUFFER_OFFSET/SIZE "
149 piglit_report_result(PIGLIT_FAIL
);
152 piglit_report_result(PIGLIT_PASS
);