1 /*
2  * Copyright © 2013 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 /**
25  * @file
26  * @brief Test GL_FIXED with attribute arrays in OpenGL ES 1.1.
27  *
28  * This test paints the window's left half green and window's right half dark
29  * blue. It uses the GL_FIXED data type for glVertexPointer and
30  * glColorPointer.
31  *
32  * This tests Mesa commit 7a9f4d3e for Intel gen4+.
33  */
34 
35 #include "piglit-util-gl.h"
36 
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38 
39 	config.supports_gl_es_version = 11;
40 	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
41 	config.khr_no_error_support = PIGLIT_NO_ERRORS;
42 
43 PIGLIT_GL_TEST_CONFIG_END
44 
45 /* From the GL_OES_fixed_point spec, GL_FIXED represents a
46  * "signed 2's complement S15.16 scaled integer".
47  */
48 #define ONE  0x00010000
49 #define HALF 0x00008000
50 
51 /* Vertices for the window's left half. */
52 static const GLfixed left_vertices[] = {
53 	-ONE, -ONE,
54 	   0, -ONE,
55 	   0, +ONE,
56 	-ONE, +ONE,
57 };
58 
59 /* Vertices for the window's right half. */
60 static const GLfixed right_vertices[] = {
61 	   0, -ONE,
62 	+ONE, -ONE,
63 	+ONE, +ONE,
64 	   0, +ONE,
65 };
66 
67 /* Green, color of the window's left half. */
68 static const GLfloat left_color_float[4] = {0, 1, 0, 1};
69 static const GLfixed left_colors_fixed[] = {
70 	0, ONE, 0, ONE,
71 	0, ONE, 0, ONE,
72 	0, ONE, 0, ONE,
73 	0, ONE, 0, ONE,
74 };
75 
76 /* Dark blue, color of the window's right half. */
77 static const GLfloat right_color_float[4] = {0, 0, 0.5, 1};
78 static const GLfixed right_colors_fixed[] = {
79 	0, 0, HALF, ONE,
80 	0, 0, HALF, ONE,
81 	0, 0, HALF, ONE,
82 	0, 0, HALF, ONE,
83 };
84 
85 enum piglit_result
piglit_display(void)86 piglit_display(void)
87 {
88 	bool pass = true;
89 
90 	glClearColor(0, 0, 0, 1);
91 	glClear(GL_COLOR_BUFFER_BIT);
92 
93 	glEnableClientState(GL_VERTEX_ARRAY);
94 	glEnableClientState(GL_COLOR_ARRAY);
95 
96 	/* Paint the window's left half. */
97 	glVertexPointer(2, GL_FIXED, 0, left_vertices);
98 	glColorPointer(4, GL_FIXED, 0, left_colors_fixed);
99 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
100 
101 	/* Paint the window's right half.*/
102 	glVertexPointer(2, GL_FIXED, 0, right_vertices);
103 	glColorPointer(4, GL_FIXED, 0, right_colors_fixed);
104 	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
105 
106 	/* Probe the window's left half. */
107 	pass &= piglit_probe_rect_rgba(
108 			0, 0,
109 			piglit_width / 2, piglit_height / 2,
110 			left_color_float);
111 
112 	/* Probe the window's right half. */
113 	pass &= piglit_probe_rect_rgba(
114 			(piglit_width + 1) / 2, (piglit_height + 1) / 2,
115 			(piglit_width - 1) / 2,  (piglit_height - 1) / 2,
116 			right_color_float);
117 
118 	piglit_present_results();
119 
120 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
121 }
122 
123 void
piglit_init(int argc,char ** argv)124 piglit_init(int argc, char **argv)
125 {
126 	piglit_require_extension("GL_OES_fixed_point");
127 }
128