summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/camera.cpp4
-rw-r--r--gfx/gl/camera.h2
-rw-r--r--gfx/gl/shaders/basicShader.fs5
-rw-r--r--gfx/models/texture.cpp32
-rw-r--r--gfx/models/texture.h15
-rw-r--r--gfx/models/vertex.hpp4
6 files changed, 42 insertions, 20 deletions
diff --git a/gfx/gl/camera.cpp b/gfx/gl/camera.cpp
index b596c43..5b7269e 100644
--- a/gfx/gl/camera.cpp
+++ b/gfx/gl/camera.cpp
@@ -6,8 +6,8 @@
#include <ray.hpp>
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)},
+ position {pos}, forward {::north}, up {::up}, near {zNear}, far {zFar}, projection {glm::perspective(
+ fov, aspect, zNear, zFar)},
viewProjection {projection * glm::lookAt(position, position + forward, up)}, inverseViewProjection {
glm::inverse(viewProjection)}
{
diff --git a/gfx/gl/camera.h b/gfx/gl/camera.h
index 9685a7d..b5611f8 100644
--- a/gfx/gl/camera.h
+++ b/gfx/gl/camera.h
@@ -72,7 +72,7 @@ private:
glm::vec3 forward;
glm::vec3 up;
- float fov, aspect, near, far;
+ float near, far;
glm::mat4 projection;
glm::mat4 viewProjection, inverseViewProjection;
};
diff --git a/gfx/gl/shaders/basicShader.fs b/gfx/gl/shaders/basicShader.fs
index 93f0a3f..24b2791 100644
--- a/gfx/gl/shaders/basicShader.fs
+++ b/gfx/gl/shaders/basicShader.fs
@@ -14,8 +14,9 @@ uniform sampler2D texture0;
void
main()
{
- float clear = round(texture(texture0, TexCoords).a);
+ vec4 textureColour = texture(texture0, TexCoords);
+ float clear = round(mix(textureColour.a, 1, Colour.a));
gPosition = vec4(FragPos, clear);
gNormal = vec4(Normal, clear);
- gAlbedoSpec = mix(texture(texture0, TexCoords), vec4(Colour.rgb, 1), Colour.a);
+ gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a);
}
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index ef6d7e7..efc76e1 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -12,34 +12,36 @@
Cache<Texture, std::filesystem::path> Texture::cachedTexture;
-Texture::Texture(const std::filesystem::path & fileName) :
- Texture {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}}
+Texture::Texture(const std::filesystem::path & fileName, TextureOptions to) :
+ Texture {Image {Resource::mapPath(fileName).c_str(), STBI_rgb_alpha}, to}
{
}
-Texture::Texture(const Image & tex) :
- Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), tex.data.data()}
+Texture::Texture(const Image & tex, TextureOptions to) :
+ Texture {static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), tex.data.data(), to}
{
}
-Texture::Texture(GLsizei width, GLsizei height, const void * data)
+Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {width, height, nullptr, to} { }
+
+Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions to) : type {to.type}
{
- glBindTexture(GL_TEXTURE_2D, m_texture);
+ glBindTexture(type, m_texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(type, GL_TEXTURE_WRAP_S, to.wrap);
+ glTexParameteri(type, GL_TEXTURE_WRAP_T, to.wrap);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ glTexParameteri(type, GL_TEXTURE_MIN_FILTER, to.minFilter);
+ glTexParameteri(type, GL_TEXTURE_MAG_FILTER, to.magFilter);
+ glTexImage2D(type, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
void
Texture::bind(GLenum unit) const
{
glActiveTexture(unit);
- glBindTexture(GL_TEXTURE_2D, m_texture);
+ glBindTexture(type, m_texture);
}
void
@@ -61,6 +63,12 @@ Texture::save(const glTexture & texture, GLenum format, GLenum type, const glm::
}
void
+Texture::save(const glm::ivec2 & size, const char * path) const
+{
+ save(m_texture, GL_BGR, GL_UNSIGNED_BYTE, size, 3, path, 2);
+}
+
+void
Texture::save(const glTexture & texture, const glm::ivec2 & size, const char * path)
{
save(texture, GL_BGR, GL_UNSIGNED_BYTE, size, 3, path, 2);
diff --git a/gfx/models/texture.h b/gfx/models/texture.h
index 1aad1e0..ffc9a4a 100644
--- a/gfx/models/texture.h
+++ b/gfx/models/texture.h
@@ -8,16 +8,24 @@
// IWYU pragma: no_forward_declare Cache
class Image;
+struct TextureOptions {
+ GLint wrap {GL_REPEAT};
+ GLint minFilter {GL_LINEAR}, magFilter {GL_LINEAR};
+ GLenum type {GL_TEXTURE_2D};
+};
+
class Texture {
public:
- explicit Texture(const std::filesystem::path & fileName);
- explicit Texture(const Image & image);
- explicit Texture(GLsizei width, GLsizei height, const void * data);
+ explicit Texture(const std::filesystem::path & fileName, TextureOptions = {});
+ explicit Texture(const Image & image, TextureOptions = {});
+ explicit Texture(GLsizei width, GLsizei height, TextureOptions = {});
+ explicit Texture(GLsizei width, GLsizei height, const void * data, TextureOptions = {});
static Cache<Texture, std::filesystem::path> cachedTexture;
void bind(GLenum unit = GL_TEXTURE0) const;
+ void save(const glm::ivec2 & size, const char * path) const;
static void save(const glTexture &, const glm::ivec2 & size, const char * path);
static void saveDepth(const glTexture &, const glm::ivec2 & size, const char * path);
static void saveNormal(const glTexture &, const glm::ivec2 & size, const char * path);
@@ -27,4 +35,5 @@ private:
const char * path, short tgaFormat);
glTexture m_texture;
+ GLenum type;
};
diff --git a/gfx/models/vertex.hpp b/gfx/models/vertex.hpp
index 325aab1..64ec3d0 100644
--- a/gfx/models/vertex.hpp
+++ b/gfx/models/vertex.hpp
@@ -4,10 +4,14 @@
class Vertex {
public:
+#ifndef __cpp_aggregate_paren_init
constexpr Vertex(glm::vec3 pos, glm::vec2 texCoord, glm::vec3 normal, glm::vec4 colour = {}) :
pos {std::move(pos)}, texCoord {std::move(texCoord)}, normal {std::move(normal)}, colour {std::move(colour)}
{
}
+#endif
+
+ bool operator==(const Vertex &) const = default;
glm::vec3 pos;
glm::vec2 texCoord;