From f848ad0e672d913c36fcb86533cbc11a9cf9d9ea Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 3 Nov 2022 18:25:28 +0000 Subject: Rename Shader to SceneShader --- game/network/network.h | 4 +- game/network/network.impl.h | 6 +-- game/network/rail.cpp | 2 +- game/network/rail.h | 4 +- game/terrain.cpp | 8 ++-- game/terrain.h | 4 +- game/vehicles/railVehicle.cpp | 2 +- game/vehicles/railVehicle.h | 4 +- game/vehicles/railVehicleClass.cpp | 5 ++- game/vehicles/railVehicleClass.h | 4 +- game/vehicles/train.cpp | 2 +- game/vehicles/train.h | 4 +- gfx/gl/sceneShader.cpp | 77 ++++++++++++++++++++++++++++++++++++++ gfx/gl/sceneShader.h | 27 +++++++++++++ gfx/gl/shader.cpp | 77 -------------------------------------- gfx/gl/shader.h | 27 ------------- gfx/renderable.h | 4 +- ui/editNetwork.cpp | 8 ++-- ui/editNetwork.h | 4 +- ui/gameMainSelector.cpp | 4 +- ui/gameMainSelector.h | 4 +- ui/gameMainWindow.cpp | 2 +- ui/gameMainWindow.h | 6 +-- ui/sceneRenderer.h | 2 +- ui/window.h | 4 +- ui/worldOverlay.h | 4 +- 26 files changed, 150 insertions(+), 149 deletions(-) create mode 100644 gfx/gl/sceneShader.cpp create mode 100644 gfx/gl/sceneShader.h delete mode 100644 gfx/gl/shader.cpp delete mode 100644 gfx/gl/shader.h diff --git a/game/network/network.h b/game/network/network.h index 4a2f56a..e7a65b5 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -12,7 +12,7 @@ #include class Texture; -class Shader; +class SceneShader; class Ray; template using GenDef = std::tuple...>; @@ -96,7 +96,7 @@ public: float findNodeDirection(Node::AnyCPtr) const override; - void render(const Shader &) const override; + void render(const SceneShader &) const override; protected: Link::CCollection addJoins(); diff --git a/game/network/network.impl.h b/game/network/network.impl.h index 597e3aa..5f60c80 100644 --- a/game/network/network.impl.h +++ b/game/network/network.impl.h @@ -1,13 +1,13 @@ #include "network.h" -#include +#include #include template void -NetworkOf::render(const Shader & shader) const +NetworkOf::render(const SceneShader & shader) const { if constexpr (std::is_base_of_v) { - shader.setModel(Location {}, Shader::Program::StaticPos); + shader.setModel(Location {}, SceneShader::Program::StaticPos); texture->bind(); links.apply(&Renderable::render, shader); } diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 2efa87a..2f09d88 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -94,7 +94,7 @@ RailLink::defaultMesh(const std::span vertices) } void -RailLink::render(const Shader &) const +RailLink::render(const SceneShader &) const { mesh->Draw(); } diff --git a/game/network/rail.h b/game/network/rail.h index 6850463..8edc363 100644 --- a/game/network/rail.h +++ b/game/network/rail.h @@ -11,7 +11,7 @@ #include #include -class Shader; +class SceneShader; class Vertex; struct Arc; @@ -26,7 +26,7 @@ public: using StraightLink = RailLinkStraight; using CurveLink = RailLinkCurve; - void render(const Shader &) const override; + void render(const SceneShader &) const override; NO_COPY(RailLink); NO_MOVE(RailLink); diff --git a/game/terrain.cpp b/game/terrain.cpp index 3a35c42..911a541 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -83,13 +83,13 @@ Terrain::tick(TickDuration dur) } void -Terrain::render(const Shader & shader) const +Terrain::render(const SceneShader & shader) const { - shader.setModel(Location {}, Shader::Program::LandMass); + shader.setModel(Location {}, SceneShader::Program::LandMass); grass->bind(); meshes.apply(&Mesh::Draw); - shader.setModel(Location {}, Shader::Program::Water); + shader.setModel(Location {}, SceneShader::Program::Water); shader.setUniform("waves", {waveCycle, 0, 0}); water->bind(); meshes.apply(&Mesh::Draw); diff --git a/game/terrain.h b/game/terrain.h index b13efb6..70f947c 100644 --- a/game/terrain.h +++ b/game/terrain.h @@ -7,7 +7,7 @@ #include #include -class Shader; +class SceneShader; class Texture; class GeoData; @@ -15,7 +15,7 @@ class Terrain : public WorldObject, public Renderable { public: explicit Terrain(std::shared_ptr); - void render(const Shader & shader) const override; + void render(const SceneShader & shader) const override; void tick(TickDuration) override; float waveCycle {0.F}; diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index fb42a28..0cf4e72 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -12,7 +12,7 @@ #include void -RailVehicle::render(const Shader & shader) const +RailVehicle::render(const SceneShader & shader) const { rvClass->render(shader, location, bogies); } diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index 5fbe1ed..39900cc 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -9,7 +9,7 @@ #include #include -class Shader; +class SceneShader; class Ray; class Train; @@ -19,7 +19,7 @@ public: void move(const Train *, float & trailBy); - void render(const Shader & shader) const override; + void render(const SceneShader & shader) const override; [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; Location location; diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 7eb4495..7d69338 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -1,5 +1,5 @@ #include "railVehicleClass.h" -#include "gfx/gl/shader.h" +#include "gfx/gl/sceneShader.h" #include "gfx/models/mesh.h" #include "gfx/models/obj.h" #include "gfx/models/texture.h" @@ -39,7 +39,8 @@ RailVehicleClass::RailVehicleClass(std::unique_ptr o, std::shared_ptr } void -RailVehicleClass::render(const Shader & shader, const Location & location, const std::array & bl) const +RailVehicleClass::render( + const SceneShader & shader, const Location & location, const std::array & bl) const { texture->bind(); for (auto b = 0U; b < bogies.size(); ++b) { diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index 604af6a..7249e76 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -5,7 +5,7 @@ #include #include -class Shader; +class SceneShader; class Texture; class ObjParser; class Location; @@ -14,7 +14,7 @@ class RailVehicleClass { public: explicit RailVehicleClass(const std::string & name); - void render(const Shader &, const Location &, const std::array &) const; + void render(const SceneShader &, const Location &, const std::array &) const; std::array bogies; Mesh::Ptr bodyMesh; diff --git a/game/vehicles/train.cpp b/game/vehicles/train.cpp index d1122f8..8fb48f5 100644 --- a/game/vehicles/train.cpp +++ b/game/vehicles/train.cpp @@ -12,7 +12,7 @@ class Ray; void -Train::render(const Shader & shader) const +Train::render(const SceneShader & shader) const { apply(&Renderable::render, shader); } diff --git a/game/vehicles/train.h b/game/vehicles/train.h index 58e5e29..dfdcf62 100644 --- a/game/vehicles/train.h +++ b/game/vehicles/train.h @@ -13,7 +13,7 @@ #include #include -class Shader; +class SceneShader; class Ray; class Train : public Vehicle, public Collection, public Can, public Can { @@ -26,7 +26,7 @@ public: return objects.front()->location; } - void render(const Shader & shader) const override; + void render(const SceneShader & shader) const override; [[nodiscard]] bool intersectRay(const Ray &, glm::vec2 *, float *) const override; diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp new file mode 100644 index 0000000..48c0f42 --- /dev/null +++ b/gfx/gl/sceneShader.cpp @@ -0,0 +1,77 @@ +#include "sceneShader.h" +#include "gfx/gl/glSource.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +SceneShader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : ProgramHandleBase {vs, fs} +{ + glBindAttribLocation(m_program, 0, "position"); + glBindAttribLocation(m_program, 1, "texCoord"); + glBindAttribLocation(m_program, 2, "normal"); + + viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection"); + model_uniform = glGetUniformLocation(m_program, "model"); +} + +SceneShader::SceneShader() : + programs {{{ + basicShader_vs.compile(), + basicShader_fs.compile(), + }, + { + waterShader_vs.compile(), + waterShader_fs.compile(), + }, + { + landmassShader_vs.compile(), + landmassShader_fs.compile(), + }, + { + landmassShader_vs.compile(), + basicShader_fs.compile(), + }}} +{ +} + +void +SceneShader::setView(glm::mat4 proj) const +{ + for (const auto & prog : programs) { + glUseProgram(prog.m_program); + glUniformMatrix4fv(prog.viewProjection_uniform, 1, GL_FALSE, glm::value_ptr(proj)); + } +} + +void +SceneShader::setUniform(const GLchar * uniform, glm::vec3 v) const +{ + for (const auto & prog : programs) { + if (auto loc = glGetUniformLocation(prog.m_program, uniform); loc >= 0) { + glUseProgram(prog.m_program); + glUniform3fv(loc, 1, glm::value_ptr(v)); + } + } +} + +void +SceneShader::setModel(const Location & loc, Program pid) const +{ + auto & prog = programs[static_cast(pid)]; + glUseProgram(prog.m_program); + if (prog.model_uniform >= 0) { + const auto model {glm::translate(loc.pos) * rotate_ypr(loc.rot)}; + glUniformMatrix4fv(prog.model_uniform, 1, GL_FALSE, glm::value_ptr(model)); + } +} diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h new file mode 100644 index 0000000..61c159b --- /dev/null +++ b/gfx/gl/sceneShader.h @@ -0,0 +1,27 @@ +#pragma once + +#include "programHandle.h" +#include +#include +#include + +class Location; + +class SceneShader { +public: + enum class Program { Basic = 0, Water = 1, LandMass = 2, StaticPos = 3 }; + + SceneShader(); + + void setView(glm::mat4 view) const; + void setModel(const Location &, Program = Program::Basic) const; + void setUniform(const GLchar *, glm::vec3 dir) const; + +private: + class ProgramHandle : public ProgramHandleBase { + public: + ProgramHandle(GLuint, GLuint); + }; + + std::array programs; +}; diff --git a/gfx/gl/shader.cpp b/gfx/gl/shader.cpp deleted file mode 100644 index a196e07..0000000 --- a/gfx/gl/shader.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "shader.h" -#include "gfx/gl/glSource.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Shader::ProgramHandle::ProgramHandle(GLuint vs, GLuint fs) : ProgramHandleBase {vs, fs} -{ - glBindAttribLocation(m_program, 0, "position"); - glBindAttribLocation(m_program, 1, "texCoord"); - glBindAttribLocation(m_program, 2, "normal"); - - viewProjection_uniform = glGetUniformLocation(m_program, "viewProjection"); - model_uniform = glGetUniformLocation(m_program, "model"); -} - -Shader::Shader() : - programs {{{ - basicShader_vs.compile(), - basicShader_fs.compile(), - }, - { - waterShader_vs.compile(), - waterShader_fs.compile(), - }, - { - landmassShader_vs.compile(), - landmassShader_fs.compile(), - }, - { - landmassShader_vs.compile(), - basicShader_fs.compile(), - }}} -{ -} - -void -Shader::setView(glm::mat4 proj) const -{ - for (const auto & prog : programs) { - glUseProgram(prog.m_program); - glUniformMatrix4fv(prog.viewProjection_uniform, 1, GL_FALSE, glm::value_ptr(proj)); - } -} - -void -Shader::setUniform(const GLchar * uniform, glm::vec3 v) const -{ - for (const auto & prog : programs) { - if (auto loc = glGetUniformLocation(prog.m_program, uniform); loc >= 0) { - glUseProgram(prog.m_program); - glUniform3fv(loc, 1, glm::value_ptr(v)); - } - } -} - -void -Shader::setModel(const Location & loc, Program pid) const -{ - auto & prog = programs[static_cast(pid)]; - glUseProgram(prog.m_program); - if (prog.model_uniform >= 0) { - const auto model {glm::translate(loc.pos) * rotate_ypr(loc.rot)}; - glUniformMatrix4fv(prog.model_uniform, 1, GL_FALSE, glm::value_ptr(model)); - } -} diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h deleted file mode 100644 index 8411b94..0000000 --- a/gfx/gl/shader.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "programHandle.h" -#include -#include -#include - -class Location; - -class Shader { -public: - enum class Program { Basic = 0, Water = 1, LandMass = 2, StaticPos = 3 }; - - Shader(); - - void setView(glm::mat4 view) const; - void setModel(const Location &, Program = Program::Basic) const; - void setUniform(const GLchar *, glm::vec3 dir) const; - -private: - class ProgramHandle : public ProgramHandleBase { - public: - ProgramHandle(GLuint, GLuint); - }; - - std::array programs; -}; diff --git a/gfx/renderable.h b/gfx/renderable.h index 565f705..9b25645 100644 --- a/gfx/renderable.h +++ b/gfx/renderable.h @@ -2,7 +2,7 @@ #include -class Shader; +class SceneShader; class Renderable { public: @@ -10,5 +10,5 @@ public: virtual ~Renderable() = default; DEFAULT_MOVE_COPY(Renderable); - virtual void render(const Shader & shader) const = 0; + virtual void render(const SceneShader & shader) const = 0; }; diff --git a/ui/editNetwork.cpp b/ui/editNetwork.cpp index 277407f..991cbc3 100644 --- a/ui/editNetwork.cpp +++ b/ui/editNetwork.cpp @@ -5,7 +5,7 @@ #include "text.h" #include #include -#include +#include #include constexpr const glm::u8vec4 TRANSPARENT_BLUE {30, 50, 255, 200}; @@ -47,17 +47,17 @@ EditNetwork::handleInput(const SDL_Event & e, const UIComponent::Position & pare } void -EditNetwork::render(const Shader & shader) const +EditNetwork::render(const SceneShader & shader) const { if (builder) { blue.bind(); - shader.setModel(Location {}, Shader::Program::StaticPos); + shader.setModel(Location {}, SceneShader::Program::StaticPos); builder->render(shader); } } void -EditNetwork::Builder::render(const Shader & shader) const +EditNetwork::Builder::render(const SceneShader & shader) const { candidateLinks.apply(&Renderable::render, shader); } diff --git a/ui/editNetwork.h b/ui/editNetwork.h index 3501ac9..1ba2e13 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -18,7 +18,7 @@ public: bool click(const SDL_MouseButtonEvent & e, const Ray &) override; bool move(const SDL_MouseMotionEvent & e, const Ray &) override; bool handleInput(const SDL_Event & e, const UIComponent::Position &) override; - void render(const Shader &) const override; + void render(const SceneShader &) const override; void render(const UIShader & shader, const UIComponent::Position & pos) const override; using NetworkClickPos = std::variant; @@ -26,7 +26,7 @@ public: class Builder { public: virtual ~Builder() = default; - virtual void render(const Shader & shader) const; + virtual void render(const SceneShader & shader) const; virtual std::string hint() const = 0; virtual void click(Network *, const GeoData *, const SDL_MouseButtonEvent &, const Ray &) = 0; virtual void move(Network *, const GeoData *, const SDL_MouseMotionEvent &, const Ray &) = 0; diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index a5356ab..0fbf687 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -29,7 +29,7 @@ GameMainSelector::render(const UIShader & shader, const Position & parentPos) co } void -GameMainSelector::render(const Shader & shader) const +GameMainSelector::render(const SceneShader & shader) const { if (target) { target->render(shader); @@ -112,6 +112,6 @@ GameMainSelector::Component::render(const UIShader &, const UIComponent::Positio } void -GameMainSelector::Component::render(const Shader &) const +GameMainSelector::Component::render(const SceneShader &) const { } diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index 38d8eb1..9c05127 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -21,13 +21,13 @@ public: virtual bool move(const SDL_MouseMotionEvent &, const Ray &); virtual bool handleInput(const SDL_Event &, const Position & pos); virtual void render(const UIShader & shader, const Position & pos) const; - virtual void render(const Shader &) const; + virtual void render(const SceneShader &) const; }; GameMainSelector(const Camera * c, glm::vec2 size); void render(const UIShader & shader, const Position & pos) const override; - void render(const Shader & shader) const override; + void render(const SceneShader & shader) const override; bool handleInput(const SDL_Event & e, const Position &) override; diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index c08588d..792ffab 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -59,7 +59,7 @@ GameMainWindow::render() const Window::render(); } -const Shader & +const SceneShader & GameMainWindow::getShader() const { return shader; diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h index 2c2c501..09d17d1 100644 --- a/ui/gameMainWindow.h +++ b/ui/gameMainWindow.h @@ -2,7 +2,7 @@ #include "chronology.hpp" #include "gfx/gl/camera.h" -#include "gfx/gl/shader.h" +#include "gfx/gl/sceneShader.h" #include "sceneRenderer.h" #include "window.h" #include @@ -16,7 +16,7 @@ public: void render() const override; private: - const Shader & getShader() const override; - Shader shader; + const SceneShader & getShader() const override; + SceneShader shader; Camera camera; }; diff --git a/ui/sceneRenderer.h b/ui/sceneRenderer.h index 1c01069..6176f1b 100644 --- a/ui/sceneRenderer.h +++ b/ui/sceneRenderer.h @@ -1,6 +1,6 @@ #pragma once -#include "gfx/gl/shader.h" +#include "gfx/gl/sceneShader.h" #include "lib/glArrays.h" #include diff --git a/ui/window.h b/ui/window.h index dc3c528..b3d3f68 100644 --- a/ui/window.h +++ b/ui/window.h @@ -10,7 +10,7 @@ #include #include -class Shader; +class SceneShader; class Window { public: @@ -30,7 +30,7 @@ public: protected: [[nodiscard]] SDL_GLContext glContext() const; virtual void render() const; - virtual const Shader & getShader() const = 0; + virtual const SceneShader & getShader() const = 0; using SDL_WindowPtr = wrapped_ptrt; const glm::ivec2 size; diff --git a/ui/worldOverlay.h b/ui/worldOverlay.h index 028122a..18fab3f 100644 --- a/ui/worldOverlay.h +++ b/ui/worldOverlay.h @@ -1,9 +1,9 @@ #pragma once -class Shader; +class SceneShader; class WorldOverlay { public: virtual ~WorldOverlay() = default; - virtual void render(const Shader &) const = 0; + virtual void render(const SceneShader &) const = 0; }; -- cgit v1.2.3