diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-23 21:31:41 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-23 21:31:41 +0100 |
commit | 687afb09ada73fb4aee932242a3b7ee492e63cb0 (patch) | |
tree | e8c654edf5b0927238c89d8c861afe9bed995c8c /game/vehicles/railVehicleClass.cpp | |
parent | Add BufferedLocation (diff) | |
download | ilt-687afb09ada73fb4aee932242a3b7ee492e63cb0.tar.bz2 ilt-687afb09ada73fb4aee932242a3b7ee492e63cb0.tar.xz ilt-687afb09ada73fb4aee932242a3b7ee492e63cb0.zip |
Handle rendering of RailVehicles through RailVehicleClass instancing
Trains no longer need rendering as their parts are all RVC assets and that just works now.
This commit creates some irritating duplication in RVC wrt body/2 bogies all of which are stored
separately, but function in exactly the same way.
This breaks RV shadows as we have no instancing shadow shaders yet.
Diffstat (limited to 'game/vehicles/railVehicleClass.cpp')
-rw-r--r-- | game/vehicles/railVehicleClass.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index b7a3b1e..3e62bf1 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,37 @@ 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(); + glBindVertexArray(instanceVAO); + glDrawElementsInstanced( + bodyMesh->type(), bodyMesh->count(), GL_UNSIGNED_INT, nullptr, static_cast<GLsizei>(count)); + glBindVertexArray(instancesBogiesVAO.front()); + glDrawElementsInstanced(bogies.front()->type(), bogies.front()->count(), GL_UNSIGNED_INT, nullptr, + static_cast<GLsizei>(instancesBogies.front().count())); + glBindVertexArray(instancesBogiesVAO.back()); + glDrawElementsInstanced(bogies.back()->type(), bogies.back()->count(), GL_UNSIGNED_INT, nullptr, + static_cast<GLsizei>(instancesBogies.back().count())); + glBindVertexArray(0); } } + void -RailVehicleClass::shadows( - const ShadowMapper & shadowMapper, const Location & location, const std::array<Location, 2> & bl) const +RailVehicleClass::shadows(const ShadowMapper &) const { - shadowMapper.dynamicPoint.use(location); - bodyMesh->Draw(); - for (auto b = 0U; b < bogies.size(); ++b) { - shadowMapper.dynamicPoint.setModel(bl[b]); - bogies[b]->Draw(); - } } |