2 * Copyright © 2009 Intel Corporation
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
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.
26 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_width
= 250;
38 config
.window_height
= 250;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DEPTH
;
41 PIGLIT_GL_TEST_CONFIG_END
44 unix_line_endings(const char *input
, size_t length
)
46 char *output
= malloc(length
+ 1);
50 for (i
= 0; i
< length
; i
++) {
51 if ((input
[i
] == 0x0D) && (input
[i
+ 1] == 0x0A)) {
67 dos_line_endings(const char *input
, size_t length
)
72 size_t new_length
= length
;
75 for (i
= 0; i
< length
; i
++) {
76 if (input
[i
] == 0x0A) {
81 output
= malloc(new_length
+ 1);
82 for (i
= 0; i
< length
; i
++) {
83 if ((input
[i
] == 0x0D) && (input
[i
+ 1] == 0x0A)) {
88 } else if (input
[i
] == 0x0A) {
104 compile(const char *filename
, GLenum target
, int use_ARB
)
112 char *converted_buffers
[2];
113 size_t buffer_sizes
[2];
117 if (!piglit_automatic
) {
118 printf("%s:\n", filename
);
121 buf
= piglit_load_text_file(filename
, &sz
);
123 fprintf(stderr
, "Failed to open %s\n", filename
);
124 piglit_report_result(PIGLIT_FAIL
);
128 /* Scan the program source looking for two different things. First,
129 * look for comments of the form '# FAIL'. This signals that the
130 * program is expected to fail compilation. Second, look for comments
131 * of the form '# REQUIRE GL_XXX_xxxx_xxxx'. This signals that the
132 * program will only compile if some OpenGL extension is available.
134 expected_fail
= (strstr(buf
, "# FAIL") != NULL
);
137 while (ptr
!= NULL
) {
138 ptr
= strstr(ptr
, "# REQUIRE ");
143 ptr
+= strlen("# REQUIRE ");
145 for (i
= 0; !isspace((int) ptr
[i
]) && (ptr
[i
] != '\0'); i
++) {
146 extension
[i
] = ptr
[i
];
150 piglit_require_extension(extension
);
155 converted_buffers
[0] = unix_line_endings(buf
, sz
);
156 buffer_sizes
[0] = strlen(converted_buffers
[0]);
157 converted_buffers
[1] = dos_line_endings(buf
, sz
);
158 buffer_sizes
[1] = strlen(converted_buffers
[1]);
162 glGenProgramsARB(2, prognum
);
164 glGenProgramsNV(2, prognum
);
168 for (i
= 0; i
< 2; i
++) {
169 /* The use_ARB flag is used instead of the target because
170 * GL_VERTEX_PROGRAM_ARB and GL_VERTEX_PROGRAM_NV have the same
174 glBindProgramARB(target
, prognum
[i
]);
175 glProgramStringARB(target
, GL_PROGRAM_FORMAT_ASCII_ARB
,
177 (const GLubyte
*) converted_buffers
[i
]);
179 glBindProgramNV(target
, prognum
[i
]);
180 glLoadProgramNV(target
, prognum
[i
],
182 (const GLubyte
*) converted_buffers
[i
]);
187 if (err
!= GL_NO_ERROR
) {
190 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorpos
);
191 if (!piglit_automatic
) {
192 printf("glGetError = 0x%04x\n", err
);
193 printf("errorpos: %d\n", errorpos
);
195 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
199 if ((err
== GL_NO_ERROR
) != (expected_fail
== FALSE
)) {
200 piglit_report_result(PIGLIT_FAIL
);
205 free(converted_buffers
[0]);
206 free(converted_buffers
[1]);
212 piglit_init(int argc
, char **argv
)
220 piglit_report_result(PIGLIT_FAIL
);
225 if (strcmp(argv
[1], "ARBvp1.0") == 0) {
226 target
= GL_VERTEX_PROGRAM_ARB
;
227 piglit_require_extension("GL_ARB_vertex_program");
228 } else if (strcmp(argv
[1], "ARBfp1.0") == 0) {
229 target
= GL_FRAGMENT_PROGRAM_ARB
;
230 piglit_require_extension("GL_ARB_fragment_program");
231 } else if (strcmp(argv
[1], "NVvp1.0") == 0) {
232 target
= GL_VERTEX_PROGRAM_NV
;
233 piglit_require_extension("GL_NV_vertex_program");
235 } else if (strcmp(argv
[1], "NVfp1.0") == 0) {
236 target
= GL_FRAGMENT_PROGRAM_NV
;
237 piglit_require_extension("GL_NV_fragment_program");
241 piglit_report_result(PIGLIT_FAIL
);
244 for (i
= 2; i
< argc
; i
++) {
245 compile(argv
[i
], target
, use_ARB
);
248 piglit_report_result(PIGLIT_PASS
);
254 /* Should never be reached */