summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/gl/sceneRenderer.cpp4
-rw-r--r--gfx/gl/shadowMapper.cpp10
-rw-r--r--gfx/models/texture.cpp17
-rw-r--r--lib/gl_traits.h22
-rw-r--r--test/testRenderOutput.cpp5
-rw-r--r--ui/font.cpp11
-rw-r--r--ui/icon.cpp10
7 files changed, 51 insertions, 28 deletions
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index 4ae4297..4c96902 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -24,8 +24,8 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) :
const auto configuregdata = [this](const GLuint data, const std::initializer_list<GLint> iformats,
const GLenum format, const GLenum attachment) {
glBindTexture(GL_TEXTURE_2D, data);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
for (const auto iformat : iformats) {
glTexImage2D(GL_TEXTURE_2D, 0, iformat, size.x, size.y, 0, format, GL_BYTE, nullptr);
diff --git a/gfx/gl/shadowMapper.cpp b/gfx/gl/shadowMapper.cpp
index ae374fe..ab4ac50 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -21,12 +21,12 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) :
{
glBindTexture(GL_TEXTURE_2D, depthMap);
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);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
static constexpr RGBA border {std::numeric_limits<RGBA::value_type>::infinity()};
- glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, glm::value_ptr(border));
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 35f8d35..0ebba08 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -6,6 +6,7 @@
#include <fcntl.h>
#include <filesystem.h>
#include <gfx/image.h>
+#include <gl_traits.h>
#include <glad/gl.h>
#include <glm/geometric.hpp>
#include <resource.h>
@@ -46,11 +47,11 @@ Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOption
glBindTexture(type, m_texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(type, GL_TEXTURE_WRAP_S, TextureOptions::glMapMode(to.wrapU));
- glTexParameteri(type, GL_TEXTURE_WRAP_T, TextureOptions::glMapMode(to.wrapV));
+ glTexParameter(type, GL_TEXTURE_WRAP_S, TextureOptions::glMapMode(to.wrapU));
+ glTexParameter(type, GL_TEXTURE_WRAP_T, TextureOptions::glMapMode(to.wrapV));
- glTexParameteri(type, GL_TEXTURE_MIN_FILTER, to.minFilter);
- glTexParameteri(type, GL_TEXTURE_MAG_FILTER, to.magFilter);
+ glTexParameter(type, GL_TEXTURE_MIN_FILTER, to.minFilter);
+ glTexParameter(type, GL_TEXTURE_MAG_FILTER, to.magFilter);
glTexImage2D(type, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}
@@ -125,11 +126,11 @@ TextureAtlas::TextureAtlas(GLsizei width, GLsizei height, GLuint count) : Textur
{
glBindTexture(GL_TEXTURE_RECTANGLE, m_atlas);
- glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_RECTANGLE, 0, GL_RGBA16UI, 2, static_cast<GLsizei>(count), 0, GL_RGBA_INTEGER,
GL_UNSIGNED_BYTE, nullptr);
}
diff --git a/lib/gl_traits.h b/lib/gl_traits.h
index f641131..14ac9d8 100644
--- a/lib/gl_traits.h
+++ b/lib/gl_traits.h
@@ -42,6 +42,8 @@ template<> struct gl_traits<glm::f32> : public gl_traits_float {
static constexpr auto glUniformFunc {&glUniform1f};
static constexpr std::array glUniformvFunc {&glUniform1fv, &glUniform2fv, &glUniform3fv, &glUniform4fv};
static constexpr std::array glUniformmFunc {&glUniformMatrix2fv, &glUniformMatrix3fv, &glUniformMatrix4fv};
+ static constexpr auto glTexParameterFunc {&glTexParameterf};
+ static constexpr auto glTexParameterfFunc {&glTexParameterfv};
};
template<> struct gl_traits<glm::f64> : public gl_traits_longfloat {
@@ -60,6 +62,8 @@ template<> struct gl_traits<glm::int32> : public gl_traits_integer {
static constexpr GLenum type {GL_INT};
static constexpr auto glUniformFunc {&glUniform1i};
static constexpr std::array glUniformvFunc {&glUniform1iv, &glUniform2iv, &glUniform3iv, &glUniform4iv};
+ static constexpr auto glTexParameterFunc {&glTexParameteri};
+ static constexpr auto glTexParameterfFunc {&glTexParameteriv};
};
template<> struct gl_traits<glm::uint8> : public gl_traits_integer {
@@ -104,6 +108,10 @@ template<typename T>
concept has_glUniformNv = requires { gl_traits<T>::glUniformvFunc; };
template<typename T>
concept has_glUniformMatrixNv = requires { gl_traits<T>::glUniformmFunc; };
+template<typename T>
+concept has_glTexParameter = requires { gl_traits<T>::glTexParameterFunc; };
+template<typename T>
+concept has_glTexParameterf = requires { gl_traits<T>::glTexParameterfFunc; };
template<has_glUniform1 T>
void
@@ -147,3 +155,17 @@ glUniform(GLint location, std::span<const glm::mat<L, L, T, Q>> v)
(*gl_traits<T>::glUniformmFunc[L - 2])(
location, static_cast<GLsizei>(v.size()), GL_FALSE, glm::value_ptr(v.front()));
}
+
+template<has_glTexParameter T>
+void
+glTexParameter(GLenum target, GLenum pname, T param)
+{
+ (*gl_traits<T>::glTexParameterFunc)(target, pname, param);
+}
+
+template<glm::length_t L, has_glTexParameterf T, glm::qualifier Q>
+void
+glTexParameter(GLenum target, GLenum pname, const glm::vec<L, T, Q> & param)
+{
+ (*gl_traits<T>::glTexParameterfFunc)(target, pname, glm::value_ptr(param));
+}
diff --git a/test/testRenderOutput.cpp b/test/testRenderOutput.cpp
index 9af4451..68b46f6 100644
--- a/test/testRenderOutput.cpp
+++ b/test/testRenderOutput.cpp
@@ -1,4 +1,5 @@
#include "testRenderOutput.h"
+#include <gl_traits.h>
#include <stdexcept>
TestRenderOutput::TestRenderOutput(TextureAbsCoord s) : size {s}
@@ -8,8 +9,8 @@ TestRenderOutput::TestRenderOutput(TextureAbsCoord s) : size {s}
= [this](const GLuint data, const GLint format, const GLenum type, const GLenum attachment) {
glBindTexture(GL_TEXTURE_2D, data);
glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGBA, type, nullptr);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, data, 0);
};
configuregdata(outImage, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0);
diff --git a/ui/font.cpp b/ui/font.cpp
index ebd856d..305e0f3 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -4,10 +4,9 @@
#include <cctype>
#include <ft2build.h>
#include FT_FREETYPE_H
-#include "glArrays.h"
+#include "gl_traits.h"
#include <glRef.h>
#include <maths.h>
-#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
@@ -124,10 +123,10 @@ Font::getTextureWithSpace(unsigned int adv) const
glBindTexture(GL_TEXTURE_2D, texture.texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, static_cast<GLsizei>(size.x), static_cast<GLsizei>(size.y), 0, GL_RED,
GL_UNSIGNED_BYTE, nullptr);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return fontTextures.size() - 1;
}
diff --git a/ui/icon.cpp b/ui/icon.cpp
index 38f4bf9..c3b5078 100644
--- a/ui/icon.cpp
+++ b/ui/icon.cpp
@@ -1,5 +1,5 @@
#include "icon.h"
-#include "glArrays.h"
+#include "gl_traits.h"
#include <gfx/image.h>
#include <glad/gl.h>
#include <resource.h>
@@ -13,11 +13,11 @@ Icon::Icon(const Image & tex) : size {tex.width, tex.height}
{
glBindTexture(GL_TEXTURE_2D, m_texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(tex.width), static_cast<GLsizei>(tex.height), 0,
GL_RGBA, GL_UNSIGNED_BYTE, tex.data.data());
}