GL/ContextEGL: Fix surface_format left uninitialized

This commit is contained in:
Stenzek 2023-11-01 01:52:28 +10:00
parent 17171101cf
commit 1831a291b4
No known key found for this signature in database
2 changed files with 35 additions and 23 deletions

View file

@ -212,6 +212,8 @@ bool ContextEGL::CreateSurface()
Log_ErrorPrintf("eglQuerySurface() failed: %d", eglGetError());
}
m_wi.surface_format = GetSurfaceTextureFormat();
return true;
}
@ -232,6 +234,8 @@ bool ContextEGL::CreatePBufferSurface()
return false;
}
m_wi.surface_format = GetSurfaceTextureFormat();
Log_DevPrintf("Created %ux%u pbuffer surface", width, height);
return true;
}
@ -249,29 +253,6 @@ bool ContextEGL::CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format f
switch (format)
{
case GPUTexture::Format::Unknown:
{
if (red_size == 5 && green_size == 6 && red_size == 5)
{
m_wi.surface_format = GPUTexture::Format::RGB565;
}
else if (red_size == 5 && green_size == 5 && red_size == 5 && alpha_size == 1)
{
m_wi.surface_format = GPUTexture::Format::RGBA5551;
}
else if (red_size == 8 && green_size == 8 && blue_size == 8 && alpha_size == 8)
{
m_wi.surface_format = GPUTexture::Format::RGBA8;
}
else
{
Log_ErrorPrintf("Unknown surface format: R=%u, G=%u, B=%u, A=%u", red_size, green_size, blue_size, alpha_size);
m_wi.surface_format = GPUTexture::Format::RGBA8;
}
return true;
}
case GPUTexture::Format::RGBA8:
return (red_size == 8 && green_size == 8 && blue_size == 8 && alpha_size == 8);
@ -281,11 +262,41 @@ bool ContextEGL::CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format f
case GPUTexture::Format::RGBA5551:
return (red_size == 5 && green_size == 5 && blue_size == 5 && alpha_size == 1);
case GPUTexture::Format::Unknown:
return true;
default:
return false;
}
}
GPUTexture::Format ContextEGL::GetSurfaceTextureFormat() const
{
int red_size = 0, green_size = 0, blue_size = 0, alpha_size = 0;
eglGetConfigAttrib(m_display, m_config, EGL_RED_SIZE, &red_size);
eglGetConfigAttrib(m_display, m_config, EGL_GREEN_SIZE, &green_size);
eglGetConfigAttrib(m_display, m_config, EGL_BLUE_SIZE, &blue_size);
eglGetConfigAttrib(m_display, m_config, EGL_ALPHA_SIZE, &alpha_size);
if (red_size == 5 && green_size == 6 && red_size == 5)
{
return GPUTexture::Format::RGB565;
}
else if (red_size == 5 && green_size == 5 && red_size == 5 && alpha_size == 1)
{
return GPUTexture::Format::RGBA5551;
}
else if (red_size == 8 && green_size == 8 && blue_size == 8 && alpha_size == 8)
{
return GPUTexture::Format::RGBA8;
}
else
{
Log_ErrorPrintf("Unknown surface format: R=%u, G=%u, B=%u, A=%u", red_size, green_size, blue_size, alpha_size);
return GPUTexture::Format::RGBA8;
}
}
void ContextEGL::DestroyContext()
{
if (eglGetCurrentContext() == m_context)

View file

@ -39,6 +39,7 @@ protected:
bool CreateSurface();
bool CreatePBufferSurface();
bool CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format format);
GPUTexture::Format GetSurfaceTextureFormat() const;
void DestroyContext();
void DestroySurface();