1 /* Copyright © 2015 Ilia Mirkin
2 * Copyright © 2017 VMware, Inc.
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
26 * Tests that we can sample texture buffers with sampler indexing.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_core_version
= 32;
33 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
34 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
35 PIGLIT_GL_TEST_CONFIG_END
40 static const float green
[4] = {0, 1, 0, 0};
43 glViewport(0, 0, piglit_width
, piglit_height
);
44 glClearColor(0.2, 0.2, 0.2, 0.2);
45 glClear(GL_COLOR_BUFFER_BIT
);
47 piglit_draw_rect(-1, -1, 2, 2);
49 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, green
);
51 piglit_present_results();
53 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
57 piglit_init(int argc
, char **argv
)
59 static const char *vs_source
=
61 "in vec4 piglit_vertex;\n"
64 " gl_Position = piglit_vertex;\n"
67 static const char *fs_source
=
69 "#extension GL_ARB_gpu_shader5: require\n"
70 "uniform samplerBuffer s[2];\n"
71 "uniform int offset;\n"
72 "uniform int index = 1;\n"
75 " gl_FragColor = texelFetch(s[index], offset);\n"
78 GLuint tex
[2], tbo
[2];
79 GLint indices
[2] = { 0, 1 };
80 static const uint8_t datag
[4] = {0x00, 0xff, 0x00, 0x00};
81 static const uint8_t datar
[4] = {0xff, 0x00, 0x00, 0x00};
84 piglit_require_extension("GL_ARB_gpu_shader5");
86 prog
= piglit_build_simple_program(vs_source
, fs_source
);
90 glGenTextures(2, tex
);
91 glBindBuffer(GL_TEXTURE_BUFFER
, tbo
[0]);
92 glBindTexture(GL_TEXTURE_BUFFER
, tex
[0]);
93 glTexBuffer(GL_TEXTURE_BUFFER
, GL_RGBA8
, tbo
[0]);
94 glBufferData(GL_TEXTURE_BUFFER
,
95 size
* sizeof(datar
), NULL
, GL_STATIC_READ
);
96 glBufferSubData(GL_TEXTURE_BUFFER
,
97 (size
- 1) * sizeof(datar
), sizeof(datar
), datar
);
99 glActiveTexture(GL_TEXTURE1
);
100 glBindBuffer(GL_TEXTURE_BUFFER
, tbo
[1]);
101 glBindTexture(GL_TEXTURE_BUFFER
, tex
[1]);
102 glTexBuffer(GL_TEXTURE_BUFFER
, GL_RGBA8
, tbo
[1]);
103 glBufferData(GL_TEXTURE_BUFFER
,
104 size
* sizeof(datag
), NULL
, GL_STATIC_READ
);
105 glBufferSubData(GL_TEXTURE_BUFFER
,
106 (size
- 1) * sizeof(datag
), sizeof(datag
), datag
);
108 glUniform1i(glGetUniformLocation(prog
, "offset"), size
- 1);
109 glUniform1iv(glGetUniformLocation(prog
, "s"), 2, indices
);