From ac05fbbc71282b059164b51efd68ee6e372870cb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 20 Apr 2023 20:27:43 +0100 Subject: Switch to render trees in bulk through foliage asset rendering --- game/scenary/foliage.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'game/scenary/foliage.cpp') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index d39d500..35be051 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -1,7 +1,9 @@ #include "foliage.h" #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" +#include "gfx/gl/vertexArrayObject.hpp" #include "gfx/models/texture.h" +#include "location.hpp" bool Foliage::persist(Persistence::PersistenceStore & store) @@ -13,21 +15,25 @@ void Foliage::postLoad() { texture = getTexture(); + bodyMesh->configureVAO(instanceVAO).addAttribs(instances.bufferName(), 1); } void -Foliage::render(const SceneShader & shader, const Location & loc) const +Foliage::render(const SceneShader & shader) const { - shader.basic.use(loc); - if (texture) { - texture->bind(); + if (const auto count = instances.count()) { + shader.basicInst.use(); + if (texture) { + texture->bind(); + } + glBindVertexArray(instanceVAO); + glDrawElementsInstanced( + bodyMesh->type(), bodyMesh->count(), GL_UNSIGNED_INT, nullptr, static_cast(count)); + glBindVertexArray(0); } - bodyMesh->Draw(); } void -Foliage::shadows(const ShadowMapper & mapper, const Location & loc) const +Foliage::shadows(const ShadowMapper &) const { - mapper.dynamicPoint.use(loc); - bodyMesh->Draw(); } -- cgit v1.2.3