GLES: Fixed swap chain MSAA and sRGB back buffer. (#4086)

This commit is contained in:
Branimir Karadžić
2026-10-23 12:09:54 -07:00
committed by GitHub
parent 6b89babdad
commit ba7b608089
3 changed files with 35 additions and 8 deletions
+31 -3
View File
@@ -170,6 +170,28 @@ WL_EGL_IMPORT
static EGLint s_contextAttrs[16];
static EGLSurface createWindowSurface(EGLDisplay _display, EGLConfig _config, EGLNativeWindowType _nwh, bool _colorspaceSupport, bool _srgb)
{
if (_colorspaceSupport
&& _srgb)
{
const EGLint attribs[] =
{
EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR,
EGL_NONE
};
EGLSurface surface = eglCreateWindowSurface(_display, _config, _nwh, attribs);
if (EGL_NO_SURFACE != surface)
{
return surface;
}
}
return eglCreateWindowSurface(_display, _config, _nwh, NULL);
}
struct SwapChainGL
{
SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh, int32_t _width, int32_t _height)
@@ -359,6 +381,9 @@ WL_EGL_IMPORT
BX_TRACE("Supported EGL extensions:");
dumpExtensions(extensions);
m_colorspaceSupport = !bx::findIdentifierMatch(extensions, "EGL_KHR_gl_colorspace").isEmpty();
m_srgb = 0 != (_swapChain.flags & BGFX_SWAP_CHAIN_SRGB_BACKBUFFER);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) )
{
EGLBoolean ok = eglBindAPI(EGL_OPENGL_API);
@@ -639,7 +664,7 @@ WL_EGL_IMPORT
}
# endif // BX_PLATFORM_LINUX
m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
m_surface = createWindowSurface(m_display, m_config, nwh, m_colorspaceSupport, m_srgb);
}
if (EGL_NO_SURFACE == m_surface)
@@ -985,6 +1010,8 @@ WL_EGL_IMPORT
m_readSurface = eglGetCurrentSurface(EGL_READ);
}
const bool srgb = 0 != (_swapChain.flags & BGFX_SWAP_CHAIN_SRGB_BACKBUFFER);
const bool hasWindow = true
&& m_ownsContext
&& NULL != m_display
@@ -993,7 +1020,7 @@ WL_EGL_IMPORT
;
bool recreateSurface = hasWindow
&& m_nwh != _swapChain.nwh
&& (m_nwh != _swapChain.nwh || m_srgb != srgb)
;
# if BX_PLATFORM_ANDROID
@@ -1004,6 +1031,7 @@ WL_EGL_IMPORT
{
BX_TRACE("EGL window changed: %p -> %p", m_nwh, _swapChain.nwh);
m_nwh = _swapChain.nwh;
m_srgb = srgb;
eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(m_display, m_surface);
@@ -1028,7 +1056,7 @@ WL_EGL_IMPORT
}
# endif // BX_PLATFORM_LINUX
m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
m_surface = createWindowSurface(m_display, m_config, nwh, m_colorspaceSupport, m_srgb);
BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");
m_readSurface = m_surface;
+4
View File
@@ -53,6 +53,8 @@ namespace bgfx { namespace gl
#endif // BX_PLATFORM_*
, m_ownsContext(false)
, m_msaaContext(false)
, m_colorspaceSupport(false)
, m_srgb(false)
, m_swapInterval(0)
{
}
@@ -92,6 +94,8 @@ namespace bgfx { namespace gl
bool m_ownsContext;
bool m_msaaContext;
bool m_colorspaceSupport;
bool m_srgb;
int m_swapInterval;
};
} /* namespace gl */ } // namespace bgfx
-5
View File
@@ -8221,11 +8221,6 @@ namespace bgfx { namespace gl
uint32_t msaa = (_desc.flags & BGFX_SWAP_CHAIN_MSAA_MASK)>>BGFX_SWAP_CHAIN_MSAA_SHIFT;
msaa = bx::min<uint32_t>(s_renderGL->m_maxMsaa, 0 == msaa ? 1 : 1<<msaa);
if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) )
{
msaa = 1;
}
const bool srgb = 0 != (_desc.flags & BGFX_SWAP_CHAIN_SRGB_BACKBUFFER);
m_swapChainMsaa = msaa;