9#ifndef AVARA3D_RENDER_BACKEND_OPENGL_OGLRESOURCECACHE_H
10#define AVARA3D_RENDER_BACKEND_OPENGL_OGLRESOURCECACHE_H
14#include <unordered_map>
17#include "a3d/render/PipelineDesc.h"
18#include "a3d/render/backend/opengl/GLTypes.h"
24 class OGLMemoryTracker;
30 PipelineDesc desc = {};
31 gl::uint_t program = 0;
34 struct OGLMeshElement {
38 gl::enum_t indexType = gl::value::unsigned_int;
39 uint32_t indexCount = 0;
40 uint32_t vertexCount = 0;
41 VertexLayout vertexLayoutKey = VertexLayout::None;
44 static constexpr size_t NUM_MATERIAL_PROPERTY_SLOTS = 4;
47 std::array<gl::uint_t, NUM_MATERIAL_PROPERTY_SLOTS> tex = {};
48 float specularExponent = 75.0f;
56 class OGLResourceCache {
61 explicit OGLResourceCache(OGLMemoryTracker& memoryTracker);
63 OGLResourceCache(
const OGLResourceCache&) =
delete;
64 OGLResourceCache& operator=(
const OGLResourceCache&) =
delete;
66 OGLResourceCache(OGLResourceCache&&) =
delete;
67 OGLResourceCache& operator=(OGLResourceCache&&) =
delete;
73 PipelineId ensurePipeline(
const PipelineDesc& desc, gl::uint_t program);
74 const OGLPipeline& pipeline(PipelineId pipelineId)
const;
75 const OGLMeshElement& ensureMeshElement(MeshElement& element);
76 const OGLMaterial& ensureMaterial(Material& material);
77 const OGLTexture& ensureTexture(Texture& texture);
82 OGLMemoryTracker& _memoryTracker;
83 std::unordered_map<PipelineDesc, PipelineId, PipelineDescHash> _pipelineMap;
84 std::vector<OGLPipeline> _pipelineList;
85 std::unordered_map<MeshElement*, OGLMeshElement> _meshElementMap;
86 std::unordered_map<Material*, OGLMaterial> _materialMap;
87 std::unordered_map<Texture*, OGLTexture> _textureMap;