From 5daf3b1ad1255c7d33a96ce4315b29ccf1873c8f Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sat, 4 Dec 2021 20:18:07 -0800 Subject: [PATCH] libobs-opengl: Ensure proper draw buffer This commit ensures that we set the appropriate draw buffer when making a context current. Mesa drivers enforce opengl ES semantics where the targets passed to eglMakeCurrent are bound, but nvidia instead ignores these parameters after the 1st eglMakeCurrent. In obs we make current with EGL_NO_SURFACE so our draw targets end up as EGL_NONE on nvidia and previews fail to render. This also allows us to fail back ignoring NATIVE_RENDERABLE requirements. Nvidia driver does not report support for this attribute on any context and after resolving the draw target issues previews render correctly on nvidia and intel drivers. --- libobs-opengl/gl-wayland-egl.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/libobs-opengl/gl-wayland-egl.c b/libobs-opengl/gl-wayland-egl.c index 724f89be3..dfc81cb54 100644 --- a/libobs-opengl/gl-wayland-egl.c +++ b/libobs-opengl/gl-wayland-egl.c @@ -24,6 +24,22 @@ #include +static const EGLint config_attribs_native[] = {EGL_SURFACE_TYPE, + EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, + EGL_OPENGL_BIT, + EGL_STENCIL_SIZE, + 0, + EGL_DEPTH_SIZE, + 0, + EGL_BUFFER_SIZE, + 32, + EGL_ALPHA_SIZE, + 8, + EGL_NATIVE_RENDERABLE, + EGL_TRUE, + EGL_NONE}; + static const EGLint config_attribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RENDERABLE_TYPE, @@ -36,8 +52,6 @@ static const EGLint config_attribs[] = {EGL_SURFACE_TYPE, 32, EGL_ALPHA_SIZE, 8, - EGL_NATIVE_RENDERABLE, - EGL_TRUE, EGL_NONE}; static const EGLint ctx_attribs[] = { @@ -110,6 +124,10 @@ static bool egl_make_current(EGLDisplay display, EGLSurface surface, blog(LOG_ERROR, "eglMakeCurrent failed"); return false; } + + if (surface != EGL_NO_SURFACE) + glDrawBuffer(GL_BACK); + return true; } @@ -122,11 +140,16 @@ static bool egl_context_create(struct gl_platform *plat, const EGLint *attribs) blog(LOG_ERROR, "eglBindAPI failed"); } - EGLBoolean result = eglChooseConfig(plat->display, config_attribs, + EGLBoolean result = eglChooseConfig(plat->display, + config_attribs_native, &plat->config, 1, &num_config); if (result != EGL_TRUE || num_config == 0) { - blog(LOG_ERROR, "eglChooseConfig failed"); - goto error; + result = eglChooseConfig(plat->display, config_attribs, + &plat->config, 1, &num_config); + if (result != EGL_TRUE || num_config == 0) { + blog(LOG_ERROR, "eglChooseConfig failed"); + goto error; + } } plat->context = eglCreateContext(plat->display, plat->config,