summaryrefslogtreecommitdiff
path: root/game/scenary
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
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')
-rw-r--r--game/scenary/illuminator.cpp43
-rw-r--r--game/scenary/illuminator.h3
2 files changed, 27 insertions, 19 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));
}
diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h
index 1c493b2..893e5c7 100644
--- a/game/scenary/illuminator.h
+++ b/game/scenary/illuminator.h
@@ -11,7 +11,8 @@ class Texture;
class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> {
Mesh::Ptr bodyMesh;
std::shared_ptr<Texture> texture;
- glVertexArray instanceVAO, instancesSpotLightVAO, instancesPointLightVAO;
+ glVertexArray instanceVAO;
+ std::optional<glVertexArray> instancesSpotLightVAO, instancesPointLightVAO;
public:
struct LightCommonVertex {