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
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};
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
56 fence
= glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0);
57 glClientWaitSync(fence
, GL_SYNC_FLUSH_COMMANDS_BIT
,
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
,
69 piglit_present_results();
71 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
75 piglit_init(int argc
, char **argv
)
77 static const char *vs_source
=
79 "in vec4 piglit_vertex;\n"
82 " gl_Position = piglit_vertex;\n"
85 static const char *fs_source
=
87 "uniform samplerBuffer s;\n"
88 "uniform int offset;\n"
91 " gl_FragColor = texelFetch(s, 0);\n"
94 static const GLfloat verts
[16] = {
112 piglit_require_extension("GL_ARB_buffer_storage");
114 prog
= piglit_build_simple_program(vs_source
, fs_source
);
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
,
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
),
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
,
145 glEnableVertexAttribArray(vertex_location
);