diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-11-09 01:57:27 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-11-09 01:57:27 +0000 |
commit | d771fbda2c171cfbc36cc0eb3122c1a02ffbb081 (patch) | |
tree | 69d2879e41da2b79264b6c3b8500b5d18383ae85 | |
parent | WIP typedefing all the things - sources (diff) | |
download | ilt-d771fbda2c171cfbc36cc0eb3122c1a02ffbb081.tar.bz2 ilt-d771fbda2c171cfbc36cc0eb3122c1a02ffbb081.tar.xz ilt-d771fbda2c171cfbc36cc0eb3122c1a02ffbb081.zip |
WIP typedefing just about everything else
-rw-r--r-- | assetFactory/assetFactory.h | 5 | ||||
-rw-r--r-- | assetFactory/modelFactoryMesh.h | 9 | ||||
-rw-r--r-- | assetFactory/style.cpp | 14 | ||||
-rw-r--r-- | assetFactory/style.h | 6 | ||||
-rw-r--r-- | config/types.h | 3 | ||||
-rw-r--r-- | game/network/network.h | 2 | ||||
-rw-r--r-- | game/network/rail.cpp | 4 | ||||
-rw-r--r-- | gfx/gl/sceneRenderer.cpp | 2 | ||||
-rw-r--r-- | gfx/gl/sceneRenderer.h | 2 | ||||
-rw-r--r-- | gfx/gl/sceneShader.cpp | 4 | ||||
-rw-r--r-- | gfx/gl/sceneShader.h | 4 | ||||
-rw-r--r-- | gfx/gl/shadowMapper.cpp | 47 | ||||
-rw-r--r-- | gfx/gl/shadowMapper.h | 2 | ||||
-rw-r--r-- | ui/editNetwork.h | 2 |
14 files changed, 54 insertions, 52 deletions
diff --git a/assetFactory/assetFactory.h b/assetFactory/assetFactory.h index e449ce2..787f0a4 100644 --- a/assetFactory/assetFactory.h +++ b/assetFactory/assetFactory.h @@ -15,10 +15,9 @@ public: using Assets = std::map<std::string, Asset::Ptr, std::less<>>; using AssImps = std::map<std::string, AssImp::Ptr, std::less<>>; using TextureFragments = std::map<std::string, TextureFragment::Ptr, std::less<>>; - using Colour = glm::vec3; - using ColourAlpha = glm::vec4; + using Colour = RGB; + using ColourAlpha = RGBA; using Colours = std::map<std::string, Colour, std::less<>>; - using TextureFragmentCoords = std::array<glm::vec2, 4>; AssetFactory(); [[nodiscard]] static std::shared_ptr<AssetFactory> loadXML(const std::filesystem::path &); diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 32e7ab5..480bf7f 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include "modelFactoryMesh_fwd.h" #include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh> #include <OpenMesh/Core/Mesh/Traits.hh> @@ -38,10 +39,10 @@ struct ModelFactoryTraits : public OpenMesh::DefaultTraits { EdgeAttributes(OpenMesh::Attributes::Status); VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); HalfedgeAttributes(OpenMesh::Attributes::TexCoord2D); - using Point = glm::vec3; - using Normal = glm::vec3; - using Color = glm::vec4; - using TexCoord2D = glm::vec2; + using Point = Position3D; + using Normal = Normal3D; + using Color = RGBA; + using TexCoord2D = TextureRelCoord; }; struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT<ModelFactoryTraits> { diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index 81a5441..265becb 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -33,10 +33,10 @@ Style::applyStyle( const auto material = mf->getMaterialIndex(texture); mesh.property(mesh.materialFaceProperty, face) = material; static constexpr std::array<ModelFactoryTraits::TexCoord2D, 4> coords {{ - {0.f, 0.f}, - {1.f, 0.f}, - {1.f, 1.f}, - {0.f, 1.f}, + {0.F, 0.F}, + {1.F, 0.F}, + {1.F, 1.F}, + {0.F, 1.F}, }}; auto coord = coords.begin(); // Wild assumption that face is a quad and the texture should apply linearly @@ -58,9 +58,9 @@ Style::getColour(const StyleStack & parents) bool Style::persist(Persistence::PersistenceStore & store) { - struct ColourParser : public Persistence::SelectionV<ColourAlpha> { - using Persistence::SelectionV<ColourAlpha>::SelectionV; - using Persistence::SelectionV<ColourAlpha>::setValue; + struct ColourParser : public Persistence::SelectionV<RGBA> { + using Persistence::SelectionV<RGBA>::SelectionV; + using Persistence::SelectionV<RGBA>::setValue; void setValue(std::string && str) override diff --git a/assetFactory/style.h b/assetFactory/style.h index d931f98..2a437aa 100644 --- a/assetFactory/style.h +++ b/assetFactory/style.h @@ -10,9 +10,7 @@ class Style { public: using StyleStack = std::vector<const Style *>; - using Colour = glm::vec3; - using ColourAlpha = glm::vec4; - using EffectiveColour = std::optional<std::reference_wrapper<const ColourAlpha>>; + using EffectiveColour = std::optional<std::reference_wrapper<const RGBA>>; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const; @@ -30,7 +28,7 @@ public: static EffectiveColour getColour(const StyleStack & parents); - ColourAlpha colour {}; + RGBA colour {}; std::optional<bool> smooth; std::string texture; std::string textureRotation; // Multiples of 90deg, no int/enum support diff --git a/config/types.h b/config/types.h index a84be90..d99735e 100644 --- a/config/types.h +++ b/config/types.h @@ -27,8 +27,11 @@ using Normal3D = Normal<3>; using Rotation2D = Rotation<2>; using Rotation3D = Rotation<3>; using TextureRelCoord = glm::vec<2, float>; +using TextureRelRegion = glm::vec<4, float>; using TextureAbsCoord = glm::vec<2, GLsizei>; +using TextureAbsRegion = glm::vec<4, GLsizei>; using RGB = Colour<3>; using RGBA = Colour<4>; using ScreenRelCoord = glm::vec<2, float>; using ScreenAbsCoord = glm::vec<2, uint16_t>; +using ViewPort = glm::vec<4, GLsizei>; diff --git a/game/network/network.h b/game/network/network.h index 02f8c30..8af06a9 100644 --- a/game/network/network.h +++ b/game/network/network.h @@ -16,7 +16,7 @@ class Texture; class SceneShader; class Ray; -template<size_t... n> using GenDef = std::tuple<glm::vec<n, float>...>; +template<size_t... n> using GenDef = std::tuple<glm::vec<n, Distance>...>; using GenCurveDef = GenDef<3, 3, 2>; class Network { diff --git a/game/network/rail.cpp b/game/network/rail.cpp index f46504b..cc61db9 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -133,7 +133,7 @@ RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const Position3D & for (auto ei : {1U, 0U}) { const auto trans {glm::translate(ends[ei].node->pos) * e}; for (const auto & rcs : railCrossSection) { - const Position3D m {(trans * glm::vec4 {rcs.first, 1})}; + const Position3D m {(trans * (rcs.first ^ 1))}; vertices.emplace_back(m, Position2D {rcs.second, len * static_cast<float>(ei)}, up); } } @@ -166,7 +166,7 @@ RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, Position3 const auto t { trans * glm::rotate(half_pi - swing.x, up) * glm::translate(Position3D {radius, 0.F, swing.y})}; for (const auto & rcs : railCrossSection) { - const Position3D m {(t * glm::vec4 {rcs.first, 1})}; + const Position3D m {(t * (rcs.first ^ 1))}; vertices.emplace_back(m, Position2D {rcs.second, swing.z}, up); } } diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 6965175..4a3fec9 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -135,7 +135,7 @@ SceneRenderer::DirectionalLightProgram::DirectionalLightProgram() : void SceneRenderer::DirectionalLightProgram::setDirectionalLight(const RGB & c, const Direction3D & d, - const std::span<const glm::mat4x4> lvp, const std::span<const glm::vec4> shadowMapRegions, + const std::span<const glm::mat4x4> lvp, const std::span<const TextureRelRegion> shadowMapRegions, std::size_t maps) const { glUniform3fv(colourLoc, 1, glm::value_ptr(c)); diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index 87f474b..30fd8d3 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -40,7 +40,7 @@ private: using Program::use; void setDirectionalLight(const RGB &, const Direction3D &, const std::span<const glm::mat4x4>, - const std::span<const glm::vec4>, std::size_t maps) const; + const std::span<const TextureRelRegion>, std::size_t maps) const; private: RequiredUniformLocation directionLoc, colourLoc, lightViewProjectionLoc, lightViewProjectionCountLoc, diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 04b6d9e..2dc2e70 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -35,7 +35,7 @@ SceneShader::setViewProjection(const glm::mat4 & viewProjection) const } void -SceneShader::setViewPort(const glm::ivec4 & viewPort) const +SceneShader::setViewPort(const ViewPort & viewPort) const { for (const auto & prog : std::array<const SceneProgram *, 7> { &basic, &basicInst, &water, &landmass, &absolute, &pointLight, &spotLight}) { @@ -51,7 +51,7 @@ SceneShader::SceneProgram::setViewProjection(const glm::mat4 & viewProjection) c } void -SceneShader::SceneProgram::setViewPort(const glm::ivec4 & viewPort) const +SceneShader::SceneProgram::setViewPort(const ViewPort & viewPort) const { if (viewPortLoc >= 0) { glUseProgram(*this); diff --git a/gfx/gl/sceneShader.h b/gfx/gl/sceneShader.h index d1c6ef2..f46b842 100644 --- a/gfx/gl/sceneShader.h +++ b/gfx/gl/sceneShader.h @@ -16,7 +16,7 @@ class SceneShader { } void setViewProjection(const glm::mat4 &) const; - void setViewPort(const glm::ivec4 &) const; + void setViewPort(const ViewPort &) const; private: RequiredUniformLocation viewProjectionLoc; @@ -88,5 +88,5 @@ public: SpotLightShader spotLight; void setViewProjection(const glm::mat4 & viewProjection) const; - void setViewPort(const glm::ivec4 & viewPort) const; + void setViewPort(const ViewPort & viewPort) const; }; diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index aea5af3..94a0791 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -24,7 +24,7 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - static constexpr glm::vec4 border {std::numeric_limits<float>::infinity()}; + static constexpr RGBA border {std::numeric_limits<RGBA::value_type>::infinity()}; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(border)); glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO); @@ -37,7 +37,7 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) : glBindFramebuffer(GL_FRAMEBUFFER, 0); } -constexpr std::array<std::array<glm::ivec4, ShadowMapper::SHADOW_BANDS>, ShadowMapper::SHADOW_BANDS> viewports {{ +constexpr std::array<std::array<TextureAbsRegion, ShadowMapper::SHADOW_BANDS>, ShadowMapper::SHADOW_BANDS> viewports {{ {{ {31, 31, 0, 0}, // full }}, @@ -57,27 +57,28 @@ constexpr std::array<std::array<glm::ivec4, ShadowMapper::SHADOW_BANDS>, ShadowM {1, 1, 1, 1}, // upper right }}, }}; -constexpr std::array<std::array<glm::vec4, ShadowMapper::SHADOW_BANDS>, ShadowMapper::SHADOW_BANDS> shadowMapRegions {{ - {{ - {0.5F, 0.5F, 0.5F, 0.5F}, // full - }}, - {{ - {0.5F, 0.25F, 0.5F, 0.25F}, // lower half - {0.5F, 0.25F, 0.5F, 0.75F}, // upper half - }}, - {{ - {0.5F, 0.25F, 0.5F, 0.25F}, // lower half - {0.25F, 0.25F, 0.25F, 0.75F}, // upper left - {0.25F, 0.25F, 0.75F, 0.75F}, // upper right - }}, - - {{ - {0.25F, 0.25F, 0.25F, 0.25F}, // lower left - {0.25F, 0.25F, 0.75F, 0.25F}, // lower right - {0.25F, 0.25F, 0.25F, 0.75F}, // upper left - {0.25F, 0.25F, 0.75F, 0.75F}, // upper right - }}, -}}; +constexpr std::array<std::array<TextureAbsRegion, ShadowMapper::SHADOW_BANDS>, ShadowMapper::SHADOW_BANDS> + shadowMapRegions {{ + {{ + {0.5F, 0.5F, 0.5F, 0.5F}, // full + }}, + {{ + {0.5F, 0.25F, 0.5F, 0.25F}, // lower half + {0.5F, 0.25F, 0.5F, 0.75F}, // upper half + }}, + {{ + {0.5F, 0.25F, 0.5F, 0.25F}, // lower half + {0.25F, 0.25F, 0.25F, 0.75F}, // upper left + {0.25F, 0.25F, 0.75F, 0.75F}, // upper right + }}, + + {{ + {0.25F, 0.25F, 0.25F, 0.25F}, // lower left + {0.25F, 0.25F, 0.75F, 0.25F}, // lower right + {0.25F, 0.25F, 0.25F, 0.75F}, // upper left + {0.25F, 0.25F, 0.75F, 0.75F}, // upper right + }}, + }}; constexpr std::array<float, ShadowMapper::SHADOW_BANDS + 1> shadowBands { 1.F, 250.F, diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h index e5272a3..d54734c 100644 --- a/gfx/gl/shadowMapper.h +++ b/gfx/gl/shadowMapper.h @@ -18,7 +18,7 @@ public: struct Definitions { std::array<glm::mat4x4, SHADOW_BANDS> projections {}; - std::array<glm::vec4, SHADOW_BANDS> regions {}; + std::array<TextureRelRegion, SHADOW_BANDS> regions {}; size_t maps {}; }; diff --git a/ui/editNetwork.h b/ui/editNetwork.h index eb1677e..e1aaa61 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -21,7 +21,7 @@ public: void render(const SceneShader &) const override; void render(const UIShader & shader, const UIComponent::Position & pos) const override; - using NetworkClickPos = std::variant<glm::vec3, Node::Ptr>; + using NetworkClickPos = std::variant<Position3D, Node::Ptr>; class Builder { public: |