fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / ext_texture_integer / texture-integer-glsl130.c
blob70d7ed4eb73d9aa1089814075168f76ef234139e
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
25 /**
26 * @file
27 * Tests GL_EXT_texture_integer texture formats.
28 * simpler test modified for GLSL1.30 by airlied
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_compat_version = 10;
37 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
38 config.khr_no_error_support = PIGLIT_NO_ERRORS;
40 PIGLIT_GL_TEST_CONFIG_END
42 static const char *TestName = "texture-integer";
44 static GLint TexWidth = 16, TexHeight = 16;
45 static GLuint Texture;
47 static GLint BiasUniform[4] = {-1, -1, -1, -1}, TexUniform[4] = {-1, -1, -1, -1};
49 static bool has_glsl_130;
50 static bool has_gpu_shader4;
52 struct format_info
54 GLenum IntFormat, BaseFormat;
55 GLuint BitsPerChannel;
56 GLboolean Signed;
59 static const struct format_info Formats[] = {
60 /* { "GL_RGBA", GL_RGBA, GL_RGBA, 8, GL_FALSE },*/
61 { GL_RGBA8I_EXT, GL_RGBA_INTEGER_EXT, 8, GL_TRUE },
62 { GL_RGBA8UI_EXT , GL_RGBA_INTEGER_EXT, 8, GL_FALSE },
63 { GL_RGBA16I_EXT, GL_RGBA_INTEGER_EXT, 16, GL_TRUE },
64 { GL_RGBA16UI_EXT, GL_RGBA_INTEGER_EXT, 16, GL_FALSE },
65 { GL_RGBA32I_EXT, GL_RGBA_INTEGER_EXT, 32, GL_TRUE },
66 { GL_RGBA32UI_EXT, GL_RGBA_INTEGER_EXT, 32, GL_FALSE },
68 { GL_RGBA8I_EXT, GL_BGRA_INTEGER_EXT, 8, GL_TRUE },
69 { GL_RGBA8UI_EXT , GL_BGRA_INTEGER_EXT, 8, GL_FALSE },
70 { GL_RGBA16I_EXT, GL_BGRA_INTEGER_EXT, 16, GL_TRUE },
71 { GL_RGBA16UI_EXT, GL_BGRA_INTEGER_EXT, 16, GL_FALSE },
72 { GL_RGBA32I_EXT, GL_BGRA_INTEGER_EXT, 32, GL_TRUE },
73 { GL_RGBA32UI_EXT, GL_BGRA_INTEGER_EXT, 32, GL_FALSE },
75 { GL_RGB8I_EXT, GL_RGB_INTEGER_EXT, 8, GL_TRUE },
76 { GL_RGB8UI_EXT , GL_RGB_INTEGER_EXT, 8, GL_FALSE },
77 { GL_RGB16I_EXT, GL_RGB_INTEGER_EXT, 16, GL_TRUE },
78 { GL_RGB16UI_EXT, GL_RGB_INTEGER_EXT, 16, GL_FALSE },
79 { GL_RGB32I_EXT, GL_RGB_INTEGER_EXT, 32, GL_TRUE },
80 { GL_RGB32UI_EXT, GL_RGB_INTEGER_EXT, 32, GL_FALSE },
82 { GL_ALPHA8I_EXT, GL_ALPHA_INTEGER_EXT, 8, GL_TRUE },
83 { GL_ALPHA8UI_EXT , GL_ALPHA_INTEGER_EXT, 8, GL_FALSE },
84 { GL_ALPHA16I_EXT, GL_ALPHA_INTEGER_EXT, 16, GL_TRUE },
85 { GL_ALPHA16UI_EXT, GL_ALPHA_INTEGER_EXT, 16, GL_FALSE },
86 { GL_ALPHA32I_EXT, GL_ALPHA_INTEGER_EXT, 32, GL_TRUE },
87 { GL_ALPHA32UI_EXT, GL_ALPHA_INTEGER_EXT, 32, GL_FALSE },
89 { GL_LUMINANCE8I_EXT, GL_LUMINANCE_INTEGER_EXT, 8, GL_TRUE },
90 { GL_LUMINANCE8UI_EXT , GL_LUMINANCE_INTEGER_EXT, 8, GL_FALSE },
91 { GL_LUMINANCE16I_EXT, GL_LUMINANCE_INTEGER_EXT, 16, GL_TRUE },
92 { GL_LUMINANCE16UI_EXT, GL_LUMINANCE_INTEGER_EXT, 16, GL_FALSE },
93 { GL_LUMINANCE32I_EXT, GL_LUMINANCE_INTEGER_EXT, 32, GL_TRUE },
94 { GL_LUMINANCE32UI_EXT, GL_LUMINANCE_INTEGER_EXT, 32, GL_FALSE },
96 { GL_LUMINANCE_ALPHA8I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 8, GL_TRUE },
97 { GL_LUMINANCE_ALPHA8UI_EXT , GL_LUMINANCE_ALPHA_INTEGER_EXT, 8, GL_FALSE },
98 { GL_LUMINANCE_ALPHA16I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 16, GL_TRUE },
99 { GL_LUMINANCE_ALPHA16UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 16, GL_FALSE },
100 { GL_LUMINANCE_ALPHA32I_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 32, GL_TRUE },
101 { GL_LUMINANCE_ALPHA32UI_EXT, GL_LUMINANCE_ALPHA_INTEGER_EXT, 32, GL_FALSE },
103 { GL_INTENSITY8I_EXT, GL_RED_INTEGER_EXT, 8, GL_TRUE },
104 { GL_INTENSITY8UI_EXT , GL_RED_INTEGER_EXT, 8, GL_FALSE },
105 { GL_INTENSITY16I_EXT, GL_RED_INTEGER_EXT, 16, GL_TRUE },
106 { GL_INTENSITY16UI_EXT, GL_RED_INTEGER_EXT, 16, GL_FALSE },
107 { GL_INTENSITY32I_EXT, GL_RED_INTEGER_EXT, 32, GL_TRUE },
108 { GL_INTENSITY32UI_EXT, GL_RED_INTEGER_EXT, 32, GL_FALSE },
112 static const struct format_info rg_formats[] = {
113 { GL_RG8I, GL_RG_INTEGER, 8, GL_TRUE },
114 { GL_RG8UI , GL_RG_INTEGER, 8, GL_FALSE },
115 { GL_RG16I, GL_RG_INTEGER, 16, GL_TRUE },
116 { GL_RG16UI, GL_RG_INTEGER, 16, GL_FALSE },
117 { GL_RG32I, GL_RG_INTEGER, 32, GL_TRUE },
118 { GL_RG32UI, GL_RG_INTEGER, 32, GL_FALSE },
119 { GL_R8I, GL_RED_INTEGER, 8, GL_TRUE },
120 { GL_R8UI , GL_RED_INTEGER, 8, GL_FALSE },
121 { GL_R16I, GL_RED_INTEGER, 16, GL_TRUE },
122 { GL_R16UI, GL_RED_INTEGER, 16, GL_FALSE },
123 { GL_R32I, GL_RED_INTEGER, 32, GL_TRUE },
124 { GL_R32UI, GL_RED_INTEGER, 32, GL_FALSE },
127 /* the rgb10 formats overload the Signed TRUE/FALSE member to test
128 * the _REV and non-REV component ordering.
130 static const struct format_info rgb10_formats[] = {
131 { GL_RGB10_A2UI, GL_RGBA_INTEGER_EXT, 10, GL_FALSE },
132 { GL_RGB10_A2UI, GL_BGRA_INTEGER_EXT, 10, GL_FALSE },
133 { GL_RGB10_A2UI, GL_RGBA_INTEGER_EXT, 10, GL_TRUE },
134 { GL_RGB10_A2UI, GL_BGRA_INTEGER_EXT, 10, GL_TRUE },
137 /* The programs will be indexed by whether the texture is signed or not. */
138 static const char *FragShaderText[4] = {
139 "#version 130\n"
140 "uniform vec4 bias; \n"
141 "uniform usampler2D tex; \n"
142 "void main() \n"
143 "{ \n"
144 " vec4 t = vec4(texture(tex, gl_TexCoord[0].xy)); \n"
145 " gl_FragColor = t + bias; \n"
146 "} \n",
148 "#version 130\n"
149 "uniform vec4 bias; \n"
150 "uniform isampler2D tex; \n"
151 "void main() \n"
152 "{ \n"
153 " vec4 t = vec4(texture(tex, gl_TexCoord[0].xy)); \n"
154 " gl_FragColor = t + bias; \n"
155 "} \n",
157 "#extension GL_EXT_gpu_shader4 : require\n"
158 "uniform vec4 bias; \n"
159 "uniform usampler2D tex; \n"
160 "void main() \n"
161 "{ \n"
162 " vec4 t = vec4(texture2D(tex, gl_TexCoord[0].xy)); \n"
163 " gl_FragColor = t + bias; \n"
164 "} \n",
166 "#extension GL_EXT_gpu_shader4 : require\n"
167 "uniform vec4 bias; \n"
168 "uniform isampler2D tex; \n"
169 "void main() \n"
170 "{ \n"
171 " vec4 t = vec4(texture2D(tex, gl_TexCoord[0].xy)); \n"
172 " gl_FragColor = t + bias; \n"
173 "} \n",
176 static GLuint Program[4];
178 static int
179 get_max_val(const struct format_info *info)
181 int max;
183 switch (info->BitsPerChannel) {
184 case 8:
185 if (info->Signed)
186 max = 127;
187 else
188 max = 255;
189 break;
190 case 10:
191 max = 1023;
192 break;
193 case 16:
194 if (info->Signed)
195 max = 32767;
196 else
197 max = 65535;
198 break;
199 case 32:
200 if (info->Signed)
201 max = 10*1000; /* don't use 0x8fffffff to avoid overflow issues */
202 else
203 max = 20*1000;
204 break;
205 default:
206 assert(0);
207 max = 0;
210 return max;
214 static int
215 num_components(GLenum format)
217 switch (format) {
218 case GL_RGBA:
219 case GL_RGBA_INTEGER_EXT:
220 case GL_BGRA_INTEGER_EXT:
221 return 4;
222 case GL_RGB_INTEGER_EXT:
223 return 3;
224 case GL_RG_INTEGER:
225 return 2;
226 case GL_ALPHA_INTEGER_EXT:
227 return 1;
228 case GL_LUMINANCE_INTEGER_EXT:
229 return 1;
230 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
231 return 2;
232 case GL_RED_INTEGER_EXT:
233 return 1;
234 default:
235 assert(0);
236 return 0;
241 static void
242 fill_array(int comps, int texels, void *buf, int bpp, const int val[4])
244 int i, j;
246 switch (bpp) {
247 case 8:
249 GLubyte *b = (GLubyte *) buf;
250 for (i = 0; i < texels; i++) {
251 for (j = 0; j < comps; j++) {
252 b[i * comps + j] = val[j];
256 break;
257 case 16:
259 GLushort *b = (GLushort *) buf;
260 for (i = 0; i < texels; i++) {
261 for (j = 0; j < comps; j++) {
262 b[i * comps + j] = val[j];
266 break;
267 case 32:
269 GLuint *b = (GLuint *) buf;
270 for (i = 0; i < texels; i++) {
271 for (j = 0; j < comps; j++) {
272 b[i * comps + j] = val[j];
276 break;
277 default:
278 assert(0);
282 static void
283 fill_array_rgb10(int comps, int texels, void *buf, int type,
284 const int val[4])
286 int i;
287 GLuint *b = (GLuint *)buf;
289 if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
290 for (i = 0; i < texels; i++) {
291 b[i] = (val[0] & 0x3ff) << 0 |
292 (val[1] & 0x3ff) << 10 |
293 (val[2] & 0x3ff) << 20 |
294 (val[3] & 0x3) << 30;
296 } else if (type == GL_UNSIGNED_INT_10_10_10_2) {
297 for (i = 0; i < texels; i++) {
298 b[i] = (val[3] & 0x3) << 0 |
299 (val[2] & 0x3ff) << 2 |
300 (val[1] & 0x3ff) << 12 |
301 (val[0] & 0x3ff) << 22;
306 static GLenum
307 get_datatype(const struct format_info *info)
309 switch (info->BitsPerChannel) {
310 case 8:
311 return info->Signed ? GL_BYTE : GL_UNSIGNED_BYTE;
312 case 10:
313 return info->Signed ? GL_UNSIGNED_INT_10_10_10_2 : GL_UNSIGNED_INT_2_10_10_10_REV;
314 case 16:
315 return info->Signed ? GL_SHORT : GL_UNSIGNED_SHORT;
316 case 32:
317 return info->Signed ? GL_INT : GL_UNSIGNED_INT;
318 default:
319 assert(0);
320 return 0;
325 static GLboolean
326 check_error(const char *file, int line)
328 GLenum err = glGetError();
329 if (err) {
330 fprintf(stderr, "%s: error 0x%x at %s:%d\n",
331 TestName, err, file, line);
332 return GL_TRUE;
334 return GL_FALSE;
338 /** \return GL_TRUE for pass, GL_FALSE for fail */
339 static GLboolean
340 test_format(const struct format_info *info, int shader_base)
342 const int max = get_max_val(info);
343 const int comps = num_components(info->BaseFormat);
344 const int texels = TexWidth * TexHeight;
345 const GLenum type = get_datatype(info);
346 const int w = piglit_width / 10;
347 const int h = piglit_height / 10;
348 const float error = 2.0 / 255.0; /* XXX fix */
349 GLfloat expected[4];
350 void *buf;
351 int value[4];
352 GLfloat result[4], bias[4];
353 GLint f;
354 GLfloat temp;
356 const char *suffix;
357 char *name;
358 if (info->IntFormat == GL_RGB10_A2UI) {
359 if (info->BaseFormat == GL_BGRA_INTEGER) {
360 if (info->Signed)
361 suffix = " (rev bgra)";
362 else
363 suffix = " (bgra)";
364 } else {
365 if (info->Signed)
366 suffix = " (rev)";
367 else
368 suffix = "";
370 } else if (info->BaseFormat == GL_BGRA_INTEGER)
371 suffix = " (bgra)";
372 else
373 suffix = "";
374 asprintf(&name, "%s%s:\n", piglit_get_gl_enum_name(info->IntFormat), suffix);
376 /* pick random texture color */
377 value[0] = rand() % max;
378 value[1] = rand() % max;
379 value[2] = rand() % max;
380 value[3] = rand() % max;
382 /* alloc, fill texture image */
383 if (info->BitsPerChannel == 10) {
384 value[3] = rand() % 3;
385 buf = malloc(texels * 4);
386 fill_array_rgb10(comps, texels, buf, type, value);
387 } else {
388 buf = malloc(comps * texels * info->BitsPerChannel / 8);
389 fill_array(comps, texels, buf, info->BitsPerChannel, value);
392 glTexImage2D(GL_TEXTURE_2D, 0, info->IntFormat, TexWidth, TexHeight, 0,
393 info->BaseFormat, type, buf);
395 if (check_error(__FILE__, __LINE__)) {
396 free(buf);
397 free(name);
398 return GL_FALSE;
401 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT,
402 &f);
404 assert(f == info->IntFormat);
407 /* setup expected polygon color */
408 expected[0] = 0.25;
409 expected[1] = 0.50;
410 expected[2] = 0.75;
411 expected[3] = 1.00;
413 /* Need to swizzle things depending on texture format.
415 * Also, for texture formats with no storage for a particular
416 * channel, instead of reading the randomly-chosen value
417 * above, we need to expect to read a 0, (for Green or Blue
418 * channels), or a 1 (for Alpha).
420 * Note: The alpha value read is an integer 1, not a
421 * maximum-valued integer representing 1.0.
423 switch (info->BaseFormat) {
424 case GL_RGBA_INTEGER_EXT:
425 /* nothing */
426 break;
427 case GL_BGRA_INTEGER_EXT:
428 /* swap 0 and 2 */
429 temp = expected[2];
430 expected[2] = expected[0];
431 expected[0] = temp;
432 temp = value[2];
433 value[2] = value[0];
434 value[0] = temp;
435 break;
436 case GL_RGB_INTEGER_EXT:
437 value[3] = 1;
438 break;
439 case GL_RG_INTEGER:
440 value[2] = 0;
441 value[3] = 1;
442 break;
443 case GL_ALPHA_INTEGER_EXT:
444 expected[0] = expected[1] = expected[2] = 0.0;
445 expected[3] = 0.25;
446 value[3] = value[0];
447 break;
448 case GL_LUMINANCE_INTEGER_EXT:
449 expected[0] = expected[1] = expected[2] = 0.25;
450 expected[3] = 1.0;
451 value[1] = value[2] = value[0];
452 value[3] = 1.0;
453 break;
454 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
455 expected[0] = expected[1] = expected[2] = 0.25;
456 value[3] = value[1];
457 value[1] = value[2] = value[0];
458 break;
459 case GL_RED_INTEGER_EXT:
460 if (info->IntFormat == GL_INTENSITY8I_EXT ||
461 info->IntFormat == GL_INTENSITY8UI_EXT ||
462 info->IntFormat == GL_INTENSITY16I_EXT ||
463 info->IntFormat == GL_INTENSITY16UI_EXT ||
464 info->IntFormat == GL_INTENSITY32I_EXT ||
465 info->IntFormat == GL_INTENSITY32UI_EXT) {
466 expected[0] = expected[1] = expected[2] = expected[3] = 0.25;
467 value[1] = value[2] = value[3] = value[0];
468 } else {
469 value[1] = value[2] = 0;
470 value[3] = 1;
472 break;
473 default:
477 glUseProgram(Program[shader_base + info->Signed]);
479 /* compute, set test bias */
480 bias[0] = expected[0] - value[0];
481 bias[1] = expected[1] - value[1];
482 bias[2] = expected[2] - value[2];
483 bias[3] = expected[3] - value[3];
484 glUniform4fv(BiasUniform[shader_base + info->Signed], 1, bias);
486 /* draw */
487 glClearColor(0, 1, 1, 0);
488 glClear(GL_COLOR_BUFFER_BIT);
489 glBegin(GL_POLYGON);
490 glTexCoord2f(0, 0); glVertex2f(0, 0);
491 glTexCoord2f(1, 0); glVertex2f(w, 0);
492 glTexCoord2f(1, 1); glVertex2f(w, h);
493 glTexCoord2f(0, 1); glVertex2f(0, h);
494 glEnd();
496 if (check_error(__FILE__, __LINE__)) {
497 free(buf);
498 free(name);
499 return GL_FALSE;
502 /* test */
503 glReadPixels(w/2, h/2, 1, 1, GL_RGBA, GL_FLOAT, result);
505 if (check_error(__FILE__, __LINE__)) {
506 free(buf);
507 free(name);
508 return GL_FALSE;
511 if (fabsf(result[0] - expected[0]) > error ||
512 fabsf(result[1] - expected[1]) > error ||
513 fabsf(result[2] - expected[2]) > error ||
514 fabsf(result[3] - expected[3]) > error) {
515 fprintf(stderr, "%s: failure with format %s:\n",
516 TestName, name);
517 fprintf(stderr, " texture color = %d, %d, %d, %d\n",
518 value[0], value[1], value[2], value[3]);
519 fprintf(stderr, " expected color = %g, %g, %g, %g\n",
520 expected[0], expected[1], expected[2], expected[3]);
521 fprintf(stderr, " result color = %g, %g, %g, %g\n",
522 result[0], result[1], result[2], result[3]);
523 free(buf);
524 free(name);
525 return GL_FALSE;
528 piglit_present_results();
530 free(buf);
531 free(name);
533 return GL_TRUE;
537 static GLboolean
538 test_general_formats(int shader_base)
540 int f, i;
542 for (f = 0; f < ARRAY_SIZE(Formats); f++) {
543 for (i = 0; i < 5; i++) {
544 if (!test_format(&Formats[f], shader_base))
545 return GL_FALSE;
549 if (piglit_is_extension_supported("GL_ARB_texture_rg")) {
550 for (f = 0; f < ARRAY_SIZE(rg_formats); f++) {
551 for (i = 0; i < 5; i++) {
552 if (!test_format(&rg_formats[f], shader_base))
553 return GL_FALSE;
558 if (piglit_is_extension_supported("GL_ARB_texture_rgb10_a2ui")) {
559 for (f = 0; f < ARRAY_SIZE(rgb10_formats); f++) {
560 for (i = 0; i < 5; i++) {
561 if (!test_format(&rgb10_formats[f], shader_base))
562 return GL_FALSE;
566 return GL_TRUE;
570 static GLboolean
571 test_specific_formats(void)
573 /* These format combinations should all work */
574 struct {
575 GLenum intFormat, srcFormat, srcType;
576 } formats[] = {
577 { GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE },
578 { GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_SHORT },
579 { GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8 },
580 { GL_RGBA8UI_EXT, GL_BGRA_INTEGER, GL_UNSIGNED_INT_8_8_8_8 },
581 { GL_LUMINANCE8I_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8 },
582 { GL_RGB16I_EXT, GL_RGB_INTEGER, GL_UNSIGNED_SHORT_5_6_5 },
583 { GL_RGB32I_EXT, GL_RGB_INTEGER, GL_UNSIGNED_SHORT_5_6_5 }
585 int i;
586 GLenum err;
587 GLboolean pass = GL_TRUE;
589 while (glGetError() != GL_NO_ERROR)
592 /* All of the packed formats require GL_ARB_texture_rgb10_a2ui.
594 if (!piglit_is_extension_supported("GL_ARB_texture_rgb10_a2ui")) {
595 return GL_TRUE;
598 for (i = 0; i < ARRAY_SIZE(formats); i++) {
599 glTexImage2D(GL_TEXTURE_2D, 0, formats[i].intFormat,
600 16, 16, 0,
601 formats[i].srcFormat, formats[i].srcType, NULL);
602 err = glGetError();
603 if (err != GL_NO_ERROR) {
604 fprintf(stderr, "%s failure: glTexImage2D(0x%x, 0x%x, 0x%x) generated"
605 " error 0x%x (case %d)\n",
606 TestName, formats[i].intFormat,
607 formats[i].srcFormat, formats[i].srcType, err, i);
608 pass = GL_FALSE;
612 return pass;
615 enum piglit_result
616 piglit_display(void)
618 if (has_glsl_130) {
619 if (!test_general_formats(0))
620 return PIGLIT_FAIL;
623 if (has_gpu_shader4) {
624 if (!test_general_formats(2))
625 return PIGLIT_FAIL;
628 if (!test_specific_formats())
629 return PIGLIT_FAIL;
631 return PIGLIT_PASS;
635 void
636 piglit_init(int argc, char **argv)
638 int i;
639 int major, minor;
641 has_gpu_shader4 = piglit_is_extension_supported("GL_EXT_gpu_shader4");
642 piglit_get_glsl_version(NULL, &major, &minor);
643 has_glsl_130 = (major * 100 + minor) >= 130;
644 /* Check if EXT_gpu_shader4 is supported */
645 if (!has_gpu_shader4) {
646 /* If EXT_gpu_shader4 is not supported GL version must be 3.0 */
647 piglit_require_gl_version(30);
648 piglit_require_GLSL_version(130);
651 for (i = 0; i < 4; i++) {
652 if ((i == 0 || i == 1) && !has_glsl_130)
653 continue;
654 if ((i == 2 || i == 3) && !has_gpu_shader4)
655 continue;
656 Program[i] = piglit_build_simple_program(NULL,
657 FragShaderText[i]);
658 BiasUniform[i] = glGetUniformLocation(Program[i], "bias");
659 TexUniform[i] = glGetUniformLocation(Program[i], "tex");
662 (void) check_error(__FILE__, __LINE__);
664 glGenTextures(1, &Texture);
665 glBindTexture(GL_TEXTURE_2D, Texture);
666 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
667 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
669 (void) check_error(__FILE__, __LINE__);
671 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);