- Split core resource architecture into Core/Asset/ (IResource, ResourceManager, ResourceCache, etc.)
- Moved IO layer into Core/IO/ (IResourceLoader, ResourceFileSystem, etc.)
- Reorganized concrete resource types into Resources/{Texture,Mesh,Material,Shader,AudioClip}/
- Updated all include paths from relative to <XCEngine/...> format
- Fixed circular dependency in Material.h (removed unnecessary ResourceManager.h include)
- Fixed malformed include syntax in ResourceManager.h and AsyncLoader.h
- Fixed glad.h path issues in CMakeLists.txt
94 lines
3.2 KiB
C++
94 lines
3.2 KiB
C++
#pragma once
|
|
#include "IResource.h"
|
|
#include "ResourceHandle.h"
|
|
#include "ResourceManager.h"
|
|
#include "Texture.h"
|
|
#include "Shader.h"
|
|
#include "../Containers/HashMap.h"
|
|
#include "../Core/Types.h"
|
|
#include "../Math/Vector2.h"
|
|
#include "../Math/Vector3.h"
|
|
#include "../Math/Vector4.h"
|
|
#include <cstring>
|
|
|
|
namespace XCEngine {
|
|
namespace Resources {
|
|
|
|
enum class MaterialPropertyType {
|
|
Float, Float2, Float3, Float4,
|
|
Int, Int2, Int3, Int4,
|
|
Bool, Texture, Cubemap
|
|
};
|
|
|
|
struct MaterialProperty {
|
|
Containers::String name;
|
|
MaterialPropertyType type;
|
|
|
|
union Value {
|
|
float floatValue[4];
|
|
Core::int32 intValue[4];
|
|
bool boolValue;
|
|
|
|
Value() { memset(this, 0, sizeof(Value)); }
|
|
} value;
|
|
|
|
Core::uint32 refCount = 0;
|
|
|
|
MaterialProperty() : type(MaterialPropertyType::Float), refCount(0) {}
|
|
};
|
|
|
|
class Material : public IResource {
|
|
public:
|
|
Material();
|
|
virtual ~Material() override;
|
|
|
|
ResourceType GetType() const override { return ResourceType::Material; }
|
|
const Containers::String& GetName() const override { return m_name; }
|
|
const Containers::String& GetPath() const override { return m_path; }
|
|
ResourceGUID GetGUID() const override { return m_guid; }
|
|
bool IsValid() const override { return m_isValid; }
|
|
size_t GetMemorySize() const override { return m_memorySize; }
|
|
void Release() override;
|
|
|
|
void SetShader(const ResourceHandle<class Shader>& shader);
|
|
class Shader* GetShader() const { return m_shader.Get(); }
|
|
|
|
void SetFloat(const Containers::String& name, float value);
|
|
void SetFloat2(const Containers::String& name, const Math::Vector2& value);
|
|
void SetFloat3(const Containers::String& name, const Math::Vector3& value);
|
|
void SetFloat4(const Containers::String& name, const Math::Vector4& value);
|
|
void SetInt(const Containers::String& name, Core::int32 value);
|
|
void SetBool(const Containers::String& name, bool value);
|
|
void SetTexture(const Containers::String& name, const ResourceHandle<Texture>& texture);
|
|
|
|
float GetFloat(const Containers::String& name) const;
|
|
Math::Vector2 GetFloat2(const Containers::String& name) const;
|
|
Math::Vector3 GetFloat3(const Containers::String& name) const;
|
|
Math::Vector4 GetFloat4(const Containers::String& name) const;
|
|
Core::int32 GetInt(const Containers::String& name) const;
|
|
bool GetBool(const Containers::String& name) const;
|
|
ResourceHandle<Texture> GetTexture(const Containers::String& name) const;
|
|
|
|
const Containers::Array<Core::uint8>& GetConstantBufferData() const { return m_constantBufferData; }
|
|
void UpdateConstantBuffer();
|
|
|
|
bool HasProperty(const Containers::String& name) const;
|
|
void RemoveProperty(const Containers::String& name);
|
|
void ClearAllProperties();
|
|
|
|
private:
|
|
ResourceHandle<class Shader> m_shader;
|
|
Containers::HashMap<Containers::String, MaterialProperty> m_properties;
|
|
Containers::Array<Core::uint8> m_constantBufferData;
|
|
|
|
struct TextureBinding {
|
|
Containers::String name;
|
|
Core::uint32 slot;
|
|
ResourceHandle<Texture> texture;
|
|
};
|
|
Containers::Array<TextureBinding> m_textureBindings;
|
|
};
|
|
|
|
} // namespace Resources
|
|
} // namespace XCEngine
|