summaryrefslogtreecommitdiff
path: root/game/scenary
diff options
context:
space:
mode:
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 {