summaryrefslogtreecommitdiff
path: root/tests/spec/gl-1.0/rendermode-feedback.c
blob: 0f64881f20c63c219dd8a6b4ba6fc6b127b573a1 (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
/* Copyright © 2011 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.
 */

#include "piglit-util-gl.h"

/**
 * @file rendermode-feedback.c
 *
 * Tests that glRenderMode(GL_FEEDBACK) rendering trivially works.
 */

static float vertex_array[] = {
	1.0, 2.0, 0.4, 1.0,
	3.0, 4.0, 0.6, 1.0,
	5.0, 6.0, 0.8, 1.0,
};

static float color_array[] = {
	0.01, 0.02, 0.03, 0.04,
	0.05, 0.06, 0.07, 0.08,
	0.09, 0.10, 0.11, 0.12,
};

static float texcoord_array[] = {
	101.0, 102.0, 103.0, 104.0,
	105.0, 106.0, 107.0, 108.0,
	109.0, 110.0, 111.0, 112.0,
};

static const float gl_2d_values[] =
	{GL_POLYGON_TOKEN, 3,
	 1.0, 2.0,
	 3.0, 4.0,
	 5.0, 6.0};

static const float gl_3d_values[] =
	{GL_POLYGON_TOKEN, 3,
	 1.0, 2.0, 0.3,
	 3.0, 4.0, 0.2,
	 5.0, 6.0, 0.1};

static const float gl_3d_color_values[] =
	{GL_POLYGON_TOKEN, 3,
	 1.0, 2.0, 0.3, 0.01, 0.02, 0.03, 0.04,
	 3.0, 4.0, 0.2, 0.05, 0.06, 0.07, 0.08,
	 5.0, 6.0, 0.1, 0.09, 0.10, 0.11, 0.12};

static const float gl_3d_color_texture_values[] =
	{GL_POLYGON_TOKEN, 3,
	 1.0, 2.0, 0.3, 0.01, 0.02, 0.03, 0.04, 101.0, 102.0, 103.0, 104.0,
	 3.0, 4.0, 0.2, 0.05, 0.06, 0.07, 0.08, 105.0, 106.0, 107.0, 108.0,
	 5.0, 6.0, 0.1, 0.09, 0.10, 0.11, 0.12, 109.0, 110.0, 111.0, 112.0};

static const float gl_4d_color_texture_values[] =
	{GL_POLYGON_TOKEN, 3,
	 1.0, 2.0, 0.3, 1.0, 0.01, 0.02, 0.03, 0.04, 101.0, 102.0, 103.0, 104.0,
	 3.0, 4.0, 0.2, 1.0, 0.05, 0.06, 0.07, 0.08, 105.0, 106.0, 107.0, 108.0,
	 5.0, 6.0, 0.1, 1.0, 0.09, 0.10, 0.11, 0.12, 109.0, 110.0, 111.0, 112.0};

struct type {
	GLenum type;
	const float *values;
	int count;
} types[] = {
	{ GL_2D, gl_2d_values, ARRAY_SIZE(gl_2d_values) },

	{ GL_3D, gl_3d_values, ARRAY_SIZE(gl_3d_values) },

	{ GL_3D_COLOR, gl_3d_color_values, ARRAY_SIZE(gl_3d_color_values) },

	{ GL_3D_COLOR_TEXTURE, gl_3d_color_texture_values,
	  ARRAY_SIZE(gl_3d_color_texture_values) },

	{ GL_4D_COLOR_TEXTURE, gl_4d_color_texture_values,
	  ARRAY_SIZE(gl_4d_color_texture_values) },
};

static enum piglit_result run_subtest(void * data);
static const struct piglit_gl_test_config * piglit_config;

PIGLIT_GL_TEST_CONFIG_BEGIN

	piglit_config = &config;

	struct piglit_subtest tests[ARRAY_SIZE(types) + 1] = { 0 };
	for (unsigned i = 0; i < ARRAY_SIZE(types); ++i) {
		tests[i].name = piglit_get_gl_enum_name(types[i].type);
		tests[i].option = tests[i].name;
		tests[i].subtest_func = run_subtest;
		tests[i].data = (void *)&types[i];
	}
	config.subtests = tests;

	config.supports_gl_compat_version = 10;

	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
	config.khr_no_error_support = PIGLIT_NO_ERRORS;

PIGLIT_GL_TEST_CONFIG_END

static void
report_failure(struct type *type, float *buffer, int count)
{
	int i;

	fprintf(stderr, "Feeback failed for %s:\n",
		piglit_get_gl_enum_name(type->type));

	fprintf(stderr, "  Expected:    Observed: (%d/%d)\n",
		count, type->count);
	for (i = 0; i < types->count; i++) {
		fprintf(stderr, "  %9f    %9f\n", type->values[i], buffer[i]);
	}
	fprintf(stderr, "\n");
}

static enum piglit_result
run_subtest(void * data) {
	struct type * type = (struct type *)data;
	bool case_pass = true;
	int returned_count, j;
	const char *name = piglit_get_gl_enum_name(type->type);
	float buffer[2 +
		     ARRAY_SIZE(vertex_array) +
		     ARRAY_SIZE(color_array) +
		     ARRAY_SIZE(texcoord_array)];

	printf("Testing %s\n", name);

	for (j = 0; j < ARRAY_SIZE(buffer); j++)
		buffer[j] = -1.0;

	glFeedbackBuffer(ARRAY_SIZE(buffer), type->type, buffer);
	glRenderMode(GL_FEEDBACK);
	glDrawArrays(GL_TRIANGLES, 0, 4);
	returned_count = glRenderMode(GL_RENDER);

	if (returned_count != type->count) {
		case_pass = false;
	} else {
		for (j = 0; j < type->count; j++) {
			if (fabs(buffer[j] - type->values[j]) > .01)
				case_pass = false;
		}
	}

	if (!case_pass) {
		report_failure(type, buffer, returned_count);
	}
	return case_pass ? PIGLIT_PASS : PIGLIT_FAIL;
}

enum piglit_result
piglit_display(void)
{
	enum piglit_result result = PIGLIT_PASS;

	piglit_ortho_projection(piglit_width, piglit_height, false);

	glClearColor(0.0, 1.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glVertexPointer(4, GL_FLOAT, 0, vertex_array);
	glColorPointer(4, GL_FLOAT, 0, color_array);
	glTexCoordPointer(4, GL_FLOAT, 0, texcoord_array);
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	result = piglit_run_selected_subtests(
		piglit_config->subtests,
		piglit_config->selected_subtests,
		piglit_config->num_selected_subtests,
		result);

	piglit_present_results();

	return result;
}

void
piglit_init(int argc, char **argv)
{
	piglit_require_extension("GL_EXT_vertex_array");
}