diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-01 20:21:23 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-01 20:21:23 +0100 |
| commit | 30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb (patch) | |
| tree | 7e782f51affa8a2a40cf47e6ba69335a1289b2be /gfx/renderable.cpp | |
| parent | Fix VertexArrayConfigurator with derived classes (diff) | |
| download | ilt-30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb.tar.bz2 ilt-30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb.tar.xz ilt-30fcb8bce7b60b6754a0d35f2f15b627d0fba4cb.zip | |
Have Renderable manage all instance lights
Spot and point lights now existing in Renderable, the vertex data
contains the owning parent object's index in CommonLocationData, the
render step is just a single draw call.
Diffstat (limited to 'gfx/renderable.cpp')
| -rw-r--r-- | gfx/renderable.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/gfx/renderable.cpp b/gfx/renderable.cpp index 90035c3..8523118 100644 --- a/gfx/renderable.cpp +++ b/gfx/renderable.cpp @@ -1,10 +1,14 @@ #include "renderable.h" +#include "gfx/gl/sceneShader.h" #include "gl_traits.h" #include "location.h" #include "maths.h" #include "util.h" std::weak_ptr<Renderable::CommonLocationData> Renderable::commonLocationData; +std::weak_ptr<Renderable::CommonSpotLights> Renderable::commonSpotLights; +std::weak_ptr<Renderable::CommonPointLights> Renderable::commonPointLights; +std::weak_ptr<glVertexArray> Renderable::commonInstancesSpotLightVAO, Renderable::commonInstancesPointLightVAO; Renderable::CommonLocation::CommonLocation(Location const & location) : position {location.pos, 0}, rotation {location.rot, 0}, rotationMatrix {location.getRotationTransform()} @@ -23,6 +27,19 @@ Renderable::CommonLocation ::operator=(Location const & location) Renderable::Renderable() { createIfRequired(locationData, commonLocationData); + createIfRequired(spotLights, commonSpotLights); + createIfRequired(pointLights, commonPointLights); + if (createIfRequired(instancesSpotLightVAO, commonInstancesSpotLightVAO)) { + instancesSpotLightVAO->configure() + .addAttribs<SpotLightVertex, &SpotLightVertex::position, &SpotLightVertex::direction, + &SpotLightVertex::colour, &SpotLightVertex::kq, &SpotLightVertex::arc, + &SpotLightVertex::parentObject>(0); + } + if (createIfRequired(instancesPointLightVAO, commonInstancesPointLightVAO)) { + instancesPointLightVAO->configure() + .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour, + &PointLightVertex::kq, &PointLightVertex::parentObject>(0); + } } GLuint @@ -40,8 +57,31 @@ Renderable::preFrame(const Frustum &, const Frustum &) } void -Renderable::lights(const SceneShader &) const +Renderable::lights(const SceneShader & shader) { + glDebugScope _ {0}; + if (const auto instancesSpotLight = commonSpotLights.lock()) { + if (const auto scount = instancesSpotLight->size()) { + if (const auto instancesSpotLightVAO = commonInstancesSpotLightVAO.lock()) { + glDebugScope _ {*instancesSpotLightVAO, "Spot lights"}; + shader.spotLightInst.use(); + glBindVertexArray(*instancesSpotLightVAO); + instancesSpotLightVAO->useBuffer(0, *instancesSpotLight); + glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(scount)); + } + } + } + if (const auto instancesPointLight = commonPointLights.lock()) { + if (const auto pcount = instancesPointLight->size()) { + if (const auto instancesPointLightVAO = commonInstancesPointLightVAO.lock()) { + glDebugScope _ {*instancesPointLightVAO, "Point lights"}; + shader.pointLightInst.use(); + glBindVertexArray(*instancesPointLightVAO); + instancesPointLightVAO->useBuffer(0, *instancesPointLight); + glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(pcount)); + } + } + } } void |
