Skip to content

Commit 1435bb0

Browse files
Load glEGLImageTargetTexture2DOES at runtime
GL_OES_EGL_image is GLES-only so glad doesn't provide glEGLImageTargetTexture2DOES for desktop GL. Load the symbol at runtime via eglGetProcAddress, store it in a static internal pointer and expose an accessor (egl_image_target_texture_2d()) instead of a public global. Update call sites to use the accessor and change the typedef to use void* for GLeglImageOES per the Khronos spec. Improve the warning text when the symbol is missing and remove an unnecessary vector reserve from surface_descriptor_to_egl_attribs as a small cleanup.
1 parent c2b6122 commit 1435bb0

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

src/platform/linux/graphics.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ using namespace std::literals;
3131

3232
namespace gl {
3333
GladGLContext ctx;
34-
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC EGLImageTargetTexture2DOES = nullptr;
34+
35+
static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture_2d_fn = nullptr;
36+
37+
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture_2d() {
38+
return egl_image_target_texture_2d_fn;
39+
}
3540

3641
void drain_errors(const std::string_view &prefix) {
3742
GLenum err;
@@ -414,12 +419,10 @@ namespace egl {
414419
return std::nullopt;
415420
}
416421

417-
// GL_OES_EGL_image is GLES-only so glad cannot generate it for desktop GL.
418-
// Load the function pointer manually at runtime.
419-
gl::EGLImageTargetTexture2DOES =
420-
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress("glEGLImageTargetTexture2DOES");
421-
if (!gl::EGLImageTargetTexture2DOES) {
422-
BOOST_LOG(warning) << "GL: glEGLImageTargetTexture2DOES not available"sv;
422+
gl::egl_image_target_texture_2d_fn =
423+
(PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLADapiproc) eglGetProcAddress("glEGLImageTargetTexture2DOES");
424+
if (!gl::egl_image_target_texture_2d_fn) {
425+
BOOST_LOG(warning) << "GL: glEGLImageTargetTexture2DOES not available; DMA-BUF import will fail"sv;
423426
}
424427

425428
// GetString returns const GLubyte* (unsigned char*); convert to std::string safely (avoids sonar cpp:S6996).
@@ -499,9 +502,6 @@ namespace egl {
499502
*/
500503
std::vector<EGLAttrib> surface_descriptor_to_egl_attribs(const surface_descriptor_t &surface) {
501504
std::vector<EGLAttrib> attribs;
502-
// Reserve worst-case capacity up front: 6 fixed + 4 planes * (6 base + 4 modifier) attrs + 1 EGL_NONE.
503-
// This avoids reallocation, which works around a GCC 13 false-positive -Warray-bounds with long int vectors.
504-
attribs.reserve(6 + 4 * 10 + 1);
505505

506506
attribs.emplace_back(EGL_WIDTH);
507507
attribs.emplace_back(surface.width);
@@ -553,7 +553,7 @@ namespace egl {
553553
}
554554

555555
gl::ctx.BindTexture(GL_TEXTURE_2D, rgb->tex[0]);
556-
gl::EGLImageTargetTexture2DOES(GL_TEXTURE_2D, rgb->xrgb8);
556+
gl::egl_image_target_texture_2d()(GL_TEXTURE_2D, rgb->xrgb8);
557557

558558
gl::ctx.BindTexture(GL_TEXTURE_2D, 0);
559559

@@ -611,10 +611,10 @@ namespace egl {
611611
}
612612

613613
gl::ctx.BindTexture(GL_TEXTURE_2D, nv12->tex[0]);
614-
gl::EGLImageTargetTexture2DOES(GL_TEXTURE_2D, nv12->r8);
614+
gl::egl_image_target_texture_2d()(GL_TEXTURE_2D, nv12->r8);
615615

616616
gl::ctx.BindTexture(GL_TEXTURE_2D, nv12->tex[1]);
617-
gl::EGLImageTargetTexture2DOES(GL_TEXTURE_2D, nv12->bg88);
617+
gl::egl_image_target_texture_2d()(GL_TEXTURE_2D, nv12->bg88);
618618

619619
nv12->buf.bind(std::begin(nv12->tex), std::end(nv12->tex));
620620

src/platform/linux/graphics.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
#include "src/utility.h"
2020
#include "src/video_colorspace.h"
2121

22-
// GL_OES_EGL_image is a GLES-only extension that glad cannot generate for desktop GL.
23-
// We load glEGLImageTargetTexture2DOES manually at runtime via eglGetProcAddress.
24-
// EGLImage (from glad/egl.h) and GLeglImageOES are both void* — the same underlying type.
25-
using PFNGLEGLIMAGETARGETTEXTURE2DOESPROC = void(GLAD_API_PTR *)(GLenum target, EGLImage image);
26-
2722
#define SUNSHINE_STRINGIFY_HELPER(x) #x
2823
#define SUNSHINE_STRINGIFY(x) SUNSHINE_STRINGIFY_HELPER(x)
2924
#define gl_drain_errors_helper(x) gl::drain_errors(x)
@@ -41,7 +36,13 @@ using frame_t = util::safe_ptr<AVFrame, free_frame>;
4136

4237
namespace gl {
4338
extern GladGLContext ctx;
44-
extern PFNGLEGLIMAGETARGETTEXTURE2DOESPROC EGLImageTargetTexture2DOES;
39+
40+
// glEGLImageTargetTexture2DOES (GL_OES_EGL_image) is not part of desktop GL —
41+
// it is a GLES extension that must be loaded manually via eglGetProcAddress.
42+
// GLeglImageOES is typedef void* per the Khronos spec (gl.xml).
43+
using PFNGLEGLIMAGETARGETTEXTURE2DOESPROC = void (*)(GLenum target, void *image);
44+
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC egl_image_target_texture_2d();
45+
4546
void drain_errors(const std::string_view &prefix);
4647

4748
class tex_t: public util::buffer_t<GLuint> {

0 commit comments

Comments
 (0)