Revert "Fix depth prepass (#722)"

This reverts commit 896c85c324.
This commit is contained in:
prideout
2019-01-18 13:09:27 -08:00
committed by Philip Rideout
parent e7169cb889
commit 98d39b7e7e
2 changed files with 22 additions and 2 deletions

View File

@@ -220,6 +220,16 @@ FMaterial::FMaterial(FEngine& engine, const Material::Builder& builder)
parser->hasCustomDepthShader(&mHasCustomDepthShader);
mIsDefaultMaterial = builder->mDefaultMaterial;
// pre-cache the shared variants -- these variants are shared with the default material.
if (UTILS_UNLIKELY(!mIsDefaultMaterial && !mHasCustomDepthShader)) {
auto& cachedPrograms = mCachedPrograms;
for (uint8_t i = 0, n = cachedPrograms.size(); i < n; ++i) {
if (Variant(i).isDepthPass()) {
cachedPrograms[i] = engine.getDefaultMaterial()->getProgram(i);
}
}
}
bool colorWrite;
parser->getColorWrite(&colorWrite);
mRasterState.colorWrite = colorWrite;
@@ -237,8 +247,17 @@ FMaterial::~FMaterial() noexcept {
void FMaterial::terminate(FEngine& engine) {
DriverApi& driverApi = engine.getDriverApi();
auto& cachedPrograms = mCachedPrograms;
for (const auto& cachedProgram : cachedPrograms) {
driverApi.destroyProgram(cachedProgram);
for (size_t i = 0, n = cachedPrograms.size(); i < n; ++i) {
if (!mIsDefaultMaterial) {
// The depth variants may be shared with the default material, in which case
// we should not free it now.
bool isSharedVariant = Variant(i).isDepthPass() && !mHasCustomDepthShader;
if (isSharedVariant) {
// we don't own this variant, skip.
continue;
}
}
driverApi.destroyProgram(cachedPrograms[i]);
}
mDefaultInstance.terminate(engine);
}

View File

@@ -28,6 +28,7 @@ namespace filament {
Variant() noexcept = default;
constexpr Variant(uint8_t key) noexcept : key(key) { }
// DIR: Directional Lighting
// DYN: Dynamic Lighting
// SRE: Shadow Receiver