2 * Copyright © 2015 Red Hat.
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 rendering into a single framebuffer surface with multiple viewports
27 * via a geometry shader.
28 * This test is inspired by a CTS test.
29 * For one point, the geom shader emits a triangle strip with a color
30 * pre invocation. The viewports then should get one shade of red lighter.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 32;
37 config
.supports_gl_core_version
= 32;
38 config
.supports_gl_es_version
= 31;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
45 #ifdef PIGLIT_USE_OPENGL
46 #define GLSL_VERSION "150"
48 #define GLSL_VERSION "310 es"
51 const char *vsSource
= {
52 "#version " GLSL_VERSION
"\n"
57 const char *gsSource
= {
58 "#version " GLSL_VERSION
"\n"
59 "#extension GL_ARB_gpu_shader5 : enable\n"
60 "#extension GL_ARB_viewport_array : enable\n"
61 "#extension GL_OES_viewport_array : enable\n"
62 "#extension GL_EXT_geometry_shader : enable\n"
63 "#extension GL_OES_geometry_shader : enable\n"
64 "layout(points, invocations = 16) in;\n"
65 "layout(triangle_strip, max_vertices = 4) out;\n"
66 " flat out int gs_fs_color;\n"
70 " gs_fs_color = gl_InvocationID;\n"
71 " gl_ViewportIndex = gl_InvocationID;\n"
72 " gl_Position = vec4(-1, -1, 0, 1);\n"
74 " gs_fs_color = gl_InvocationID;\n"
75 " gl_ViewportIndex = gl_InvocationID;\n"
76 " gl_Position = vec4(-1, 1, 0, 1);\n"
78 " gs_fs_color = gl_InvocationID;\n"
79 " gl_ViewportIndex = gl_InvocationID;\n"
80 " gl_Position = vec4(1, -1, 0, 1);\n"
82 " gs_fs_color = gl_InvocationID;\n"
83 " gl_ViewportIndex = gl_InvocationID;\n"
84 " gl_Position = vec4(1, 1, 0, 1);\n"
89 const char *fsSource
= {
90 "#version " GLSL_VERSION
"\n"
92 "precision highp float;\n"
94 "flat in int gs_fs_color;\n"
95 "uniform vec3 color;\n"
98 " c = vec4(1.0 / float(gs_fs_color + 1), 0.0, 0.0, 1.0);\n"
103 draw_multi_viewport(void)
107 const int divX
=4, divY
=4;
108 GLfloat w
= (GLfloat
) piglit_width
/ (GLfloat
) divX
;
109 GLfloat h
= (GLfloat
) piglit_height
/ (GLfloat
) divY
;
110 GLfloat data
[16 * 4 /* 4x4 * (x + y + w + h) */];
115 for (i
= 0; i
< divX
; i
++) {
116 for (j
= 0; j
< divY
; j
++) {
117 data
[idx
* 4 + 0] = (GLfloat
)(i
* w
);
118 data
[idx
* 4 + 1] = (GLfloat
)(j
* h
);
119 data
[idx
* 4 + 2] = w
;
120 data
[idx
* 4 + 3] = h
;
124 glViewport(0, 0, piglit_width
, piglit_height
); /* for glClear() */
125 glClear(GL_COLOR_BUFFER_BIT
);
126 glViewportArrayv(0, 16, data
);
128 glDrawArrays(GL_POINTS
, 0, 1);
129 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
131 for (i
= 0; i
< divX
; i
++) {
132 for (j
= 0; j
< divY
; j
++) {
135 expected
[0] = 1.0 / (1 + i
*4 + j
);
139 p
= piglit_probe_pixel_rgba(i
* w
+ w
/2, j
* h
+ h
/2,
142 printf("Wrong color for viewport i,j %d %d\n",
149 piglit_present_results();
159 pass
= draw_multi_viewport();
160 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
161 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
165 piglit_init(int argc
, char **argv
)
170 #ifdef PIGLIT_USE_OPENGL
171 piglit_require_extension("GL_ARB_viewport_array");
172 piglit_require_extension("GL_ARB_gpu_shader5");
174 piglit_require_extension("GL_OES_viewport_array");
177 program
= piglit_build_simple_program_multiple_shaders(
178 GL_VERTEX_SHADER
, vsSource
,
179 GL_GEOMETRY_SHADER
, gsSource
,
180 GL_FRAGMENT_SHADER
, fsSource
,
182 glUseProgram(program
);
184 glGenVertexArrays(1, &vao
);
185 glBindVertexArray(vao
);