Skip to content

Commit

Permalink
Share gltf pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
kochol committed May 5, 2020
1 parent 7a3c2b0 commit c08ea9c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@
.fips-settings.yml
*.pyc
*.ktx
tests/07-gltf/assets/Buggy.gltf
tests/07-gltf/assets/Buggy0.bin
17 changes: 16 additions & 1 deletion src/3d/private/gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ namespace ari::en
core::String BasePath;
};

core::Array<core::KeyValuePair<gfx::PipelineSetup, gfx::PipelineHandle>> 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)
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/en/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace ari::en
template<class T, class BASE>
ComponentHandle<T> World::CreateComponent()
{
core::MemoryPool<BASE>::Setup(102400);
core::MemoryPool<BASE>::Setup(302400);
uint32_t i;
const uint32_t h = core::HandleManager<BASE>::GetNewHandle(i);

Expand Down
44 changes: 44 additions & 0 deletions src/gfx/gfx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gfx/private/glfw/gfx_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c08ea9c

Please sign in to comment.