glsl-1.30: add more loop unroll tests
[piglit.git] / tests / general / gl30basic.c
blobcb85a9143a31c07713ee6bfd321e8737554f28d7
1 /*
2 * Copyright (c) 2010 VMware, Inc.
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 * @file gl30basic.c
27 * Test basic GL 3.0 features.
29 * Author:
30 * Brian Paul
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_compat_version = 10;
40 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH | PIGLIT_GL_VISUAL_STENCIL;
42 config.requires_displayed_window = true;
44 PIGLIT_GL_TEST_CONFIG_END
46 static const char *Prog = "gl30basic";
50 static enum piglit_result
51 test_version(void)
53 const GLubyte *version = glGetString(GL_VERSION);
54 GLuint iversion;
55 GLint major, minor, k;
57 piglit_require_gl_version(30);
59 major = version[0] - '0';
60 minor = version[2] - '0';
62 iversion = major * 10 + minor;
64 if (iversion < 30) {
65 return PIGLIT_SKIP;
68 glGetIntegerv(GL_MAJOR_VERSION, &k);
69 if (k != major) {
70 printf("%s: major version mismatch (%d vs. %d)\n", Prog, k, major);
71 return PIGLIT_FAIL;
74 glGetIntegerv(GL_MINOR_VERSION, &k);
75 if (k != minor) {
76 printf("%s: minor version mismatch (%d vs. %d)\n", Prog, k, minor);
77 return PIGLIT_FAIL;
80 return PIGLIT_PASS;
84 static enum piglit_result
85 test_extension_list(void)
87 GLint k, num_ext;
89 glGetIntegerv(GL_NUM_EXTENSIONS, &num_ext);
90 if (num_ext < 1 || num_ext > 10000) {
91 printf("%s: unreasonable value for GL_NUM_EXTENSIONS: %d\n", Prog, num_ext);
92 return PIGLIT_FAIL;
95 /* check that extension strings are reasonable */
96 for (k = 0; k < num_ext; k++) {
97 const char *ext = (const char *) glGetStringi(GL_EXTENSIONS, k);
98 if (0)
99 printf("Ext[%d] = %s\n", k, ext);
101 /* In some drivers WGL_EXT_swap_control is in the extension string
102 * for historical reasons.
104 if (!ext || (strncmp(ext, "GL_", 3) != 0 &&
105 strcmp(ext, "WGL_EXT_swap_control") != 0)){
106 printf("%s: bad extension string [%d]: %s\n", Prog, k, ext);
107 return PIGLIT_FAIL;
109 if (strchr((char *) ext, ' ')) {
110 printf("%s: extension string [%d] contains a space: %s\n", Prog, k, ext);
111 return PIGLIT_FAIL;
115 return PIGLIT_PASS;
119 enum piglit_result
120 test_clearing(void)
122 static const GLfloat purple[] = {1.0, 0.0, 1.0};
123 static const GLfloat blue[] = {0.0, 0.0, 1.0};
124 static const GLfloat green[] = {0.0, 1.0, 0.0};
125 GLenum err;
126 GLboolean pass = GL_TRUE;
128 while (glGetError() != GL_NO_ERROR)
131 /* Front buffer. */
132 glDrawBuffer(GL_FRONT);
133 glClearBufferfv(GL_COLOR, 0, purple);
134 err = glGetError();
135 if (err) {
136 printf("%s: glClearBufferfv(GL_FRONT) generated error 0x%x.\n", Prog, err);
137 return PIGLIT_FAIL;
140 glReadBuffer(GL_FRONT);
141 if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, purple)) {
142 printf(" from glClearBufferfv(GL_FRONT) failed.\n");
143 pass = GL_FALSE;
146 /* Back buffer. */
147 glDrawBuffer(GL_BACK);
148 glClearBufferfv(GL_COLOR, 0, blue);
149 err = glGetError();
150 if (err) {
151 printf("%s: glClearBufferfv(GL_BACK) generated error 0x%x.\n", Prog, err);
152 return PIGLIT_FAIL;
155 glReadBuffer(GL_BACK);
156 if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, blue)) {
157 printf(" from glClearBufferfv(GL_BACK) failed.\n");
158 pass = GL_FALSE;
161 /* Front and back buffer. */
162 glDrawBuffer(GL_FRONT_AND_BACK);
163 glClearBufferfv(GL_COLOR, 0, green);
164 err = glGetError();
165 if (err) {
166 printf("%s: glClearBufferfv(GL_FRONT_AND_BACK) generated error 0x%x.\n", Prog, err);
167 return PIGLIT_FAIL;
170 glReadBuffer(GL_FRONT);
171 if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, green)) {
172 printf(" the front buffer from glClearBufferfv(GL_FRONT_AND_BACK) failed.\n");
173 pass = GL_FALSE;
176 glReadBuffer(GL_BACK);
177 if (!piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, green)) {
178 printf(" the back buffer from glClearBufferfv(GL_FRONT_AND_BACK) failed.\n");
179 pass = GL_FALSE;
182 /* Depth & Stencil */
183 glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5, 3);
184 err = glGetError();
185 if (err) {
186 printf("%s: glClearBufferfi() generated error 0x%x.\n", Prog, err);
187 return PIGLIT_FAIL;
190 if (!piglit_probe_rect_depth(0, 0, piglit_width, piglit_height, 0.5)) {
191 printf(" from glClearBufferfi() failed.\n");
192 pass = GL_FALSE;
195 if (!piglit_probe_rect_stencil(0, 0, piglit_width, piglit_height, 3)) {
196 printf(" from glClearBufferfi() failed.\n");
197 pass = GL_FALSE;
200 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
204 enum piglit_result
205 piglit_display(void)
207 enum piglit_result res;
209 res = test_version();
210 if (res != PIGLIT_PASS)
211 return res;
213 res = test_extension_list();
214 if (res != PIGLIT_PASS)
215 return res;
217 res = test_clearing();
218 if (res != PIGLIT_PASS)
219 return res;
221 return res;
226 void piglit_init(int argc, char**argv)