summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-13 15:44:09 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-14 23:46:14 +0000
commitb27c66cb2aaa897e4c18b3be3a0b121b6695e7e1 (patch)
treedec28585a610de4618d392fe72fd4e4968c2f636
parentPass the output framebuffer id to scene renderer (diff)
downloadilt-b27c66cb2aaa897e4c18b3be3a0b121b6695e7e1.tar.bz2
ilt-b27c66cb2aaa897e4c18b3be3a0b121b6695e7e1.tar.xz
ilt-b27c66cb2aaa897e4c18b3be3a0b121b6695e7e1.zip
Refactor shading output components
SceneShader and Camera are part of SceneRenderer
-rw-r--r--ui/gameMainWindow.cpp7
-rw-r--r--ui/gameMainWindow.h6
-rw-r--r--ui/sceneRenderer.cpp10
-rw-r--r--ui/sceneRenderer.h7
4 files changed, 15 insertions, 15 deletions
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
index dfb51e9..e49f4a9 100644
--- a/ui/gameMainWindow.cpp
+++ b/ui/gameMainWindow.cpp
@@ -3,7 +3,6 @@
#include "gameMainSelector.h"
#include "gfx/camera_controller.h"
#include "manualCameraController.h"
-#include "maths.h"
#include "modeHelper.hpp"
#include "toolbar.h"
#include "window.h"
@@ -30,8 +29,7 @@ public:
};
GameMainWindow::GameMainWindow(size_t w, size_t h) :
- Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {size, 0}, camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(w, h),
- 0.1F, 10000.0F}
+ Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {size, 0}
{
uiComponents.create<ManualCameraController>(glm::vec2 {-1150, -1150});
auto gms = uiComponents.create<GameMainSelector>(&camera, glm::vec2 {w, h});
@@ -42,13 +40,12 @@ void
GameMainWindow::tick(TickDuration)
{
uiComponents.apply<CameraController>(&CameraController::updateCamera, &camera);
- shader.setView(camera.GetViewProjection());
}
void
GameMainWindow::render() const
{
- SceneRenderer::render([this] {
+ SceneRenderer::render([this](const auto & shader) {
gameState->world.apply<Renderable>(&Renderable::render, shader);
uiComponents.apply<WorldOverlay>(&WorldOverlay::render, shader);
});
diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h
index c01888f..1e6af20 100644
--- a/ui/gameMainWindow.h
+++ b/ui/gameMainWindow.h
@@ -1,8 +1,6 @@
#pragma once
#include "chronology.hpp"
-#include "gfx/gl/camera.h"
-#include "gfx/gl/sceneShader.h"
#include "sceneRenderer.h"
#include "window.h"
#include <cstddef>
@@ -14,8 +12,4 @@ public:
void tick(TickDuration) override;
void render() const override;
-
-private:
- SceneShader shader;
- Camera camera;
};
diff --git a/ui/sceneRenderer.cpp b/ui/sceneRenderer.cpp
index 9432710..852f64c 100644
--- a/ui/sceneRenderer.cpp
+++ b/ui/sceneRenderer.cpp
@@ -1,4 +1,5 @@
#include "sceneRenderer.h"
+#include "maths.h"
#include <gfx/gl/shaders/fs-lightingShader.h>
#include <gfx/gl/shaders/vs-lightingShader.h>
#include <glm/gtc/type_ptr.hpp>
@@ -10,7 +11,9 @@ static constexpr std::array<glm::vec4, 4> displayVAOdata {{
{1.0f, 1.0f, 1.0f, 1.0f},
{1.0f, -1.0f, 1.0f, 0.0f},
}};
-SceneRenderer::SceneRenderer(glm::ivec2 size, GLuint o) : output {o}, lighting {lightingShader_vs, lightingShader_fs}
+SceneRenderer::SceneRenderer(glm::ivec2 size, GLuint o) :
+ camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(size.x, size.y), 0.1F, 10000.0F}, output {o},
+ lighting {lightingShader_vs, lightingShader_fs}
{
glBindVertexArray(displayVAO);
glBindBuffer(GL_ARRAY_BUFFER, displayVBO);
@@ -47,8 +50,9 @@ SceneRenderer::SceneRenderer(glm::ivec2 size, GLuint o) : output {o}, lighting {
}
void
-SceneRenderer::render(std::function<void()> content) const
+SceneRenderer::render(std::function<void(const SceneShader &)> content) const
{
+ shader.setView(camera.GetViewProjection());
// Geometry pass
glEnable(GL_BLEND);
glEnable(GL_CULL_FACE);
@@ -57,7 +61,7 @@ SceneRenderer::render(std::function<void()> content) const
glEnable(GL_DEPTH_TEST);
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- content();
+ content(shader);
glBindFramebuffer(GL_FRAMEBUFFER, output);
// Lighting pass
diff --git a/ui/sceneRenderer.h b/ui/sceneRenderer.h
index 9352fc9..50feaa2 100644
--- a/ui/sceneRenderer.h
+++ b/ui/sceneRenderer.h
@@ -1,6 +1,8 @@
#pragma once
+#include "gfx/gl/camera.h"
#include "gfx/gl/program.h"
+#include "gfx/gl/sceneShader.h"
#include "lib/glArrays.h"
#include <functional>
#include <glm/fwd.hpp>
@@ -9,7 +11,9 @@ class SceneRenderer {
public:
explicit SceneRenderer(glm::ivec2 size, GLuint output);
- void render(std::function<void()> content) const;
+ void render(std::function<void(const SceneShader &)> content) const;
+
+ Camera camera;
private:
GLuint output;
@@ -24,4 +28,5 @@ private:
DeferredLightProgram lighting;
glVertexArray displayVAO;
glBuffer displayVBO;
+ SceneShader shader;
};