From 5a0b3927a33807cca4c77c40eb873f8a3b51b0b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Apr 2023 19:07:11 +0100 Subject: Drop .hpp for header only things Half of them acquired a .cpp part anyway --- gfx/camera_controller.h | 2 +- gfx/followCameraController.cpp | 2 +- gfx/gl/bufferedLocation.cpp | 2 +- gfx/gl/bufferedLocation.h | 2 +- gfx/gl/camera.cpp | 4 +- gfx/gl/camera.h | 2 +- gfx/gl/instanceVertices.h | 2 +- gfx/gl/program.cpp | 2 +- gfx/gl/program.h | 4 +- gfx/gl/sceneProvider.h | 2 +- gfx/gl/sceneRenderer.cpp | 2 +- gfx/gl/sceneShader.cpp | 4 +- gfx/gl/shader.h | 2 +- gfx/gl/shadowMapper.cpp | 6 +-- gfx/gl/vertexArrayObject.h | 109 +++++++++++++++++++++++++++++++++++++++++ gfx/gl/vertexArrayObject.hpp | 109 ----------------------------------------- gfx/image.h | 2 +- gfx/models/mesh.cpp | 4 +- gfx/models/mesh.h | 2 +- gfx/models/vertex.h | 23 +++++++++ gfx/models/vertex.hpp | 23 --------- gfx/renderable.h | 2 +- 22 files changed, 156 insertions(+), 156 deletions(-) create mode 100644 gfx/gl/vertexArrayObject.h delete mode 100644 gfx/gl/vertexArrayObject.hpp create mode 100644 gfx/models/vertex.h delete mode 100644 gfx/models/vertex.hpp (limited to 'gfx') diff --git a/gfx/camera_controller.h b/gfx/camera_controller.h index fd5c885..83c0d38 100644 --- a/gfx/camera_controller.h +++ b/gfx/camera_controller.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class Camera; diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp index d15ecda..5b08483 100644 --- a/gfx/followCameraController.cpp +++ b/gfx/followCameraController.cpp @@ -2,7 +2,7 @@ #include "game/vehicles/vehicle.h" #include #include -#include +#include #include #include #include diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 4484053..7027b4c 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -1,5 +1,5 @@ #include "bufferedLocation.h" -#include "location.hpp" +#include "location.h" #include "maths.h" #include diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index cf7afed..6d148cd 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -1,7 +1,7 @@ #pragma once #include "instanceVertices.h" -#include "location.hpp" +#include "location.h" #include #include diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp index 5b7269e..f642423 100644 --- a/gfx/gl/camera.cpp +++ b/gfx/gl/camera.cpp @@ -1,9 +1,9 @@ #include "camera.h" -#include +#include #include // IWYU pragma: keep #include // IWYU pragma: keep #include -#include +#include Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) : position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, projection {glm::perspective( diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h index 5c168e7..3f1c3a7 100644 --- a/gfx/gl/camera.h +++ b/gfx/gl/camera.h @@ -2,7 +2,7 @@ #include #include -#include +#include class Camera { public: diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h index 8bb2f21..9df6e12 100644 --- a/gfx/gl/instanceVertices.h +++ b/gfx/gl/instanceVertices.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/gfx/gl/program.cpp b/gfx/gl/program.cpp index 7791e3e..0b60eaa 100644 --- a/gfx/gl/program.cpp +++ b/gfx/gl/program.cpp @@ -2,7 +2,7 @@ #include "shader.h" #include #include -#include +#include #include void diff --git a/gfx/gl/program.h b/gfx/gl/program.h index 787a53c..2708ff0 100644 --- a/gfx/gl/program.h +++ b/gfx/gl/program.h @@ -2,9 +2,9 @@ #include "shader.h" #include -#include +#include #include -#include +#include class Location; diff --git a/gfx/gl/sceneProvider.h b/gfx/gl/sceneProvider.h index 1d9ba57..f5e8e99 100644 --- a/gfx/gl/sceneProvider.h +++ b/gfx/gl/sceneProvider.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class SceneRenderer; class ShadowMapper; diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 6542bea..aa9453a 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -1,6 +1,6 @@ #include "sceneRenderer.h" #include "maths.h" -#include "vertexArrayObject.hpp" +#include "vertexArrayObject.h" #include #include #include diff --git a/gfx/gl/sceneShader.cpp b/gfx/gl/sceneShader.cpp index 00d9826..1354611 100644 --- a/gfx/gl/sceneShader.cpp +++ b/gfx/gl/sceneShader.cpp @@ -13,10 +13,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include SceneShader::SceneShader() : diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h index c1e3981..cb8065b 100644 --- a/gfx/gl/shader.h +++ b/gfx/gl/shader.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp index 9f1e420..55d986c 100644 --- a/gfx/gl/shadowMapper.cpp +++ b/gfx/gl/shadowMapper.cpp @@ -1,14 +1,14 @@ #include "shadowMapper.h" #include "camera.h" -#include "collections.hpp" +#include "collections.h" #include "gfx/gl/shaders/vs-shadowDynamicPoint.h" #include "gfx/gl/shaders/vs-shadowDynamicPointInst.h" #include "gfx/gl/shaders/vs-shadowFixedPoint.h" -#include "location.hpp" +#include "location.h" #include "maths.h" #include "sceneProvider.h" #include "sceneShader.h" -#include "sorting.hpp" +#include "sorting.h" #include #include #include diff --git a/gfx/gl/vertexArrayObject.h b/gfx/gl/vertexArrayObject.h new file mode 100644 index 0000000..085cba6 --- /dev/null +++ b/gfx/gl/vertexArrayObject.h @@ -0,0 +1,109 @@ +#pragma once + +#include "collections.h" +#include "gl_traits.h" +#include "special_members.h" +#include + +class VertexArrayObject { +public: + template [[nodiscard]] VertexArrayObject(const T & arrayObject) + { + glBindVertexArray(arrayObject); + } + ~VertexArrayObject() + { + glBindVertexArray(0); + } + NO_MOVE(VertexArrayObject); + NO_COPY(VertexArrayObject); + + template struct MP { + constexpr MP(m T::*p) : P {p} { } + operator void *() const + { + return &(static_cast(nullptr)->*P); + } + m T::*P; + using value_type = m; + }; + template MP(m T::*) -> MP; + + template + VertexArrayObject & + addAttribs(const GLuint arrayBuffer, const SequentialCollection auto & vertices, const GLuint divisor = 0) + { + addAttribs(arrayBuffer, divisor); + data(vertices, arrayBuffer, GL_ARRAY_BUFFER); + return *this; + } + + template + VertexArrayObject & + addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) + { + configure_attribs(arrayBuffer, divisor); + return *this; + } + + template + VertexArrayObject & + addIndices(const GLuint arrayBuffer, const Indices & indices) + { + data(indices, arrayBuffer, GL_ELEMENT_ARRAY_BUFFER); + return *this; + } + + VertexArrayObject & + addIndices(const GLuint arrayBuffer) + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, arrayBuffer); + return *this; + } + + template + static void + data(const Data & data, const GLuint arrayBuffer, GLenum target) + { + using Value = typename Data::value_type; + glBindBuffer(target, arrayBuffer); + glBufferData(target, static_cast(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); + } + +private: + template + static auto + set_pointer(const GLuint vertexArrayId, const void * ptr, const GLuint divisor) + { + using traits = gl_traits; + const auto usedAttribs + = traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr); + for (GLuint i {}; i < usedAttribs; i++) { + glEnableVertexAttribArray(vertexArrayId + i); + glVertexAttribDivisor(vertexArrayId + i, divisor); + } + return usedAttribs; + } + + template + static auto + set_pointer(const GLuint vertexArrayId, const GLuint divisor) + { + return set_pointer(vertexArrayId, attrib, divisor); + } + + template + void + configure_attribs(const GLuint arrayBuffer, const GLuint divisor) + { + glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); + if constexpr (sizeof...(attribs) == 0) { + vertexArrayId += set_pointer(vertexArrayId, nullptr, divisor); + } + else { + ((vertexArrayId += set_pointer(vertexArrayId, divisor)), ...); + } + } + + GLuint vertexArrayId {}; +}; diff --git a/gfx/gl/vertexArrayObject.hpp b/gfx/gl/vertexArrayObject.hpp deleted file mode 100644 index 7ded03e..0000000 --- a/gfx/gl/vertexArrayObject.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#pragma once - -#include "collections.hpp" -#include "gl_traits.hpp" -#include "special_members.hpp" -#include - -class VertexArrayObject { -public: - template [[nodiscard]] VertexArrayObject(const T & arrayObject) - { - glBindVertexArray(arrayObject); - } - ~VertexArrayObject() - { - glBindVertexArray(0); - } - NO_MOVE(VertexArrayObject); - NO_COPY(VertexArrayObject); - - template struct MP { - constexpr MP(m T::*p) : P {p} { } - operator void *() const - { - return &(static_cast(nullptr)->*P); - } - m T::*P; - using value_type = m; - }; - template MP(m T::*) -> MP; - - template - VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const SequentialCollection auto & vertices, const GLuint divisor = 0) - { - addAttribs(arrayBuffer, divisor); - data(vertices, arrayBuffer, GL_ARRAY_BUFFER); - return *this; - } - - template - VertexArrayObject & - addAttribs(const GLuint arrayBuffer, const GLuint divisor = 0) - { - configure_attribs(arrayBuffer, divisor); - return *this; - } - - template - VertexArrayObject & - addIndices(const GLuint arrayBuffer, const Indices & indices) - { - data(indices, arrayBuffer, GL_ELEMENT_ARRAY_BUFFER); - return *this; - } - - VertexArrayObject & - addIndices(const GLuint arrayBuffer) - { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, arrayBuffer); - return *this; - } - - template - static void - data(const Data & data, const GLuint arrayBuffer, GLenum target) - { - using Value = typename Data::value_type; - glBindBuffer(target, arrayBuffer); - glBufferData(target, static_cast(sizeof(Value) * data.size()), data.data(), GL_STATIC_DRAW); - } - -private: - template - static auto - set_pointer(const GLuint vertexArrayId, const void * ptr, const GLuint divisor) - { - using traits = gl_traits; - const auto usedAttribs - = traits::vertexAttribFunc(vertexArrayId, traits::size, traits::type, sizeof(VertexT), ptr); - for (GLuint i {}; i < usedAttribs; i++) { - glEnableVertexAttribArray(vertexArrayId + i); - glVertexAttribDivisor(vertexArrayId + i, divisor); - } - return usedAttribs; - } - - template - static auto - set_pointer(const GLuint vertexArrayId, const GLuint divisor) - { - return set_pointer(vertexArrayId, attrib, divisor); - } - - template - void - configure_attribs(const GLuint arrayBuffer, const GLuint divisor) - { - glBindBuffer(GL_ARRAY_BUFFER, arrayBuffer); - if constexpr (sizeof...(attribs) == 0) { - vertexArrayId += set_pointer(vertexArrayId, nullptr, divisor); - } - else { - ((vertexArrayId += set_pointer(vertexArrayId, divisor)), ...); - } - } - - GLuint vertexArrayId {}; -}; diff --git a/gfx/image.h b/gfx/image.h index 97c2731..8bb4067 100644 --- a/gfx/image.h +++ b/gfx/image.h @@ -1,7 +1,7 @@ #pragma once #include // IWYU pragma: export -#include +#include #include class Image { diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp index 7c5ddd4..a1ce991 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,7 +1,7 @@ #include "mesh.h" -#include "gfx/gl/vertexArrayObject.hpp" +#include "gfx/gl/vertexArrayObject.h" #include "glArrays.h" -#include "vertex.hpp" +#include "vertex.h" #include Mesh::Mesh(const std::span vertices, const std::span indices, GLenum m) : diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 9b22b02..f022c2a 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include class Vertex; class VertexArrayObject; diff --git a/gfx/models/vertex.h b/gfx/models/vertex.h new file mode 100644 index 0000000..181e7e7 --- /dev/null +++ b/gfx/models/vertex.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class Vertex { +public: +#ifndef __cpp_aggregate_paren_init + constexpr Vertex(glm::vec3 pos, glm::vec2 texCoord, glm::vec3 normal, glm::vec4 colour = {}, GLuint material = 0) : + pos {std::move(pos)}, texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)}, + material {material} + { + } +#endif + + bool operator==(const Vertex &) const = default; + + glm::vec3 pos; + glm::vec2 texCoord; + glm::vec3 normal; + glm::vec4 colour {}; + GLuint material {}; +}; diff --git a/gfx/models/vertex.hpp b/gfx/models/vertex.hpp deleted file mode 100644 index 181e7e7..0000000 --- a/gfx/models/vertex.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -class Vertex { -public: -#ifndef __cpp_aggregate_paren_init - constexpr Vertex(glm::vec3 pos, glm::vec2 texCoord, glm::vec3 normal, glm::vec4 colour = {}, GLuint material = 0) : - pos {std::move(pos)}, texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)}, - material {material} - { - } -#endif - - bool operator==(const Vertex &) const = default; - - glm::vec3 pos; - glm::vec2 texCoord; - glm::vec3 normal; - glm::vec4 colour {}; - GLuint material {}; -}; diff --git a/gfx/renderable.h b/gfx/renderable.h index 5a9b1cd..e126fff 100644 --- a/gfx/renderable.h +++ b/gfx/renderable.h @@ -1,6 +1,6 @@ #pragma once -#include +#include class SceneShader; class ShadowMapper; -- cgit v1.2.3