#include "railVehicleClass.h" #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" #include "gfx/gl/vertexArrayObject.h" #include "gfx/models/mesh.h" #include "gfx/models/texture.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include bool RailVehicleClass::persist(Persistence::PersistenceStore & store) { return STORE_TYPE && STORE_MEMBER(length) && STORE_MEMBER(wheelBase) && STORE_MEMBER(maxSpeed) && STORE_NAME_HELPER("bogie", bogies, Asset::MeshArrayConstruct) && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store); } void RailVehicleClass::postLoad() { texture = getTexture(); bodyMesh->configureVAO(instanceVAO).addAttribs(instancesBody.bufferName(), 1); bogies.front() ->configureVAO(instancesBogiesVAO.front()) .addAttribs(instancesBogies.front().bufferName(), 1); bogies.back() ->configureVAO(instancesBogiesVAO.back()) .addAttribs(instancesBogies.back().bufferName(), 1); } void RailVehicleClass::render(const SceneShader & shader) const { if (const auto count = instancesBody.size()) { if (texture) { texture->bind(); } shader.basicInst.use(); bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); bogies.front()->DrawInstanced(instancesBogiesVAO.front(), static_cast(instancesBogies.front().size())); bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().size())); } } void RailVehicleClass::shadows(const ShadowMapper & mapper) const { if (const auto count = instancesBody.size()) { mapper.dynamicPointInst.use(); bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); bogies.front()->DrawInstanced(instancesBogiesVAO.front(), static_cast(instancesBogies.front().size())); bogies.back()->DrawInstanced(instancesBogiesVAO.back(), static_cast(instancesBogies.back().size())); } }