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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
/**
* Copyright 2017 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 compare-framebuffer-parameter-with-get.
*
* OpenGL 4.5 spec introduced new valid pnames for
* GetFramebufferParameter. From OpenGL 4.5 spec, Section 9.2.3
* "Framebuffer Object Queries":
*
* "pname may also be one of DOUBLEBUFFER, IMPLEMENTATION_COLOR_-
* READ_FORMAT, IMPLEMENTATION_COLOR_READ_TYPE, SAMPLES,
* SAMPLE_BUFFERS, or STEREO, indicating the corresponding
* framebuffer-dependent state from table 23.73. Values of
* framebuffer-dependent state are identical to those that would be
* obtained were the framebuffer object bound and queried using the
* simple state queries in that table. These values may be queried
* from either a framebuffer object or a default framebuffer."
*
* That "simple state queries in that table" are either glGetBooleanv
* or glGetIntegerv.
*
* 4.5 also defines a new method, available on previous versions
* through the direct state access extension,
* GetNamedFramebufferParameteriv:
*
* "For GetFramebufferParameteriv, the framebuffer object is that
* bound to target"
*
* "For GetNamedFramebufferParameteriv, framebuffer may be zero,
* indicating the default draw framebuffer, or the name of the
* framebuffer object."
*
* So with the Named version, you can query the same info, but you can
* query for a framebuffer not bound at that moment.
*
* This test checks that the behaviour of GetFramebufferParameter,
* GetNamedFramebufferParameter and glGetX is the same for the bound
* framebuffer (default or user defined). Behaviour in the sense of
* same value returned or same error generated. For *Named* we will
* explicitly bound to a different framebuffer, to ensure that it
* works when the queried framebuffer is not bound at that moment.
*
* Note that we will not check if the error or the value is correct,
* just that are the same. Value and error correctness should be
* evaluated by other tests.
*
*/
#include "piglit-util-gl.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_core_version = 45;
config.window_visual = PIGLIT_GL_VISUAL_RGBA |
PIGLIT_GL_VISUAL_DOUBLE;
config.khr_no_error_support = PIGLIT_NO_ERRORS;
PIGLIT_GL_TEST_CONFIG_END
/*
* Values of table 23.73, defined on 4.5 spec, allowed on
* GetFramebufferParameteriv (so the full table minus SAMPLE_POSITION)
*/
static const GLenum table_23_73_allowed[] = {
GL_IMPLEMENTATION_COLOR_READ_FORMAT,
GL_IMPLEMENTATION_COLOR_READ_TYPE,
GL_DOUBLEBUFFER,
GL_STEREO,
GL_SAMPLE_BUFFERS,
GL_SAMPLES,
};
GLuint framebuffers[3];
bool filter_pname = false;
GLenum global_pname;
bool filter_framebuffer = false;
int global_framebuffer;
/*
* Returns if any of the table_23_73 enums is a boolean or not
*/
static bool
is_boolean(GLenum pname)
{
switch(pname) {
case GL_DOUBLEBUFFER:
case GL_STEREO:
return true;
default:
return false;
}
}
static void
print_usage()
{
printf("Usage: gl-4.5-compare-framebuffer-parameter-with-get <pname> <framebuffer>\n");
printf("\tpname: only test this pname from table 23.73 (minus "
"SAMPLE_POSITION) to use. Optional. \n");
printf("\tframebuffer: only test this framebuffer. Optional. Allowed values:\n "
"\t\t 0 (default framebuffer)\n"
"\t\t 1 (incomplete framebuffer)\n"
"\t\t 2 (complete framebuffer)\n");
}
static void
parse_args(int argc, char **argv)
{
int i;
bool found = false;
if (argc > 3) {
printf("Only two possible params supported\n");
goto bad_params;
}
if (argc == 1)
return;
filter_pname = true;
/* Note that this call will abort if the enum is not recognized */
global_pname = piglit_get_gl_enum_from_name(argv[1]);
for (i = 0; i < ARRAY_SIZE(table_23_73_allowed); i++) {
if (global_pname == table_23_73_allowed[i]) {
found = true;
break;
}
}
if (!found) {
printf("pname %s is not valid for this test\n", argv[1]);
goto bad_params;
}
if (argc == 2)
return;
filter_framebuffer = true;
global_framebuffer = atoi(argv[2]);
if (global_framebuffer < 0 || global_framebuffer > 2) {
printf("Wrong value for framebuffer: %i\n", global_framebuffer);
goto bad_params;
}
return;
bad_params:
print_usage();
piglit_report_result(PIGLIT_FAIL);
}
/*
* This method calls wraps glGetBooleanv and glGetInteger, as
* depending of the pname you will call one or the other. It also does
* the boolean to integer casting, as GetFramebufferParameteriv
* returns always int.
*/
static void
call_get_x(GLenum pname,
GLint *value,
GLenum *error)
{
if (is_boolean(pname)) {
GLboolean local_value;
glGetBooleanv(pname, &local_value);
*value = local_value;
} else {
GLint local_value;
glGetIntegerv(pname, &local_value);
*value = local_value;
}
*error = glGetError();
}
static const char*
get_framebuffer_name(int index)
{
switch(index) {
case 0:
return "default framebuffer";
case 1:
return "incomplete framebuffer";
case 2:
return "complete framebuffer";
default:
assert(!"unknown framebuffer");
return "unknown framebuffer";
}
}
/*
* Gets a framebuffer and attachs to it renderbuffer and other stuff,
* in order to ensure that it is a complete framebuffer.
*
* returns if it was successful.
*/
static bool
complete_framebuffer(GLint fb)
{
GLuint rb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glGenRenderbuffers(1, &rb);
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_R8, 1, 2);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
if (GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) &&
glGetError() == GL_NO_ERROR) {
return true;
} else {
return false;
}
}
/*
* We pass the index inside the array of available framebuffers,
* instead of the fb itself, because we also want to test binding with
* a different valid fb.
*/
static bool
execute_subtest(int index,
GLenum pname)
{
GLint get_value;
GLint parameter_value;
GLint named_value;
GLenum get_error;
GLenum parameter_error;
GLenum named_error;
bool subtest_pass;
GLuint fb;
GLuint other_fb;
fb = framebuffers[index];
other_fb = framebuffers[(index + 1) % ARRAY_SIZE(framebuffers)];
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glGetFramebufferParameteriv(GL_FRAMEBUFFER, pname, ¶meter_value);
parameter_error = glGetError();
/*
* We re-bind to a different (but valid) framebuffer, as we
* want to check that NamedFramebufferParameter gets the same
* value even if other framebuffer is bound.
*/
glBindFramebuffer(GL_FRAMEBUFFER, other_fb);
glGetNamedFramebufferParameteriv(fb, pname, &named_value);
named_error = glGetError();
glBindFramebuffer(GL_FRAMEBUFFER, fb);
call_get_x(pname, &get_value, &get_error);
subtest_pass = (get_error == parameter_error &&
get_value == parameter_value &&
parameter_error == named_error &&
parameter_value == named_value);
if (!subtest_pass) {
printf("Different behaviour for pname %s.\n\tGetBooleanv/Integerv"
" returns %i and generate the error %s.\n"
"\tGetFramebufferParameter returns %i and generate the "
"error %s.\n\tGetNamedFramebufferParameter returns %i "
"and generate the error %s\n",
piglit_get_gl_enum_name(pname),
get_value, piglit_get_gl_error_name(get_error),
parameter_value, piglit_get_gl_error_name(parameter_error),
named_value, piglit_get_gl_error_name(named_error));
}
return subtest_pass;
}
enum piglit_result
piglit_display(void)
{
/* UNREACHED */
return PIGLIT_FAIL;
}
void
piglit_init(int argc, char **argv)
{
/*
* We don't check for framebuffer object extension support an
* any other, as we are already asking core version 4.5 on
* PIGLIT CONFIG
*/
parse_args(argc, argv);
bool pass = true;
int i;
int c;
bool subtest_pass;
framebuffers[0] = 0;
glCreateFramebuffers(2, &framebuffers[1]);
piglit_check_gl_error(GL_NO_ERROR);
if (!complete_framebuffer(framebuffers[2])) {
printf("Not able to allocate a complete framebuffer\n");
piglit_report_result(PIGLIT_FAIL);
}
for (c = 0; c < ARRAY_SIZE(framebuffers); c++) {
if (filter_framebuffer && global_framebuffer != c)
continue;
for (i = 0; i < ARRAY_SIZE(table_23_73_allowed); i++) {
GLenum pname = table_23_73_allowed[i];
if (filter_pname && global_pname != pname)
continue;
subtest_pass = execute_subtest(c, pname);
PIGLIT_SUBTEST_CONDITION(subtest_pass, pass, "%s pname %s",
get_framebuffer_name(c),
piglit_get_gl_enum_name(pname));
}
}
piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
|