Add attr info printers for EGL config
This commit is contained in:
parent
b3401b13ad
commit
66ca44bb4e
1 changed files with 75 additions and 15 deletions
90
wayland.c
90
wayland.c
|
|
@ -8,9 +8,7 @@
|
||||||
|
|
||||||
struct wl_compositor *compositor = NULL;
|
struct wl_compositor *compositor = NULL;
|
||||||
struct wl_registry *registry = NULL;
|
struct wl_registry *registry = NULL;
|
||||||
struct wl_shell *shell = NULL;
|
|
||||||
struct wl_surface *surface = NULL;
|
struct wl_surface *surface = NULL;
|
||||||
struct wl_shm *shm = NULL;
|
|
||||||
EGLBoolean errcode = 0;
|
EGLBoolean errcode = 0;
|
||||||
|
|
||||||
void registry_handle_global(void *data, struct wl_registry *registry,
|
void registry_handle_global(void *data, struct wl_registry *registry,
|
||||||
|
|
@ -23,12 +21,6 @@ void registry_handle_global(void *data, struct wl_registry *registry,
|
||||||
fprintf(stdout, "Registering compositor...\n");
|
fprintf(stdout, "Registering compositor...\n");
|
||||||
compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
|
compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(interface, wl_shell_interface.name))
|
|
||||||
{
|
|
||||||
fprintf(stdout, "Getting shell interface...\n");
|
|
||||||
shell = wl_registry_bind(registry, name, &wl_shell_interface, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -106,7 +98,7 @@ int main()
|
||||||
;
|
;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLConfig *configs = calloc(config_count, sizeof(EGLConfig));
|
EGLConfig *configs = calloc(config_count, sizeof(EGLConfig));
|
||||||
|
|
||||||
EGLint attr_list[] = {
|
EGLint attr_list[] = {
|
||||||
|
|
@ -114,11 +106,10 @@ int main()
|
||||||
EGL_RED_SIZE, 8,
|
EGL_RED_SIZE, 8,
|
||||||
EGL_GREEN_SIZE, 8,
|
EGL_GREEN_SIZE, 8,
|
||||||
EGL_BLUE_SIZE, 8,
|
EGL_BLUE_SIZE, 8,
|
||||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
EGL_RENDERABLE_TYPE, (EGL_OPENGL_BIT | EGL_OPENGL_ES_BIT | EGL_OPENGL_ES2_BIT), // better be safe than sorry with our compatibility bitmask
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
int chosen_config_count;
|
int chosen_config_count;
|
||||||
|
|
||||||
errcode = eglChooseConfig(egl_display, attr_list, configs, config_count * sizeof(EGLConfig), &chosen_config_count);
|
errcode = eglChooseConfig(egl_display, attr_list, configs, config_count * sizeof(EGLConfig), &chosen_config_count);
|
||||||
switch (errcode)
|
switch (errcode)
|
||||||
{
|
{
|
||||||
|
|
@ -133,7 +124,74 @@ int main()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLSurface egl_surface = eglCreateWindowSurface(egl_display, configs[0], (EGLNativeWindowType)window, NULL);
|
int chosen_config_id = 0;
|
||||||
|
EGLConfig *chosen_config = configs[0];
|
||||||
|
|
||||||
|
fprintf(stdout, "Found %d possible configurations:\n", chosen_config_count);
|
||||||
|
for (int i = 0; i < chosen_config_count; ++i)
|
||||||
|
{
|
||||||
|
fprintf(stdout, "\tCONFIG %d:\n", i);
|
||||||
|
int attr;
|
||||||
|
#define PRINT_ATTR(attr_name) \
|
||||||
|
errcode = eglGetConfigAttrib(egl_display, configs[i], attr_name, &attr); \
|
||||||
|
[[maybe_unused]] int attr_##attr_name = -1; \
|
||||||
|
do { \
|
||||||
|
if (errcode == EGL_TRUE) { \
|
||||||
|
fprintf(stdout, "\t\t" #attr_name ": %d (%#0x)\n", attr, attr); \
|
||||||
|
attr_##attr_name = attr; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
PRINT_ATTR(EGL_ALPHA_SIZE);
|
||||||
|
PRINT_ATTR(EGL_ALPHA_MASK_SIZE);
|
||||||
|
PRINT_ATTR(EGL_BIND_TO_TEXTURE_RGB);
|
||||||
|
PRINT_ATTR(EGL_BIND_TO_TEXTURE_RGBA);
|
||||||
|
PRINT_ATTR(EGL_BLUE_SIZE);
|
||||||
|
PRINT_ATTR(EGL_BUFFER_SIZE);
|
||||||
|
PRINT_ATTR(EGL_COLOR_BUFFER_TYPE);
|
||||||
|
PRINT_ATTR(EGL_CONFIG_CAVEAT);
|
||||||
|
PRINT_ATTR(EGL_CONFIG_ID);
|
||||||
|
PRINT_ATTR(EGL_CONFORMANT);
|
||||||
|
PRINT_ATTR(EGL_DEPTH_SIZE);
|
||||||
|
PRINT_ATTR(EGL_GREEN_SIZE);
|
||||||
|
PRINT_ATTR(EGL_LEVEL);
|
||||||
|
PRINT_ATTR(EGL_LUMINANCE_SIZE);
|
||||||
|
PRINT_ATTR(EGL_MAX_PBUFFER_WIDTH);
|
||||||
|
PRINT_ATTR(EGL_MAX_PBUFFER_HEIGHT);
|
||||||
|
PRINT_ATTR(EGL_MAX_PBUFFER_PIXELS);
|
||||||
|
PRINT_ATTR(EGL_MAX_SWAP_INTERVAL);
|
||||||
|
PRINT_ATTR(EGL_NATIVE_RENDERABLE);
|
||||||
|
PRINT_ATTR(EGL_NATIVE_VISUAL_ID);
|
||||||
|
PRINT_ATTR(EGL_NATIVE_VISUAL_TYPE);
|
||||||
|
PRINT_ATTR(EGL_RED_SIZE);
|
||||||
|
PRINT_ATTR(EGL_RENDERABLE_TYPE);
|
||||||
|
PRINT_ATTR(EGL_SAMPLE_BUFFERS);
|
||||||
|
PRINT_ATTR(EGL_SAMPLES);
|
||||||
|
PRINT_ATTR(EGL_STENCIL_SIZE);
|
||||||
|
PRINT_ATTR(EGL_SURFACE_TYPE);
|
||||||
|
PRINT_ATTR(EGL_TRANSPARENT_TYPE);
|
||||||
|
PRINT_ATTR(EGL_TRANSPARENT_RED_VALUE);
|
||||||
|
PRINT_ATTR(EGL_TRANSPARENT_GREEN_VALUE);
|
||||||
|
PRINT_ATTR(EGL_TRANSPARENT_BLUE_VALUE);
|
||||||
|
|
||||||
|
// Try to at least choose an RGBA 32bit config
|
||||||
|
if (attr_EGL_ALPHA_SIZE == 8 &&
|
||||||
|
attr_EGL_BLUE_SIZE == 8 &&
|
||||||
|
attr_EGL_RED_SIZE == 8 &&
|
||||||
|
attr_EGL_GREEN_SIZE == 8 &&
|
||||||
|
attr_EGL_BUFFER_SIZE == 32 &&
|
||||||
|
attr_EGL_COLOR_BUFFER_TYPE == EGL_RGB_BUFFER &&
|
||||||
|
attr_EGL_SAMPLE_BUFFERS == 0) // with no multisampling
|
||||||
|
{
|
||||||
|
chosen_config_id = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef PRINT_ATTR
|
||||||
|
|
||||||
|
chosen_config = configs[chosen_config_id];
|
||||||
|
fprintf(stdout, "Chosen config #%d\n", chosen_config_id);
|
||||||
|
EGLSurface egl_surface = eglCreateWindowSurface(egl_display, chosen_config, (EGLNativeWindowType)window, NULL);
|
||||||
|
|
||||||
switch ((intptr_t)egl_surface)
|
switch ((intptr_t)egl_surface)
|
||||||
{
|
{
|
||||||
|
|
@ -155,7 +213,9 @@ int main()
|
||||||
static const EGLint context_attribs[] = {
|
static const EGLint context_attribs[] = {
|
||||||
EGL_CONTEXT_MAJOR_VERSION, 3,
|
EGL_CONTEXT_MAJOR_VERSION, 3,
|
||||||
EGL_CONTEXT_MINOR_VERSION, 2,
|
EGL_CONTEXT_MINOR_VERSION, 2,
|
||||||
|
#ifdef DEBUG
|
||||||
EGL_CONTEXT_OPENGL_DEBUG, EGL_TRUE,
|
EGL_CONTEXT_OPENGL_DEBUG, EGL_TRUE,
|
||||||
|
#endif
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -169,7 +229,7 @@ int main()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
EGLContext egl_context = eglCreateContext(egl_display, configs[0], EGL_NO_CONTEXT, context_attribs);
|
EGLContext egl_context = eglCreateContext(egl_display, chosen_config, EGL_NO_CONTEXT, context_attribs);
|
||||||
|
|
||||||
errcode = eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
|
errcode = eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
|
||||||
switch (errcode)
|
switch (errcode)
|
||||||
|
|
@ -186,7 +246,7 @@ int main()
|
||||||
fprintf(stderr, "Could not make EGL context current\n");
|
fprintf(stderr, "Could not make EGL context current\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wl_region *region = wl_compositor_create_region(compositor);
|
struct wl_region *region = wl_compositor_create_region(compositor);
|
||||||
wl_region_add(region, 0, 0, 480, 360);
|
wl_region_add(region, 0, 0, 480, 360);
|
||||||
wl_surface_set_opaque_region(surface, region);
|
wl_surface_set_opaque_region(surface, region);
|
||||||
|
|
@ -194,7 +254,7 @@ int main()
|
||||||
// Main event loop
|
// Main event loop
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
//wl_display_dispatch_pending(display);
|
wl_display_dispatch_pending(display);
|
||||||
fprintf(stdout, "Dispatching event...\n");
|
fprintf(stdout, "Dispatching event...\n");
|
||||||
glClearColor(0.5, 0.3, 0.0, 1.0);
|
glClearColor(0.5, 0.3, 0.0, 1.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue