summaryrefslogtreecommitdiff
path: root/game/vehicles/railVehicleClass.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-27 17:55:30 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-27 17:55:30 +0100
commit4f34ed9c949785784f0006f971b5fd2bb9508553 (patch)
tree20f6627a2f441212365d05d04160a5a6a97063e7 /game/vehicles/railVehicleClass.cpp
parentMerge remote-tracking branch 'origin/assimp-normals' (diff)
parentRevert "Export mesh size and primitive type" (diff)
downloadilt-4f34ed9c949785784f0006f971b5fd2bb9508553.tar.bz2
ilt-4f34ed9c949785784f0006f971b5fd2bb9508553.tar.xz
ilt-4f34ed9c949785784f0006f971b5fd2bb9508553.zip
Merge branch 'instancing-pt2'
Diffstat (limited to 'game/vehicles/railVehicleClass.cpp')
-rw-r--r--game/vehicles/railVehicleClass.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp
index b7a3b1e..82a442e 100644
--- a/game/vehicles/railVehicleClass.cpp
+++ b/game/vehicles/railVehicleClass.cpp
@@ -1,6 +1,7 @@
#include "railVehicleClass.h"
#include "gfx/gl/sceneShader.h"
#include "gfx/gl/shadowMapper.h"
+#include "gfx/gl/vertexArrayObject.hpp"
#include "gfx/models/mesh.h"
#include "gfx/models/texture.h"
#include <algorithm>
@@ -33,30 +34,38 @@ void
RailVehicleClass::postLoad()
{
texture = getTexture();
+ bodyMesh->configureVAO(instanceVAO).addAttribs<glm::mat4>(instancesBody.bufferName(), 1);
+ bogies.front()
+ ->configureVAO(instancesBogiesVAO.front())
+ .addAttribs<glm::mat4>(instancesBogies.front().bufferName(), 1);
+ bogies.back()
+ ->configureVAO(instancesBogiesVAO.back())
+ .addAttribs<glm::mat4>(instancesBogies.back().bufferName(), 1);
}
void
-RailVehicleClass::render(
- const SceneShader & shader, const Location & location, const std::array<Location, 2> & bl) const
+RailVehicleClass::render(const SceneShader & shader) const
{
- shader.basic.use(location);
- if (texture) {
- texture->bind();
- }
- bodyMesh->Draw();
- for (auto b = 0U; b < bogies.size(); ++b) {
- shader.basic.setModel(bl[b]);
- bogies[b]->Draw();
+ if (const auto count = instancesBody.count()) {
+ if (texture) {
+ texture->bind();
+ }
+ shader.basicInst.use();
+ bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
+ bogies.front()->DrawInstanced(
+ instancesBogiesVAO.front(), static_cast<GLsizei>(instancesBogies.front().count()));
+ bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast<GLsizei>(instancesBogies.back().count()));
}
}
+
void
-RailVehicleClass::shadows(
- const ShadowMapper & shadowMapper, const Location & location, const std::array<Location, 2> & bl) const
+RailVehicleClass::shadows(const ShadowMapper & mapper) const
{
- shadowMapper.dynamicPoint.use(location);
- bodyMesh->Draw();
- for (auto b = 0U; b < bogies.size(); ++b) {
- shadowMapper.dynamicPoint.setModel(bl[b]);
- bogies[b]->Draw();
+ if (const auto count = instancesBody.count()) {
+ mapper.dynamicPointInst.use();
+ bodyMesh->DrawInstanced(instanceVAO, static_cast<GLsizei>(count));
+ bogies.front()->DrawInstanced(
+ instancesBogiesVAO.front(), static_cast<GLsizei>(instancesBogies.front().count()));
+ bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast<GLsizei>(instancesBogies.back().count()));
}
}