2 * Copyright © 2016 Intel Corporation
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
25 /** @file innercoverage.c
27 * Verifies that the inner_coverage layout qualifier works when
28 * GL_INTEL_conservative_rasterization is enabled.
31 #include "piglit-util-gl.h"
32 #include "piglit-matrix.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 #if defined(PIGLIT_USE_OPENGL)
37 config
.supports_gl_core_version
= 42;
38 #elif defined(PIGLIT_USE_OPENGL_ES3)
39 config
.supports_gl_es_version
= 31;
42 config
.window_width
= 400;
43 config
.window_height
= 400;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
46 PIGLIT_GL_TEST_CONFIG_END
51 enum piglit_result result
= PIGLIT_PASS
;
53 /* The following fragment programs render the opaque red color
54 * only when dispatched with a gl_SampleMaskIn empty. It
55 * should therefore expose the effect of the inner_coverage
56 * (i.e. no color with this qualifier and a triangle outline
58 GLuint inner_prog
= piglit_build_simple_program(
59 #if defined(PIGLIT_USE_OPENGL)
61 #elif defined(PIGLIT_USE_OPENGL_ES3)
64 "in vec4 piglit_vertex;\n"
67 " gl_Position = piglit_vertex;\n"
69 #if defined(PIGLIT_USE_OPENGL)
71 "#extension GL_INTEL_conservative_rasterization: enable\n"
72 #elif defined(PIGLIT_USE_OPENGL_ES3)
74 "#extension GL_OES_sample_variables: enable\n"
75 "#extension GL_INTEL_conservative_rasterization: enable\n"
76 "precision highp float;\n"
78 "layout(inner_coverage) in;\n"
82 " float one = 1.0 - float(gl_SampleMaskIn[0]);\n"
83 " color = vec4(one, 0.0, 0.0, one);\n"
86 piglit_report_result(PIGLIT_FAIL
);
88 GLuint conservative_prog
= piglit_build_simple_program(
89 #if defined(PIGLIT_USE_OPENGL)
91 #elif defined(PIGLIT_USE_OPENGL_ES3)
94 "in vec4 piglit_vertex;\n"
97 " gl_Position = piglit_vertex;\n"
99 #if defined(PIGLIT_USE_OPENGL)
101 "#extension GL_INTEL_conservative_rasterization: enable\n"
102 #elif defined(PIGLIT_USE_OPENGL_ES3)
104 "#extension GL_OES_sample_variables: enable\n"
105 "#extension GL_INTEL_conservative_rasterization: enable\n"
106 "precision highp float;\n"
111 " float one = 1.0 - float(gl_SampleMaskIn[0]);\n"
112 " color = vec4(one, 0.0, 0.0, one);\n"
114 if (!conservative_prog
)
115 piglit_report_result(PIGLIT_FAIL
);
117 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, piglit_winsys_fbo
);
118 glViewport(0, 0, piglit_width
, piglit_height
);
120 glClearColor(0.0, 0.0, 0.0, 0.0);
123 glGenVertexArrays(1, &vao
);
124 glBindVertexArray(vao
);
127 float delta
= 1.01 / piglit_width
;
128 float vertices
[3][2] = {
129 { -0.5, -1 + delta
, },
131 { 0.5, -1 + delta
, },
133 glGenBuffers(1, &vbo
);
134 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
135 glBufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), vertices
, GL_STATIC_DRAW
);
136 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, 2 * sizeof(GLfloat
), NULL
);
137 glEnableVertexAttribArray(0);
139 glEnable(GL_CONSERVATIVE_RASTERIZATION_INTEL
);
141 glUseProgram(conservative_prog
);
142 glClear(GL_COLOR_BUFFER_BIT
);
143 glDrawArrays(GL_TRIANGLES
, 0, 3);
145 if(!piglit_check_gl_error(GL_NO_ERROR
))
148 piglit_present_results();
150 const float conservative_expected
[] = { 0.0, 0.0, 0.0, 0.0 };
151 if (!piglit_probe_pixel_rgba(piglit_width
/ 2, 0, conservative_expected
))
152 result
= PIGLIT_FAIL
;
154 glUseProgram(inner_prog
);
155 glClear(GL_COLOR_BUFFER_BIT
);
156 glDrawArrays(GL_TRIANGLES
, 0, 3);
158 if(!piglit_check_gl_error(GL_NO_ERROR
))
159 result
= PIGLIT_FAIL
;
161 piglit_present_results();
163 const float inner_expected
[] = { 1.0, 0.0, 0.0, 1.0 };
164 if (!piglit_probe_pixel_rgba(piglit_width
/ 2, 0, inner_expected
))
165 result
= PIGLIT_FAIL
;
170 void piglit_init(int argc
, char **argv
)
172 piglit_require_extension("GL_INTEL_conservative_rasterization");