summaryrefslogtreecommitdiff
path: root/tests/spec/arb_color_buffer_float/render.c
blob: 3160f89b6e0429a738d19f3a32bd11201f2c846c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * Copyright © 2010 Luca Barbieri
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 */

/** @file spec/arb_color_buffer_float/render.c
 *
 * Tests that vertex and fragment color clamping affects rendering as
 * specified by ARB_color_buffer_float.
 *
 * It also checks that fog, blending and logic op are done as specified by
 * ARB_color_buffer_float.
 *
 * Note that it's unclear what should happen when ARB_fog is specified in
 * the fragment program and fragment clamping is disabled: does the
 * color still get clamped before applying fog?
 *
 * Both ATI and nVidia do that, but they have fixed function fog in the tested
 * cards.
 * TODO: what happens on GeForce 8xxx, GTX 2xx and GTX 4xx?
 */

#include "common.h"

const char *blend_strings[] = { "disabled", "(ONE, ZERO)", "(CONSTANT_COLOR, ZERO)", "(ONE, ONE)" };
GLenum blend_src[] = { 0, GL_ONE, GL_CONSTANT_COLOR, GL_ONE };
GLenum blend_dst[] = { 0, GL_ZERO, GL_ZERO, GL_ONE };

const char *vp_strings[] = {
	"!!ARBvp1.0\n"
	"MOV result.position, vertex.position;\n"
	"MOV result.color, {7, -2.75, -0.25, 0.75};\n" "END\n",

	"!!ARBvp1.0\n"
	"MOV result.position, vertex.position;\n"
	"MOV result.texcoord[0], {7, -2.75, -0.25, 0.75};\n" "END\n"
};

const char *fp_strings[] = {
	"!!ARBfp1.0\n"
	"MOV result.color, fragment.color;\n"
	"END\n",

	"!!ARBfp1.0\n"
	"MOV result.color, fragment.texcoord[0];\n"
	"END\n",

	"!!ARBfp1.0\n"
	"OPTION ARB_fog_linear;\n"
	"MOV result.color, fragment.color;\n"
	"END\n",

	"!!ARBfp1.0\n"
	"OPTION ARB_fog_linear;\n"
	"MOV result.color, fragment.texcoord[0];\n"
	"END\n",
};

unsigned vps[2];
unsigned fps[4];

GLboolean test()
{
	GLboolean pass = GL_TRUE;
	unsigned semantic, blend, logicop, vpmode, fpmode, fog;
	unsigned vpmodes = 1 + !!GLEW_ARB_vertex_program;
	unsigned fpmodes = 1 + !!GLEW_ARB_fragment_program;
	glFogi(GL_FOG_MODE, GL_LINEAR);

	for(vert_clamp = 0; vert_clamp < 3; ++vert_clamp)
	for(frag_clamp = 0; frag_clamp < 3; ++frag_clamp)
	for(semantic = 0; semantic < 2; ++semantic)
	for(blend = 0; blend < 4; ++blend)
	for(logicop = 0; logicop < 2; ++logicop)
	for(vpmode = 0; vpmode < vpmodes; ++vpmode)
	for(fpmode = 0; fpmode < fpmodes; ++fpmode)
	for(fog = 0; fog < 2; ++fog)
	{
		unsigned clamped = (semantic == 0 && (clamp_enums[vert_clamp] == GL_TRUE || (clamp_enums[vert_clamp] == GL_FIXED_ONLY_ARB && fixed))) || clamp_enums[frag_clamp] == GL_TRUE || (clamp_enums[frag_clamp] == GL_FIXED_ONLY_ARB && fixed);
		float *expected;
		GLboolean cpass;
		GLboolean opass;

		if(!fpmode && semantic)
			continue;

		sprintf(test_name, "%s: render constant through %s with vertex clamp %s and fragment clamp %s and blending %s and logicop %s using %s and %s%s (expecting %sclamping)", format_name, semantic ? "TEXCOORD0" : "COLOR", clamp_strings[vert_clamp], clamp_strings[frag_clamp], blend_strings[blend], logicop ? "enabled" : "disabled", vpmode ? "ARB_vp" : "ffvp", fpmode ? "ARB_fp" : "fffp", fog ? " with fog" : "", clamped ? "" : "no ");
		printf("%s\n", test_name);
		glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, clamp_enums[vert_clamp]);
		glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, clamp_enums[frag_clamp]);

		glColor4f(0.1f, 0.2f, 0.3f, 0.4f);
		glTexCoord4f(0.5f, 0.6f, 0.7f, 0.8f);

		if(vpmode)
		{
			glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vps[semantic]);
			glEnable(GL_VERTEX_PROGRAM_ARB);
		}
		else
		{
			if(semantic == 0)
				glColor4f(pixels[0], pixels[1], pixels[2], pixels[3]);
			else
				glTexCoord4f(pixels[0], pixels[1], pixels[2], pixels[3]);
		}

		if(fpmode)
		{
			glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fps[semantic + (fog ? 2 : 0)]);
			glEnable(GL_FRAGMENT_PROGRAM_ARB);
		}
		else
		{
			if(fog)
				glEnable(GL_FOG);
		}

		glClearColor(0.5, 0.5, 0.5, 0.5);
		glClear(GL_COLOR_BUFFER_BIT);

		if(blend)
		{
			glEnable(GL_BLEND);
			glBlendFunc(blend_src[blend], blend_dst[blend]);
			glBlendColor(2.0f, 2.0f, 2.0f, 2.0f);
		}
		if(logicop)
			glEnable(GL_COLOR_LOGIC_OP);

		piglit_draw_rect(-1, -1, 1, 1);

		if(logicop)
			glDisable(GL_COLOR_LOGIC_OP);
		if(blend)
			glDisable(GL_BLEND);
		if(vpmode)
			glDisable(GL_VERTEX_PROGRAM_ARB);
		if(fpmode)
			glDisable(GL_FRAGMENT_PROGRAM_ARB);
		else if(fog)
			glDisable(GL_FOG);

		if(blend == 2 && !logicop)
		{
			if(fixed)
				expected = clamped_pixels;
			else
				expected = clamped ? clamped_pixels_mul_2 : pixels_mul_2;
		}
		else if(blend == 3 && !logicop)
		{
			if(fixed)
				expected = clamped_pixels_plus_half_clamped;
			else
				expected = clamped ? clamped_pixels_plus_half : pixels_plus_half;
		}
		else
			expected = (clamped || fixed) ? clamped_pixels : pixels;

		opass = cpass = piglit_probe_pixel_rgba(0, 0, expected);

		if(!cpass && nvidia_driver && clamped && !(semantic == 0 && clamp_enums[vert_clamp] == GL_TRUE) && clamp_enums[frag_clamp] == GL_TRUE && !fixed && fpmode && (!blend || logicop || format == GL_RGBA16F_ARB))
		{
			printf("nVidia driver known *** MAJOR BUG ***: they don't clamp fragment program results with ARB_fp on either fp32 with no blending or fp16!\n");
			opass = GL_TRUE;
		}
		if(!cpass && nvidia_driver && clamped && !fixed && !fpmode && semantic == 0 && clamp_enums[vert_clamp] != GL_TRUE && clamp_enums[frag_clamp] == GL_TRUE)
		{
			printf("nVidia driver known *** MAJOR BUG ***: they don't clamp fragment program results with fffp, vertex clamp off and fragment clamp on fp16/fp32!\n");
			opass = GL_TRUE;
		}
		if(!cpass && fog && fpmode)
		{
			printf("Unclear specification on GL_ARB_fog_*\n");
			opass = GL_TRUE;
		}
		printf("%s: %s\n", (cpass ? "PASS" : (opass ? "XFAIL" : "FAIL")), test_name);
		pass = opass && pass;
	}

	return pass;
}

unsigned
init()
{
	if(GLEW_ARB_vertex_program)
	{
		unsigned i;
		for(i = 0; i < 2; ++i)
			vps[i] = piglit_compile_program(GL_VERTEX_PROGRAM_ARB, vp_strings[i]);
	}

	if(GLEW_ARB_fragment_program)
	{
		unsigned i;
		for(i = 0; i < 4; ++i)
			fps[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, fp_strings[i]);
	}

	return TEST_SRT;
}