From 8740d30b01f6c12e2fcea0450df73736cd17dc87 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 10 Jan 2024 01:10:44 +0000 Subject: Add spot light definition, loader, and rendering Rendering is untested, data is passed to whatever GL program is currently active. --- game/scenary/illuminator.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'game/scenary/illuminator.cpp') diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index 4989933..43b6e4e 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -4,10 +4,18 @@ #include "gfx/models/texture.h" #include "location.h" +bool +Illuminator::SpotLight::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(direction) && STORE_MEMBER(colour) && STORE_MEMBER(kq) + && STORE_MEMBER(arc); +} + bool Illuminator::persist(Persistence::PersistenceStore & store) { - return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store); + return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct) + && STORE_HELPER(spotLight, Persistence::Appender) && Asset::persist(store); } void @@ -16,6 +24,14 @@ Illuminator::postLoad() texture = getTexture(); bodyMesh->configureVAO(instanceVAO) .addAttribs(instances.bufferName(), 1); + VertexArrayObject {instancesSpotLightVAO} + .addAttribs(instances.bufferName(), 0) + .addAttribs( + instancesSpotLight.bufferName(), 1); + std::transform(spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) { + return instancesSpotLight.acquire(*s); + }); } void @@ -34,7 +50,12 @@ void Illuminator::lights(const SceneShader &) const { if (const auto count = instances.size()) { - // shader.pointLight.use(); - // bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); + if (const auto scount = instancesSpotLight.size()) { + // shader.pointLight.use(); + glBindVertexArray(instancesSpotLightVAO); + glDrawArraysInstanced(GL_POINTS, 0, static_cast(count), static_cast(scount)); + } + + glBindVertexArray(0); } } -- cgit v1.2.3