2 * Copyright (C) 2015 Ilia Mirkin
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
27 * Test that glPolygonOffsetClampEXT works inside of a call list. See
28 * draw.c for testing technique comments.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 21;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DEPTH
| PIGLIT_GL_VISUAL_DOUBLE
;
38 PIGLIT_GL_TEST_CONFIG_END
45 static const float blue
[4] = {0, 0, 1, 1};
46 static const float red
[4] = {1, 0, 0, 1};
47 static const float green
[4] = {0, 1, 0, 1};
50 bool passa
= true, passb
= true;
54 glViewport(0, 0, piglit_width
, piglit_height
);
55 glEnable(GL_DEPTH_TEST
);
56 glEnable(GL_POLYGON_OFFSET_FILL
);
58 glClearColor(0, 0, 1, 1);
60 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
64 /* Draw red rectangle that slopes between 1 and 0.1. Use a
65 * polygon offset with a high factor but small clamp
67 glNewList(list
, GL_COMPILE_AND_EXECUTE
);
68 glPolygonOffsetClampEXT(-1000, 0, -0.05);
69 glUniform4fv(color
, 1, red
);
70 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
73 if (!piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, blue
)) {
74 printf(" FAIL: red rect peeks over blue rect\n");
78 /* And now set the clamp such that all parts of the polygon
79 * can pass the depth test.
81 glNewList(list
+ 1, GL_COMPILE_AND_EXECUTE
);
82 glPolygonOffsetClampEXT(-1000, 0, -0.51);
83 glUniform4fv(color
, 1, green
);
84 glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
87 if (!piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, green
)) {
88 printf(" FAIL: green rect does not cover blue rect\n");
92 piglit_report_subtest_result(passa
? PIGLIT_PASS
: PIGLIT_FAIL
,
93 "compile and execute");
94 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
97 if (!piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, blue
)) {
98 printf(" FAIL: red rect peeks over blue rect\n");
102 glCallList(list
+ 1);
103 if (!piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, green
)) {
104 printf(" FAIL: green rect does not cover blue rect\n");
108 piglit_report_subtest_result(passb
? PIGLIT_PASS
: PIGLIT_FAIL
,
111 piglit_present_results();
113 return (passa
&& passb
) ? PIGLIT_PASS
: PIGLIT_FAIL
;
117 piglit_init(int argc
, char **argv
)
119 static const float verts
[4][4] = {
129 piglit_require_extension("GL_EXT_polygon_offset_clamp");
131 prog
= piglit_build_simple_program(
133 "void main() { gl_Position = gl_Vertex; }\n",
136 "uniform vec4 color;\n"
137 "void main() { gl_FragColor = color; }\n");
138 color
= glGetUniformLocation(prog
, "color");
140 glEnableVertexAttribArray(0);
141 glGenBuffers(1, &bo
);
142 glBindBuffer(GL_ARRAY_BUFFER
, bo
);
143 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
, GL_STATIC_DRAW
);
144 glVertexAttribPointer(0, 4, GL_FLOAT
, GL_FALSE
, 0, (GLvoid
const *)0);