diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-03 19:47:46 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2022-11-03 19:48:31 +0000 |
commit | c3eea71370eb94cff1fd96185458643fab6eb2c5 (patch) | |
tree | cb331dd81d9cb36d69e1b659353796ec170a78e4 /ui | |
parent | Rename Shader to SceneShader (diff) | |
download | ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.tar.bz2 ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.tar.xz ilt-c3eea71370eb94cff1fd96185458643fab6eb2c5.zip |
Restructure how shaders are worked with
Needs a tidy-up
Diffstat (limited to 'ui')
-rw-r--r-- | ui/editNetwork.cpp | 2 | ||||
-rw-r--r-- | ui/gameMainSelector.h | 2 | ||||
-rw-r--r-- | ui/gameMainWindow.cpp | 10 | ||||
-rw-r--r-- | ui/gameMainWindow.h | 1 | ||||
-rw-r--r-- | ui/sceneRenderer.cpp | 4 | ||||
-rw-r--r-- | ui/sceneRenderer.h | 12 | ||||
-rw-r--r-- | ui/text.cpp | 2 | ||||
-rw-r--r-- | ui/toolbar.cpp | 2 | ||||
-rw-r--r-- | ui/window.h | 3 |
9 files changed, 16 insertions, 22 deletions
diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp index 991cbc3..754053b 100644 --- a/ui/editNetwork.cpp +++ b/ui/editNetwork.cpp @@ -51,7 +51,7 @@ EditNetwork::render(const SceneShader & shader) const { if (builder) { blue.bind(); - shader.setModel(Location {}, SceneShader::Program::StaticPos); + shader.absolute.use(); builder->render(shader); } } diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index 9c05127..aacd67a 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -7,6 +7,8 @@ #include <glm/glm.hpp> #include <memory> #include <string> + +class SceneShader; class Ray; class UIShader; class Camera; diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 792ffab..1d90417 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -36,10 +36,6 @@ GameMainWindow::GameMainWindow(size_t w, size_t h) : uiComponents.create<ManualCameraController>(glm::vec2 {-1150, -1150}); auto gms = uiComponents.create<GameMainSelector>(&camera, glm::vec2 {w, h}); uiComponents.create<GameMainToolbar>(gms.get()); - - shader.setUniform("lightDirection", glm::normalize(glm::vec3 {1, 0, -1})); - shader.setUniform("lightColor", {.6, .6, .6}); - shader.setUniform("ambientColor", {0.5, 0.5, 0.5}); } void @@ -58,9 +54,3 @@ GameMainWindow::render() const }); Window::render(); } - -const SceneShader & -GameMainWindow::getShader() const -{ - return shader; -} diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h index 09d17d1..c01888f 100644 --- a/ui/gameMainWindow.h +++ b/ui/gameMainWindow.h @@ -16,7 +16,6 @@ public: void render() const override; private: - const SceneShader & getShader() const override; SceneShader shader; Camera camera; }; diff --git a/ui/sceneRenderer.cpp b/ui/sceneRenderer.cpp index 5e03704..6e75dec 100644 --- a/ui/sceneRenderer.cpp +++ b/ui/sceneRenderer.cpp @@ -10,7 +10,7 @@ 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) : lighting {lightingShader_vs.compile(), lightingShader_fs.compile()} +SceneRenderer::SceneRenderer(glm::ivec2 size) : lighting {lightingShader_vs, lightingShader_fs} { glBindVertexArray(displayVAO); glBindBuffer(GL_ARRAY_BUFFER, displayVBO); @@ -60,7 +60,6 @@ SceneRenderer::render(std::function<void()> content) const // Lighting pass glDisable(GL_BLEND); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glUseProgram(lighting.m_program); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, gPosition); glActiveTexture(GL_TEXTURE1); @@ -68,6 +67,7 @@ SceneRenderer::render(std::function<void()> content) const glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, gAlbedoSpec); // TODO Configure lights + lighting.use(); glBindVertexArray(displayVAO); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindVertexArray(0); diff --git a/ui/sceneRenderer.h b/ui/sceneRenderer.h index 6176f1b..6c96418 100644 --- a/ui/sceneRenderer.h +++ b/ui/sceneRenderer.h @@ -1,12 +1,13 @@ #pragma once -#include "gfx/gl/sceneShader.h" +#include "gfx/gl/program.h" #include "lib/glArrays.h" #include <functional> +#include <glm/fwd.hpp> class SceneRenderer { public: - SceneRenderer(glm::ivec2 size); + explicit SceneRenderer(glm::ivec2 size); void render(std::function<void()> content) const; @@ -14,7 +15,12 @@ private: glFrameBuffer gBuffer; glTexture gPosition, gNormal, gAlbedoSpec; glRenderBuffer depth; - ProgramHandleBase lighting; + class DeferredLightProgram : public Program { + public: + using Program::Program; + using Program::use; + }; + DeferredLightProgram lighting; glVertexArray displayVAO; glBuffer displayVBO; }; diff --git a/ui/text.cpp b/ui/text.cpp index 872e3f3..d24c268 100644 --- a/ui/text.cpp +++ b/ui/text.cpp @@ -43,7 +43,7 @@ Text::Text(std::string_view s, Position pos, glm::vec3 c) : UIComponent {pos}, c void Text::render(const UIShader & shader, const Position &) const { - shader.useText(colour); + shader.text.use(colour); glActiveTexture(GL_TEXTURE0); for (const auto & m : models) { glBindTexture(GL_TEXTURE_2D, m.texture); diff --git a/ui/toolbar.cpp b/ui/toolbar.cpp index ada97b0..31d87dc 100644 --- a/ui/toolbar.cpp +++ b/ui/toolbar.cpp @@ -18,7 +18,7 @@ Toolbar::Toolbar(const std::initializer_list<InitInfo> & initInfo) : UIComponent void Toolbar::render(const UIShader & uiShader, const Position & parentPos) const { - uiShader.useDefault(); + uiShader.icon.use(); const auto absPos = this->position + parentPos; icons.apply(&UIComponent::render, uiShader, absPos); } diff --git a/ui/window.h b/ui/window.h index b3d3f68..0661915 100644 --- a/ui/window.h +++ b/ui/window.h @@ -10,8 +10,6 @@ #include <special_members.hpp>
#include <string>
-class SceneShader;
-
class Window {
public:
Window(size_t width, size_t height, const std::string & title);
@@ -30,7 +28,6 @@ public: protected:
[[nodiscard]] SDL_GLContext glContext() const;
virtual void render() const;
- virtual const SceneShader & getShader() const = 0;
using SDL_WindowPtr = wrapped_ptrt<SDL_Window, SDL_CreateWindow, SDL_DestroyWindow>;
const glm::ivec2 size;
|