30 #ifndef EGL_GL_COLORSPACE_KHR
31 #define EGL_GL_COLORSPACE_KHR 0x309D
34 #ifndef EGL_GL_COLORSPACE_SRGB_KHR
35 #define EGL_GL_COLORSPACE_SRGB_KHR 0x3089
45 const std::string &name,
54 DCAST_INTO_V(egl_pipe, _pipe);
55 _egl_display = egl_pipe->_egl_display;
63 ~eglGraphicsWindow() {
74 PStatTimer timer(_make_current_pcollector, current_thread);
76 begin_frame_spam(mode);
77 if (_gsg ==
nullptr) {
80 if (_awaiting_configure) {
87 DCAST_INTO_R(eglgsg, _gsg,
false);
91 if (eglGetCurrentDisplay() == _egl_display &&
92 eglGetCurrentSurface(EGL_READ) == _egl_surface &&
93 eglGetCurrentSurface(EGL_DRAW) == _egl_surface &&
94 eglGetCurrentContext() == eglgsg->_context) {
99 if (!eglMakeCurrent(_egl_display, _egl_surface, _egl_surface, eglgsg->_context)) {
100 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: "
110 eglgsg->reset_if_new();
112 if (mode == FM_render) {
114 clear_cube_map_selection();
118 return _gsg->begin_frame(current_thread);
128 end_frame_spam(mode);
129 nassertv(_gsg !=
nullptr);
131 if (mode == FM_render) {
136 _gsg->end_frame(current_thread);
138 if (mode == FM_render) {
140 clear_cube_map_selection();
153 if (_gsg !=
nullptr && _flip_ready) {
162 eglSwapBuffers(_egl_display, _egl_surface);
170 void eglGraphicsWindow::
172 if (_gsg !=
nullptr) {
173 if (!eglMakeCurrent(_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
174 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: "
180 if (_ic != (XIC)
nullptr) {
185 if (_egl_surface != 0) {
186 if (!eglDestroySurface(_egl_display, _egl_surface)) {
187 egldisplay_cat.error() <<
"Failed to destroy surface: "
192 if (_xwindow != (X11_Window)
nullptr) {
193 XDestroyWindow(_display, _xwindow);
194 _xwindow = (X11_Window)
nullptr;
200 GraphicsWindow::close_window();
207 bool eglGraphicsWindow::
210 DCAST_INTO_R(egl_pipe, _pipe,
false);
222 DCAST_INTO_R(eglgsg, _gsg,
false);
230 _visual_info = eglgsg->_visual;
231 if (_visual_info ==
nullptr) {
233 egldisplay_cat.error()
234 <<
"No X visual: cannot open window.\n";
238 setup_colormap(_visual_info);
240 if (!x11GraphicsWindow::open_window()) {
245 EGLint *attribs_p =
nullptr;
247 attribs[0] = EGL_GL_COLORSPACE_KHR;
248 attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR;
249 attribs[2] = EGL_NONE;
250 attribs[3] = EGL_NONE;
253 _egl_surface = eglCreateWindowSurface(_egl_display, eglgsg->_fbconfig, (NativeWindowType) _xwindow, attribs_p);
254 if (eglGetError() != EGL_SUCCESS) {
255 egldisplay_cat.error()
256 <<
"Failed to create window surface.\n";
260 if (!eglMakeCurrent(_egl_display, _egl_surface, _egl_surface, eglgsg->_context)) {
261 egldisplay_cat.error() <<
"Failed to call eglMakeCurrent: "
264 eglgsg->reset_if_new();
265 if (!eglgsg->is_valid()) {
270 (_fb_properties, eglgsg->get_gl_renderer())) {