filamat: add Backend-to-TargetApi utility.

This commit is contained in:
Philip Rideout
2019-09-10 16:16:15 -07:00
parent 2072b67e04
commit 88bcd133f2
3 changed files with 20 additions and 20 deletions

View File

@@ -112,6 +112,20 @@ inline constexpr MaterialBuilderBase::TargetApi operator|=(MaterialBuilderBase::
return lhs = (lhs | rhs);
}
// Utility function that looks at an Engine backend to determine TargetApi
inline constexpr MaterialBuilderBase::TargetApi targetApiFromBackend(
filament::backend::Backend backend) noexcept {
using filament::backend::Backend;
using TargetApi = MaterialBuilderBase::TargetApi;
switch (backend) {
case Backend::DEFAULT: return TargetApi::ALL;
case Backend::OPENGL: return TargetApi::OPENGL;
case Backend::VULKAN: return TargetApi::VULKAN;
case Backend::METAL: return TargetApi::METAL;
case Backend::NOOP: return TargetApi::OPENGL;
}
}
inline constexpr bool operator&(MaterialBuilderBase::TargetApi lhs,
MaterialBuilderBase::TargetApi rhs) noexcept {
return bool(uint8_t(lhs) & uint8_t(rhs));

View File

@@ -203,22 +203,8 @@ Material* createMaterial(Engine* engine, const MaterialKey& config, const UvMap&
.name(name)
.flipUV(false)
.material(shader.c_str())
.doubleSided(config.doubleSided);
switch (engine->getBackend()) {
case Engine::Backend::OPENGL:
builder.targetApi(MaterialBuilder::TargetApi::OPENGL);
break;
case Engine::Backend::VULKAN:
builder.targetApi(MaterialBuilder::TargetApi::VULKAN);
break;
case Engine::Backend::METAL:
builder.targetApi(MaterialBuilder::TargetApi::METAL);
break;
default:
slog.e << "Unresolved backend, unable to use filamat." << io::endl;
return nullptr;
}
.doubleSided(config.doubleSided)
.targetApi(filamat::targetApiFromBackend(engine->getBackend()));
#ifndef NDEBUG
builder.optimization(MaterialBuilder::Optimization::NONE);

View File

@@ -88,7 +88,7 @@ Entity createQuad(Engine* engine, Texture* tex, ImageOp op, Texture* secondary)
)SHADER")
.require(VertexAttribute::UV0)
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "color")
.targetApi(filamat::MaterialBuilder::TargetApi::OPENGL)
.targetApi(filamat::targetApiFromBackend(engine.getBackend()))
.shading(Shading::UNLIT)
.depthWrite(false)
.depthCulling(false)
@@ -112,7 +112,7 @@ Entity createQuad(Engine* engine, Texture* tex, ImageOp op, Texture* secondary)
.require(VertexAttribute::UV0)
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "color")
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "secondary")
.targetApi(filamat::MaterialBuilder::TargetApi::OPENGL)
.targetApi(filamat::targetApiFromBackend(engine.getBackend()))
.shading(Shading::UNLIT)
.depthWrite(false)
.depthCulling(false)
@@ -196,7 +196,7 @@ Entity createQuad(Engine* engine, Texture* tex, ImageOp op, Texture* secondary)
.require(VertexAttribute::UV0)
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "color")
.parameter(filamat::MaterialBuilder::UniformType::FLOAT4, SAMPLE_COUNT, "weights")
.targetApi(filamat::MaterialBuilder::TargetApi::OPENGL)
.targetApi(filamat::targetApiFromBackend(engine.getBackend()))
.shading(Shading::UNLIT)
.depthWrite(false)
.depthCulling(false)
@@ -312,7 +312,7 @@ Entity createDisk(Engine* engine, Texture* reflection) {
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "roughness")
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "ao")
.parameter(filamat::MaterialBuilder::SamplerType::SAMPLER_2D, "reflection")
.targetApi(filamat::MaterialBuilder::TargetApi::OPENGL)
.targetApi(filamat::targetApiFromBackend(engine->getBackend()))
.specularAntiAliasing(true)
.shading(Shading::LIT)
.build();