@@ -43,9 +43,11 @@ class native_window : public ruis::render::native_window
4343 wayland_egl_window_wrapper wayland_egl_window;
4444
4545 egl_config_wrapper egl_config;
46- egl_surface_wrapper egl_surface;
4746 egl_context_wrapper egl_context;
4847
48+ std::optional<egl_pbuffer_surface_wrapper> egl_dummy_surface;
49+ std::optional<egl_surface_wrapper> egl_surface;
50+
4951 wayland_surface_wrapper::scale_and_dpi scale_and_dpi;
5052
5153public:
@@ -91,11 +93,6 @@ public:
9193 gl_version,
9294 window_params
9395 ),
94- egl_surface (
95- this ->display.get().egl_display, //
96- this ->egl_config,
97- this ->wayland_egl_window.window
98- ),
9996 egl_context (
10097 this ->display.get().egl_display, //
10198 gl_version,
@@ -125,21 +122,59 @@ public:
125122 return this ->wayland_surface .surface ;
126123 }
127124
125+ void create_egl_surface ()
126+ {
127+ this ->egl_surface .emplace (
128+ this ->display .get ().egl_display , //
129+ this ->egl_config ,
130+ this ->wayland_egl_window .window
131+ );
132+ }
133+
128134 void swap_frame_buffers () override
129135 {
130- this ->egl_surface .swap_frame_buffers ();
136+ if (this ->egl_surface .has_value ()) {
137+ this ->egl_surface .value ().swap_frame_buffers ();
138+ }
131139 }
132140
133141 void bind_rendering_context () override
134142 {
135- if (eglMakeCurrent (
136- this ->display .get ().egl_display .display ,
137- this ->egl_surface .surface ,
138- this ->egl_surface .surface ,
139- this ->egl_context .context
140- ) == EGL_FALSE)
141- {
142- throw std::runtime_error (" eglMakeCurrent() failed" );
143+ auto & egl_display = this ->display .get ().egl_display ;
144+
145+ if (this ->egl_surface .has_value ()) {
146+ if (eglMakeCurrent (
147+ egl_display.display ,
148+ this ->egl_surface .value ().surface ,
149+ this ->egl_surface .value ().surface ,
150+ this ->egl_context .context
151+ ) == EGL_FALSE)
152+ {
153+ throw std::runtime_error (" eglMakeCurrent() failed" );
154+ }
155+ } else {
156+ if (egl_display.extensions .get (egl::extension::khr_surfaceless_context)) {
157+ eglMakeCurrent (
158+ egl_display.display , //
159+ EGL_NO_SURFACE,
160+ EGL_NO_SURFACE,
161+ this ->egl_context .context
162+ );
163+ } else {
164+ // KHR_surfaceless_context EGL extension is not available, create a dummy pbuffer surface to make the context current
165+ if (!this ->egl_dummy_surface .has_value ()) {
166+ this ->egl_dummy_surface .emplace (
167+ egl_display, //
168+ this ->egl_config
169+ );
170+ }
171+ eglMakeCurrent (
172+ egl_display.display , //
173+ this ->egl_dummy_surface .value ().surface ,
174+ this ->egl_dummy_surface .value ().surface ,
175+ this ->egl_context .context
176+ );
177+ }
143178 }
144179 }
145180
0 commit comments