summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/camera.cpp13
-rw-r--r--gfx/gl/camera.h4
-rw-r--r--gfx/gl/program.h4
-rw-r--r--gfx/gl/sceneProvider.h5
-rw-r--r--gfx/gl/sceneRenderer.cpp2
-rw-r--r--gfx/gl/shader.h2
-rw-r--r--gfx/gl/shadowMapper.cpp2
-rw-r--r--gfx/gl/shadowMapper.h7
-rw-r--r--gfx/gl/uiShader.h5
-rw-r--r--gfx/models/texture.cpp4
10 files changed, 30 insertions, 18 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index 2ea326d..b596c43 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -7,9 +7,10 @@
Camera::Camera(glm::vec3 pos, float fov, float aspect, float zNear, float zFar) :
position {pos}, forward {::north}, up {::up}, fov {fov}, aspect {aspect}, near {zNear}, far {zFar},
- projection {glm::perspective(fov, aspect, zNear, zFar)}
+ projection {glm::perspective(fov, aspect, zNear, zFar)},
+ viewProjection {projection * glm::lookAt(position, position + forward, up)}, inverseViewProjection {
+ glm::inverse(viewProjection)}
{
- updateView();
}
Ray
@@ -38,9 +39,9 @@ std::array<glm::vec4, 4>
Camera::extentsAtDist(const float dist) const
{
const auto clampToSeaFloor = [this, dist](const glm::vec3 & target) {
- if (target.z < -1.5f) {
+ if (target.z < -1.5F) {
const auto vec = glm::normalize(target - position);
- constexpr glm::vec3 seafloor {0, 0, -1.5};
+ constexpr glm::vec3 seafloor {0, 0, -1.5F};
float outdist;
if (glm::intersectRayPlane(position, vec, seafloor, ::up, outdist)) {
return (vec * outdist + position) ^ outdist;
@@ -48,11 +49,11 @@ Camera::extentsAtDist(const float dist) const
}
return target ^ dist;
};
- const auto depth = -(2.f * (dist - near) * far) / (dist * (near - far)) - 1.f;
+ const auto depth = -(2.F * (dist - near) * far) / (dist * (near - far)) - 1.F;
static constexpr const std::array extents {-1.F, 1.F};
static constexpr const auto cartesianExtents = extents * extents;
return cartesianExtents * [&depth, this, &clampToSeaFloor](const auto & extent) {
- const glm::vec4 in {extent.first, extent.second, depth, 1.f};
+ const glm::vec4 in {extent.first, extent.second, depth, 1.F};
return clampToSeaFloor(perspective_divide(inverseViewProjection * in));
};
}
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 94fd48b..9685a7d 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -61,9 +61,9 @@ public:
return position;
}
- std::array<glm::vec4, 4> extentsAtDist(float) const;
+ [[nodiscard]] std::array<glm::vec4, 4> extentsAtDist(float) const;
- static glm::vec3 upFromForward(const glm::vec3 & forward);
+ [[nodiscard]] static glm::vec3 upFromForward(const glm::vec3 & forward);
private:
void updateView();
diff --git a/gfx/gl/program.h b/gfx/gl/program.h
index fd9edbf..787a53c 100644
--- a/gfx/gl/program.h
+++ b/gfx/gl/program.h
@@ -4,6 +4,7 @@
#include <GL/glew.h>
#include <glRef.hpp>
#include <glm/mat4x4.hpp>
+#include <special_members.hpp>
class Location;
@@ -16,10 +17,12 @@ public:
linkAndValidate();
}
virtual ~Program() = default;
+ DEFAULT_MOVE_NO_COPY(Program);
class UniformLocation {
public:
UniformLocation(GLuint prog, const char * name);
+ // NOLINTNEXTLINE(hicpp-explicit-conversions)
operator auto() const
{
return location;
@@ -34,6 +37,7 @@ public:
RequiredUniformLocation(GLuint prog, const char * name);
};
+ // NOLINTNEXTLINE(hicpp-explicit-conversions)
operator GLuint() const
{
return m_program;
diff --git a/gfx/gl/sceneProvider.h b/gfx/gl/sceneProvider.h
index ef269b3..1d9ba57 100644
--- a/gfx/gl/sceneProvider.h
+++ b/gfx/gl/sceneProvider.h
@@ -1,12 +1,17 @@
#pragma once
+#include <special_members.hpp>
+
class SceneRenderer;
class ShadowMapper;
class SceneShader;
class SceneProvider {
public:
+ SceneProvider() = default;
virtual ~SceneProvider() = default;
+ DEFAULT_MOVE_COPY(SceneProvider);
+
virtual void content(const SceneShader &) const = 0;
virtual void environment(const SceneShader &, const SceneRenderer &) const;
virtual void lights(const SceneShader &) const = 0;
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index e7ce049..31b01ff 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -27,7 +27,7 @@ SceneRenderer::SceneRenderer(glm::ivec2 s, GLuint o) :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
for (const auto format : formats) {
- glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGB, GL_BYTE, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGB, GL_BYTE, nullptr);
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, data, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) {
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h
index a20636d..c1e3981 100644
--- a/gfx/gl/shader.h
+++ b/gfx/gl/shader.h
@@ -10,7 +10,7 @@ public:
using ShaderRef = glRef<GLuint, &__glewCreateShader, &__glewDeleteShader>;
constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { }
- ShaderRef compile() const;
+ [[nodiscard]] ShaderRef compile() const;
static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);
private:
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 01043e6..1787ee6 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -17,7 +17,7 @@
ShadowMapper::ShadowMapper(const glm::ivec2 & s) : size {s}
{
glBindTexture(GL_TEXTURE_2D, depthMap);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size.x, size.y, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size.x, size.y, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index 2805d64..b4793ed 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -14,11 +14,11 @@ public:
static constexpr std::size_t SHADOW_BANDS {4};
struct Definitions {
- std::array<glm::mat4x4, SHADOW_BANDS> projections;
- std::array<glm::vec4, SHADOW_BANDS> regions;
+ std::array<glm::mat4x4, SHADOW_BANDS> projections {};
+ std::array<glm::vec4, SHADOW_BANDS> regions {};
size_t maps {};
};
- Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const;
+ [[nodiscard]] Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const;
class FixedPoint : public Program {
public:
@@ -42,6 +42,7 @@ public:
FixedPoint fixedPoint;
DynamicPoint dynamicPoint;
+ // NOLINTNEXTLINE(hicpp-explicit-conversions)
operator GLuint() const
{
return depthMap;
diff --git a/gfx/gl/uiShader.h b/gfx/gl/uiShader.h
index ee44af7..054c944 100644
--- a/gfx/gl/uiShader.h
+++ b/gfx/gl/uiShader.h
@@ -15,9 +15,10 @@ private:
class UIProgram : public Program {
public:
- template<typename... S> UIProgram(const glm::mat4 & vp, S &&... srcs) : Program {std::forward<S>(srcs)...}
+ template<typename... S>
+ explicit UIProgram(const glm::mat4 & vp, S &&... srcs) : Program {std::forward<S>(srcs)...}
{
- RequiredUniformLocation uiProjectionLoc {*this, "uiProjection"};
+ const RequiredUniformLocation uiProjectionLoc {*this, "uiProjection"};
glUseProgram(*this);
glUniformMatrix4fv(uiProjectionLoc, 1, GL_FALSE, glm::value_ptr(vp));
}
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 942cedf..ef6d7e7 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -48,8 +48,8 @@ Texture::save(const glTexture & texture, GLenum format, GLenum type, const glm::
{
using TGAHead = std::array<short, 9>;
- size_t dataSize = (static_cast<size_t>(size.x * size.y * channels));
- size_t fileSize = dataSize + sizeof(TGAHead);
+ const size_t dataSize = (static_cast<size_t>(size.x * size.y * channels));
+ const size_t fileSize = dataSize + sizeof(TGAHead);
filesystem::fh out {path, O_RDWR | O_CREAT, 0660};
out.truncate(fileSize);