Compare commits

...

2 commits

Author SHA1 Message Date
Jonathan De Wachter 701136f8ce Compute the closest matching EGL config
Instead of picking the best one.
2016-10-11 15:30:18 +07:00
Jonathan De Wachter 72e8cad18e Fixed anti-aliasing on OpenGL ES (EGL context) 2016-09-28 18:43:10 +07:00

View file

@ -237,24 +237,55 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
{
// Set our video settings constraint
const EGLint attributes[] = {
EGL_BUFFER_SIZE, bitsPerPixel,
EGL_DEPTH_SIZE, settings.depthBits,
EGL_STENCIL_SIZE, settings.stencilBits,
EGL_SAMPLE_BUFFERS, settings.antialiasingLevel,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
EGL_NONE
};
EGLint configCount;
EGLConfig configs[1];
// Detect the number of available configuration
EGLint configsCount;
eglCheck(eglChooseConfig(display, attributes, NULL, 0, &configsCount));
// Ask EGL for the best config matching our video settings
eglCheck(eglChooseConfig(display, attributes, configs, 1, &configCount));
// Retrieve the list of available configuration
EGLConfig* configs = new EGLConfig[configsCount];
eglCheck(eglChooseConfig(display, attributes, configs, configsCount, &configsCount));
// TODO: This should check EGL_CONFORMANT and pick the first conformant configuration.
int bestScore = 0x7FFFFFFF;
EGLConfig bestConfig;
return configs[0];
for(GLint i = 0; i < configsCount ; i++)
{
EGLint red, green, blue, alpha, depth, stencil, multiSampling, samples, sRgb;
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &alpha));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_DEPTH_SIZE, &depth));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_STENCIL_SIZE, &stencil));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SAMPLE_BUFFERS, &multiSampling));
eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SAMPLES, &samples));
sRgb = 0;
// TODO: Replace this with proper acceleration detection
bool accelerated = true;
// TODO: Detect sRGB capable
// Evaluate the visual
int color = red + green + blue + alpha;
int score = evaluateFormat(bitsPerPixel, settings, color, depth, stencil, multiSampling ? samples : 0, accelerated, false);
// If it's better than the current best, make it the new best
if (score < bestScore)
{
bestScore = score;
bestConfig = configs[i];
}
}
delete configs;
return bestConfig;
}
@ -262,17 +293,17 @@ EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixe
void EglContext::updateSettings()
{
EGLint tmp;
// Update the internal context settings with the current config
eglCheck(eglGetConfigAttrib(m_display, m_config, EGL_DEPTH_SIZE, &tmp));
m_settings.depthBits = tmp;
eglCheck(eglGetConfigAttrib(m_display, m_config, EGL_STENCIL_SIZE, &tmp));
m_settings.stencilBits = tmp;
eglCheck(eglGetConfigAttrib(m_display, m_config, EGL_SAMPLES, &tmp));
eglCheck(eglGetConfigAttrib(m_display, m_config, EGL_SAMPLE_BUFFERS, &tmp));
m_settings.antialiasingLevel = tmp;
m_settings.majorVersion = 1;
m_settings.minorVersion = 1;
m_settings.attributeFlags = ContextSettings::Default;