diff --git a/panda/src/egldisplay/eglGraphicsStateGuardian.cxx b/panda/src/egldisplay/eglGraphicsStateGuardian.cxx index f31040bd87..ae3867feec 100644 --- a/panda/src/egldisplay/eglGraphicsStateGuardian.cxx +++ b/panda/src/egldisplay/eglGraphicsStateGuardian.cxx @@ -223,6 +223,20 @@ choose_pixel_format(const FrameBufferProperties &properties, int err = eglGetError(); if (_context && err == EGL_SUCCESS) { if (_visual) { + // This is set during window creation, but for now we have to pretend + // that we can honor the request, if we support the extension. + if (properties.get_srgb_color()) { + const char *extensions = eglQueryString(_egl_display, EGL_EXTENSIONS); + if (extensions != nullptr) { + vector_string tokens; + extract_words(extensions, tokens); + + if (std::find(tokens.begin(), tokens.end(), "EGL_KHR_gl_colorspace") != tokens.end()) { + best_props.set_srgb_color(true); + } + } + } + _fbprops = best_props; delete[] configs; return; diff --git a/panda/src/egldisplay/eglGraphicsWindow.cxx b/panda/src/egldisplay/eglGraphicsWindow.cxx index 89deb47deb..8827325ce0 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.cxx +++ b/panda/src/egldisplay/eglGraphicsWindow.cxx @@ -27,6 +27,14 @@ #include "nativeWindowHandle.h" #include "get_x11.h" +#ifndef EGL_GL_COLORSPACE_KHR +#define EGL_GL_COLORSPACE_KHR 0x309D +#endif + +#ifndef EGL_GL_COLORSPACE_SRGB_KHR +#define EGL_GL_COLORSPACE_SRGB_KHR 0x3089 +#endif + TypeHandle eglGraphicsWindow::_type_handle; /** @@ -233,7 +241,16 @@ open_window() { return false; } - _egl_surface = eglCreateWindowSurface(_egl_display, eglgsg->_fbconfig, (NativeWindowType) _xwindow, nullptr); + EGLint attribs[4]; + EGLint *attribs_p = nullptr; + if (eglgsg->get_fb_properties().get_srgb_color()) { + attribs[0] = EGL_GL_COLORSPACE_KHR; + attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR; + attribs[2] = EGL_NONE; + attribs[3] = EGL_NONE; + attribs_p = attribs; + } + _egl_surface = eglCreateWindowSurface(_egl_display, eglgsg->_fbconfig, (NativeWindowType) _xwindow, attribs_p); if (eglGetError() != EGL_SUCCESS) { egldisplay_cat.error() << "Failed to create window surface.\n";