#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; std::weak_ptr Renderable::commonSpotLights; std::weak_ptr Renderable::commonPointLights; std::weak_ptr Renderable::commonInstancesSpotLightVAO, Renderable::commonInstancesPointLightVAO; Renderable::CommonLocation::CommonLocation(Location const & location) : position {location.pos, 0}, rotation {location.rot, 0}, rotationMatrix {location.getRotationTransform()} { } Renderable::CommonLocation & Renderable::CommonLocation ::operator=(Location const & location) { position = location.pos || 0; rotation = location.rot || 0.F; rotationMatrix = location.getRotationTransform(); return *this; } Renderable::Renderable() { createIfRequired(locationData, commonLocationData); createIfRequired(spotLights, commonSpotLights); createIfRequired(pointLights, commonPointLights); if (createIfRequired(instancesSpotLightVAO, commonInstancesSpotLightVAO)) { instancesSpotLightVAO->configure() .addAttribs(0); } if (createIfRequired(instancesPointLightVAO, commonInstancesPointLightVAO)) { instancesPointLightVAO->configure() .addAttribs(0); } } GLuint gl_traits::InstanceProxy>::vertexArrayAttribFormat( GLuint vao, GLuint index, GLuint offset) { return gl_traits< decltype(InstanceVertices::InstanceProxy::index)>::vertexArrayAttribFormat(vao, index, offset + offsetof(InstanceVertices::InstanceProxy, index)); }; void Renderable::preFrame(const Frustum &, const Frustum &) { } void 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(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(pcount)); } } } } void Renderable::shadows(const ShadowMapper &, const Frustum &) const { } void Renderable::updateStencil(const ShadowStenciller &) const { } void Renderable::updateBillboard(const BillboardPainter &) const { }