Repository: google/filament
File: filament/src/details/Engine.cpp (C++)

Code before:
bool FEngine::isPaused() const noexcept {
    return mCommandBufferQueue.isPaused();
}

void FEngine::setPaused(bool const paused) {
    mCommandBufferQueue.setPaused(paused);
}

Engine::FeatureLevel FEngine::getSupportedFeatureLevel() const noexcept {
    DriverApi& driver = const_cast<FEngine*>(this)->getDriverApi();
    return driver.getFeatureLevel();
}

Engine::FeatureLevel FEngine::setActiveFeatureLevel(FeatureLevel featureLevel) {
    FILAMENT_CHECK_PRECONDITION(featureLevel <= getSupportedFeatureLevel())
            << "Feature level " << unsigned(featureLevel) << " not supported";
    FILAMENT_CHECK_PRECONDITION(mActiveFeatureLevel >= FeatureLevel::FEATURE_LEVEL_1)
            << "Cannot adjust feature level beyond 0 at runtime";
    return (mActiveFeatureLevel = std::max(mActiveFeatureLevel, featureLevel));
}

bool FEngine::isAsynchronousOperationSupported() const noexcept {
    DriverApi& driver = const_cast<FEngine*>(this)->getDriverApi();
    return features.backend.enable_asynchronous_operation &&
            mConfig.asynchronousMode != AsynchronousMode::NONE &&
            driver.isAsynchronousOperationSupported();
}

#if defined(__EMSCRIPTEN__)
void FEngine::resetBackendState() noexcept {
    getDriverApi().resetState();
}
#endif

void FEngine::unprotected() noexcept {
    if (UTILS_UNLIKELY(!mUnprotectedDummySwapchain)) {
        mUnprotectedDummySwapchain = createSwapChain(1, 1, 0);
    }
    mUnprotectedDummySwapchain->makeCurrent(getDriverApi());
}

bool FEngine::setFeatureFlag(char const* name, bool const value) const noexcept {
    auto* const p = getFeatureFlagPtr(name);
    if (p) {
        *p = value;
    }
    return p != nullptr;
}

std::optional<bool> FEngine::getFeatureFlag(char const* name) const noexcept {
    auto* const p = getFeatureFlagPtr(name, true);

Review comment (bug):
I think this is okay, but in reality `mConfig.asynchronousMode` should never be anything other than `NONE` if either the feature is off or the driver doesn't support it. And technically this value can be cached entirely, since it can never change after the engine is created.

I think it okay to document that setting the async mode can silently fail if not supported, as long as there is a query (e.g. getAsynchronousMode()) and it returns `false` when not supported or not enabled.

make sense?



Code after:
bool FEngine::isPaused() const noexcept {
    return mCommandBufferQueue.isPaused();
}

void FEngine::setPaused(bool const paused) {
    mCommandBufferQueue.setPaused(paused);
}

Engine::FeatureLevel FEngine::getSupportedFeatureLevel() const noexcept {
    DriverApi& driver = const_cast<FEngine*>(this)->getDriverApi();
    return driver.getFeatureLevel();
}

Engine::FeatureLevel FEngine::setActiveFeatureLevel(FeatureLevel featureLevel) {
    FILAMENT_CHECK_PRECONDITION(featureLevel <= getSupportedFeatureLevel())
            << "Feature level " << unsigned(featureLevel) << " not supported";
    FILAMENT_CHECK_PRECONDITION(mActiveFeatureLevel >= FeatureLevel::FEATURE_LEVEL_1)
            << "Cannot adjust feature level beyond 0 at runtime";
    return (mActiveFeatureLevel = std::max(mActiveFeatureLevel, featureLevel));
}

bool FEngine::isAsynchronousModeEnabled() const noexcept {
    DriverApi& driver = const_cast<FEngine*>(this)->getDriverApi();
    return driver.isAsynchronousModeEnabled();
}

#if defined(__EMSCRIPTEN__)
void FEngine::resetBackendState() noexcept {
    getDriverApi().resetState();
}
#endif

void FEngine::unprotected() noexcept {
    if (UTILS_UNLIKELY(!mUnprotectedDummySwapchain)) {
        mUnprotectedDummySwapchain = createSwapChain(1, 1, 0);
    }
    mUnprotectedDummySwapchain->makeCurrent(getDriverApi());
}

bool FEngine::setFeatureFlag(char const* name, bool const value) const noexcept {
    auto* const p = getFeatureFlagPtr(name);
    if (p) {
        *p = value;
    }
    return p != nullptr;
}

std::optional<bool> FEngine::getFeatureFlag(char const* name) const noexcept {
    auto* const p = getFeatureFlagPtr(name, true);
    if (p) {
        return *p;