1 /* Copyright © 2015 Ilia Mirkin
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 * Tests that we can sample a maximally-sized texture buffer.
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config
.supports_gl_core_version
= 31;
32 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
33 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
34 PIGLIT_GL_TEST_CONFIG_END
39 static const float green
[4] = {0, 1, 0, 0};
42 glViewport(0, 0, piglit_width
, piglit_height
);
43 glClearColor(0.2, 0.2, 0.2, 0.2);
44 glClear(GL_COLOR_BUFFER_BIT
);
46 piglit_draw_rect(-1, -1, 2, 2);
48 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, green
);
50 piglit_present_results();
52 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
56 piglit_init(int argc
, char **argv
)
58 static const char *vs_source
=
60 "in vec4 piglit_vertex;\n"
63 " gl_Position = piglit_vertex;\n"
66 static const char *fs_source
=
68 "uniform samplerBuffer s;\n"
69 "uniform int offset;\n"
72 " gl_FragColor = texelFetch(s, offset);\n"
76 static const uint8_t data
[4] = {0x00, 0xff, 0x00, 0x00};
81 prog
= piglit_build_simple_program(vs_source
, fs_source
);
84 glGenBuffers(1, &tbo
);
85 glBindBuffer(GL_TEXTURE_BUFFER
, tbo
);
87 glGenTextures(1, &tex
);
88 glBindTexture(GL_TEXTURE_BUFFER
, tex
);
90 glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE
, &max
);
92 printf("MAX_TEXTURE_BUFFER_SIZE: %d\n", max
);
93 if (max
>= 512 * 1024 * 1024) {
94 /* Buffer sizes >= 2G are a bit dicey, ideally this
95 * test would try various formats, including GL_R8.
97 printf("MAX_TEXTURE_BUFFER_SIZE >= 512M, "
98 "testing with size 512M-1\n");
99 max
= 512 * 1024 * 1024 - 1;
102 glTexBuffer(GL_TEXTURE_BUFFER
, GL_RGBA8
, tbo
);
103 glBufferData(GL_TEXTURE_BUFFER
,
104 max
* sizeof(data
), NULL
, GL_STATIC_READ
);
106 if (err
== GL_OUT_OF_MEMORY
) {
107 printf("couldn't allocate buffer due to OOM, skipping.\n");
108 piglit_report_result(PIGLIT_SKIP
);
110 glBufferSubData(GL_TEXTURE_BUFFER
,
111 (max
- 1) * sizeof(data
), sizeof(data
), data
);
113 glUniform1i(glGetUniformLocation(prog
, "offset"), max
- 1);