refactor: add minimal material gpu binding
This commit is contained in:
@@ -225,6 +225,75 @@ TEST(Material, SetTextureReplacesExistingBinding) {
|
||||
EXPECT_EQ(material.GetTexture("uDiffuse").Get(), secondTexture);
|
||||
}
|
||||
|
||||
TEST(Material, ChangeVersionIncrementsWhenMaterialMutates) {
|
||||
Material material;
|
||||
const XCEngine::Core::uint64 initialVersion = material.GetChangeVersion();
|
||||
|
||||
material.SetFloat("uTime", 1.0f);
|
||||
const XCEngine::Core::uint64 afterFloatVersion = material.GetChangeVersion();
|
||||
EXPECT_GT(afterFloatVersion, initialVersion);
|
||||
|
||||
material.SetTexture("uDiffuse", ResourceHandle<Texture>(new Texture()));
|
||||
EXPECT_GT(material.GetChangeVersion(), afterFloatVersion);
|
||||
}
|
||||
|
||||
TEST(Material, UpdateConstantBufferPacksNumericPropertiesIntoStableSlots) {
|
||||
Material material;
|
||||
material.SetFloat("alpha", 3.5f);
|
||||
material.SetFloat4("beta", Vector4(1.0f, 2.0f, 3.0f, 4.0f));
|
||||
material.SetInt("gamma", 7);
|
||||
|
||||
const auto& constantBufferData = material.GetConstantBufferData();
|
||||
ASSERT_EQ(constantBufferData.Size(), 48u);
|
||||
|
||||
const float* alphaSlot = reinterpret_cast<const float*>(constantBufferData.Data());
|
||||
EXPECT_FLOAT_EQ(alphaSlot[0], 3.5f);
|
||||
EXPECT_FLOAT_EQ(alphaSlot[1], 0.0f);
|
||||
EXPECT_FLOAT_EQ(alphaSlot[2], 0.0f);
|
||||
EXPECT_FLOAT_EQ(alphaSlot[3], 0.0f);
|
||||
|
||||
const float* betaSlot = reinterpret_cast<const float*>(constantBufferData.Data() + 16);
|
||||
EXPECT_FLOAT_EQ(betaSlot[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(betaSlot[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(betaSlot[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(betaSlot[3], 4.0f);
|
||||
|
||||
const XCEngine::Core::int32* gammaSlot =
|
||||
reinterpret_cast<const XCEngine::Core::int32*>(constantBufferData.Data() + 32);
|
||||
EXPECT_EQ(gammaSlot[0], 7);
|
||||
EXPECT_EQ(gammaSlot[1], 0);
|
||||
EXPECT_EQ(gammaSlot[2], 0);
|
||||
EXPECT_EQ(gammaSlot[3], 0);
|
||||
}
|
||||
|
||||
TEST(Material, RemoveTexturePropertyAlsoRemovesTextureBinding) {
|
||||
Material material;
|
||||
Texture* texture = new Texture();
|
||||
|
||||
material.SetTexture("uDiffuse", ResourceHandle<Texture>(texture));
|
||||
ASSERT_EQ(material.GetTextureBindingCount(), 1u);
|
||||
|
||||
material.RemoveProperty("uDiffuse");
|
||||
|
||||
EXPECT_FALSE(material.HasProperty("uDiffuse"));
|
||||
EXPECT_EQ(material.GetTextureBindingCount(), 0u);
|
||||
EXPECT_EQ(material.GetTexture("uDiffuse").Get(), nullptr);
|
||||
}
|
||||
|
||||
TEST(Material, ReplacingTexturePropertyWithScalarRemovesTextureBinding) {
|
||||
Material material;
|
||||
Texture* texture = new Texture();
|
||||
|
||||
material.SetTexture("uMain", ResourceHandle<Texture>(texture));
|
||||
ASSERT_EQ(material.GetTextureBindingCount(), 1u);
|
||||
|
||||
material.SetFloat("uMain", 2.0f);
|
||||
|
||||
EXPECT_EQ(material.GetTextureBindingCount(), 0u);
|
||||
EXPECT_EQ(material.GetTexture("uMain").Get(), nullptr);
|
||||
EXPECT_FLOAT_EQ(material.GetFloat("uMain"), 2.0f);
|
||||
}
|
||||
|
||||
TEST(Material, HasProperty) {
|
||||
Material material;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user