From f695b14edc59e7c778566820988f9998df5190ba Mon Sep 17 00:00:00 2001 From: Kurt Kartaltepe Date: Sun, 10 Apr 2022 14:28:58 -0700 Subject: [PATCH] libobs-opengl: Use gl helpers in create_dmabuf_image This replaces direct OpenGL calls to error handling helpers. Previously this would cause errors to be misattributed to the next OpenGL functions called. Fixes DMA-BUF importing returning a texture on failure on KDE+NVIDIA. --- libobs-opengl/gl-egl-common.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libobs-opengl/gl-egl-common.c b/libobs-opengl/gl-egl-common.c index d26e6e1a3..4bc1d24e9 100644 --- a/libobs-opengl/gl-egl-common.c +++ b/libobs-opengl/gl-egl-common.c @@ -199,17 +199,23 @@ gl_egl_create_dmabuf_image(EGLDisplay egl_display, unsigned int width, return NULL; } - texture = gs_texture_create(width, height, color_format, 1, NULL, - GS_DYNAMIC); + if ((texture = gs_texture_create(width, height, color_format, 1, NULL, + GS_DYNAMIC)) == NULL) { + return NULL; + } const GLuint gltex = *(GLuint *)gs_texture_get_obj(texture); - glBindTexture(GL_TEXTURE_2D, gltex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + gl_bind_texture(GL_TEXTURE_2D, gltex); + gl_tex_param_i(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + gl_tex_param_i(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image); + if (!gl_success("glEGLImageTargetTexture2DOES")) { + gs_texture_destroy(texture); + texture = NULL; + } - glBindTexture(GL_TEXTURE_2D, 0); + gl_bind_texture(GL_TEXTURE_2D, 0); eglDestroyImage(egl_display, egl_image); return texture;