ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_buffer_object / bufferstorage.c
blob16e4dcdf25efabfe49e81fa3e224a40001c1ec0a
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
12 * Software.
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
20 * IN THE SOFTWARE.
23 /** @file bufferstorage.c
25 * Tests that we can modify texture buffers using coherently mapped buffers.
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
36 static const float green[4] = {0, 1, 0, 0};
37 static const float red[4] = {1, 0, 0, 0};
38 static float *map;
40 enum piglit_result
41 piglit_display(void)
43 GLsync fence;
44 bool pass = true;
46 glViewport(0, 0, piglit_width, piglit_height);
47 glClearColor(0.2, 0.2, 0.2, 0.2);
48 glClear(GL_COLOR_BUFFER_BIT);
50 memcpy(map, red, sizeof(red));
51 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
53 /* Wait for any previous rendering to finish before updating
54 * the texture buffer
56 fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
57 glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT,
58 GL_TIMEOUT_IGNORED);
60 memcpy(map, green, sizeof(green));
61 glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
63 pass = piglit_probe_rect_rgba(
64 0, 0, piglit_width / 2, piglit_height, red) && pass;
65 pass = piglit_probe_rect_rgba(piglit_width / 2, 0,
66 piglit_width / 2, piglit_height,
67 green) && pass;
69 piglit_present_results();
71 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
74 void
75 piglit_init(int argc, char **argv)
77 static const char *vs_source =
78 "#version 140\n"
79 "in vec4 piglit_vertex;\n"
80 "void main()\n"
81 "{\n"
82 " gl_Position = piglit_vertex;\n"
83 "}\n";
85 static const char *fs_source =
86 "#version 140\n"
87 "uniform samplerBuffer s;\n"
88 "uniform int offset;\n"
89 "void main()\n"
90 "{\n"
91 " gl_FragColor = texelFetch(s, 0);\n"
92 "}\n";
94 static const GLfloat verts[16] = {
95 -1, -1,
96 0, -1,
97 0, 1,
98 -1, 1,
100 0, -1,
101 1, -1,
102 1, 1,
103 0, 1
106 GLuint tex, tbo;
107 GLuint prog;
109 int vertex_location;
110 GLuint vao, vbo;
112 piglit_require_extension("GL_ARB_buffer_storage");
114 prog = piglit_build_simple_program(vs_source, fs_source);
115 glUseProgram(prog);
116 vertex_location = glGetAttribLocation(prog, "piglit_vertex");
118 glGenBuffers(1, &tbo);
119 glBindBuffer(GL_TEXTURE_BUFFER, tbo);
120 glBufferStorage(GL_TEXTURE_BUFFER, sizeof(red), NULL,
121 GL_MAP_WRITE_BIT |
122 GL_MAP_PERSISTENT_BIT |
123 GL_MAP_COHERENT_BIT |
124 GL_DYNAMIC_STORAGE_BIT);
125 piglit_check_gl_error(GL_NO_ERROR);
127 map = glMapBufferRange(GL_TEXTURE_BUFFER, 0, sizeof(red),
128 GL_MAP_WRITE_BIT |
129 GL_MAP_PERSISTENT_BIT |
130 GL_MAP_COHERENT_BIT);
132 glGenTextures(1, &tex);
133 glBindTexture(GL_TEXTURE_BUFFER, tex);
135 glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, tbo);
137 glGenVertexArrays(1, &vao);
138 glBindVertexArray(vao);
140 glGenBuffers(1, &vbo);
141 glBindBuffer(GL_ARRAY_BUFFER, vbo);
142 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_READ);
143 glVertexAttribPointer(vertex_location, 2, GL_FLOAT,
144 GL_FALSE, 0, NULL);
145 glEnableVertexAttribArray(vertex_location);