summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/camera.h8
-rw-r--r--gfx/gl/instanceVertices.h13
-rw-r--r--gfx/gl/program.h3
-rw-r--r--gfx/gl/sceneProvider.cpp1
-rw-r--r--gfx/gl/sceneRenderer.cpp1
-rw-r--r--gfx/gl/sceneRenderer.h2
-rw-r--r--gfx/gl/shader.h1
-rw-r--r--gfx/gl/shadowMapper.cpp7
-rw-r--r--gfx/gl/shadowMapper.h5
-rw-r--r--gfx/gl/uiShader.cpp2
-rw-r--r--gfx/gl/vertexArrayObject.h5
-rw-r--r--gfx/image.h2
-rw-r--r--gfx/models/texture.cpp2
-rw-r--r--gfx/models/tga.h1
-rw-r--r--gfx/renderable.cpp1
15 files changed, 52 insertions, 2 deletions
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 3f1c3a7..7956ec3 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -13,6 +13,7 @@ public:
{
return viewProjection;
}
+
[[nodiscard]] Ray unProject(const glm::vec2 &) const;
void
@@ -21,11 +22,13 @@ public:
position = p;
updateView();
}
+
void
setForward(const glm::vec3 & f)
{
setForward(f, upFromForward(f));
}
+
void
setForward(const glm::vec3 & f, const glm::vec3 & u)
{
@@ -33,28 +36,33 @@ public:
up = u;
updateView();
}
+
void
setView(const glm::vec3 & p, const glm::vec3 & f)
{
position = p;
setForward(f);
}
+
void
setView(const glm::vec3 & p, const glm::vec3 & f, const glm::vec3 & u)
{
position = p;
setView(f, u);
}
+
void
lookAt(const glm::vec3 & target)
{
setForward(glm::normalize(target - position));
}
+
[[nodiscard]] auto
getForward() const
{
return forward;
}
+
[[nodiscard]] auto
getPosition() const
{
diff --git a/gfx/gl/instanceVertices.h b/gfx/gl/instanceVertices.h
index 7b0341b..a89aa78 100644
--- a/gfx/gl/instanceVertices.h
+++ b/gfx/gl/instanceVertices.h
@@ -13,9 +13,11 @@ public:
class [[nodiscard]] InstanceProxy {
public:
InstanceProxy(InstanceVertices * iv, std::size_t idx) : instances {iv}, index {idx} { }
+
InstanceProxy(InstanceProxy && other) : instances {std::exchange(other.instances, nullptr)}, index {other.index}
{
}
+
NO_COPY(InstanceProxy);
~InstanceProxy()
@@ -35,6 +37,7 @@ public:
index = other.index;
return *this;
}
+
template<typename U>
T &
operator=(U && v)
@@ -42,40 +45,46 @@ public:
return instances->lookup(index) = std::forward<U>(v);
}
- [[nodiscard]]
- operator T &()
+ [[nodiscard]] operator T &()
{
return instances->lookup(index);
}
+
[[nodiscard]] operator const T &() const
{
return instances->lookup(index);
}
+
[[nodiscard]] T *
get()
{
return &instances->lookup(index);
}
+
[[nodiscard]] const T *
get() const
{
return &instances->lookup(index);
}
+
[[nodiscard]] T *
operator->()
{
return get();
}
+
[[nodiscard]] const T *
operator->() const
{
return get();
}
+
[[nodiscard]] T &
operator*()
{
return instances->lookup(index);
}
+
[[nodiscard]] const T &
operator*() const
{
diff --git a/gfx/gl/program.h b/gfx/gl/program.h
index 76b6742..1a1c306 100644
--- a/gfx/gl/program.h
+++ b/gfx/gl/program.h
@@ -9,6 +9,7 @@
class Location;
using ProgramRef = glRef<GLuint, &glCreateProgram, &glDeleteProgram>;
+
class Program {
public:
template<typename... S> explicit Program(const S &... srcs)
@@ -16,12 +17,14 @@ public:
(glAttachShader(m_program, srcs.compile()), ...);
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
{
diff --git a/gfx/gl/sceneProvider.cpp b/gfx/gl/sceneProvider.cpp
index 0163b36..2e8604c 100644
--- a/gfx/gl/sceneProvider.cpp
+++ b/gfx/gl/sceneProvider.cpp
@@ -7,6 +7,7 @@ SceneProvider::environment(const SceneShader &, const SceneRenderer & renderer)
renderer.setAmbientLight({0.5F, 0.5F, 0.5F});
renderer.setDirectionalLight({0.6F, 0.6F, 0.6F}, {-1, 1, -1}, *this);
}
+
void
SceneProvider::shadows(const ShadowMapper &) const
{
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index aa9453a..5799daf 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -13,6 +13,7 @@ static constexpr const std::array<const glm::i8vec4, 4> displayVAOdata {{
{1, 1, 1, 1},
{1, -1, 1, 0},
}};
+
SceneRenderer::SceneRenderer(glm::ivec2 s, GLuint o) :
camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(s), 0.1F, 10000.0F}, size {s}, output {o},
lighting {lighting_vs, lighting_fs}, shadowMapper {{2048, 2048}}
diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h
index d4af665..55df84d 100644
--- a/gfx/gl/sceneRenderer.h
+++ b/gfx/gl/sceneRenderer.h
@@ -27,11 +27,13 @@ private:
glFrameBuffer gBuffer;
glTexture gPosition, gNormal, gAlbedoSpec, gIllumination;
glRenderBuffer depth;
+
class DeferredLightProgram : public Program {
public:
using Program::Program;
using Program::use;
};
+
class DirectionalLightProgram : public Program {
public:
DirectionalLightProgram();
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h
index 0810e6b..cff2281 100644
--- a/gfx/gl/shader.h
+++ b/gfx/gl/shader.h
@@ -8,6 +8,7 @@
class Shader {
public:
using ShaderRef = glRef<GLuint, &glCreateShader, &glDeleteShader>;
+
constexpr Shader(const GLchar * text, GLint len, GLuint type) : text {text}, len {len}, type {type} { }
[[nodiscard]] ShaderRef compile() const;
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index 55d986c..79b39c0 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -94,11 +94,13 @@ struct DefinitionsInserter {
{
return out.maps++;
};
+
auto
operator*()
{
return std::tie(out.projections[out.maps], out.regions[out.maps]);
}
+
ShadowMapper::Definitions & out;
};
@@ -161,12 +163,14 @@ ShadowMapper::update(const SceneProvider & scene, const glm::vec3 & dir, const C
}
ShadowMapper::FixedPoint::FixedPoint(const Shader & vs) : Program {vs}, viewProjectionLoc {*this, "viewProjection"} { }
+
void
ShadowMapper::FixedPoint::setViewProjection(const glm::mat4 & viewProjection) const
{
use();
glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection));
}
+
void
ShadowMapper::FixedPoint::use() const
{
@@ -177,12 +181,14 @@ ShadowMapper::DynamicPoint::DynamicPoint() :
Program {shadowDynamicPoint_vs}, viewProjectionLoc {*this, "viewProjection"}, modelLoc {*this, "model"}
{
}
+
void
ShadowMapper::DynamicPoint::setViewProjection(const glm::mat4 & viewProjection) const
{
glUseProgram(*this);
glUniformMatrix4fv(viewProjectionLoc, 1, GL_FALSE, glm::value_ptr(viewProjection));
}
+
void
ShadowMapper::DynamicPoint::use(const Location & location) const
{
@@ -191,6 +197,7 @@ ShadowMapper::DynamicPoint::use(const Location & location) const
const auto model = glm::translate(location.pos) * rotate_ypr(location.rot);
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
}
+
void
ShadowMapper::DynamicPoint::setModel(const Location & location) const
{
diff --git a/gfx/gl/shadowMapper.h b/gfx/gl/shadowMapper.h
index 36371eb..cd1b975 100644
--- a/gfx/gl/shadowMapper.h
+++ b/gfx/gl/shadowMapper.h
@@ -8,16 +8,19 @@ class SceneProvider;
class Camera;
#include <gfx/models/texture.h>
+
class ShadowMapper {
public:
explicit ShadowMapper(const glm::ivec2 & size);
static constexpr std::size_t SHADOW_BANDS {4};
+
struct Definitions {
std::array<glm::mat4x4, SHADOW_BANDS> projections {};
std::array<glm::vec4, SHADOW_BANDS> regions {};
size_t maps {};
};
+
[[nodiscard]] Definitions update(const SceneProvider &, const glm::vec3 & direction, const Camera &) const;
class FixedPoint : public Program {
@@ -29,6 +32,7 @@ public:
private:
RequiredUniformLocation viewProjectionLoc;
};
+
class DynamicPoint : public Program {
public:
DynamicPoint();
@@ -40,6 +44,7 @@ public:
RequiredUniformLocation viewProjectionLoc;
RequiredUniformLocation modelLoc;
};
+
FixedPoint fixedPoint, dynamicPointInst;
DynamicPoint dynamicPoint;
diff --git a/gfx/gl/uiShader.cpp b/gfx/gl/uiShader.cpp
index 78e0064..0b47211 100644
--- a/gfx/gl/uiShader.cpp
+++ b/gfx/gl/uiShader.cpp
@@ -9,6 +9,7 @@
#include <initializer_list>
UIShader::IconProgram::IconProgram(const glm::mat4 & vp) : UIProgram {vp, uiShader_vs, uiShader_fs} { }
+
UIShader::TextProgram::TextProgram(const glm::mat4 & vp) :
UIProgram {vp, uiShader_vs, uiShaderFont_fs}, colorLoc {*this, "colour"}
{
@@ -18,6 +19,7 @@ UIShader::UIShader(size_t width, size_t height) :
UIShader {glm::ortho<float>(0, static_cast<float>(width), 0, static_cast<float>(height))}
{
}
+
UIShader::UIShader(const glm::mat4 & viewProjection) : icon {viewProjection}, text {viewProjection} { }
void
diff --git a/gfx/gl/vertexArrayObject.h b/gfx/gl/vertexArrayObject.h
index fa6baa3..57daaf3 100644
--- a/gfx/gl/vertexArrayObject.h
+++ b/gfx/gl/vertexArrayObject.h
@@ -11,22 +11,27 @@ public:
{
glBindVertexArray(arrayObject);
}
+
~VertexArrayObject()
{
glBindVertexArray(0);
}
+
NO_MOVE(VertexArrayObject);
NO_COPY(VertexArrayObject);
template<typename m, typename T> struct MP {
constexpr MP(m T::*p) : P {p} { }
+
operator void *() const
{
return &(static_cast<T *>(nullptr)->*P);
}
+
m T::*P;
using value_type = m;
};
+
template<typename m, typename T> MP(m T::*) -> MP<m, T>;
template<typename VertexT, MP... attribs>
diff --git a/gfx/image.h b/gfx/image.h
index 8bb4067..6fbbdd1 100644
--- a/gfx/image.h
+++ b/gfx/image.h
@@ -7,7 +7,9 @@
class Image {
public:
Image(const char * fileName, int flags);
+
Image(const std::string & fileName, int flags) : Image(fileName.c_str(), flags) { }
+
Image(std::span<unsigned char> data, int flags);
~Image();
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 380f2e0..b7f1bee 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -139,11 +139,13 @@ GLuint
TextureAtlas::add(glm::ivec2 position, glm::ivec2 size, void * data, TextureOptions to)
{
glTextureSubImage2D(m_texture, 0, position.x, position.y, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, data);
+
struct Material {
glm::vec<2, uint16_t> position, size;
TextureOptions::MapMode wrapU;
TextureOptions::MapMode wrapV;
} material {position, size, to.wrapU, to.wrapV};
+
static_assert(sizeof(Material) <= 32);
glTextureSubImage2D(m_atlas, 0, 0, static_cast<GLsizei>(used), 2, 1, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, &material);
return ++used;
diff --git a/gfx/models/tga.h b/gfx/models/tga.h
index 1f400ef..52db220 100644
--- a/gfx/models/tga.h
+++ b/gfx/models/tga.h
@@ -11,4 +11,5 @@ struct TGAHead {
uint8_t pixelDepth {};
uint8_t descriptor {};
};
+
static_assert(sizeof(TGAHead) == 18);
diff --git a/gfx/renderable.cpp b/gfx/renderable.cpp
index 539efb1..0340189 100644
--- a/gfx/renderable.cpp
+++ b/gfx/renderable.cpp
@@ -4,6 +4,7 @@ void
Renderable::lights(const SceneShader &) const
{
}
+
void
Renderable::shadows(const ShadowMapper &) const
{