glx-multithread-texture: Avoid front-buffer rendering.
[piglit.git] / tests / shaders / fp-fog.c
blob77efb392764c222306cf17d3649ba1aa3e9501df
1 /*
2 * Copyright © 2008 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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file
26 * Test passing fog coordinates into a fragment program.
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util-gl.h"
33 static GLint prog = 0;
35 static const char* const program_text =
36 "!!ARBfp1.0\n"
37 "MOV result.color, fragment.fogcoord;\n"
38 "END\n"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_compat_version = 10;
45 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
47 PIGLIT_GL_TEST_CONFIG_END
49 static PFNGLFOGCOORDFPROC pglFogCoordf = NULL;
51 enum piglit_result
52 piglit_display(void)
54 static const struct {
55 float x, y, r;
57 probes[4] = {
58 { 0.5, 1.5, 0.3 },
59 { 1.5, 1.5, 0.6 },
60 { 0.5, 0.5, 0.8 },
61 { 1.5, 0.5, 0.4 },
63 int pass = 1;
64 unsigned i;
66 piglit_ortho_projection(2.0, 2.0, GL_FALSE);
68 glClear(GL_COLOR_BUFFER_BIT);
70 pglFogCoordf(0.3);
71 glBegin(GL_QUADS);
72 glVertex2f(0, 1);
73 glVertex2f(1, 1);
74 glVertex2f(1, 2);
75 glVertex2f(0, 2);
76 glEnd();
78 pglFogCoordf(0.6);
79 glBegin(GL_QUADS);
80 glVertex2f(1, 1);
81 glVertex2f(2, 1);
82 glVertex2f(2, 2);
83 glVertex2f(1, 2);
84 glEnd();
86 pglFogCoordf(0.8);
87 glBegin(GL_QUADS);
88 glVertex2f(0, 0);
89 glVertex2f(1, 0);
90 glVertex2f(1, 1);
91 glVertex2f(0, 1);
92 glEnd();
94 pglFogCoordf(0.4);
95 glBegin(GL_QUADS);
96 glVertex2f(1, 0);
97 glVertex2f(2, 0);
98 glVertex2f(2, 1);
99 glVertex2f(1, 1);
100 glEnd();
102 for (i = 0; i < 4; i++) {
103 float expected_color[4];
105 expected_color[0] = probes[i].r;
106 expected_color[1] = 0.0;
107 expected_color[2] = 0.0;
108 expected_color[3] = 1.0;
110 pass &= piglit_probe_pixel_rgba(probes[i].x * piglit_width / 2,
111 probes[i].y * piglit_height / 2,
112 expected_color);
115 piglit_present_results();
117 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
120 void
121 piglit_init(int argc, char **argv)
123 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
125 glClearColor(0.3, 0.3, 0.3, 0.3);
127 if (piglit_get_gl_version() >= 14) {
128 pglFogCoordf = glFogCoordf;
129 } else if (piglit_is_extension_supported("GL_EXT_fog_coord")) {
130 pglFogCoordf = glFogCoordfEXT;
131 } else {
132 piglit_report_result(PIGLIT_SKIP);
135 piglit_require_fragment_program();
136 prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, program_text);
138 glEnable(GL_FRAGMENT_PROGRAM_ARB);
139 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
141 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);