///////////////////////////////////////////////////////
| 269 | |
| 270 | //////////////////////////////////////////////////////////// |
| 271 | EGLConfig EglContext::getBestConfig(EGLDisplay display, unsigned int bitsPerPixel, const ContextSettings& settings) |
| 272 | { |
| 273 | EglContextImpl::ensureInit(); |
| 274 | |
| 275 | // Determine the number of available configs |
| 276 | EGLint configCount = 0; |
| 277 | eglCheck(eglGetConfigs(display, nullptr, 0, &configCount)); |
| 278 | |
| 279 | // Retrieve the list of available configs |
| 280 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays) |
| 281 | const auto configs = std::make_unique<EGLConfig[]>(static_cast<std::size_t>(configCount)); |
| 282 | |
| 283 | eglCheck(eglGetConfigs(display, configs.get(), configCount, &configCount)); |
| 284 | |
| 285 | // Evaluate all the returned configs, and pick the best one |
| 286 | int bestScore = 0x7FFFFFFF; |
| 287 | EGLConfig bestConfig{}; |
| 288 | |
| 289 | for (std::size_t i = 0; i < static_cast<std::size_t>(configCount); ++i) |
| 290 | { |
| 291 | // Check mandatory attributes |
| 292 | int surfaceType = 0; |
| 293 | int renderableType = 0; |
| 294 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SURFACE_TYPE, &surfaceType)); |
| 295 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RENDERABLE_TYPE, &renderableType)); |
| 296 | if (!(surfaceType & (EGL_WINDOW_BIT | EGL_PBUFFER_BIT)) || !(renderableType & EGL_OPENGL_ES_BIT)) |
| 297 | continue; |
| 298 | |
| 299 | // Extract the components of the current config |
| 300 | int red = 0; |
| 301 | int green = 0; |
| 302 | int blue = 0; |
| 303 | int alpha = 0; |
| 304 | int depth = 0; |
| 305 | int stencil = 0; |
| 306 | int multiSampling = 0; |
| 307 | int samples = 0; |
| 308 | int caveat = 0; |
| 309 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red)); |
| 310 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green)); |
| 311 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue)); |
| 312 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &alpha)); |
| 313 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_DEPTH_SIZE, &depth)); |
| 314 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_STENCIL_SIZE, &stencil)); |
| 315 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SAMPLE_BUFFERS, &multiSampling)); |
| 316 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_SAMPLES, &samples)); |
| 317 | eglCheck(eglGetConfigAttrib(display, configs[i], EGL_CONFIG_CAVEAT, &caveat)); |
| 318 | |
| 319 | // Evaluate the config |
| 320 | const int color = red + green + blue + alpha; |
| 321 | const int score = evaluateFormat(bitsPerPixel, |
| 322 | settings, |
| 323 | color, |
| 324 | depth, |
| 325 | stencil, |
| 326 | multiSampling ? samples : 0, |
| 327 | caveat == EGL_NONE, |
| 328 | false); |
nothing calls this directly
no test coverage detected