Cashing of indices and vertices count

This commit is contained in:
Antoine Pilote
2023-10-02 01:35:58 -04:00
parent cf7a6c20d6
commit fc7645b4c6
5 changed files with 24 additions and 8 deletions

View File

@@ -30,6 +30,11 @@ namespace Nuake
{
m_Material = MaterialManager::Get()->GetMaterial("default");
}
m_IndicesCount = static_cast<uint32_t>(m_Indices.size());
m_VerticesCount = static_cast<uint32_t>(m_Vertices.size());
//m_Indices.clear();
}
std::vector<Vertex>& Mesh::GetVertices()
@@ -104,7 +109,7 @@ namespace Nuake
m_Material->Bind(shader);
m_VertexArray->Bind();
RenderCommand::DrawElements(RendererEnum::TRIANGLES, (int)m_Indices.size(), RendererEnum::UINT, 0);
RenderCommand::DrawElements(RendererEnum::TRIANGLES, m_IndicesCount, RendererEnum::UINT, 0);
}
void Mesh::DebugDraw()
@@ -113,14 +118,18 @@ namespace Nuake
Renderer::m_DebugShader->SetUniform4f("u_Color", 1.0f, 0.0f, 0.0f, 1.f);
m_VertexArray->Bind();
RenderCommand::DrawElements(RendererEnum::TRIANGLES, (int)m_Indices.size(), RendererEnum::UINT, 0);
RenderCommand::DrawElements(RendererEnum::TRIANGLES, m_IndicesCount, RendererEnum::UINT, 0);
}
json Mesh::Serialize()
{
BEGIN_SERIALIZE();
j["Material"] = m_Material->Serialize();
if (m_Material)
{
j["Material"] = m_Material->Serialize();
}
j["Indices"] = m_Indices;
json v;
@@ -155,7 +164,7 @@ namespace Nuake
bool Mesh::Deserialize(const json& j)
{
bool loadedMaterialFile = false;
if (j["Material"].contains("Path"))
if (j.contains("Material") && j["Material"].contains("Path"))
{
const std::string materialPath = j["Material"]["Path"];
if (!materialPath.empty())
@@ -166,7 +175,7 @@ namespace Nuake
}
}
if(!loadedMaterialFile)
if(!loadedMaterialFile && j.contains("Material"))
{
m_Material = CreateRef<Material>();
m_Material->Deserialize(j["Material"]);
@@ -178,6 +187,8 @@ namespace Nuake
m_Indices.push_back(i);
}
m_IndicesCount = m_Indices.size();
std::vector<Vertex> vertices;
std::async(std::launch::async, [&]()

View File

@@ -39,6 +39,9 @@ namespace Nuake
std::vector<uint32_t> m_Indices;
std::vector<Vertex> m_Vertices;
uint32_t m_IndicesCount;
uint32_t m_VerticesCount;
Scope<VertexBuffer> m_VertexBuffer;
Scope<VertexArray> m_VertexArray;
Scope<VertexBuffer> m_ElementBuffer;

View File

@@ -86,7 +86,7 @@ namespace Nuake {
glMultiDrawElements(GetType(mode), &count, GetType(type), indices, drawCount);
}
void OGLRendererAPI::DrawElements(const RendererEnum mode, const int count, const RendererEnum type, const void* indices)
void OGLRendererAPI::DrawElements(const RendererEnum mode, const uint32_t count, const RendererEnum type, const void* indices)
{
glDrawElements(GetType(mode), count, GetType(type), indices);
}

View File

@@ -2,7 +2,9 @@
#include "RendererAPI.h"
typedef unsigned int GLenum;
namespace Nuake {
class OGLRendererAPI : public RendererAPI
{
public:
@@ -27,7 +29,7 @@ namespace Nuake {
void VertexAttribPointer(const unsigned int index, const int size, const RendererEnum type, bool normalized, int stride, const void* pointer) override;
void DrawMultiElements(const RendererEnum mode, const int count, const RendererEnum type, const void* const* indices, unsigned int drawCount) override;
void DrawElements(const RendererEnum mode, const int count, const RendererEnum type, const void* indices) override;
void DrawElements(const RendererEnum mode, const uint32_t count, const RendererEnum type, const void* indices) override;
void DrawArrays(int from, int count) override;
void DrawLines(int from, int count) override;

View File

@@ -35,7 +35,7 @@ namespace Nuake {
virtual void VertexAttribPointer(const unsigned int index, const int size, const RendererEnum type, bool normalized, int stride, const void* pointer) = 0;
virtual void DrawMultiElements(const RendererEnum mode, const int count, const RendererEnum type, const void* const* indices, unsigned int drawCount) = 0;
virtual void DrawElements(const RendererEnum mode, const int count, const RendererEnum type, const void* indices) = 0;
virtual void DrawElements(const RendererEnum mode, const uint32_t count, const RendererEnum type, const void* indices) = 0;
virtual void DrawArrays(int from, int count) = 0;
virtual void DrawLines(int from, int count) = 0;
};