File size: 10,525 Bytes
8b7c501 |
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 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#define COUNT_OF(x) (sizeof(x) / sizeof(0[x]))
struct egl_enum_item {
EGLint id;
const char* name;
};
struct egl_enum_item egl_enum_boolean[] = {
{
.id = EGL_TRUE,
.name = "EGL_TRUE",
},
{
.id = EGL_FALSE,
.name = "EGL_FALSE",
},
};
struct egl_enum_item egl_enum_caveat[] = {
{
.id = EGL_NONE,
.name = "EGL_NONE",
},
{
.id = EGL_SLOW_CONFIG,
.name = "EGL_SLOW_CONFIG",
},
{
.id = EGL_NON_CONFORMANT_CONFIG,
.name = "EGL_NON_CONFORMANT_CONFIG",
},
};
struct egl_enum_item egl_enum_transparency[] = {
{
.id = EGL_NONE,
.name = "EGL_NONE",
},
{
.id = EGL_TRANSPARENT_RGB,
.name = "EGL_TRANSPARENT_RGB",
},
};
struct egl_enum_item egl_enum_color_buffer[] = {
{
.id = EGL_RGB_BUFFER,
.name = "EGL_RGB_BUFFER",
},
{
.id = EGL_LUMINANCE_BUFFER,
.name = "EGL_LUMINANCE_BUFFER",
},
};
#ifndef EGL_OPENGL_ES3_BIT
#define EGL_OPENGL_ES3_BIT 0x40
#endif
struct egl_enum_item egl_enum_conformant[] = {
{
.id = EGL_OPENGL_BIT,
.name = "EGL_OPENGL_BIT",
},
{
.id = EGL_OPENGL_ES_BIT,
.name = "EGL_OPENGL_ES_BIT",
},
{
.id = EGL_OPENGL_ES2_BIT,
.name = "EGL_OPENGL_ES2_BIT",
},
{
.id = EGL_OPENGL_ES3_BIT,
.name = "EGL_OPENGL_ES3_BIT",
},
{
.id = EGL_OPENVG_BIT,
.name = "EGL_OPENVG_BIT",
},
};
struct egl_enum_item egl_enum_surface_type[] = {
{
.id = EGL_PBUFFER_BIT,
.name = "EGL_PBUFFER_BIT",
},
{
.id = EGL_PIXMAP_BIT,
.name = "EGL_PIXMAP_BIT",
},
{
.id = EGL_WINDOW_BIT,
.name = "EGL_WINDOW_BIT",
},
{
.id = EGL_VG_COLORSPACE_LINEAR_BIT,
.name = "EGL_VG_COLORSPACE_LINEAR_BIT",
},
{
.id = EGL_VG_ALPHA_FORMAT_PRE_BIT,
.name = "EGL_VG_ALPHA_FORMAT_PRE_BIT",
},
{
.id = EGL_MULTISAMPLE_RESOLVE_BOX_BIT,
.name = "EGL_MULTISAMPLE_RESOLVE_BOX_BIT",
},
{
.id = EGL_SWAP_BEHAVIOR_PRESERVED_BIT,
.name = "EGL_SWAP_BEHAVIOR_PRESERVED_BIT",
},
};
struct egl_enum_item egl_enum_renderable_type[] = {
{
.id = EGL_OPENGL_ES_BIT,
.name = "EGL_OPENGL_ES_BIT",
},
{
.id = EGL_OPENVG_BIT,
.name = "EGL_OPENVG_BIT",
},
{
.id = EGL_OPENGL_ES2_BIT,
.name = "EGL_OPENGL_ES2_BIT",
},
{
.id = EGL_OPENGL_BIT,
.name = "EGL_OPENGL_BIT",
},
{
.id = EGL_OPENGL_ES3_BIT,
.name = "EGL_OPENGL_ES3_BIT",
},
};
struct egl_config_attribute {
EGLint id;
const char* name;
int32_t cardinality;
const struct egl_enum_item* values;
};
struct egl_config_attribute egl_config_attributes[] = {
{
.id = EGL_CONFIG_ID,
.name = "EGL_CONFIG_ID",
},
{
.id = EGL_CONFIG_CAVEAT,
.name = "EGL_CONFIG_CAVEAT",
.cardinality = COUNT_OF(egl_enum_caveat),
.values = egl_enum_caveat,
},
{
.id = EGL_LUMINANCE_SIZE,
.name = "EGL_LUMINANCE_SIZE",
},
{
.id = EGL_RED_SIZE,
.name = "EGL_RED_SIZE",
},
{
.id = EGL_GREEN_SIZE,
.name = "EGL_GREEN_SIZE",
},
{
.id = EGL_BLUE_SIZE,
.name = "EGL_BLUE_SIZE",
},
{
.id = EGL_ALPHA_SIZE,
.name = "EGL_ALPHA_SIZE",
},
{
.id = EGL_DEPTH_SIZE,
.name = "EGL_DEPTH_SIZE",
},
{
.id = EGL_STENCIL_SIZE,
.name = "EGL_STENCIL_SIZE",
},
{
.id = EGL_ALPHA_MASK_SIZE,
.name = "EGL_ALPHA_MASK_SIZE",
},
{
.id = EGL_BIND_TO_TEXTURE_RGB,
.name = "EGL_BIND_TO_TEXTURE_RGB",
.cardinality = COUNT_OF(egl_enum_boolean),
.values = egl_enum_boolean,
},
{
.id = EGL_BIND_TO_TEXTURE_RGBA,
.name = "EGL_BIND_TO_TEXTURE_RGBA",
.cardinality = COUNT_OF(egl_enum_boolean),
.values = egl_enum_boolean,
},
{
.id = EGL_MAX_PBUFFER_WIDTH,
.name = "EGL_MAX_PBUFFER_WIDTH",
},
{
.id = EGL_MAX_PBUFFER_HEIGHT,
.name = "EGL_MAX_PBUFFER_HEIGHT",
},
{
.id = EGL_MAX_PBUFFER_PIXELS,
.name = "EGL_MAX_PBUFFER_PIXELS",
},
{
.id = EGL_TRANSPARENT_RED_VALUE,
.name = "EGL_TRANSPARENT_RED_VALUE",
},
{
.id = EGL_TRANSPARENT_GREEN_VALUE,
.name = "EGL_TRANSPARENT_GREEN_VALUE",
},
{
.id = EGL_TRANSPARENT_BLUE_VALUE,
.name = "EGL_TRANSPARENT_BLUE_VALUE",
},
{
.id = EGL_SAMPLE_BUFFERS,
.name = "EGL_SAMPLE_BUFFERS",
},
{
.id = EGL_SAMPLES,
.name = "EGL_SAMPLES",
},
{
.id = EGL_LEVEL,
.name = "EGL_LEVEL",
},
{
.id = EGL_MAX_SWAP_INTERVAL,
.name = "EGL_MAX_SWAP_INTERVAL",
},
{
.id = EGL_MIN_SWAP_INTERVAL,
.name = "EGL_MIN_SWAP_INTERVAL",
},
{
.id = EGL_SURFACE_TYPE,
.name = "EGL_SURFACE_TYPE",
.cardinality = -(int32_t) COUNT_OF(egl_enum_surface_type),
.values = egl_enum_surface_type,
},
{
.id = EGL_RENDERABLE_TYPE,
.name = "EGL_RENDERABLE_TYPE",
.cardinality = -(int32_t) COUNT_OF(egl_enum_renderable_type),
.values = egl_enum_renderable_type,
},
{
.id = EGL_CONFORMANT,
.name = "EGL_CONFORMANT",
.cardinality = -(int32_t) COUNT_OF(egl_enum_conformant),
.values = egl_enum_conformant,
},
{
.id = EGL_TRANSPARENT_TYPE,
.name = "EGL_TRANSPARENT_TYPE",
.cardinality = COUNT_OF(egl_enum_transparency),
.values = egl_enum_transparency,
},
{
.id = EGL_COLOR_BUFFER_TYPE,
.name = "EGL_COLOR_BUFFER_TYPE",
.cardinality = COUNT_OF(egl_enum_color_buffer),
.values = egl_enum_color_buffer,
},
};
void report_gles_attributes(void) {
void* libEGL = NULL;
EGLConfig* configs = NULL;
EGLDisplay display = EGL_NO_DISPLAY;
EGLSurface surface = EGL_NO_SURFACE;
EGLContext context = EGL_NO_CONTEXT;
EGLBoolean egl_init_status = EGL_FALSE;
EGLBoolean egl_make_current_status = EGL_FALSE;
EGLBoolean egl_status;
libEGL = dlopen("libEGL.so", RTLD_LAZY | RTLD_LOCAL);
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (display == EGL_NO_DISPLAY) {
fprintf(stderr, "failed to get default EGL display\n");
goto cleanup;
}
EGLint egl_major = 0, egl_minor = 0;
egl_init_status = eglInitialize(display, &egl_major, &egl_minor);
if (egl_init_status != EGL_TRUE) {
fprintf(stderr, "failed to initialize EGL display connection\n");
goto cleanup;
}
printf("initialized display connection with EGL %d.%d\n", (int) egl_major, (int) egl_minor);
EGLint configs_count = 0;
egl_status = eglGetConfigs(display, NULL, 0, &configs_count);
if (egl_status != EGL_TRUE) {
fprintf(stderr, "failed to get the number of EGL frame buffer configurations\n");
goto cleanup;
}
configs = (EGLConfig*) malloc(configs_count * sizeof(EGLConfig));
if (configs == NULL) {
fprintf(stderr, "failed to allocate %zu bytes for %d frame buffer configurations\n",
configs_count * sizeof(EGLConfig), configs_count);
goto cleanup;
}
egl_status = eglGetConfigs(display, configs, configs_count, &configs_count);
if (egl_status != EGL_TRUE || configs_count == 0) {
fprintf(stderr, "failed to get EGL frame buffer configurations\n");
goto cleanup;
}
printf("EGL framebuffer configurations:\n");
for (EGLint i = 0; i < configs_count; i++) {
printf("\tConfiguration #%d:\n", (int) i);
for (size_t n = 0; n < COUNT_OF(egl_config_attributes); n++) {
EGLint value = 0;
egl_status = eglGetConfigAttrib(display, configs[i], egl_config_attributes[n].id, &value);
if (egl_config_attributes[n].cardinality == 0) {
printf("\t\t%s: %d\n", egl_config_attributes[n].name, (int) value);
} else if (egl_config_attributes[n].cardinality > 0) {
/* Enumeration */
bool known_value = false;
for (size_t k = 0; k < (size_t) egl_config_attributes[n].cardinality; k++) {
if (egl_config_attributes[n].values[k].id == value) {
printf("\t\t%s: %s\n", egl_config_attributes[n].name, egl_config_attributes[n].values[k].name);
known_value = true;
break;
}
}
if (!known_value) {
printf("\t\t%s: unknown (%d)\n", egl_config_attributes[n].name, value);
}
} else {
/* Bitfield */
printf("\t\t%s: ", egl_config_attributes[n].name);
if (value == 0) {
printf("none\n");
} else {
for (size_t k = 0; k < (size_t) -egl_config_attributes[n].cardinality; k++) {
if (egl_config_attributes[n].values[k].id & value) {
value &= ~egl_config_attributes[n].values[k].id;
if (value != 0) {
printf("%s | ", egl_config_attributes[n].values[k].name);
} else {
printf("%s\n", egl_config_attributes[n].values[k].name);
}
}
}
if (value != 0) {
printf("0x%08X\n", (int) value);
}
}
}
}
}
EGLint const config_attributes[] = {
EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE,
};
EGLConfig config = NULL;
EGLint config_count = 0;
egl_status = eglChooseConfig(display, config_attributes, &config, 1, &config_count);
if (egl_status != EGL_TRUE || config_count == 0 || config == NULL) {
fprintf(stderr, "failed to find EGL frame buffer configuration that match required attributes\n");
goto cleanup;
}
EGLint const surface_attributes[] = {
EGL_HEIGHT, 1,
EGL_WIDTH, 1,
EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
EGL_NONE,
};
surface = eglCreatePbufferSurface(display, config, surface_attributes);
if (surface == EGL_NO_SURFACE) {
fprintf(stderr, "failed to create PBuffer surface\n");
goto cleanup;
}
EGLint const context_attributes[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE,
};
context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attributes);
if (context == EGL_NO_CONTEXT) {
fprintf(stderr, "failed to create OpenGL ES context\n");
goto cleanup;
}
egl_make_current_status = eglMakeCurrent(display, surface, surface, context);
if (egl_make_current_status != EGL_TRUE) {
fprintf(stderr, "failed to attach OpenGL ES rendering context\n");
goto cleanup;
}
printf("OpenGL ES Attributes:\n");
printf("\t%s: \"%s\"\n", "GL_VENDOR", glGetString(GL_VENDOR));
printf("\t%s: \"%s\"\n", "GL_RENDERER", glGetString(GL_RENDERER));
printf("\t%s: \"%s\"\n", "GL_VERSION", glGetString(GL_VERSION));
printf("\t%s: \"%s\"\n", "GL_SHADING_LANGUAGE_VERSION", glGetString(GL_SHADING_LANGUAGE_VERSION));
printf("\t%s: \"%s\"\n", "GL_EXTENSIONS", glGetString(GL_EXTENSIONS));
cleanup:
if (egl_make_current_status == EGL_TRUE) {
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
if (context != EGL_NO_CONTEXT) {
eglDestroyContext(display, context);
}
if (surface != EGL_NO_SURFACE) {
eglDestroySurface(display, surface);
}
if (egl_init_status == EGL_TRUE) {
eglTerminate(display);
}
free(configs);
if (libEGL != NULL) {
dlclose(libEGL);
}
}
int main(int argc, char** argv) {
report_gles_attributes();
return 0;
}
|