Skip to content

Commit

Permalink
GL/ContextEGL: Fix surface_format left uninitialized
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Nov 4, 2023
1 parent 1717110 commit 1831a29
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
57 changes: 34 additions & 23 deletions src/util/gl/context_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ bool ContextEGL::CreateSurface()
Log_ErrorPrintf("eglQuerySurface() failed: %d", eglGetError());
}

m_wi.surface_format = GetSurfaceTextureFormat();

return true;
}

Expand All @@ -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;
}
Expand All @@ -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);

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/util/gl/context_egl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ContextEGL : public Context
bool CreateSurface();
bool CreatePBufferSurface();
bool CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Format format);
GPUTexture::Format GetSurfaceTextureFormat() const;
void DestroyContext();
void DestroySurface();

Expand Down

0 comments on commit 1831a29

Please sign in to comment.