From 14e1b0def33339f2221f1101e115d0aff69727ad Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 14 Mar 2023 01:00:08 +0000 Subject: Basic fragment ahader should use final colour to determine clear flag --- gfx/gl/shaders/basicShader.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gfx') 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); } -- cgit v1.2.3 From ee1912e4f181594df40203f9c227b89d02a91242 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Mar 2023 01:04:05 +0000 Subject: Add support for setting Texture options on construction --- gfx/models/texture.cpp | 20 +++++++++++--------- gfx/models/texture.h | 12 +++++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'gfx') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index ef6d7e7..87b73e7 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -12,26 +12,28 @@ Cache 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(tex.width), static_cast(tex.height), tex.data.data()} +Texture::Texture(const Image & tex, TextureOptions to) : + Texture {static_cast(tex.width), static_cast(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) { glBindTexture(GL_TEXTURE_2D, 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(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, to.wrap); + glTexParameteri(GL_TEXTURE_2D, 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); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, to.minFilter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, to.magFilter); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); } diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 1aad1e0..31ffaa5 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -8,11 +8,17 @@ // IWYU pragma: no_forward_declare Cache class Image; +struct TextureOptions { + GLint wrap {GL_REPEAT}; + GLint minFilter {GL_LINEAR}, magFilter {GL_LINEAR}; +}; + 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 cachedTexture; -- cgit v1.2.3 From 5d7bb934068b0f2ce8b6315517a005cc2c1305f5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Mar 2023 02:08:43 +0000 Subject: Texture member to save the texture as a TGA --- gfx/models/texture.cpp | 6 ++++++ gfx/models/texture.h | 1 + 2 files changed, 7 insertions(+) (limited to 'gfx') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 87b73e7..639ae0f 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -62,6 +62,12 @@ Texture::save(const glTexture & texture, GLenum format, GLenum type, const glm:: tga.msync(MS_ASYNC); } +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) { diff --git a/gfx/models/texture.h b/gfx/models/texture.h index 31ffaa5..cc0c07e 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -24,6 +24,7 @@ public: 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); -- cgit v1.2.3 From 393eba5f9f72fdec566b1d6771d40916793c2bc1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 16 Mar 2023 23:21:25 +0000 Subject: Allow specifiying the texture type/target --- gfx/models/texture.cpp | 16 ++++++++-------- gfx/models/texture.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'gfx') diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp index 639ae0f..efc76e1 100644 --- a/gfx/models/texture.cpp +++ b/gfx/models/texture.cpp @@ -24,24 +24,24 @@ Texture::Texture(const Image & tex, TextureOptions to) : Texture::Texture(GLsizei width, GLsizei height, TextureOptions to) : Texture {width, height, nullptr, to} { } -Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOptions 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, to.wrap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, to.wrap); + glTexParameteri(type, GL_TEXTURE_WRAP_S, to.wrap); + glTexParameteri(type, GL_TEXTURE_WRAP_T, to.wrap); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, to.minFilter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, to.magFilter); - 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 diff --git a/gfx/models/texture.h b/gfx/models/texture.h index cc0c07e..ffc9a4a 100644 --- a/gfx/models/texture.h +++ b/gfx/models/texture.h @@ -11,6 +11,7 @@ class Image; struct TextureOptions { GLint wrap {GL_REPEAT}; GLint minFilter {GL_LINEAR}, magFilter {GL_LINEAR}; + GLenum type {GL_TEXTURE_2D}; }; class Texture { @@ -34,4 +35,5 @@ private: const char * path, short tgaFormat); glTexture m_texture; + GLenum type; }; -- cgit v1.2.3 From 997e03433fd41ad2ba1dc4242ff5a90f55ce694d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 19 Mar 2023 23:30:02 +0000 Subject: Make Vertex aggregrate constructor conditional on requirement --- gfx/models/vertex.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gfx') diff --git a/gfx/models/vertex.hpp b/gfx/models/vertex.hpp index 325aab1..28dc8f3 100644 --- a/gfx/models/vertex.hpp +++ b/gfx/models/vertex.hpp @@ -4,10 +4,12 @@ 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 glm::vec3 pos; glm::vec2 texCoord; -- cgit v1.2.3 From c3617a13b6e4d9fb50d32478c68fae94be1b2cba Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 19 Mar 2023 23:31:17 +0000 Subject: Add defaulted Vertex equality operator --- gfx/models/vertex.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gfx') diff --git a/gfx/models/vertex.hpp b/gfx/models/vertex.hpp index 28dc8f3..64ec3d0 100644 --- a/gfx/models/vertex.hpp +++ b/gfx/models/vertex.hpp @@ -11,6 +11,8 @@ public: } #endif + bool operator==(const Vertex &) const = default; + glm::vec3 pos; glm::vec2 texCoord; glm::vec3 normal; -- cgit v1.2.3 From 187783a322faed9c830493cc0346376e9809c9b5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 19 Mar 2023 23:59:49 +0000 Subject: Remove (as yet) unused members from Camera --- gfx/gl/camera.cpp | 4 ++-- gfx/gl/camera.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'gfx') 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 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; }; -- cgit v1.2.3