summaryrefslogtreecommitdiff
path: root/gfx/gl/shadowStenciller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/gl/shadowStenciller.cpp')
-rw-r--r--gfx/gl/shadowStenciller.cpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp
index 86b77e4..77ce309 100644
--- a/gfx/gl/shadowStenciller.cpp
+++ b/gfx/gl/shadowStenciller.cpp
@@ -1,18 +1,18 @@
#include "shadowStenciller.h"
-#include "gfx/gl/program.h"
-#include "gfx/gl/shaders/fs-shadowStencil.h"
-#include "gfx/gl/shaders/gs-shadowStencil.h"
-#include "gfx/gl/shaders/vs-shadowStencil.h"
#include "gfx/lightDirection.h"
#include "gfx/models/mesh.h"
-#include "glArrays.h"
#include "gl_traits.h"
+#include "gldebug.h"
#include "maths.h"
+#include <gfx/gl/shaders/shadowStencil-frag.h>
+#include <gfx/gl/shaders/shadowStencil-geom.h>
+#include <gfx/gl/shaders/shadowStencil-vert.h>
#include <stdexcept>
ShadowStenciller::ShadowStenciller() :
- shadowCaster {shadowStencil_vs, shadowStencil_gs, shadowStencil_fs}, viewProjections {}
+ shadowCaster {shadowStencil_vert, shadowStencil_geom, shadowStencil_frag}, lightDir {}, viewProjections {}
{
+ glDebugScope _ {fbo};
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
@@ -22,6 +22,7 @@ ShadowStenciller::ShadowStenciller() :
void
ShadowStenciller::setLightDirection(const LightDirection & lightDir)
{
+ this->lightDir = lightDir.position();
viewProjections = [&lightDir]<GLint... Ep>(std::integer_sequence<GLint, Ep...>) {
constexpr float STEP = two_pi / STENCIL_ANGLES<decltype(two_pi)>;
return std::array {rotate_pitch<4>(half_pi - lightDir.position().y)
@@ -29,38 +30,38 @@ ShadowStenciller::setLightDirection(const LightDirection & lightDir)
}(std::make_integer_sequence<GLint, STENCIL_ANGLES<GLint>>());
}
-glTexture
-ShadowStenciller::createStencilTexture(GLsizei width, GLsizei height)
+Direction2D
+ShadowStenciller::getLightDirection() const
{
- glTexture stencil;
- glBindTexture(GL_TEXTURE_2D_ARRAY, stencil);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT, width, height, STENCIL_ANGLES<GLint>, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
+ return lightDir;
+}
- return stencil;
+void
+ShadowStenciller::configureStencilTexture(glTexture<GL_TEXTURE_2D_ARRAY> & stencil, ImageDimensions size)
+{
+ glDebugScope _ {0};
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ stencil.storage(1, GL_DEPTH_COMPONENT16, size || STENCIL_ANGLES<GLsizei>);
+ stencil.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ stencil.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ stencil.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ stencil.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
void
-ShadowStenciller::renderStencil(const glTexture & stencil, const MeshBase & mesh, const Texture::AnyPtr texture) const
+ShadowStenciller::renderStencil(
+ const glTexture<GL_TEXTURE_2D_ARRAY> & stencil, const MeshBase & mesh, const Texture::AnyPtr texture) const
{
+ glDebugScope _ {fbo};
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, stencil, 0);
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
- throw std::runtime_error("Stencil framebuffer not complete!");
- }
+ fbo.texture(GL_DEPTH_ATTACHMENT, stencil);
+ fbo.assertComplete();
if (texture) {
- texture->bind();
+ texture->bind(0);
}
glUseProgram(shadowCaster);
glClear(GL_DEPTH_BUFFER_BIT);
- const auto stencilSize = Texture::getSize(stencil);
+ const auto stencilSize = stencil.getSize();
glViewport(0, 0, stencilSize.x, stencilSize.y);
const auto & centre = mesh.getDimensions().centre;
const auto & size = mesh.getDimensions().size;
@@ -70,5 +71,5 @@ ShadowStenciller::renderStencil(const glTexture & stencil, const MeshBase & mesh
const auto & viewProjection) {
return viewProjection * extentsMat;
}});
- mesh.Draw();
+ mesh.draw();
}