Common: Prefer returning std::array by lambda expression

GL/ContextEGL.cpp:
Replace raw-index manipulation / arithmetic as logic. Variable now using IIFE (Immediately invoked function expression) to strengthen immutability.
This commit is contained in:
tcoyvwac 2022-03-16 11:14:52 +01:00 committed by refractionpcsx2
parent 1a0a0423e7
commit 6e6a70b8ed
1 changed files with 10 additions and 12 deletions

View File

@ -334,17 +334,15 @@ namespace GL
config = configs.front();
}
int attribs[8];
int nattribs = 0;
const auto attribs = [version]() -> std::array<int, 8> {
if (version.profile != Profile::NoProfile)
{
attribs[nattribs++] = EGL_CONTEXT_MAJOR_VERSION;
attribs[nattribs++] = version.major_version;
attribs[nattribs++] = EGL_CONTEXT_MINOR_VERSION;
attribs[nattribs++] = version.minor_version;
}
attribs[nattribs++] = EGL_NONE;
attribs[nattribs++] = 0;
return {
EGL_CONTEXT_MAJOR_VERSION, version.major_version,
EGL_CONTEXT_MINOR_VERSION, version.minor_version,
EGL_NONE
};
return {EGL_NONE};
}();
if (!eglBindAPI((version.profile == Profile::ES) ? EGL_OPENGL_ES_API : EGL_OPENGL_API))
{
@ -352,7 +350,7 @@ namespace GL
return false;
}
m_context = eglCreateContext(m_display, config.value(), share_context, attribs);
m_context = eglCreateContext(m_display, config.value(), share_context, attribs.data());
if (!m_context)
{
Console.Error("eglCreateContext() failed: %d", eglGetError());