From 00fc3cb9b2c06026fab0e4760609fe02e027b6df Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 8 Mar 2026 16:02:56 +0000 Subject: Move all low level texture operations to DSA helpers in glTexture --- gfx/gl/glTexture.h | 58 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 9 deletions(-) (limited to 'gfx/gl/glTexture.h') diff --git a/gfx/gl/glTexture.h b/gfx/gl/glTexture.h index 5e5c838..3472c4a 100644 --- a/gfx/gl/glTexture.h +++ b/gfx/gl/glTexture.h @@ -1,14 +1,34 @@ #pragma once -#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 struct TextureTargetTraits; + + template struct TextureTargetTraitsCommon { + static void + create(GLsizei count, GLuint * textures) + { + glCreateTextures(Target, count, textures); + } + }; + + template<> struct TextureTargetTraits : TextureTargetTraitsCommon { + constexpr static glm::length_t dims = 2; + }; + + template<> struct TextureTargetTraits : TextureTargetTraitsCommon { + constexpr static glm::length_t dims = 3; + }; + + template<> struct TextureTargetTraits : TextureTargetTraitsCommon { + constexpr static glm::length_t dims = 2; + }; + + struct glTextureBase : Detail::glNamed { + void bind(GLuint unit) const; + void generateMipmap(); template void @@ -24,9 +44,29 @@ namespace Impl { (*gl_traits::glTextureParametervFunc)(name, pname, glm::value_ptr(param)); } }; + + template + requires(Dims >= 1 && Dims <= 3) + struct glTextureDims : glTextureBase { + [[nodiscard]] glm::vec getSize() const; + void storage(GLsizei levels, GLenum internalformat, glm::vec dims); + void image(GLenum format, GLenum type, const void * pixels); + void image(glm::vec size, GLenum format, GLenum type, const void * pixels); + void subImage(glm::vec offset, glm::vec size, GLenum format, GLenum type, + const void * pixels); + + void saveColour(const char * path) const; + void saveDepth(const char * path) const; + void saveNormal(const char * path) const; + void savePosition(const char * path) const; + }; + + template struct glTexture : glTextureDims::dims> { }; } -// NOLINTBEGIN(readability-identifier-naming) -template using glTextures = glManagedArray; -using glTexture = glManagedSingle; -// NOLINTEND(readability-identifier-naming) +template +using glTextures + = glManagedArray, N, &Impl::TextureTargetTraits::create, &glDeleteTextures>; +template +using glTexture + = glManagedSingle, &Impl::TextureTargetTraits::create, &glDeleteTextures>; -- cgit v1.3