1 /* Copyright © 2012, 2014 Intel Corporation
2  *
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:
9  *
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
12  * Software.
13  *
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
20  * IN THE SOFTWARE.
21  */
22 
23 /** @file edgeflag-immediate.c
24  *
25  * Test for glEdgeFlag() API working with a GLSL program enabled.
26  */
27 
28 #include "piglit-util-gl.h"
29 
30 PIGLIT_GL_TEST_CONFIG_BEGIN
31 
32 	config.supports_gl_compat_version = 10;
33 
34 	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
35 
36 	config.khr_no_error_support = PIGLIT_NO_ERRORS;
37 
38 PIGLIT_GL_TEST_CONFIG_END
39 
40 static GLuint color_index;
41 
42 enum piglit_result
piglit_display(void)43 piglit_display(void)
44 {
45 	bool pass = true;
46 	float green[] = {0, 1, 0, 0};
47 	float clear[] = {0.5, 0.5, 0.5, 0.5};
48 
49 	piglit_ortho_projection(piglit_width, piglit_height, false);
50 
51 	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
52 
53 	glClearColor(0.5, 0.5, 0.5, 0.5);
54 	glClear(GL_COLOR_BUFFER_BIT);
55 
56 	glVertexAttrib4f(color_index, 0, 1, 0, 0);
57 
58 	glBegin(GL_POLYGON);
59 	glEdgeFlag(GL_TRUE);
60 	glVertex2f(1.5, 1.5);
61 	glEdgeFlag(GL_FALSE);
62 	glVertex2f(5.5, 1.5);
63 	glEdgeFlag(GL_TRUE);
64 	glVertex2f(5.5, 5.5);
65 	glEdgeFlag(GL_FALSE);
66 	glVertex2f(1.5, 5.5);
67 	glEnd();
68 
69 	pass = piglit_probe_pixel_rgba(3, 1, green) && pass;
70 	pass = piglit_probe_pixel_rgba(3, 5, green) && pass;
71 	pass = piglit_probe_pixel_rgba(1, 3, clear) && pass;
72 	pass = piglit_probe_pixel_rgba(5, 3, clear) && pass;
73 
74 	piglit_present_results();
75 
76 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
77 }
78 
79 const char *vs_source =
80 	"attribute vec4 in_color;\n"
81 	"varying vec4 color;\n"
82 	"\n"
83 	"void main()\n"
84 	"{\n"
85 	"	gl_Position = ftransform();\n"
86 	"	color = in_color;\n"
87 	"}\n";
88 
89 const char *fs_source =
90 	"varying vec4 color;\n"
91 	"\n"
92 	"void main()\n"
93 	"{\n"
94 	"	gl_FragColor = color;\n"
95 	"}\n";
96 
97 void
piglit_init(int argc,char ** argv)98 piglit_init(int argc, char **argv)
99 {
100 	GLuint prog;
101 
102 	prog = piglit_build_simple_program(vs_source, fs_source);
103 	glUseProgram(prog);
104 	color_index = glGetAttribLocation(prog, "in_color");
105 }
106