1 /*
2  * Copyright (c) 2010 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 DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 /**
25  * @file gl30basic.c
26  *
27  * Test basic GL 3.0 features.
28  *
29  * Author:
30  *    Brian Paul
31  */
32 
33 
34 #include "piglit-util-gl.h"
35 
36 PIGLIT_GL_TEST_CONFIG_BEGIN
37 
38 	config.supports_gl_compat_version = 10;
39 
40 	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH | PIGLIT_GL_VISUAL_STENCIL;
41 
42 	config.requires_displayed_window = true;
43 
44 PIGLIT_GL_TEST_CONFIG_END
45 
46 static const char *Prog = "gl30basic";
47 
48 
49 
50 static enum piglit_result
test_version(void)51 test_version(void)
52 {
53    const GLubyte *version = glGetString(GL_VERSION);
54    GLuint iversion;
55    GLint major, minor, k;
56 
57    piglit_require_gl_version(30);
58 
59    major = version[0] - '0';
60    minor = version[2] - '0';
61 
62    iversion = major * 10 + minor;
63 
64    if (iversion < 30) {
65       return PIGLIT_SKIP;
66    }
67 
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;
72    }
73 
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;
78    }
79 
80    return PIGLIT_PASS;
81 }
82 
83 
84 static enum piglit_result
test_extension_list(void)85 test_extension_list(void)
86 {
87    GLint k, num_ext;
88 
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;
93    }
94 
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);
100 
101       /* In some drivers WGL_EXT_swap_control is in the extension string
102        * for historical reasons.
103        */
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;
108       }
109       if (strchr((char *) ext, ' ')) {
110          printf("%s: extension string [%d] contains a space: %s\n", Prog, k, ext);
111          return PIGLIT_FAIL;
112       }
113    }
114 
115    return PIGLIT_PASS;
116 }
117 
118 
119 enum piglit_result
test_clearing(void)120 test_clearing(void)
121 {
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;
127 
128    while (glGetError() != GL_NO_ERROR)
129       ;
130 
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;
138    }
139 
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;
144    }
145 
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;
153    }
154 
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;
159    }
160 
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;
168    }
169 
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;
174    }
175 
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;
180    }
181 
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;
188    }
189 
190    if (!piglit_probe_rect_depth(0, 0, piglit_width, piglit_height, 0.5)) {
191       printf("  from glClearBufferfi() failed.\n");
192       pass = GL_FALSE;
193    }
194 
195    if (!piglit_probe_rect_stencil(0, 0, piglit_width, piglit_height, 3)) {
196       printf("  from glClearBufferfi() failed.\n");
197       pass = GL_FALSE;
198    }
199 
200    return pass ? PIGLIT_PASS : PIGLIT_FAIL;
201 }
202 
203 
204 enum piglit_result
piglit_display(void)205 piglit_display(void)
206 {
207    enum piglit_result res;
208 
209    res = test_version();
210    if (res != PIGLIT_PASS)
211       return res;
212 
213    res = test_extension_list();
214    if (res != PIGLIT_PASS)
215       return res;
216 
217    res = test_clearing();
218    if (res != PIGLIT_PASS)
219       return res;
220 
221    return res;
222 }
223 
224 
225 
piglit_init(int argc,char ** argv)226 void piglit_init(int argc, char**argv)
227 {
228 }
229