From a12a3454c4af9a0a80447f18af1ea9cadc3ddcee Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 2 Jun 2026 08:51:34 +0200 Subject: [PATCH] Move texture defaults behind renderer gl --- docs/modernization/build-inventory.md | 4 ++ docs/modernization/roadmap.md | 4 ++ src/renderer_gl/opengl_capabilities.cpp | 5 ++ src/renderer_gl/opengl_capabilities.h | 1 + src/rtt.cpp | 18 ++++++ src/rtt.h | 4 +- src/texture.cpp | 73 ++++++++++++++++++++++-- src/texture.h | 18 ++++-- tests/renderer_gl/capabilities_tests.cpp | 1 + 9 files changed, 118 insertions(+), 10 deletions(-) diff --git a/docs/modernization/build-inventory.md b/docs/modernization/build-inventory.md index 387b11e..2f935f1 100644 --- a/docs/modernization/build-inventory.md +++ b/docs/modernization/build-inventory.md @@ -192,6 +192,10 @@ Known local toolchain state: `NodeStrokePreview` brush preview rendering also consumes backend-owned depth/scissor/blend state, viewport/clear-color queries, active texture units, 2D texture targets, copy targets, and sampler filters/wraps. + Legacy `Texture2D`, `TextureManager`, `Sampler`, and `RTT` public headers no + longer expose raw OpenGL enum defaults; default texture formats, sampler + filters/wraps, and render-target formats resolve through backend-owned + overloads. - `windows-msvc-vcpkg-headless` validates manifest install/configure/build/test for the current headless component matrix; see DEBT-0007 for remaining app and platform triplet migration. diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 9e78e4a..51c723f 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -459,6 +459,10 @@ active texture units to `pp_renderer_gl`. `NodeStrokePreview` brush preview rendering now delegates depth/scissor/blend state, viewport/clear-color queries, active texture units, 2D texture targets, copy targets, and sampler filters/wraps to `pp_renderer_gl`. +Legacy `Texture2D`, `TextureManager`, `Sampler`, and `RTT` public headers no +longer expose raw OpenGL enum defaults; default texture formats, sampler +filters/wraps, and render-target formats are resolved through backend-owned +overloads. The existing renderer classes are not yet fully behind the renderer interfaces. diff --git a/src/renderer_gl/opengl_capabilities.cpp b/src/renderer_gl/opengl_capabilities.cpp index f7b85ef..9c44fcf 100644 --- a/src/renderer_gl/opengl_capabilities.cpp +++ b/src/renderer_gl/opengl_capabilities.cpp @@ -647,6 +647,11 @@ std::uint32_t repeat_texture_wrap() noexcept return gl_repeat; } +std::uint32_t clamp_to_edge_texture_wrap() noexcept +{ + return gl_clamp_to_edge; +} + std::uint32_t active_texture_unit(std::uint32_t unit_index) noexcept { return gl_texture0 + unit_index; diff --git a/src/renderer_gl/opengl_capabilities.h b/src/renderer_gl/opengl_capabilities.h index c16cfec..17b072c 100644 --- a/src/renderer_gl/opengl_capabilities.h +++ b/src/renderer_gl/opengl_capabilities.h @@ -126,6 +126,7 @@ struct OpenGlReadbackFormat { [[nodiscard]] std::uint32_t linear_mipmap_linear_texture_filter() noexcept; [[nodiscard]] std::uint32_t nearest_texture_filter() noexcept; [[nodiscard]] std::uint32_t repeat_texture_wrap() noexcept; +[[nodiscard]] std::uint32_t clamp_to_edge_texture_wrap() noexcept; [[nodiscard]] std::uint32_t active_texture_unit(std::uint32_t unit_index) noexcept; [[nodiscard]] std::uint32_t texture_cube_map_target() noexcept; [[nodiscard]] std::uint32_t cube_map_allocation_face_texture_target(std::uint32_t face_index) noexcept; diff --git a/src/rtt.cpp b/src/rtt.cpp index 84d85cf..90cb26d 100644 --- a/src/rtt.cpp +++ b/src/rtt.cpp @@ -236,6 +236,24 @@ RTT RTT::clone() const noexcept return dup; } +bool RTT::create(int width, int height) +{ + return create( + width, + height, + -1, + static_cast(pp::renderer::gl::rgba8_internal_format())); +} + +bool RTT::create(int width, int height, int tex) +{ + return create( + width, + height, + tex, + static_cast(pp::renderer::gl::rgba8_internal_format())); +} + bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format, bool depth_buffer /*= false*/) { GLenum status = 0; diff --git a/src/rtt.h b/src/rtt.h index fd54d76..0d8cff5 100644 --- a/src/rtt.h +++ b/src/rtt.h @@ -61,7 +61,9 @@ public: void copy(const RTT& source, const glm::vec4& rect); RTT clone() const noexcept; bool resize(int width, int height); - bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8, bool depth_buffer = false); + bool create(int width, int height); + bool create(int width, int height, int tex); + bool create(int width, int height, int tex, GLint internal_format, bool depth_buffer = false); bool recreate() { return create(w, h); } void clear(glm::vec4 color = glm::vec4(0)); void clear_mask(glm::bool4 mask, glm::vec4 color = glm::vec4(0)); diff --git a/src/texture.cpp b/src/texture.cpp index aecfc0c..346fce8 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -126,11 +126,22 @@ bool TextureManager::load(const char* path, bool generate_mipmaps) return true; } -void TextureManager::assign(uint16_t id, GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/) +void TextureManager::assign(uint16_t id, GLuint tex, int w, int h, GLuint internal_format, GLuint format) { m_textures[id].assign(tex, w, h, internal_format, format); } +void TextureManager::assign(uint16_t id, GLuint tex, int w, int h) +{ + assign( + id, + tex, + w, + h, + pp::renderer::gl::rgba8_internal_format(), + pp::renderer::gl::rgba_pixel_format()); +} + Texture2D& TextureManager::get(uint16_t id) { return m_textures[id]; @@ -215,6 +226,24 @@ void Texture2D::operator=(Texture2D&& other) noexcept other.m_tex = false; } +bool Texture2D::create(int width, int height) +{ + return create( + width, + height, + static_cast(pp::renderer::gl::rgba8_internal_format()), + static_cast(pp::renderer::gl::rgba_pixel_format())); +} + +bool Texture2D::create(int width, int height, GLint internal_format) +{ + return create( + width, + height, + internal_format, + static_cast(pp::renderer::gl::rgba_pixel_format())); +} + bool Texture2D::create(int width, int height, GLint internal_format, GLint format, const uint8_t* data) { App::I->render_task([=] @@ -259,7 +288,7 @@ void Texture2D::create_mipmaps() }); } -void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint internal_format/* = GL_RGBA8*/, GLuint format/* = GL_RGBA*/) +void Texture2D::assign(GLuint tex, int w, int h, GLuint internal_format, GLuint format) { m_tex = tex; m_width = w; @@ -268,6 +297,16 @@ void Texture2D::assign(GLuint tex, int w/* = -1*/, int h/* = -1*/, GLuint intern m_iformat = internal_format; } +void Texture2D::assign(GLuint tex, int w, int h) +{ + assign( + tex, + w, + h, + pp::renderer::gl::rgba8_internal_format(), + pp::renderer::gl::rgba_pixel_format()); +} + bool Texture2D::load(std::string filename) { LOG("load texture %s", filename.c_str()); @@ -338,7 +377,7 @@ Texture2D::~Texture2D() destroy(); } -bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/) +bool Sampler::create(GLint filter, GLint wrap) { bool ret = false; App::I->render_task([this, &ret, filter, wrap] @@ -356,7 +395,20 @@ bool Sampler::create(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_ED }); return ret; } -void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE*/) + +bool Sampler::create() +{ + return create( + static_cast(pp::renderer::gl::linear_texture_filter()), + static_cast(pp::renderer::gl::clamp_to_edge_texture_wrap())); +} + +bool Sampler::create(GLint filter) +{ + return create(filter, static_cast(pp::renderer::gl::clamp_to_edge_texture_wrap())); +} + +void Sampler::set(GLint filter, GLint wrap) { App::I->render_task([=] { @@ -370,6 +422,19 @@ void Sampler::set(GLint filter /*= GL_LINEAR*/, GLint wrap /*= GL_CLAMP_TO_EDGE* #endif // USE_SAMPLER }); } + +void Sampler::set() +{ + set( + static_cast(pp::renderer::gl::linear_texture_filter()), + static_cast(pp::renderer::gl::clamp_to_edge_texture_wrap())); +} + +void Sampler::set(GLint filter) +{ + set(filter, static_cast(pp::renderer::gl::clamp_to_edge_texture_wrap())); +} + void Sampler::set_filter(GLint filter_min, GLint filter_mag) { App::I->render_task([=] diff --git a/src/texture.h b/src/texture.h index eb0fea2..9e1b142 100644 --- a/src/texture.h +++ b/src/texture.h @@ -17,9 +17,12 @@ public: ~Texture2D(); bool has_mips = false; - bool create(int width, int height, GLint internal_format = GL_RGBA8, GLint format = GL_RGBA, const uint8_t* data = nullptr); + bool create(int width, int height); + bool create(int width, int height, GLint internal_format); + bool create(int width, int height, GLint internal_format, GLint format, const uint8_t* data = nullptr); bool create(const Image& img); - void assign(GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA); + void assign(GLuint tex, int w = -1, int h = -1); + void assign(GLuint tex, int w, int h, GLuint internal_format, GLuint format); bool load(std::string filename); bool load_file(std::string filename); void destroy(); @@ -57,8 +60,12 @@ class Sampler GLuint id = 0; mutable GLint current_unit = 0; public: - bool create(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE); - void set(GLint filter = GL_LINEAR, GLint wrap = GL_CLAMP_TO_EDGE); + bool create(); + bool create(GLint filter); + bool create(GLint filter, GLint wrap); + void set(); + void set(GLint filter); + void set(GLint filter, GLint wrap); void set_filter(GLint filter_min, GLint filter_mag); void set_border(glm::vec4 rgba); void bind(int unit) const; @@ -71,7 +78,8 @@ class TextureManager public: static std::map m_textures; static bool load(const char* path, bool generate_mipmpas = false); - static void assign(uint16_t id, GLuint tex, int w = -1, int h = -1, GLuint internal_format = GL_RGBA8, GLuint format = GL_RGBA); + static void assign(uint16_t id, GLuint tex, int w = -1, int h = -1); + static void assign(uint16_t id, GLuint tex, int w, int h, GLuint internal_format, GLuint format); static Texture2D& get(uint16_t id); static void invalidate(); }; diff --git a/tests/renderer_gl/capabilities_tests.cpp b/tests/renderer_gl/capabilities_tests.cpp index 05e5273..f670d47 100644 --- a/tests/renderer_gl/capabilities_tests.cpp +++ b/tests/renderer_gl/capabilities_tests.cpp @@ -358,6 +358,7 @@ void maps_app_initialization_parameters(pp::tests::Harness& h) PP_EXPECT(h, pp::renderer::gl::linear_mipmap_linear_texture_filter() == 0x2703U); PP_EXPECT(h, pp::renderer::gl::nearest_texture_filter() == 0x2600U); PP_EXPECT(h, pp::renderer::gl::repeat_texture_wrap() == 0x2901U); + PP_EXPECT(h, pp::renderer::gl::clamp_to_edge_texture_wrap() == 0x812FU); PP_EXPECT(h, pp::renderer::gl::active_texture_unit(0U) == 0x84C0U); PP_EXPECT(h, pp::renderer::gl::active_texture_unit(4U) == 0x84C4U); }