summaryrefslogtreecommitdiff
path: root/tests/shaders/fp-set-01.c
blob: e405bc3bce9a47a9a617789dca6c1c12199b93d3 (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
/*
 * Copyright © 2009 Intel Corporation
 *
 * 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 fp-set-01.c
 * Validate the two set-on instructions in GL_ARB_fragment_program
 *
 * \author Ian Romanick <ian.d.romanick@intel.com>
 */

#include "piglit-util.h"
#include "piglit-framework.h"

/* One column for each possible combination of set-on results
 */
#define TEST_COLS  16

/* One for the reference square and each of the 2 set-on instructions
 */
#define TEST_ROWS  3

#define BOX_SIZE   16

PIGLIT_GL_TEST_MAIN(
    (((BOX_SIZE+1)*TEST_COLS)+1) /*window_width*/,
    (((BOX_SIZE+1)*TEST_ROWS)+1) /*window_height*/,
    GLUT_DOUBLE)

/**
 * Source for the fragment program to render the reference box.
 */
static const char reference_shader_source[] =
	"!!ARBfp1.0\n"
	"MOV	result.color, program.env[0];\n"
	"END"
	;

static const char slt_shader_source[] =
	"!!ARBfp1.0\n"
	"SLT	result.color, program.env[1], fragment.color;\n"
	"END"
	;

static const char sge_shader_source[] =
	"!!ARBfp1.0\n"
	"SGE	result.color, fragment.color, program.env[1];\n"
	"END"
	;

/**
 * \name Handles to fragment programs.
 */
/*@{*/
static GLint reference_prog;
static GLint progs[2];
/*@}*/


enum piglit_result
piglit_display(void)
{
	const GLfloat comparitor[4] = { 0.5, 0.5, 0.5, 0.5 };
	unsigned i;
	unsigned j;
	enum piglit_result result = PIGLIT_PASS;


	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_FRAGMENT_PROGRAM_ARB);

	for (i = 0; i < TEST_COLS; i++) {
		const int x = (i * (BOX_SIZE + 1)) + 1;
		GLfloat color[4];

		color[0] = (i & 0x01) ? 1.0 : 0.0;
		color[1] = (i & 0x02) ? 1.0 : 0.0;
		color[2] = (i & 0x04) ? 1.0 : 0.0;
		color[3] = (i & 0x08) ? 1.0 : 0.0;

		glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, reference_prog);

		glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0,
					    color);
		glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1,
					    comparitor);

		piglit_draw_rect(x, 1, BOX_SIZE, BOX_SIZE);

		glColor4fv(color);

		for (j = 0; j < ARRAY_SIZE(progs); j++) {
			const int y = ((j + 1) * (BOX_SIZE + 1)) + 1;

			glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, progs[j]);
			piglit_draw_rect(x, y, BOX_SIZE, BOX_SIZE);

			if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
						    y + (BOX_SIZE / 2),
						    color)) {
				if (!piglit_automatic)
                                        printf("shader %u failed on index %u\n",
					       j, i);

				result = PIGLIT_FAIL;
			}
		}
	}

	glutSwapBuffers();
	return result;
}


void
piglit_init(int argc, char **argv)
{
	(void) argc;
	(void) argv;

	piglit_require_fragment_program();
	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	reference_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
						reference_shader_source);

	progs[0] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
					  slt_shader_source);
	progs[1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
					  sge_shader_source);

	glClearColor(1.0, 1.0, 1.0, 1.0);
}