1 /*
2 * Copyright 2015 VMware, Inc.
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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 /**
25 * Test drawing large points with a fragment shader.
26 * Brian Paul
27 * July 2015
28 */
29
30 #include "piglit-util-gl.h"
31
32 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config.supports_gl_compat_version = 20;
34 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
35 config.khr_no_error_support = PIGLIT_NO_ERRORS;
36 PIGLIT_GL_TEST_CONFIG_END
37
38
39 static const char *vertShaderText =
40 "#version 120 \n"
41 "uniform vec4 color_bias; \n"
42 "varying vec4 color_bias_varying; \n"
43 " \n"
44 "void main() \n"
45 "{ \n"
46 " gl_Position = ftransform(); \n"
47 " color_bias_varying = color_bias; \n"
48 " gl_FrontColor = gl_Color; \n"
49 "} \n";
50
51 static const char *fragShaderText =
52 "varying vec4 color_bias_varying; \n"
53 "uniform vec4 color_scale; \n"
54 "varying vec4 color;\n"
55 "void main()\n"
56 "{ \n"
57 " gl_FragColor = gl_Color * color_scale + color_bias_varying; \n"
58 "} \n";
59
60
61 static int color_scale_uniform, color_bias_uniform;
62
63
64 enum piglit_result
piglit_display(void)65 piglit_display(void)
66 {
67 const float colors[4][4] = {
68 { 0.5, 0, 1, 1 },
69 { 0, .5, 1, 1 },
70 { 0.0, 0, 0.5, 0.5 },
71 { 0.25, 0, 0.25, 0.25 }
72 };
73 const float scale[4] = { 2.0, 3.0, 0.0, 0.0 };
74 const float bias[4] = { 0, 0, 0.5, 0.5 };
75 float expected[4][4];
76 bool pass = true;
77 GLfloat size, probeSize;
78 int i;
79
80 /* compute expected colors */
81 for (i = 0; i < 4; i++) {
82 expected[i][0] = MIN2(1.0, colors[i][0] * scale[0] + bias[0]);
83 expected[i][1] = MIN2(1.0, colors[i][1] * scale[1] + bias[1]);
84 expected[i][2] = MIN2(1.0, colors[i][2] * scale[2] + bias[2]);
85 expected[i][3] = MIN2(1.0, colors[i][3] * scale[3] + bias[3]);
86 }
87
88 glGetFloatv(GL_POINT_SIZE_MAX, &size);
89 if (size < 3.0) {
90 /* legal, but unusual */
91 printf("Max point size is %g pixel(s)\n", size);
92 fflush(stdout);
93 return PIGLIT_SKIP;
94 }
95
96 size = MIN2(30, size);
97 probeSize = size - 2; /* to accomodate small rasterization errors */
98
99 glUniform4fv(color_scale_uniform, 1, scale);
100 glUniform4fv(color_bias_uniform, 1, bias);
101
102 glPointSize(size);
103
104 glMatrixMode(GL_PROJECTION);
105 glLoadIdentity();
106 glOrtho(0, piglit_width, 0, piglit_height, -1, 1);
107
108 glClear(GL_COLOR_BUFFER_BIT);
109
110 /* draw row of four lage points, each with different color */
111 glBegin(GL_POINTS);
112 for (i = 0; i < 4; i++) {
113 float x = size / 2 + i * size;
114 float y = size / 2;
115 glColor4fv(colors[i]);
116 glVertex2f(x, y);
117 }
118 glEnd();
119
120 /* check results */
121 for (i = 0; i < 4; i++) {
122 int x = i * size + 1;
123 int y = 1;
124
125 if (!piglit_probe_rect_rgba(x, y,
126 probeSize, probeSize, expected[i]))
127 pass = false;
128 }
129 piglit_present_results();
130
131 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
132 }
133
134
135 void
piglit_init(int argc,char ** argv)136 piglit_init(int argc, char **argv)
137 {
138 GLuint prog;
139
140 piglit_require_gl_version(20);
141
142 prog = piglit_build_simple_program(vertShaderText, fragShaderText);
143 if (!prog) {
144 printf("Failed to compile/link program\n");
145 piglit_report_result(PIGLIT_FAIL);
146 }
147
148 glUseProgram(prog);
149
150 color_bias_uniform = glGetUniformLocation(prog, "color_bias");
151 color_scale_uniform = glGetUniformLocation(prog, "color_scale");
152 }
153