Repository: google/filament
File: filament/backend/src/opengl/OpenGLDriver.cpp (C++)

Code before:
        #if defined(__EMSCRIPTEN__)
            return false;
        #else
            return gl.ext.EXT_color_buffer_half_float;
        #endif

        // Float formats from GL_EXT_color_buffer_float
        case TextureFormat::R32F:
        case TextureFormat::RG32F:
        case TextureFormat::RGBA32F:
            return gl.ext.EXT_color_buffer_float;

        // RGB_11_11_10 is only supported with some  specific extensions
        case TextureFormat::R11F_G11F_B10F:
            return gl.ext.EXT_color_buffer_float || gl.ext.APPLE_color_buffer_packed_float;

        default:
            return false;
    }
}

bool OpenGLDriver::isFrameBufferFetchSupported() {
    auto& gl = mContext;
    if (gl.bugs.disable_framebuffer_fetch_extension) {
        return false;
    }
    return gl.ext.EXT_shader_framebuffer_fetch;
}

bool OpenGLDriver::isFrameBufferFetchMultiSampleSupported() {
    return isFrameBufferFetchSupported();
}

bool OpenGLDriver::isFrameTimeSupported() {
    return TimerQueryFactory::isGpuTimeSupported();
}

bool OpenGLDriver::isAutoDepthResolveSupported() {
    // TODO: this should return true only for GLES3.1+ and EXT_multisampled_render_to_texture2
    return true;
}

bool OpenGLDriver::isSRGBSwapChainSupported() {
    if (UTILS_UNLIKELY(mContext.isES2())) {
        // On ES2 backend (i.e. feature level 0), we always pretend to the client that sRGB
        // SwapChain are available. If we actually have that feature, it'll be used, otherwise
        // we emulate it in the shaders.
        return true;
    }
    return mPlatform.isSRGBSwapChainSupported();
}

Review comment (suggestion):
I think it would be better to do this where (or just after) `gl.ext.EXT_shader_framebuffer_fetch` is set. This way the whole backend is coherent (in case gl.ext.EXT_shader_framebuffer_fetch is checked directly somewhere else), and we don't have to do to checks here.

Code after:
        case TextureFormat::DEPTH32F:
        case TextureFormat::DEPTH24_STENCIL8:
        case TextureFormat::DEPTH32F_STENCIL8:
        case TextureFormat::RG32UI:
        case TextureFormat::RG32I:
        case TextureFormat::RGBA16UI:
        case TextureFormat::RGBA16I:
            return true;

        // Three-component SRGB is a color-renderable texture format in core OpenGL on desktop.
        case TextureFormat::SRGB8:
            return mContext.isAtLeastGL<4, 5>();

        // Half-float formats, requires extension.
        case TextureFormat::R16F:
        case TextureFormat::RG16F:
        case TextureFormat::RGBA16F:
            return gl.ext.EXT_color_buffer_float || gl.ext.EXT_color_buffer_half_float;

        // RGB16F is only supported with EXT_color_buffer_half_float, however
        // some WebGL implementations do not consider this extension to be sufficient:
        // https://bugs.chromium.org/p/chromium/issues/detail?id=941671#c10
        case TextureFormat::RGB16F:
        #if defined(__EMSCRIPTEN__)
            return false;
        #else
            return gl.ext.EXT_color_buffer_half_float;
        #endif

        // Float formats from GL_EXT_color_buffer_float
        case TextureFormat::R32F:
        case TextureFormat::RG32F:
        case TextureFormat::RGBA32F:
            return gl.ext.EXT_color_buffer_float;

        // RGB_11_11_10 is only supported with some  specific extensions
        case TextureFormat::R11F_G11F_B10F:
            return gl.ext.EXT_color_buffer_float || gl.ext.APPLE_color_buffer_packed_float;

        default:
            return false;
    }
}

bool OpenGLDriver::isFrameBufferFetchSupported() {
    auto const& gl = mContext;
    return gl.ext.EXT_shader_framebuffer_fetch;
}

bool OpenGLDriver::isFrameBufferFetchMultiSampleSupported() {
    return isFrameBufferFetchSupported();