diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-20 20:27:43 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-20 20:27:43 +0100 |
commit | ac05fbbc71282b059164b51efd68ee6e372870cb (patch) | |
tree | a505ed3e38a8e2419c1d706f45dd39873b627962 /game/scenary/foliage.cpp | |
parent | Expose bufferName and count from InstanceVertices (diff) | |
download | ilt-ac05fbbc71282b059164b51efd68ee6e372870cb.tar.bz2 ilt-ac05fbbc71282b059164b51efd68ee6e372870cb.tar.xz ilt-ac05fbbc71282b059164b51efd68ee6e372870cb.zip |
Switch to render trees in bulk through foliage asset rendering
Diffstat (limited to 'game/scenary/foliage.cpp')
-rw-r--r-- | game/scenary/foliage.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
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<glm::mat4>(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<GLsizei>(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(); } |