Import material textures with mesh assets
This commit is contained in:
@@ -15,10 +15,12 @@ void Material::Release() {
|
||||
m_textureBindings.Clear();
|
||||
m_constantBufferData.Clear();
|
||||
m_isValid = false;
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetShader(const ResourceHandle<Shader>& shader) {
|
||||
m_shader = shader;
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetFloat(const Containers::String& name, float value) {
|
||||
@@ -28,6 +30,7 @@ void Material::SetFloat(const Containers::String& name, float value) {
|
||||
prop.value.floatValue[0] = value;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetFloat2(const Containers::String& name, const Math::Vector2& value) {
|
||||
@@ -38,6 +41,7 @@ void Material::SetFloat2(const Containers::String& name, const Math::Vector2& va
|
||||
prop.value.floatValue[1] = value.y;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetFloat3(const Containers::String& name, const Math::Vector3& value) {
|
||||
@@ -49,6 +53,7 @@ void Material::SetFloat3(const Containers::String& name, const Math::Vector3& va
|
||||
prop.value.floatValue[2] = value.z;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetFloat4(const Containers::String& name, const Math::Vector4& value) {
|
||||
@@ -61,6 +66,7 @@ void Material::SetFloat4(const Containers::String& name, const Math::Vector4& va
|
||||
prop.value.floatValue[3] = value.w;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetInt(const Containers::String& name, Core::int32 value) {
|
||||
@@ -70,6 +76,7 @@ void Material::SetInt(const Containers::String& name, Core::int32 value) {
|
||||
prop.value.intValue[0] = value;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetBool(const Containers::String& name, bool value) {
|
||||
@@ -79,6 +86,7 @@ void Material::SetBool(const Containers::String& name, bool value) {
|
||||
prop.value.boolValue = value;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::SetTexture(const Containers::String& name, const ResourceHandle<Texture>& texture) {
|
||||
@@ -87,12 +95,21 @@ void Material::SetTexture(const Containers::String& name, const ResourceHandle<T
|
||||
prop.type = MaterialPropertyType::Texture;
|
||||
prop.refCount = 1;
|
||||
m_properties.Insert(name, prop);
|
||||
|
||||
|
||||
for (auto& binding : m_textureBindings) {
|
||||
if (binding.name == name) {
|
||||
binding.texture = texture;
|
||||
UpdateMemorySize();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextureBinding binding;
|
||||
binding.name = name;
|
||||
binding.slot = static_cast<Core::uint32>(m_textureBindings.Size());
|
||||
binding.texture = texture;
|
||||
m_textureBindings.PushBack(binding);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
float Material::GetFloat(const Containers::String& name) const {
|
||||
@@ -155,6 +172,7 @@ ResourceHandle<Texture> Material::GetTexture(const Containers::String& name) con
|
||||
|
||||
void Material::UpdateConstantBuffer() {
|
||||
m_constantBufferData.Clear();
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
bool Material::HasProperty(const Containers::String& name) const {
|
||||
@@ -163,12 +181,26 @@ bool Material::HasProperty(const Containers::String& name) const {
|
||||
|
||||
void Material::RemoveProperty(const Containers::String& name) {
|
||||
m_properties.Erase(name);
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::ClearAllProperties() {
|
||||
m_properties.Clear();
|
||||
m_textureBindings.Clear();
|
||||
m_constantBufferData.Clear();
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
void Material::UpdateMemorySize() {
|
||||
m_memorySize = m_constantBufferData.Size() +
|
||||
m_textureBindings.Size() * sizeof(TextureBinding) +
|
||||
m_properties.Size() * sizeof(MaterialProperty) +
|
||||
m_name.Length() +
|
||||
m_path.Length();
|
||||
|
||||
for (const auto& binding : m_textureBindings) {
|
||||
m_memorySize += binding.name.Length();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Resources
|
||||
|
||||
Reference in New Issue
Block a user