summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx/gl/billboardPainter.cpp11
-rw-r--r--gfx/gl/glTexture.h15
-rw-r--r--gfx/gl/sceneRenderer.cpp6
-rw-r--r--gfx/gl/shadowMapper.cpp10
-rw-r--r--gfx/gl/shadowStenciller.cpp8
-rw-r--r--gfx/models/texture.cpp18
-rw-r--r--lib/gl_traits.h26
-rw-r--r--test/testRenderOutput.cpp6
-rw-r--r--ui/font.cpp9
-rw-r--r--ui/icon.cpp10
-rw-r--r--ui/svgIcon.cpp10
11 files changed, 61 insertions, 68 deletions
diff --git a/gfx/gl/billboardPainter.cpp b/gfx/gl/billboardPainter.cpp
index d021efb..3b03c87 100644
--- a/gfx/gl/billboardPainter.cpp
+++ b/gfx/gl/billboardPainter.cpp
@@ -1,5 +1,4 @@
#include "billboardPainter.h"
-#include "gl_traits.h"
#include "gldebug.h"
#include "maths.h"
#include <gfx/gl/shaders/billboardPainter-frag.h>
@@ -44,12 +43,12 @@ BillboardPainter::configureBillBoardTextures(glTextures<3> & textures, GLsizei w
glDebugScope _ {0};
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- const auto configuregdata = [width, height](const auto & texture, const GLint iformat, const GLenum format) {
+ const auto configuregdata = [width, height](Impl::glTexture & texture, const GLint iformat, const GLenum format) {
texture.bind(GL_TEXTURE_2D_ARRAY);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ texture.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ texture.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ texture.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ texture.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, iformat, width, height, VIEW_ANGLES<GLint>, 0, format, GL_BYTE, nullptr);
};
configuregdata(textures[0], GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT);
diff --git a/gfx/gl/glTexture.h b/gfx/gl/glTexture.h
index c482198..5e5c838 100644
--- a/gfx/gl/glTexture.h
+++ b/gfx/gl/glTexture.h
@@ -2,12 +2,27 @@
#include "config/types.h"
#include "glArrays.h"
+#include "gl_traits.h"
namespace Impl {
// NOLINTNEXTLINE(readability-identifier-naming)
struct glTexture : Detail::glNamed {
[[nodiscard]] TextureDimensions getSize() const;
void bind(GLenum type = GL_TEXTURE_2D, GLenum unit = GL_TEXTURE0) const;
+
+ template<has_glTextureParameter T>
+ void
+ parameter(GLenum pname, T param)
+ {
+ (*gl_traits<T>::glTextureParameterFunc)(name, pname, param);
+ }
+
+ template<glm::length_t L, has_glTextureParameterv T, glm::qualifier Q>
+ void
+ parameter(GLenum pname, const glm::vec<L, T, Q> & param)
+ {
+ (*gl_traits<T>::glTextureParametervFunc)(name, pname, glm::value_ptr(param));
+ }
};
}
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index e67711b..d4812df 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -23,11 +23,11 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o, glDebugScope) :
shader.setViewPort({0, 0, size.x, size.y});
displayVAO.configure().addAttribs<glm::i8vec4>(0, displayVBO, displayVAOdata);
- const auto configuregdata = [this](const auto & data, const std::initializer_list<GLint> iformats,
+ const auto configuregdata = [this](glTexture & data, const std::initializer_list<GLint> iformats,
const GLenum format, const GLenum attachment) {
data.bind();
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ data.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ data.parameter(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 03851f5..fb57668 100644
--- a/gfx/gl/shadowMapper.cpp
+++ b/gfx/gl/shadowMapper.cpp
@@ -35,12 +35,12 @@ ShadowMapper::ShadowMapper(const TextureAbsCoord & s) :
depthMap.bind(GL_TEXTURE_2D_ARRAY);
glTexImage3D(
GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT, size.x, size.y, 4, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ depthMap.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ depthMap.parameter(GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ depthMap.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ depthMap.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
static constexpr RGBA border {std::numeric_limits<RGBA::value_type>::infinity()};
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BORDER_COLOR, border);
+ depthMap.parameter(GL_TEXTURE_BORDER_COLOR, border);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthMap, 0);
diff --git a/gfx/gl/shadowStenciller.cpp b/gfx/gl/shadowStenciller.cpp
index 3625524..a5f9d68 100644
--- a/gfx/gl/shadowStenciller.cpp
+++ b/gfx/gl/shadowStenciller.cpp
@@ -42,10 +42,10 @@ ShadowStenciller::configureStencilTexture(glTexture & stencil, GLsizei width, GL
stencil.bind(GL_TEXTURE_2D_ARRAY);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameter(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ stencil.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ stencil.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ stencil.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ stencil.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH_COMPONENT, width, height, STENCIL_ANGLES<GLint>, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, nullptr);
diff --git a/gfx/models/texture.cpp b/gfx/models/texture.cpp
index 46bdff8..d175b34 100644
--- a/gfx/models/texture.cpp
+++ b/gfx/models/texture.cpp
@@ -43,11 +43,10 @@ Texture::Texture(GLsizei width, GLsizei height, const void * data, TextureOption
m_texture.bind(type);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameter(type, GL_TEXTURE_WRAP_S, TextureOptions::glMapMode(to.wrapU));
- glTexParameter(type, GL_TEXTURE_WRAP_T, TextureOptions::glMapMode(to.wrapV));
-
- glTexParameter(type, GL_TEXTURE_MIN_FILTER, to.minFilter);
- glTexParameter(type, GL_TEXTURE_MAG_FILTER, to.magFilter);
+ m_texture.parameter(GL_TEXTURE_WRAP_S, TextureOptions::glMapMode(to.wrapU));
+ m_texture.parameter(GL_TEXTURE_WRAP_T, TextureOptions::glMapMode(to.wrapV));
+ m_texture.parameter(GL_TEXTURE_MIN_FILTER, to.minFilter);
+ m_texture.parameter(GL_TEXTURE_MAG_FILTER, to.magFilter);
glTexImage2D(type, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
auto isMimmap = [](auto value) {
auto eqAnyOf = [value](auto... test) {
@@ -122,11 +121,10 @@ TextureAtlas::TextureAtlas(GLsizei width, GLsizei height, GLuint count) : Textur
{
m_atlas.bind(GL_TEXTURE_RECTANGLE);
- glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameter(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ m_atlas.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ m_atlas.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ m_atlas.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ m_atlas.parameter(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 35ae9e8..eff9304 100644
--- a/lib/gl_traits.h
+++ b/lib/gl_traits.h
@@ -48,8 +48,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};
+ static constexpr auto glTextureParameterFunc {&glTextureParameterf};
+ static constexpr auto glTextureParametervFunc {&glTextureParameterfv};
static constexpr auto vertexArrayAttribFormat {&vertexAttribFormatFunc<type, 1>};
};
@@ -72,8 +72,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};
+ static constexpr auto glTextureParameterFunc {&glTextureParameteri};
+ static constexpr auto glTextureParametervFunc {&glTextureParameteriv};
static constexpr auto vertexArrayAttribFormat {&vertexAttribFormatFunc<type, 1>};
};
@@ -139,9 +139,9 @@ 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; };
+concept has_glTextureParameter = requires { gl_traits<T>::glTextureParameterFunc; };
template<typename T>
-concept has_glTexParameterf = requires { gl_traits<T>::glTexParameterfFunc; };
+concept has_glTextureParameterv = requires { gl_traits<T>::glTextureParametervFunc; };
template<has_glUniform1 T>
void
@@ -185,17 +185,3 @@ 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 ae2e60d..7243032 100644
--- a/test/testRenderOutput.cpp
+++ b/test/testRenderOutput.cpp
@@ -6,11 +6,11 @@ TestRenderOutput::TestRenderOutput(TextureAbsCoord outputSize) : size {outputSiz
{
glBindFramebuffer(GL_FRAMEBUFFER, output);
const auto configuregdata
- = [this](const auto & data, const GLint format, const GLenum type, const GLenum attachment) {
+ = [this](glTexture & data, const GLint format, const GLenum type, const GLenum attachment) {
data.bind();
glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGBA, type, nullptr);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ data.parameter(GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ data.parameter(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 d8e1257..b028c52 100644
--- a/ui/font.cpp
+++ b/ui/font.cpp
@@ -4,7 +4,6 @@
#include <format>
#include <ft2build.h>
#include FT_FREETYPE_H
-#include "gl_traits.h"
#include <glRef.h>
#include <maths.h>
#include <optional>
@@ -124,10 +123,10 @@ Font::getTextureWithSpace(unsigned int adv) const
texture.texture.bind();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, static_cast<GLsizei>(size.x), static_cast<GLsizei>(size.y), 0, GL_RED,
GL_UNSIGNED_BYTE, nullptr);
- 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);
+ texture.texture.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ texture.texture.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ texture.texture.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ texture.texture.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return fontTextures.size() - 1;
}
diff --git a/ui/icon.cpp b/ui/icon.cpp
index 0422804..5ab9c64 100644
--- a/ui/icon.cpp
+++ b/ui/icon.cpp
@@ -1,5 +1,4 @@
#include "icon.h"
-#include "gl_traits.h"
#include <gfx/image.h>
#include <glad/gl.h>
#include <resource.h>
@@ -13,11 +12,10 @@ Icon::Icon(const Image & tex) : size {tex.width, tex.height}
{
m_texture.bind();
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ m_texture.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ m_texture.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ m_texture.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ m_texture.parameter(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());
}
diff --git a/ui/svgIcon.cpp b/ui/svgIcon.cpp
index 42e046a..82ef69d 100644
--- a/ui/svgIcon.cpp
+++ b/ui/svgIcon.cpp
@@ -1,5 +1,4 @@
#include "svgIcon.h"
-#include "gl_traits.h"
#include <resource.h>
SvgIcon::SvgIcon(ImageDimensions dim, const std::filesystem::path & path)
@@ -17,11 +16,10 @@ SvgIcon::SvgIcon(ImageDimensions dim, const std::filesystem::path & path)
texture.bind();
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ texture.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+ texture.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+ texture.parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ texture.parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, dim.x, dim.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap.data());
}