|
32 | 32 | #endif
|
33 | 33 | #include <utils/compiler.h>
|
34 | 34 |
|
35 |
| -#include <utils/algorithm.h> |
36 | 35 | #include <utils/Invocable.h>
|
37 | 36 | #include <utils/Logger.h>
|
38 | 37 | #include <utils/debug.h>
|
@@ -108,7 +107,9 @@ void PlatformEGL::clearGlError() noexcept {
|
108 | 107 |
|
109 | 108 | // ---------------------------------------------------------------------------------------------
|
110 | 109 |
|
111 |
| -PlatformEGL::PlatformEGL() noexcept = default; |
| 110 | +PlatformEGL::PlatformEGL() noexcept : OpenGLPlatform() { |
| 111 | + mMSAA4XSupport = checkIfMSAASwapChainSupported(4); |
| 112 | +} |
112 | 113 |
|
113 | 114 | int PlatformEGL::getOSVersion() const noexcept {
|
114 | 115 | return 0;
|
@@ -494,58 +495,17 @@ bool PlatformEGL::isMSAASwapChainSupported(uint32_t samples) const noexcept {
|
494 | 495 |
|
495 | 496 | // The number of samples must be a power-of-two > 1.
|
496 | 497 | if ((samples & (samples - 1)) != 0) {
|
497 |
| - LOG(INFO) << "The number of samples for MSAA is not a power of two: " << samples; |
| 498 | + LOG(WARNING) << "The number of samples for MSAA is not a power of two: " << samples; |
498 | 499 | return false;
|
499 | 500 | }
|
500 | 501 |
|
501 |
| - // `samples` is a power-of-two that is greater than 1 (e.g., 2, 4, 8, ...). |
502 |
| - // We use this to compute an index into our cache. |
503 |
| - const uint32_t power = utils::ctz(samples); // `power` is 3 if the number of samples is 8x. |
504 |
| - const uint32_t index = power - 1; // The index 0 originally means 1x, which we don't count. |
505 |
| - // So make the index 0 to indicate 2x. |
506 |
| - if (mMSAASupport.size() <= index) { |
507 |
| - mMSAASupport.resize(index + 1); |
508 |
| - } |
509 |
| - |
510 |
| - // Return the cached value if we have one. |
511 |
| - if (mMSAASupport[index]) { |
512 |
| - return *mMSAASupport[index]; |
513 |
| - } |
514 |
| - |
515 |
| - // Retrieve the config to see if the given number of samples is supported. The result is cached. |
516 |
| - Config configAttribs = { |
517 |
| - { EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT }, |
518 |
| - { EGL_RED_SIZE, 8 }, |
519 |
| - { EGL_GREEN_SIZE, 8 }, |
520 |
| - { EGL_BLUE_SIZE, 8 }, |
521 |
| - { EGL_DEPTH_SIZE, 24 }, |
522 |
| - { EGL_SAMPLE_BUFFERS, 1 }, |
523 |
| - { EGL_SAMPLES, (EGLint)samples }, |
524 |
| - }; |
525 |
| - |
526 |
| - if (!ext.egl.KHR_no_config_context) { |
527 |
| - if (isOpenGL()) { |
528 |
| - configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_BIT; |
529 |
| - } else { |
530 |
| - configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_ES2_BIT; |
531 |
| - if (ext.egl.KHR_create_context) { |
532 |
| - configAttribs[EGL_RENDERABLE_TYPE] |= EGL_OPENGL_ES3_BIT_KHR; |
533 |
| - } |
534 |
| - } |
535 |
| - } |
536 |
| - |
537 |
| - EGLConfig config = EGL_NO_CONFIG_KHR; |
538 |
| - EGLint configsCount; |
539 |
| - bool supported = false; |
540 |
| - if (!eglChooseConfig(mEGLDisplay, configAttribs.data(), &config, 1, &configsCount)) { |
541 |
| - supported = false; |
542 |
| - } else { |
543 |
| - supported = configsCount > 0; |
| 502 | + if (samples == 4) { |
| 503 | + return mMSAA4XSupport; |
544 | 504 | }
|
545 | 505 |
|
546 |
| - mMSAASupport[index] = supported; |
547 |
| - |
548 |
| - return supported; |
| 506 | + // Other sample counts are not cached, retrieve it. |
| 507 | + LOG(INFO) << "MSAA sample count " << samples << " is queried, consider caching it."; |
| 508 | + return checkIfMSAASwapChainSupported(samples); |
549 | 509 | }
|
550 | 510 |
|
551 | 511 | Platform::SwapChain* PlatformEGL::createSwapChain(
|
@@ -865,6 +825,38 @@ EGLContext PlatformEGL::getContextForType(ContextType type) const noexcept {
|
865 | 825 | }
|
866 | 826 | }
|
867 | 827 |
|
| 828 | +bool PlatformEGL::checkIfMSAASwapChainSupported(uint32_t samples) const noexcept { |
| 829 | + // Retrieve the config to see if the given number of samples is supported. The result is cached. |
| 830 | + Config configAttribs = { |
| 831 | + { EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT }, |
| 832 | + { EGL_RED_SIZE, 8 }, |
| 833 | + { EGL_GREEN_SIZE, 8 }, |
| 834 | + { EGL_BLUE_SIZE, 8 }, |
| 835 | + { EGL_DEPTH_SIZE, 24 }, |
| 836 | + { EGL_SAMPLE_BUFFERS, 1 }, |
| 837 | + { EGL_SAMPLES, (EGLint)samples }, |
| 838 | + }; |
| 839 | + |
| 840 | + if (!ext.egl.KHR_no_config_context) { |
| 841 | + if (isOpenGL()) { |
| 842 | + configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_BIT; |
| 843 | + } else { |
| 844 | + configAttribs[EGL_RENDERABLE_TYPE] = EGL_OPENGL_ES2_BIT; |
| 845 | + if (ext.egl.KHR_create_context) { |
| 846 | + configAttribs[EGL_RENDERABLE_TYPE] |= EGL_OPENGL_ES3_BIT_KHR; |
| 847 | + } |
| 848 | + } |
| 849 | + } |
| 850 | + |
| 851 | + EGLConfig config = EGL_NO_CONFIG_KHR; |
| 852 | + EGLint configsCount; |
| 853 | + if (!eglChooseConfig(mEGLDisplay, configAttribs.data(), &config, 1, &configsCount)) { |
| 854 | + return false; |
| 855 | + } |
| 856 | + |
| 857 | + return configsCount > 0; |
| 858 | +} |
| 859 | + |
868 | 860 | // ---------------------------------------------------------------------------------------------
|
869 | 861 |
|
870 | 862 | PlatformEGL::Config::Config() = default;
|
|
0 commit comments