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
|
/*
* 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.
*/
/**
* \file max-clip-distances.c
*
* From the GLSL 1.30 spec, section 7.4 (Built-In Constants):
*
* "The following built-in constants are provided to vertex and
* fragment shaders. The actual values used are implementation
* dependent, but must be at least the value shown.
*
* ...
*
* const int gl_MaxClipDistances = 8;
*
* ...
*
* const int gl_MaxClipPlanes = 8; // deprecated"
*
* And from the GL 3.0 spec, section N.3 (Changed Tokens):
*
* "New token names are introduced to be used in place of old,
* inconsistent names. However, the old token names continue to be
* supported, for backwards compatibility with code written for
* previous versions of OpenGL.
*
* ...
*
* New Token Name Old Token Name
* ...
* MAX_CLIP_DISTANCES MAX_CLIP_PLANES
*
* This test verifies that glGetIntegerv() returns the same result for
* the tokens MAX_CLIP_DISTANCES and MAX_CLIP_PLANES, that this value
* matches the value of gl_MaxClipDistances and gl_MaxClipPlanes
* defined in the vertex and fragment shaders, and that this value is
* at least 8.
*/
#include "piglit-util-gl-common.h"
PIGLIT_GL_TEST_MAIN(
100 /*window_width*/,
100 /*window_height*/,
PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE)
static const char vert[] =
"#version 130\n"
"uniform int expected_value;\n"
"uniform bool test_distances;\n"
"uniform bool test_in_vs;\n"
"void main()\n"
"{\n"
" gl_Position = gl_Vertex;\n"
" if (test_in_vs) {\n"
" int value = test_distances ? gl_MaxClipDistances\n"
" : gl_MaxClipPlanes;\n"
" gl_FrontColor = (value == expected_value)\n"
" ? vec4(0.0, 1.0, 0.0, 1.0)\n"
" : vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
"}\n";
static const char frag[] =
"#version 130\n"
"uniform int expected_value;\n"
"uniform bool test_distances;\n"
"uniform bool test_in_vs;\n"
"void main()\n"
"{\n"
" if (test_in_vs) {\n"
" gl_FragColor = gl_Color;\n"
" } else {\n"
" int value = test_distances ? gl_MaxClipDistances\n"
" : gl_MaxClipPlanes;\n"
" gl_FragColor = (value == expected_value)\n"
" ? vec4(0.0, 1.0, 0.0, 1.0)\n"
" : vec4(1.0, 0.0, 0.0, 1.0);\n"
" }\n"
"}\n";
GLuint prog;
enum piglit_result
piglit_display(void)
{
GLint max_clip_planes, max_clip_distances, expected_value;
GLint test_distances, test_in_vs;
float green[] = { 0.0, 1.0, 0.0, 1.0 };
GLint loc;
enum piglit_result result = PIGLIT_PASS;
glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes);
printf("GL_MAX_CLIP_PLANES = %d\n", max_clip_planes);
glGetIntegerv(GL_MAX_CLIP_DISTANCES, &max_clip_distances);
printf("GL_MAX_CLIP_DISTANCES = %d\n", max_clip_distances);
if (max_clip_planes != max_clip_distances) {
printf("GL_MAX_CLIP_PLANES != GL_MAX_CLIP_DISTANCES\n");
piglit_report_result(PIGLIT_FAIL);
}
if (max_clip_distances < 8) {
printf("GL_MAX_CLIP_DISTANCES < 8\n");
piglit_report_result(PIGLIT_FAIL);
}
expected_value = max_clip_distances;
loc = piglit_GetUniformLocation(prog, "expected_value");
piglit_Uniform1i(loc, expected_value);
for (test_distances = 0; test_distances <= 1; ++test_distances) {
loc = piglit_GetUniformLocation(prog, "test_distances");
piglit_Uniform1i(loc, test_distances);
for (test_in_vs = 0; test_in_vs <= 1; ++test_in_vs) {
bool pass;
loc = piglit_GetUniformLocation(prog, "test_in_vs");
piglit_Uniform1i(loc, test_in_vs);
piglit_draw_rect(-1, -1, 2, 2);
pass = piglit_probe_rect_rgba(0, 0, piglit_width,
piglit_height, green);
printf("Checking that gl_MaxClip%s == %d in %s: %s\n",
test_distances ? "Distances" : "Planes",
expected_value,
test_in_vs ? "VS" : "FS",
pass ? "pass" : "fail");
if (!pass) {
result = PIGLIT_FAIL;
}
}
}
return result;
}
void
piglit_init(int argc, char **argv)
{
GLuint vs;
GLuint fs;
piglit_require_GLSL();
piglit_require_GLSL_version(130);
vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vert);
fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, frag);
prog = piglit_CreateProgram();
piglit_AttachShader(prog, vs);
piglit_AttachShader(prog, fs);
piglit_LinkProgram(prog);
piglit_DeleteShader(vs);
piglit_DeleteShader(fs);
piglit_UseProgram(prog);
}
|