Implement initial Unity-style asset library cache
This commit is contained in:
@@ -46,7 +46,7 @@ void Material::SetShaderPass(const Containers::String& shaderPass) {
|
||||
}
|
||||
|
||||
void Material::SetTag(const Containers::String& name, const Containers::String& value) {
|
||||
for (TagEntry& tag : m_tags) {
|
||||
for (MaterialTagEntry& tag : m_tags) {
|
||||
if (tag.name == name) {
|
||||
tag.value = value;
|
||||
UpdateMemorySize();
|
||||
@@ -54,7 +54,7 @@ void Material::SetTag(const Containers::String& name, const Containers::String&
|
||||
}
|
||||
}
|
||||
|
||||
TagEntry tag;
|
||||
MaterialTagEntry tag;
|
||||
tag.name = name;
|
||||
tag.value = value;
|
||||
m_tags.PushBack(tag);
|
||||
@@ -62,7 +62,7 @@ void Material::SetTag(const Containers::String& name, const Containers::String&
|
||||
}
|
||||
|
||||
Containers::String Material::GetTag(const Containers::String& name) const {
|
||||
for (const TagEntry& tag : m_tags) {
|
||||
for (const MaterialTagEntry& tag : m_tags) {
|
||||
if (tag.name == name) {
|
||||
return tag.value;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ Containers::String Material::GetTag(const Containers::String& name) const {
|
||||
}
|
||||
|
||||
bool Material::HasTag(const Containers::String& name) const {
|
||||
for (const TagEntry& tag : m_tags) {
|
||||
for (const MaterialTagEntry& tag : m_tags) {
|
||||
if (tag.name == name) {
|
||||
return true;
|
||||
}
|
||||
@@ -99,6 +99,14 @@ void Material::ClearTags() {
|
||||
UpdateMemorySize();
|
||||
}
|
||||
|
||||
Containers::String Material::GetTagName(Core::uint32 index) const {
|
||||
return index < m_tags.Size() ? m_tags[index].name : Containers::String();
|
||||
}
|
||||
|
||||
Containers::String Material::GetTagValue(Core::uint32 index) const {
|
||||
return index < m_tags.Size() ? m_tags[index].value : Containers::String();
|
||||
}
|
||||
|
||||
void Material::SetFloat(const Containers::String& name, float value) {
|
||||
MaterialProperty prop;
|
||||
prop.name = name;
|
||||
@@ -180,7 +188,7 @@ void Material::SetTexture(const Containers::String& name, const ResourceHandle<T
|
||||
}
|
||||
}
|
||||
|
||||
TextureBinding binding;
|
||||
MaterialTextureBinding binding;
|
||||
binding.name = name;
|
||||
binding.slot = static_cast<Core::uint32>(m_textureBindings.Size());
|
||||
binding.texture = texture;
|
||||
@@ -246,6 +254,24 @@ ResourceHandle<Texture> Material::GetTexture(const Containers::String& name) con
|
||||
return ResourceHandle<Texture>();
|
||||
}
|
||||
|
||||
Containers::String Material::GetTextureBindingName(Core::uint32 index) const {
|
||||
return index < m_textureBindings.Size() ? m_textureBindings[index].name : Containers::String();
|
||||
}
|
||||
|
||||
ResourceHandle<Texture> Material::GetTextureBindingTexture(Core::uint32 index) const {
|
||||
return index < m_textureBindings.Size() ? m_textureBindings[index].texture : ResourceHandle<Texture>();
|
||||
}
|
||||
|
||||
std::vector<MaterialProperty> Material::GetProperties() const {
|
||||
std::vector<MaterialProperty> properties;
|
||||
const auto pairs = m_properties.GetPairs();
|
||||
properties.reserve(pairs.Size());
|
||||
for (const auto& pair : pairs) {
|
||||
properties.push_back(pair.second);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
void Material::UpdateConstantBuffer() {
|
||||
m_constantBufferData.Clear();
|
||||
UpdateMemorySize();
|
||||
@@ -275,13 +301,13 @@ void Material::UpdateMemorySize() {
|
||||
m_memorySize = m_constantBufferData.Size() +
|
||||
sizeof(MaterialRenderState) +
|
||||
m_shaderPass.Length() +
|
||||
m_tags.Size() * sizeof(TagEntry) +
|
||||
m_textureBindings.Size() * sizeof(TextureBinding) +
|
||||
m_tags.Size() * sizeof(MaterialTagEntry) +
|
||||
m_textureBindings.Size() * sizeof(MaterialTextureBinding) +
|
||||
m_properties.Size() * sizeof(MaterialProperty) +
|
||||
m_name.Length() +
|
||||
m_path.Length();
|
||||
|
||||
for (const TagEntry& tag : m_tags) {
|
||||
for (const MaterialTagEntry& tag : m_tags) {
|
||||
m_memorySize += tag.name.Length();
|
||||
m_memorySize += tag.value.Length();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user