ext_framebuffer_object: setup max mipmap level to make fbo complete
[piglit.git] / tests / spec / gl-1.0 / bitmap-heart-dance.c
blobd133e213bf6fcb9897b83681d5b8d16ea8a8a7f5
1 /*
2 * Copyright (C) 2018 Laura Ekstrand
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
13 * Software.
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.
24 /**
25 * Test glBitmap in a methodical way using a series of heart shapes.
26 * Heart shape is diagram A.2 from Garnstudio free sock pattern Heart Dance
27 * (https://www.garnstudio.com/pattern.php?id=7440&cid=17).
28 * Knitting color work is basically glBitmap for knits!
30 * _ * _ _ _ * _ _ where _ = 0
31 * * * * _ * * * _ * = 1
32 * * * * * * * * _
33 * * * * * * * * _
34 * _ * * * * * _ _
35 * _ _ * * * _ _ _
36 * _ _ _ * _ _ _ _
37 * _ _ _ _ _ _ _ _
39 * Or: Little end Big end
40 * 0 1 0 0 0 1 0 0 68 0x44 0x22
41 * 1 1 1 0 1 1 1 0 238 0xEE 0x77
42 * 1 1 1 1 1 1 1 0 254 0xFE 0xF7
43 * 1 1 1 1 1 1 1 0 254 0xFE 0xF7
44 * 0 1 1 1 1 1 0 0 124 0x7C 0xE3
45 * 0 0 1 1 1 0 0 0 56 0x38 0xC2
46 * 0 0 0 1 0 0 0 0 16 0x10 0x80
47 * 0 0 0 0 0 0 0 0 0 0x00 0x00
49 * Laura Ekstrand
50 * March 2018
53 #include "piglit-util-gl.h"
55 PIGLIT_GL_TEST_CONFIG_BEGIN
56 config.supports_gl_compat_version = 10;
57 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE |
58 PIGLIT_GL_VISUAL_RGBA;
59 config.window_width = 340;
60 config.window_height = 200;
61 config.khr_no_error_support = PIGLIT_NO_ERRORS;
62 PIGLIT_GL_TEST_CONFIG_END
64 static const float red[4] = {0.502, 0.082, 0.082, 1.0};
65 static const float salmon[4] = {1.000, 0.353, 0.353, 1.0};
66 static const float pink[4] = {0.945, 0.471, 0.639, 1.0};
67 static const float orange[4] = {1.000, 0.286, 0.000, 1.0};
68 static const float ltorange[4] = {1.000, 0.514, 0.322, 1.0};
69 static const float yellow[4] = {1.000, 0.871, 0.133, 1.0};
70 static GLubyte bitmap[8] = { 0x00, 0x10, 0x38, 0x7C,
71 0xFE, 0xFE, 0xEE, 0x44 };
73 static const char *fragShaderText =
74 "#version 130 \n"
75 "uniform vec4 red; \n"
76 "uniform vec4 salmon; \n"
77 "uniform vec4 pink; \n"
78 "uniform vec4 orange; \n"
79 "uniform vec4 ltorange; \n"
80 "uniform vec4 yellow; \n"
81 "uniform int xorig; \n"
82 "uniform int yorig; \n"
83 "uniform int length; \n"
84 "uniform int ysp; \n"
85 "uniform int height; \n"
86 "uniform int heart[8]; \n"
87 "\n"
88 "void main() \n"
89 "{ \n"
90 " float zoom = 1.0; \n"
91 " vec4 black = vec4(0.0, 0.0, 0.0, 1.0); \n"
92 " int xsp = ysp + 8; // Must be > 8. \n"
93 " vec2 fragCoord = gl_FragCoord.xy; \n"
94 " if ((fragCoord.x < xorig) || (fragCoord.y < height + yorig) ||\n"
95 " (fragCoord.x > xorig + ((length - 1) * xsp) + 8) || \n"
96 " (fragCoord.y > height + yorig + (5*ysp) + 8)) { \n"
97 " gl_FragColor = black; \n"
98 " return; \n"
99 " } \n"
100 " fragCoord = fragCoord/zoom; \n"
101 " int i = int(fragCoord.y - yorig - height) % ysp; \n"
102 " int pointmask = i < 8 ? heart[i] : 0; \n"
103 " int j = int(fragCoord.x - xorig) % xsp; \n"
104 " if (j > 8) { \n"
105 " j = 0; \n"
106 " } \n"
107 " for (int r = 0; r < j; r++) { \n"
108 " pointmask = pointmask/2; //left shift. \n"
109 " } \n"
110 " if (pointmask % 2 == 1) { \n"
111 " int c = (int(fragCoord.y - height - yorig) / ysp) % 6; \n"
112 " switch (c) { \n"
113 " case 0: \n"
114 " gl_FragColor = yellow; \n"
115 " break; \n"
116 " case 1: \n"
117 " gl_FragColor = ltorange; \n"
118 " break; \n"
119 " case 2: \n"
120 " gl_FragColor = orange; \n"
121 " break; \n"
122 " case 3: \n"
123 " gl_FragColor = pink; \n"
124 " break; \n"
125 " case 4: \n"
126 " gl_FragColor = salmon; \n"
127 " break; \n"
128 " case 5: \n"
129 " gl_FragColor = red; \n"
130 " break; \n"
131 " } \n"
132 " } else { \n"
133 " gl_FragColor = black; \n"
134 " } \n"
135 "} \n";
138 static void
139 draw_row(const float* color, int length,
140 int x, int y, int spacex) {
141 glColor4fv(color);
142 glRasterPos2f(x, y);
143 for (int i = 0; i < length; i++) {
144 /* A line of hearts. */
145 glBitmap(8, 8, 0, 0, 8 + spacex, 0, bitmap);
149 static bool
150 check_row(const float *color, int length, int x, int y, int spacex)
152 bool pass = true;
153 for (int i = 0; i < length; i++) {
154 int probe_x = x + 8 + spacex + 4;
155 int probe_y = y + 4;
156 pass &= piglit_probe_pixel_rgb(probe_x, probe_y, color);
158 return pass;
161 static GLuint fragShader, program;
163 enum piglit_result
164 piglit_display(void)
166 /* Draw with glBitmap */
167 bool pass = true;
168 int length = 17;
169 int x = 20;
170 int y = 30;
171 int spacing = 10;
173 glUseProgram(0);
175 glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
176 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
178 glViewport(0, 0, piglit_width, piglit_height);
179 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
181 glClear(GL_COLOR_BUFFER_BIT);
182 draw_row( red, length, x, y + 5*spacing, spacing);
183 draw_row( salmon, length, x, y + 4*spacing, spacing);
184 draw_row( pink, length, x, y + 3*spacing, spacing);
185 draw_row( orange, length, x, y + 2*spacing, spacing);
186 draw_row(ltorange, length, x, y + 1*spacing, spacing);
187 draw_row( yellow, length, x, y + 0*spacing, spacing);
189 glUseProgram(program);
192 * Upload heart pattern. glBitmap is a bit mysterious in its bit
193 * interpretation, and GLSL doesn't have ubyte.
195 int heart[8];
196 for (int i = 0; i < 8; i++) {
197 heart[i] = (int) bitmap[i];
199 glUniform1iv(glGetUniformLocation(program, "heart"), 8, heart);
201 /* Load Colors. */
202 glUniform4fv(glGetUniformLocation(program, "red"), 1, red);
203 glUniform4fv(glGetUniformLocation(program, "salmon"), 1, salmon);
204 glUniform4fv(glGetUniformLocation(program, "pink"), 1, pink);
205 glUniform4fv(glGetUniformLocation(program, "orange"), 1, orange);
206 glUniform4fv(glGetUniformLocation(program, "ltorange"), 1, ltorange);
207 glUniform4fv(glGetUniformLocation(program, "yellow"), 1, yellow);
209 /* Load spacing. */
210 glUniform1i(glGetUniformLocation(program, "xorig"), x);
211 glUniform1i(glGetUniformLocation(program, "yorig"), y);
212 glUniform1i(glGetUniformLocation(program, "length"), length);
213 glUniform1i(glGetUniformLocation(program, "ysp"), spacing);
215 /* Draw shader in top half. */
216 glUniform1i(glGetUniformLocation(program, "height"), piglit_height/2);
217 piglit_draw_rect(0, piglit_height/2, piglit_width, piglit_height/2);
219 piglit_present_results();
221 pass &= check_row( red, length, x, y + 5*spacing, spacing);
222 pass &= check_row( salmon, length, x, y + 4*spacing, spacing);
223 pass &= check_row( pink, length, x, y + 3*spacing, spacing);
224 pass &= check_row( orange, length, x, y + 2*spacing, spacing);
225 pass &= check_row(ltorange, length, x, y + 1*spacing, spacing);
226 pass &= check_row( yellow, length, x, y + 0*spacing, spacing);
228 pass &= piglit_probe_rects_equal(0, 0, 0, piglit_height/2,
229 piglit_width, piglit_height/2, GL_RGB);
231 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
234 void
235 piglit_init(int argc, char **argv)
237 fragShader = piglit_compile_shader_text(GL_FRAGMENT_SHADER,
238 fragShaderText);
239 program = piglit_link_simple_program(0, fragShader);