cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / glsl-vs-int-attrib.c
blobe50232c681a7a22962c05d7d41fef1ddce9237e4
1 /*
2 * Copyright (c) 2014 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
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 /** @file glsl-vs-int-attrib.c
26 * Tests that we can set an integer vertex attribute to a value that
27 * looks like a signalling NaN if it were interpreted as a float. If
28 * an implementation passes this through a floating point variable it
29 * might incorrectly get corrupted to a quiet NaN.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 20;
38 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
40 PIGLIT_GL_TEST_CONFIG_END
42 /* This value looks like a signalling NaN if it were interpreted as a
43 * float */
44 #define TEST_VALUE 0x7f817f81
46 #define STR(x) #x
47 #define STRINGIFY(x) STR(x)
49 static const char
50 vertex_source[] =
51 "#version 130\n"
52 "\n"
53 "attribute vec4 piglit_vertex;\n"
54 "attribute uint a_value;\n"
55 "\n"
56 "void\n"
57 "main()\n"
58 "{\n"
59 " if (a_value == " STRINGIFY(TEST_VALUE) "u)\n"
60 " gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
61 " else\n"
62 " gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
63 " gl_Position = piglit_vertex;\n"
64 "}\n";
66 static const float green[] = { 0.0f, 1.0f, 0.0f };
68 static bool
69 run_test(void)
71 GLuint prog;
72 GLint attrib;
73 bool pass;
75 prog = piglit_build_simple_program(vertex_source,
76 NULL /* fs_source */);
77 glUseProgram(prog);
79 attrib = glGetAttribLocation(prog, "a_value");
80 glVertexAttribI1ui(attrib, TEST_VALUE);
82 piglit_draw_rect(-1, -1, 2, 2);
83 pass = piglit_probe_pixel_rgb(0, 0, green);
85 glUseProgram(0);
86 glDeleteProgram(prog);
88 return pass;
91 void
92 piglit_init(int argc, char **argv)
94 bool pass;
96 /* We need to be able to call glVertexAttribI1ui */
97 if (piglit_get_gl_version() < 30
98 && !piglit_is_extension_supported("GL_EXT_gpu_shader4")) {
99 printf("OpenGL 3.0 or GL_EXT_gpu_shader4 is required.\n");
100 piglit_report_result(PIGLIT_SKIP);
103 piglit_require_GLSL_version(130);
105 pass = run_test();
107 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
110 enum piglit_result
111 piglit_display(void)
113 /* unused */
114 return PIGLIT_FAIL;