diff --git a/.gitignore b/.gitignore index 834cb7f..fda8550 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ .fips-settings.yml *.pyc *.ktx +tests/07-gltf/assets/Buggy.gltf +tests/07-gltf/assets/Buggy0.bin diff --git a/src/3d/private/gltf.cpp b/src/3d/private/gltf.cpp index 59fcc2a..5dc7181 100644 --- a/src/3d/private/gltf.cpp +++ b/src/3d/private/gltf.cpp @@ -65,6 +65,21 @@ namespace ari::en core::String BasePath; }; + core::Array> g_aGltfPipelines; + + gfx::PipelineHandle GetPipelineHandle(const gfx::PipelineSetup& setup) + { + for (auto& pair: g_aGltfPipelines) + { + const auto& p = pair.Key(); + if (p == setup) + return pair.Value(); + } + const auto pipe = gfx::CreatePipeline(setup); + g_aGltfPipelines.Add({ setup, pipe }); + return pipe; + } + void SetPipelineAttribute(gfx::VertexAttrSetup& attr, cgltf_attribute* gltf_attr) { switch (gltf_attr->data->component_type) @@ -463,7 +478,7 @@ namespace ari::en bindings.vertexBufferOffsets[2] = bindings.vertexBufferOffsets[7]; bindings.vertexBuffers[2] = bindings.vertexBuffers[7]; } - sub_mesh->Pipeline = gfx::CreatePipeline(pipeline_setup); + sub_mesh->Pipeline = GetPipelineHandle(pipeline_setup); sub_mesh->Binding = gfx::CreateBinding(bindings); } } diff --git a/src/en/World.hpp b/src/en/World.hpp index a3b0d68..27a50f0 100644 --- a/src/en/World.hpp +++ b/src/en/World.hpp @@ -183,7 +183,7 @@ namespace ari::en template ComponentHandle World::CreateComponent() { - core::MemoryPool::Setup(102400); + core::MemoryPool::Setup(302400); uint32_t i; const uint32_t h = core::HandleManager::GetNewHandle(i); diff --git a/src/gfx/gfx.hpp b/src/gfx/gfx.hpp index 05fd9e2..ccd2338 100644 --- a/src/gfx/gfx.hpp +++ b/src/gfx/gfx.hpp @@ -88,6 +88,29 @@ namespace ari LayoutSetup layout; ShaderHandle shader; IndexType index_type = IndexType::None; + + /// equality operator + bool operator==(const PipelineSetup& rhs) const + { + if (shader.Handle != rhs.shader.Handle + || index_type != rhs.index_type) + return false; + for (int i = 0; i < ARI_MAX_SHADERSTAGE_BUFFERS; ++i) + { + if (layout.buffers[i].step != rhs.layout.buffers[i].step + || layout.buffers[i].stepRate != rhs.layout.buffers[i].stepRate + || layout.buffers[i].stride != rhs.layout.buffers[i].stride) + return false; + } + for (int i = 0; i < ARI_MAX_VERTEX_ATTRIBUTES; ++i) + { + if (layout.attrs[i].bufferIndex != rhs.layout.attrs[i].bufferIndex + || layout.attrs[i].offset != rhs.layout.attrs[i].offset + || layout.attrs[i].format != rhs.layout.attrs[i].format) + return false; + } + return true; + } }; struct Bindings @@ -98,6 +121,27 @@ namespace ari int indexBufferOffset = 0; TextureHandle vsTextures[ARI_MAX_SHADERSTAGE_TEXTURES]; TextureHandle fsTextures[ARI_MAX_SHADERSTAGE_TEXTURES]; + + /// equality operator + bool operator==(const Bindings& rhs) const + { + if (indexBuffer.Handle != rhs.indexBuffer.Handle + || indexBufferOffset != rhs.indexBufferOffset) + return false; + for (int i = 0; i < ARI_MAX_SHADERSTAGE_BUFFERS; ++i) + { + if (vertexBufferOffsets[i] != rhs.vertexBufferOffsets[i] + || vertexBuffers[i].Handle != rhs.vertexBuffers[i].Handle) + return false; + } + for (int i = 0; i < ARI_MAX_SHADERSTAGE_TEXTURES; ++i) + { + if (fsTextures[i].Handle != rhs.fsTextures[i].Handle + || vsTextures[i].Handle != rhs.vsTextures[i].Handle) + return false; + } + return true; + } }; enum class ShaderStage diff --git a/src/gfx/private/glfw/gfx_glfw.cpp b/src/gfx/private/glfw/gfx_glfw.cpp index 0a5ac08..b4f2c8a 100644 --- a/src/gfx/private/glfw/gfx_glfw.cpp +++ b/src/gfx/private/glfw/gfx_glfw.cpp @@ -17,7 +17,7 @@ namespace ari { bool SetupGfx(GfxSetup& setup) { - const io::WindowHandle window = io::CreateAriWindow(setup.window, "Ari 0.3"); + const io::WindowHandle window = io::CreateAriWindow(setup.window, "Ari 0.4"); if (!window.IsValid()) return false;