44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <assets/handle.h>
|
|
#include <functional>
|
|
#include <mutex>
|
|
#include <renderer/material.h>
|
|
#include <renderer/shader.h>
|
|
#include <renderer/texture.h>
|
|
#include <shared_mutex>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace extra2d {
|
|
|
|
class AssetDependencyGraph {
|
|
public:
|
|
void clear();
|
|
void registerDependency(Handle<Material> material, Handle<Texture> texture);
|
|
void registerDependency(Handle<Material> material, Handle<Shader> shader);
|
|
void notifyTextureReloaded(
|
|
Handle<Texture> texture,
|
|
const std::function<void(Handle<Material>)> &onMaterialUpdate) const;
|
|
void notifyShaderReloaded(
|
|
Handle<Shader> shader,
|
|
const std::function<void(Handle<Material>)> &onMaterialUpdate) const;
|
|
|
|
private:
|
|
struct TextureDeps {
|
|
Handle<Texture> texture;
|
|
std::vector<Handle<Material>> materials;
|
|
};
|
|
|
|
struct ShaderDeps {
|
|
Handle<Shader> shader;
|
|
std::vector<Handle<Material>> materials;
|
|
};
|
|
|
|
std::unordered_map<uint32_t, TextureDeps> textureDeps_;
|
|
std::unordered_map<uint32_t, ShaderDeps> shaderDeps_;
|
|
mutable std::shared_mutex mutex_;
|
|
};
|
|
|
|
} // namespace extra2d
|