From: Daniel Karbach Date: Fri, 18 Dec 2015 13:28:42 +0000 (+0100) Subject: avoid zero vertex draw calls X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=ef2427f841a434f93805321f8bbac44be2dd4555;p=blank.git avoid zero vertex draw calls --- diff --git a/src/graphics/BlockMesh.hpp b/src/graphics/BlockMesh.hpp index 399ff32..5342992 100644 --- a/src/graphics/BlockMesh.hpp +++ b/src/graphics/BlockMesh.hpp @@ -69,7 +69,13 @@ public: public: void Update(const Buffer &) noexcept; - void Draw() const noexcept; + bool Empty() const noexcept { + return vao.Empty(); + } + + void Draw() const noexcept { + vao.DrawTriangleElements(); + } private: VAO vao; diff --git a/src/graphics/EntityMesh.hpp b/src/graphics/EntityMesh.hpp index 804bb6e..58b29e5 100644 --- a/src/graphics/EntityMesh.hpp +++ b/src/graphics/EntityMesh.hpp @@ -69,7 +69,13 @@ public: public: void Update(const Buffer &) noexcept; - void Draw() const noexcept; + bool Empty() const noexcept { + return vao.Empty(); + } + + void Draw() const noexcept { + vao.DrawTriangleElements(); + } private: VAO vao; diff --git a/src/graphics/PrimitiveMesh.hpp b/src/graphics/PrimitiveMesh.hpp index 6a8b696..577321a 100644 --- a/src/graphics/PrimitiveMesh.hpp +++ b/src/graphics/PrimitiveMesh.hpp @@ -66,8 +66,14 @@ public: public: void Update(const Buffer &) noexcept; - void DrawLines() noexcept; - void DrawTriangles() noexcept; + bool Empty() const noexcept { + return vao.Empty(); + } + + void DrawLines() const noexcept; + void DrawTriangles() const noexcept { + vao.DrawTriangleElements(); + } private: VAO vao; diff --git a/src/graphics/SkyBoxMesh.hpp b/src/graphics/SkyBoxMesh.hpp index ab1da8d..2378327 100644 --- a/src/graphics/SkyBoxMesh.hpp +++ b/src/graphics/SkyBoxMesh.hpp @@ -47,7 +47,13 @@ public: void LoadUnitBox(); void Update(const Buffer &) noexcept; - void Draw() const noexcept; + bool Empty() const noexcept { + return vao.Empty(); + } + + void Draw() const noexcept { + vao.DrawTriangleElements(); + } private: VAO vao; diff --git a/src/graphics/SpriteMesh.hpp b/src/graphics/SpriteMesh.hpp index a7cfd64..0c6c9a1 100644 --- a/src/graphics/SpriteMesh.hpp +++ b/src/graphics/SpriteMesh.hpp @@ -60,7 +60,13 @@ public: public: void Update(const Buffer &) noexcept; - void Draw() noexcept; + bool Empty() const noexcept { + return vao.Empty(); + } + + void Draw() const noexcept { + vao.DrawTriangleElements(); + } private: VAO vao; diff --git a/src/graphics/VertexArray.hpp b/src/graphics/VertexArray.hpp index 5f70f42..ab02a56 100644 --- a/src/graphics/VertexArray.hpp +++ b/src/graphics/VertexArray.hpp @@ -24,6 +24,8 @@ public: VertexArray &operator =(VertexArray &&) noexcept; public: + bool Empty() const noexcept { return idx_count == 0; } + void Bind() const noexcept; template diff --git a/src/graphics/mesh.cpp b/src/graphics/mesh.cpp index 9cb8c92..906b20f 100644 --- a/src/graphics/mesh.cpp +++ b/src/graphics/mesh.cpp @@ -18,10 +18,10 @@ void EntityMesh::Update(const Buffer &buf) noexcept { std::cerr << "EntityMesh: not enough tex coords!" << std::endl; } if (buf.hsl_mods.size() < buf.vertices.size()) { - std::cerr << "BlockMesh: not enough HSL modifiers!" << std::endl; + std::cerr << "EntityMesh: not enough HSL modifiers!" << std::endl; } if (buf.rgb_mods.size() < buf.vertices.size()) { - std::cerr << "BlockMesh: not enough RGB modifiers!" << std::endl; + std::cerr << "EntityMesh: not enough RGB modifiers!" << std::endl; } if (buf.normals.size() < buf.vertices.size()) { std::cerr << "EntityMesh: not enough normals!" << std::endl; @@ -38,11 +38,6 @@ void EntityMesh::Update(const Buffer &buf) noexcept { } -void EntityMesh::Draw() const noexcept { - vao.DrawTriangleElements(); -} - - void BlockMesh::Update(const Buffer &buf) noexcept { #ifndef NDEBUG if (buf.tex_coords.size() < buf.vertices.size()) { @@ -69,11 +64,6 @@ void BlockMesh::Update(const Buffer &buf) noexcept { } -void BlockMesh::Draw() const noexcept { - vao.DrawTriangleElements(); -} - - void PrimitiveMesh::Buffer::FillRect( float w, float h, const Color &color, @@ -129,16 +119,12 @@ void PrimitiveMesh::Update(const Buffer &buf) noexcept { } -void PrimitiveMesh::DrawLines() noexcept { +void PrimitiveMesh::DrawLines() const noexcept { glEnable(GL_LINE_SMOOTH); glLineWidth(2.0f); vao.DrawLineElements(); } -void PrimitiveMesh::DrawTriangles() noexcept { - vao.DrawTriangleElements(); -} - void SkyBoxMesh::LoadUnitBox() { Buffer buffer; @@ -169,10 +155,6 @@ void SkyBoxMesh::Update(const Buffer &buf) noexcept { vao.PushIndices(ATTRIB_INDEX, buf.indices); } -void SkyBoxMesh::Draw() const noexcept { - vao.DrawTriangleElements(); -} - void SpriteMesh::Buffer::LoadRect( float w, float h, @@ -210,9 +192,4 @@ void SpriteMesh::Update(const Buffer &buf) noexcept { vao.PushIndices(ATTRIB_INDEX, buf.indices); } - -void SpriteMesh::Draw() noexcept { - vao.DrawTriangleElements(); -} - } diff --git a/src/world/chunk.cpp b/src/world/chunk.cpp index 6eb027a..596bcaf 100644 --- a/src/world/chunk.cpp +++ b/src/world/chunk.cpp @@ -815,33 +815,21 @@ void ChunkRenderer::Render(Viewport &viewport) { Frustum frustum(transpose(chunk_prog.GetVP())); AABB box; - //std::cout << "V = " << chunk_prog.View() << std::endl; - //std::cout << "P = " << chunk_prog.Projection() << std::endl; - //std::cout << "VP = " << chunk_prog.GetVP() << std::endl; - //std::cout << "frustum = " << frustum << std::endl; - for (int i = 0; i < index.TotalChunks(); ++i) { if (!index[i]) continue; box.min = (index[i]->Position() - index.Base()) * ExactLocation::Extent(); box.max = box.min + ExactLocation::FExtent(); if (!CullTest(box, frustum)) { - - //glm::mat4 m(index[i]->Transform(index.Base())); - //if (CullTest(Chunk::Bounds(), chunk_prog.GetVP() * m)) { - // std::cout << "M = " << m << std::endl; - // std::cout << "box = " << box.min << ", " << box.max << std::endl; - // std::cout << "should've been culled" << std::endl; - //} - if (index[i]->ShouldUpdateMesh()) { index[i]->Update(models[i]); } - chunk_prog.SetM(index[i]->Transform(index.Base())); - models[i].Draw(); + if (!models[i].Empty()) { + chunk_prog.SetM(index[i]->Transform(index.Base())); + models[i].Draw(); + } } } - //std::cout << std::endl; }