Repository: google/filament
File: libs/iblprefilter/src/IBLPrefilterContext.cpp (C++)

Code before:
}

IBLPrefilterContext::EquirectangularToCubemap&
IBLPrefilterContext::EquirectangularToCubemap::operator=(
        EquirectangularToCubemap&& rhs) noexcept {
    using std::swap;
    if (this != &rhs) {
        swap(mEquirectMaterial, rhs.mEquirectMaterial);
    }
    return *this;
}

Texture* IBLPrefilterContext::EquirectangularToCubemap::operator()(
        Texture const* equirect, Texture* outCube) {
    FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
    using namespace backend;

    const TextureCubemapFace faces[2][3] = {
            { TextureCubemapFace::POSITIVE_X, TextureCubemapFace::POSITIVE_Y, TextureCubemapFace::POSITIVE_Z },
            { TextureCubemapFace::NEGATIVE_X, TextureCubemapFace::NEGATIVE_Y, TextureCubemapFace::NEGATIVE_Z }
    };

    Engine& engine = mContext.mEngine;
    View* const view = mContext.mView;
    Renderer* const renderer = mContext.mRenderer;
    MaterialInstance* const defaultMi = mEquirectMaterial->getDefaultInstance();

    FILAMENT_CHECK_PRECONDITION(equirect != nullptr) << "equirect is null!";

    FILAMENT_CHECK_PRECONDITION(equirect->getTarget() == Texture::Sampler::SAMPLER_2D)
            << "equirect must be a 2D texture.";

    UTILS_UNUSED_IN_RELEASE
    const uint8_t maxLevelCount = std::max(1, std::ilogbf(float(equirect->getWidth())) + 1);

    FILAMENT_CHECK_PRECONDITION(equirect->getLevels() == maxLevelCount)
            << "equirect must have " << +maxLevelCount << " mipmap levels allocated.";

    if (outCube == nullptr) {
        outCube = Texture::Builder()
                .sampler(Texture::Sampler::SAMPLER_CUBEMAP)
                .format(Texture::InternalFormat::R11F_G11F_B10F)
                .usage(Texture::Usage::COLOR_ATTACHMENT | Texture::Usage::SAMPLEABLE)
                .width(256).height(256).levels(0xFF)
                .build(engine);
    }

    FILAMENT_CHECK_PRECONDITION(outCube->getTarget() == Texture::Sampler::SAMPLER_CUBEMAP)
            << "outCube must be a Cubemap texture.";

    const uint32_t dim = outCube->getWidth();

Review comment (suggestion):
I would like to continue to use `createInstance()` instead of `getDefaultInstance()`. This is because I think `getDefaultInstance()` was an API mistake and I would like to make it deprecated one day.

Code after:
}

IBLPrefilterContext::EquirectangularToCubemap&
IBLPrefilterContext::EquirectangularToCubemap::operator=(
        EquirectangularToCubemap&& rhs) noexcept {
    using std::swap;
    if (this != &rhs) {
        swap(mEquirectMaterial, rhs.mEquirectMaterial);
    }
    return *this;
}

Texture* IBLPrefilterContext::EquirectangularToCubemap::operator()(
        Texture const* equirect, Texture* outCube) {
    FILAMENT_TRACING_CALL(FILAMENT_TRACING_CATEGORY_FILAMENT);
    using namespace backend;

    const TextureCubemapFace faces[2][3] = {
            { TextureCubemapFace::POSITIVE_X, TextureCubemapFace::POSITIVE_Y, TextureCubemapFace::POSITIVE_Z },
            { TextureCubemapFace::NEGATIVE_X, TextureCubemapFace::NEGATIVE_Y, TextureCubemapFace::NEGATIVE_Z }
    };

    Engine& engine = mContext.mEngine;
    View* const view = mContext.mView;
    Renderer* const renderer = mContext.mRenderer;
    MaterialInstance* const mi = mEquirectMaterial->createInstance();

    FILAMENT_CHECK_PRECONDITION(equirect != nullptr) << "equirect is null!";

    FILAMENT_CHECK_PRECONDITION(equirect->getTarget() == Texture::Sampler::SAMPLER_2D)
            << "equirect must be a 2D texture.";

    UTILS_UNUSED_IN_RELEASE
    const uint8_t maxLevelCount = std::max(1, std::ilogbf(float(equirect->getWidth())) + 1);

    FILAMENT_CHECK_PRECONDITION(equirect->getLevels() == maxLevelCount)
            << "equirect must have " << +maxLevelCount << " mipmap levels allocated.";

    if (outCube == nullptr) {
        outCube = Texture::Builder()
                .sampler(Texture::Sampler::SAMPLER_CUBEMAP)
                .format(Texture::InternalFormat::R11F_G11F_B10F)
                .usage(Texture::Usage::COLOR_ATTACHMENT | Texture::Usage::SAMPLEABLE)
                .width(256).height(256).levels(0xFF)
                .build(engine);
    }

    FILAMENT_CHECK_PRECONDITION(outCube->getTarget() == Texture::Sampler::SAMPLER_CUBEMAP)
            << "outCube must be a Cubemap texture.";

    const uint32_t dim = outCube->getWidth();