summaryrefslogtreecommitdiff
path: root/game/scenary/illuminator.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-13 11:23:12 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-13 11:23:12 +0000
commite31f69ec26f5c128ae421eb418628ebcdfafb8f3 (patch)
tree4998cde56004f53a0218dc5f00d578f939ffea08 /game/scenary/illuminator.cpp
parentMerge common parts of light type vertices (diff)
downloadilt-e31f69ec26f5c128ae421eb418628ebcdfafb8f3.tar.bz2
ilt-e31f69ec26f5c128ae421eb418628ebcdfafb8f3.tar.xz
ilt-e31f69ec26f5c128ae421eb418628ebcdfafb8f3.zip
Only create VAOs for the light type(s) in use
Diffstat (limited to 'game/scenary/illuminator.cpp')
-rw-r--r--game/scenary/illuminator.cpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp
index 7d072f9..e3810ec 100644
--- a/game/scenary/illuminator.cpp
+++ b/game/scenary/illuminator.cpp
@@ -33,22 +33,29 @@ Illuminator::postLoad()
texture = getTexture();
bodyMesh->configureVAO(instanceVAO)
.addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
- VertexArrayObject {instancesSpotLightVAO}
- .addAttribs<SpotLightVertex, &SpotLightVertex::position, &SpotLightVertex::direction,
- &SpotLightVertex::colour, &SpotLightVertex::kq, &SpotLightVertex::arc>(
- instancesSpotLight.bufferName(), 0)
- .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
- std::transform(spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) {
- return instancesSpotLight.acquire(*s);
- });
- VertexArrayObject {instancesPointLightVAO}
- .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour,
- &PointLightVertex::kq>(instancesPointLight.bufferName(), 0)
- .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
- std::transform(
- pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) {
- return instancesPointLight.acquire(*s);
- });
+ if (!spotLight.empty()) {
+ instancesSpotLightVAO.emplace();
+ VertexArrayObject {*instancesSpotLightVAO}
+ .addAttribs<SpotLightVertex, &SpotLightVertex::position, &SpotLightVertex::direction,
+ &SpotLightVertex::colour, &SpotLightVertex::kq, &SpotLightVertex::arc>(
+ instancesSpotLight.bufferName(), 0)
+ .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
+ std::transform(
+ spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) {
+ return instancesSpotLight.acquire(*s);
+ });
+ }
+ if (!pointLight.empty()) {
+ instancesPointLightVAO.emplace();
+ VertexArrayObject {*instancesPointLightVAO}
+ .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour,
+ &PointLightVertex::kq>(instancesPointLight.bufferName(), 0)
+ .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
+ std::transform(
+ pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) {
+ return instancesPointLight.acquire(*s);
+ });
+ }
}
void
@@ -69,12 +76,12 @@ Illuminator::lights(const SceneShader & shader) const
if (const auto count = instances.size()) {
if (const auto scount = instancesSpotLight.size()) {
shader.spotLightInst.use();
- glBindVertexArray(instancesSpotLightVAO);
+ glBindVertexArray(*instancesSpotLightVAO);
glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(scount), static_cast<GLsizei>(count));
}
if (const auto pcount = instancesPointLight.size()) {
shader.pointLightInst.use();
- glBindVertexArray(instancesPointLightVAO);
+ glBindVertexArray(*instancesPointLightVAO);
glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(pcount), static_cast<GLsizei>(count));
}