From 478aabb2c27374117cbd91fb6812058d0a18f873 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Mar 2025 01:54:26 +0000 Subject: Add support for resizing a SceneRenderer --- gfx/gl/sceneRenderer.cpp | 19 ++++++++++++++++++- gfx/gl/sceneRenderer.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 188c4fd..5d35d01 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -39,7 +39,7 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) : glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); configuregdata(gPosition, {GL_RGB32I}, GL_RGB_INTEGER, GL_COLOR_ATTACHMENT0); - configuregdata(gNormal, {GL_RGB8_SNORM, GL_RGB16F}, GL_RGB, GL_COLOR_ATTACHMENT1); + normaliFormat = configuregdata(gNormal, {GL_RGB8_SNORM, GL_RGB16F}, GL_RGB, GL_COLOR_ATTACHMENT1); configuregdata(gAlbedoSpec, {GL_RGB8}, GL_RGB, GL_COLOR_ATTACHMENT2); constexpr std::array attachments { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2}; @@ -56,6 +56,23 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) : glBindFramebuffer(GL_FRAMEBUFFER, output); } +void +SceneRenderer::resize(ScreenAbsCoord newSize) +{ + size = newSize; + camera.setAspect(ratio(size)); + const auto configuregdata = [this](const GLuint data, const GLint iformat, const GLenum format) { + glBindTexture(GL_TEXTURE_2D, data); + glTexImage2D(GL_TEXTURE_2D, 0, iformat, size.x, size.y, 0, format, GL_BYTE, nullptr); + }; + configuregdata(gPosition, GL_RGB32I, GL_RGB_INTEGER); + configuregdata(gNormal, normaliFormat, GL_RGB); + configuregdata(gAlbedoSpec, GL_RGB8, GL_RGB); + configuregdata(gIllumination, GL_RGB8, GL_RGB); + glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.x, size.y); +} + void SceneRenderer::render(const SceneProvider & scene) const { diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index 4649a68..31f0cda 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -13,6 +13,8 @@ class SceneRenderer { public: explicit SceneRenderer(ScreenAbsCoord size, GLuint output); + void resize(ScreenAbsCoord size); + void render(const SceneProvider &) const; void setAmbientLight(const RGB & colour) const; void setDirectionalLight(const RGB & colour, const LightDirection & direction, const SceneProvider &) const; @@ -25,6 +27,7 @@ protected: ScreenAbsCoord size; GLuint output; glFrameBuffer gBuffer, gBufferIll; + GLint normaliFormat; glTexture gPosition, gNormal, gAlbedoSpec, gIllumination; glRenderBuffer depth; -- cgit v1.2.3