Share retained texture dispatch bridge

This commit is contained in:
2026-06-05 14:29:59 +02:00
parent df21d673dd
commit 421f2713db
6 changed files with 306 additions and 250 deletions

View File

@@ -427,7 +427,9 @@ powershell -ExecutionPolicy Bypass -File scripts\automation\apple-remote-build.p
used by `RTT` and `Texture2D` diagnostics. It also owns the 2D texture target, used by `RTT` and `Texture2D` diagnostics. It also owns the 2D texture target,
framebuffer setup, readback format, mipmap target, and update component-type framebuffer setup, readback format, mipmap target, and update component-type
tokens used by `Texture2D`, plus cube-map binding and allocation face targets tokens used by `Texture2D`, plus cube-map binding and allocation face targets
used by `TextureCube`. It also owns and used by `TextureCube`. Retained `Texture2D`, `TextureCube`, and RTT texture
allocation, bind, parameter, update, mipmap, and delete dispatch now share
the retained `legacy_gl_texture_dispatch` raw callback bridge. It also owns and
validates framebuffer blit color mask and linear/nearest filters used by validates framebuffer blit color mask and linear/nearest filters used by
`RTT::resize` and `RTT::copy`, renderer API blit-filter to OpenGL token `RTT::resize` and `RTT::copy`, renderer API blit-filter to OpenGL token
mapping, plus the default linear clamp-to-edge render-target texture mapping, plus the default linear clamp-to-edge render-target texture

File diff suppressed because one or more lines are too long

View File

@@ -1137,7 +1137,10 @@ format mapping for `Texture2D` image uploads and framebuffer status naming for
OpenGL internal/pixel/component token mapping, including depth-stencil formats, OpenGL internal/pixel/component token mapping, including depth-stencil formats,
for future backend texture objects. `Texture2D` 2D texture binding, upload, for future backend texture objects. `Texture2D` 2D texture binding, upload,
mipmap generation, framebuffer readback setup, and update component-type tokens mipmap generation, framebuffer readback setup, and update component-type tokens
now delegate to `pp_renderer_gl`. `TextureCube` cube-map binding, allocation now delegate to `pp_renderer_gl`; retained `Texture2D`, `TextureCube`, and
`RTT` texture allocation, bind, parameter, update, mipmap, and delete dispatch
now share the retained `legacy_gl_texture_dispatch` raw callback bridge.
`TextureCube` cube-map binding, allocation
face targets, RGBA allocation format, and unsigned-byte component type also face targets, RGBA allocation format, and unsigned-byte component type also
delegate to `pp_renderer_gl`. RGBA8/RGBA32F readback formats, checked byte-count math, PBO delegate to `pp_renderer_gl`. RGBA8/RGBA32F readback formats, checked byte-count math, PBO
pixel-buffer target/usage/access tokens, and PBO allocation/readback/map/unmap/delete pixel-buffer target/usage/access tokens, and PBO allocation/readback/map/unmap/delete
@@ -2547,6 +2550,11 @@ Results:
`legacy_gl_renderbuffer_dispatch`, removing duplicated raw renderbuffer `legacy_gl_renderbuffer_dispatch`, removing duplicated raw renderbuffer
callbacks from `src/canvas.cpp` and `src/rtt.cpp` while resource lifetime callbacks from `src/canvas.cpp` and `src/rtt.cpp` while resource lifetime
ownership remains open under DEBT-0036. ownership remains open under DEBT-0036.
- Retained `Texture2D`, `TextureCube`, and RTT texture allocation, deletion,
binding, parameter setup, 2D update, and mipmap dispatch now share
`legacy_gl_texture_dispatch`, removing duplicated raw texture callbacks from
`src/texture.cpp` and `src/rtt.cpp` while texture resource ownership remains
retained under DEBT-0036.
- Canvas draw-merge shader-blend selection now consumes the extracted - Canvas draw-merge shader-blend selection now consumes the extracted
`pp_paint_renderer` stroke composite planner for current layer and primary `pp_paint_renderer` stroke composite planner for current layer and primary
brush blend modes, while preserving legacy OpenGL compositing execution under brush blend modes, while preserving legacy OpenGL compositing execution under

View File

@@ -0,0 +1,242 @@
#pragma once
#include <cstdint>
#include <span>
#include "log.h"
#include "renderer_gl/opengl_capabilities.h"
namespace pp::legacy::gl_texture {
inline void gen_opengl_textures(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenTextures(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
inline void delete_opengl_textures(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteTextures(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
inline void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept
{
glBindTexture(static_cast<GLenum>(target), static_cast<GLuint>(texture));
}
inline void upload_opengl_texture_2d(
std::uint32_t target,
std::int32_t level,
std::int32_t internal_format,
std::int32_t width,
std::int32_t height,
std::int32_t border,
std::uint32_t pixel_format,
std::uint32_t component_type,
const void* data) noexcept
{
glTexImage2D(
static_cast<GLenum>(target),
static_cast<GLint>(level),
static_cast<GLint>(internal_format),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLint>(border),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
data);
}
inline void update_opengl_texture_2d_region(
std::uint32_t target,
std::int32_t level,
std::int32_t x,
std::int32_t y,
std::int32_t width,
std::int32_t height,
std::uint32_t pixel_format,
std::uint32_t component_type,
const void* data) noexcept
{
glTexSubImage2D(
static_cast<GLenum>(target),
static_cast<GLint>(level),
static_cast<GLint>(x),
static_cast<GLint>(y),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
data);
}
inline void set_opengl_texture_parameter_f(std::uint32_t target, std::uint32_t parameter, float value) noexcept
{
glTexParameterf(static_cast<GLenum>(target), static_cast<GLenum>(parameter), static_cast<GLfloat>(value));
}
inline void generate_opengl_mipmap(std::uint32_t target) noexcept
{
glGenerateMipmap(static_cast<GLenum>(target));
}
inline pp::renderer::gl::OpenGlTexture2DAllocationDispatch texture_2d_allocation_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTexture2DAllocationDispatch {
.gen_textures = gen_opengl_textures,
.bind_texture = bind_opengl_texture,
.tex_image_2d = upload_opengl_texture_2d,
};
}
inline pp::renderer::gl::OpenGlTextureCubeAllocationDispatch texture_cube_allocation_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTextureCubeAllocationDispatch {
.gen_textures = gen_opengl_textures,
.bind_texture = bind_opengl_texture,
.tex_image_2d = upload_opengl_texture_2d,
};
}
inline pp::renderer::gl::OpenGlTexture2DDeleteDispatch texture_delete_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTexture2DDeleteDispatch {
.delete_textures = delete_opengl_textures,
};
}
inline pp::renderer::gl::OpenGlTexture2DBindDispatch texture_bind_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTexture2DBindDispatch {
.bind_texture = bind_opengl_texture,
};
}
inline pp::renderer::gl::OpenGlTexture2DUpdateDispatch texture_update_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTexture2DUpdateDispatch {
.bind_texture = bind_opengl_texture,
.tex_sub_image_2d = update_opengl_texture_2d_region,
};
}
inline pp::renderer::gl::OpenGlTexture2DParameterDispatch texture_parameter_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTexture2DParameterDispatch {
.bind_texture = bind_opengl_texture,
.tex_parameter_f = set_opengl_texture_parameter_f,
};
}
inline pp::renderer::gl::OpenGlTexture2DMipmapDispatch texture_mipmap_dispatch() noexcept
{
return pp::renderer::gl::OpenGlTexture2DMipmapDispatch {
.bind_texture = bind_opengl_texture,
.generate_mipmap = generate_opengl_mipmap,
};
}
inline std::uint32_t allocate_texture_2d(
pp::renderer::gl::OpenGlTexture2DAllocation allocation,
const char* context)
{
const auto result = pp::renderer::gl::allocate_opengl_texture_2d(allocation, texture_2d_allocation_dispatch());
if (!result.ok()) {
LOG("%s failed because: %s", context, result.status().message);
return 0U;
}
return result.value();
}
inline std::uint32_t allocate_texture_cube(
pp::renderer::gl::OpenGlTextureCubeAllocation allocation,
const char* context)
{
const auto result = pp::renderer::gl::allocate_opengl_texture_cube(
allocation,
texture_cube_allocation_dispatch());
if (!result.ok()) {
LOG("%s failed because: %s", context, result.status().message);
return 0U;
}
return result.value();
}
inline bool delete_texture_2d(std::uint32_t texture_id, const char* context)
{
const auto status = pp::renderer::gl::delete_opengl_texture_2d(texture_id, texture_delete_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool delete_texture_objects(std::span<const std::uint32_t> texture_ids, const char* context)
{
const auto status = pp::renderer::gl::delete_opengl_texture_objects(texture_ids, texture_delete_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool bind_texture_2d(std::uint32_t texture_id, const char* context)
{
const auto status = pp::renderer::gl::bind_opengl_texture_2d(texture_id, texture_bind_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool bind_texture_cube(std::uint32_t texture_id, const char* context)
{
const auto status = pp::renderer::gl::bind_opengl_texture_cube(texture_id, texture_bind_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool update_texture_2d(pp::renderer::gl::OpenGlTexture2DUpdate update, const char* context)
{
const auto status = pp::renderer::gl::update_opengl_texture_2d(update, texture_update_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool set_texture_2d_parameters(
std::uint32_t texture_id,
std::span<const pp::renderer::gl::OpenGlTextureParameter> parameters,
const char* context)
{
const auto status = pp::renderer::gl::set_opengl_texture_2d_parameters(
texture_id,
parameters,
texture_parameter_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
inline bool generate_texture_2d_mipmaps(std::uint32_t texture_id, const char* context)
{
const auto status = pp::renderer::gl::generate_opengl_texture_2d_mipmaps(
texture_id,
texture_mipmap_dispatch());
if (!status.ok()) {
LOG("%s failed because: %s", context, status.message);
return false;
}
return true;
}
} // namespace pp::legacy::gl_texture

View File

@@ -4,17 +4,13 @@
#include "util.h" #include "util.h"
#include "app.h" #include "app.h"
#include "legacy_gl_renderbuffer_dispatch.h" #include "legacy_gl_renderbuffer_dispatch.h"
#include "legacy_gl_texture_dispatch.h"
#include "renderer_gl/opengl_capabilities.h" #include "renderer_gl/opengl_capabilities.h"
#include <cstdint> #include <cstdint>
namespace { namespace {
[[nodiscard]] GLenum texture_2d_target() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::texture_2d_target());
}
[[nodiscard]] GLenum framebuffer_target() noexcept [[nodiscard]] GLenum framebuffer_target() noexcept
{ {
return static_cast<GLenum>(pp::renderer::gl::framebuffer_target()); return static_cast<GLenum>(pp::renderer::gl::framebuffer_target());
@@ -50,72 +46,6 @@ void set_opengl_color_mask(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::
glColorMask(r, g, b, a); glColorMask(r, g, b, a);
} }
void gen_opengl_textures(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenTextures(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
void delete_opengl_textures(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteTextures(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept
{
glBindTexture(static_cast<GLenum>(target), static_cast<GLuint>(texture));
}
void set_opengl_texture_2d_image(
std::uint32_t target,
std::int32_t level,
std::int32_t internal_format,
std::int32_t width,
std::int32_t height,
std::int32_t border,
std::uint32_t pixel_format,
std::uint32_t component_type,
const void* data) noexcept
{
glTexImage2D(
static_cast<GLenum>(target),
static_cast<GLint>(level),
static_cast<GLint>(internal_format),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLint>(border),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
data);
}
void set_opengl_texture_2d_sub_image(
std::uint32_t target,
std::int32_t level,
std::int32_t x,
std::int32_t y,
std::int32_t width,
std::int32_t height,
std::uint32_t pixel_format,
std::uint32_t component_type,
const void* data) noexcept
{
glTexSubImage2D(
static_cast<GLenum>(target),
static_cast<GLint>(level),
static_cast<GLint>(x),
static_cast<GLint>(y),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
data);
}
void set_opengl_texture_parameter_f(std::uint32_t target, std::uint32_t parameter, float value) noexcept
{
glTexParameterf(static_cast<GLenum>(target), static_cast<GLenum>(parameter), static_cast<GLfloat>(value));
}
void gen_opengl_framebuffers(std::uint32_t count, std::uint32_t* ids) noexcept void gen_opengl_framebuffers(std::uint32_t count, std::uint32_t* ids) noexcept
{ {
glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids)); glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
@@ -362,13 +292,9 @@ void RTT::destroy()
if (texID) if (texID)
{ {
//unbindTexture(); //unbindTexture();
const auto status = pp::renderer::gl::delete_opengl_texture_2d( pp::legacy::gl_texture::delete_texture_2d(
static_cast<std::uint32_t>(texID), static_cast<std::uint32_t>(texID),
pp::renderer::gl::OpenGlTexture2DDeleteDispatch { "RTT::destroy texture delete");
.delete_textures = delete_opengl_textures,
});
if (!status.ok())
LOG("RTT::destroy texture delete failed because: %s", status.message);
//LOG("TEX rtt destroy %d", texID) //LOG("TEX rtt destroy %d", texID)
} }
if (fboID) if (fboID)
@@ -492,7 +418,7 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
if (tex == -1) if (tex == -1)
{ {
const auto texture = pp::renderer::gl::allocate_opengl_texture_2d( const auto texture = pp::legacy::gl_texture::allocate_texture_2d(
pp::renderer::gl::OpenGlTexture2DAllocation { pp::renderer::gl::OpenGlTexture2DAllocation {
.width = width, .width = width,
.height = height, .height = height,
@@ -502,18 +428,13 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
static_cast<std::uint32_t>(internal_format)), static_cast<std::uint32_t>(internal_format)),
.data = nullptr, .data = nullptr,
}, },
pp::renderer::gl::OpenGlTexture2DAllocationDispatch { "RTT::create texture allocation");
.gen_textures = gen_opengl_textures, if (texture == 0U)
.bind_texture = bind_opengl_texture,
.tex_image_2d = set_opengl_texture_2d_image,
});
if (!texture.ok())
{ {
LOG("RTT::create texture allocation failed because: %s", texture.status().message);
status = 0; status = 0;
return; return;
} }
texID = static_cast<GLuint>(texture.value()); texID = static_cast<GLuint>(texture);
//LOG("TEX rtt create %d", texID); //LOG("TEX rtt create %d", texID);
} }
else else
@@ -521,16 +442,11 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
texID = tex; texID = tex;
} }
const auto parameter_status = pp::renderer::gl::set_opengl_texture_2d_parameters( if (!pp::legacy::gl_texture::set_texture_2d_parameters(
static_cast<std::uint32_t>(texID), static_cast<std::uint32_t>(texID),
pp::renderer::gl::default_render_target_texture_parameters(), pp::renderer::gl::default_render_target_texture_parameters(),
pp::renderer::gl::OpenGlTexture2DParameterDispatch { "RTT::create texture parameter setup"))
.bind_texture = bind_opengl_texture,
.tex_parameter_f = set_opengl_texture_parameter_f,
});
if (!parameter_status.ok())
{ {
LOG("RTT::create texture parameter setup failed because: %s", parameter_status.message);
status = 0; status = 0;
return; return;
} }
@@ -734,7 +650,7 @@ bool RTT::updateRgba8(int x, int y, int width, int height, const void* data) noe
if (!valid() || data == nullptr) if (!valid() || data == nullptr)
return false; return false;
const auto status = pp::renderer::gl::update_opengl_texture_2d( if (!pp::legacy::gl_texture::update_texture_2d(
pp::renderer::gl::OpenGlTexture2DUpdate { pp::renderer::gl::OpenGlTexture2DUpdate {
.texture_id = texID, .texture_id = texID,
.x = x, .x = x,
@@ -745,12 +661,7 @@ bool RTT::updateRgba8(int x, int y, int width, int height, const void* data) noe
.component_type = pp::renderer::gl::unsigned_byte_component_type(), .component_type = pp::renderer::gl::unsigned_byte_component_type(),
.data = data, .data = data,
}, },
pp::renderer::gl::OpenGlTexture2DUpdateDispatch { "RTT::updateRgba8()")) {
.bind_texture = bind_opengl_texture,
.tex_sub_image_2d = set_opengl_texture_2d_sub_image,
});
if (!status.ok()) {
LOG("RTT::updateRgba8() failed because: %s", status.message);
return false; return false;
} }
unbindTexture(); unbindTexture();
@@ -835,25 +746,17 @@ float * RTT::createBufferFloat() const noexcept
void RTT::bindTexture() void RTT::bindTexture()
{ {
assert(App::I->is_render_thread()); assert(App::I->is_render_thread());
const auto status = pp::renderer::gl::bind_opengl_texture_2d( pp::legacy::gl_texture::bind_texture_2d(
static_cast<std::uint32_t>(texID), static_cast<std::uint32_t>(texID),
pp::renderer::gl::OpenGlTexture2DBindDispatch { "RTT::bindTexture()");
.bind_texture = bind_opengl_texture,
});
if (!status.ok())
LOG("RTT::bindTexture() failed because: %s", status.message);
} }
void RTT::unbindTexture() void RTT::unbindTexture()
{ {
assert(App::I->is_render_thread()); assert(App::I->is_render_thread());
const auto status = pp::renderer::gl::bind_opengl_texture_2d( pp::legacy::gl_texture::bind_texture_2d(
0U, 0U,
pp::renderer::gl::OpenGlTexture2DBindDispatch { "RTT::unbindTexture()");
.bind_texture = bind_opengl_texture,
});
if (!status.ok())
LOG("RTT::unbindTexture() failed because: %s", status.message);
} }
Image RTT::get_image() const noexcept Image RTT::get_image() const noexcept

View File

@@ -3,78 +3,13 @@
#include "texture.h" #include "texture.h"
#include "util.h" #include "util.h"
#include "app.h" #include "app.h"
#include "legacy_gl_texture_dispatch.h"
#include "renderer_gl/opengl_capabilities.h" #include "renderer_gl/opengl_capabilities.h"
#include <cstdint> #include <cstdint>
namespace { namespace {
void gen_opengl_textures(std::uint32_t count, std::uint32_t* ids) noexcept
{
glGenTextures(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
}
void delete_opengl_textures(std::uint32_t count, const std::uint32_t* ids) noexcept
{
glDeleteTextures(static_cast<GLsizei>(count), reinterpret_cast<const GLuint*>(ids));
}
void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept
{
glBindTexture(static_cast<GLenum>(target), static_cast<GLuint>(texture));
}
void upload_opengl_texture_2d(
std::uint32_t target,
std::int32_t level,
std::int32_t internal_format,
std::int32_t width,
std::int32_t height,
std::int32_t border,
std::uint32_t pixel_format,
std::uint32_t component_type,
const void* data) noexcept
{
glTexImage2D(
static_cast<GLenum>(target),
static_cast<GLint>(level),
static_cast<GLint>(internal_format),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLint>(border),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
data);
}
void update_opengl_texture_2d_region(
std::uint32_t target,
std::int32_t level,
std::int32_t x,
std::int32_t y,
std::int32_t width,
std::int32_t height,
std::uint32_t pixel_format,
std::uint32_t component_type,
const void* data) noexcept
{
glTexSubImage2D(
static_cast<GLenum>(target),
static_cast<GLint>(level),
static_cast<GLint>(x),
static_cast<GLint>(y),
static_cast<GLsizei>(width),
static_cast<GLsizei>(height),
static_cast<GLenum>(pixel_format),
static_cast<GLenum>(component_type),
data);
}
void generate_opengl_mipmap(std::uint32_t target) noexcept
{
glGenerateMipmap(static_cast<GLenum>(target));
}
void gen_opengl_framebuffers(std::uint32_t count, std::uint32_t* ids) noexcept void gen_opengl_framebuffers(std::uint32_t count, std::uint32_t* ids) noexcept
{ {
glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids)); glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
@@ -227,24 +162,19 @@ bool TextureCube::create(int resolution) noexcept
destroy(); destroy();
m_resolution = resolution; m_resolution = resolution;
const auto format = pp::renderer::gl::texture_format_for_channel_count(4U); const auto format = pp::renderer::gl::texture_format_for_channel_count(4U);
const auto texture = pp::renderer::gl::allocate_opengl_texture_cube( const auto texture = pp::legacy::gl_texture::allocate_texture_cube(
pp::renderer::gl::OpenGlTextureCubeAllocation { pp::renderer::gl::OpenGlTextureCubeAllocation {
.resolution = m_resolution, .resolution = m_resolution,
.internal_format = static_cast<std::int32_t>(format.internal_format), .internal_format = static_cast<std::int32_t>(format.internal_format),
.pixel_format = format.pixel_format, .pixel_format = format.pixel_format,
.component_type = pp::renderer::gl::unsigned_byte_component_type(), .component_type = pp::renderer::gl::unsigned_byte_component_type(),
}, },
pp::renderer::gl::OpenGlTextureCubeAllocationDispatch { "TextureCube::create()");
.gen_textures = gen_opengl_textures, if (texture == 0U)
.bind_texture = bind_opengl_texture,
.tex_image_2d = upload_opengl_texture_2d,
});
if (!texture.ok())
{ {
LOG("TextureCube::create() failed because: %s", texture.status().message);
return; return;
} }
m_cubetex_id = static_cast<GLuint>(texture.value()); m_cubetex_id = static_cast<GLuint>(texture);
}); });
return m_cubetex_id != 0; return m_cubetex_id != 0;
} }
@@ -259,13 +189,9 @@ void TextureCube::destroy() noexcept
for (std::size_t i = 0U; i < f.size(); ++i) for (std::size_t i = 0U; i < f.size(); ++i)
texture_ids[i] = static_cast<std::uint32_t>(f[i]); texture_ids[i] = static_cast<std::uint32_t>(f[i]);
texture_ids[f.size()] = static_cast<std::uint32_t>(id); texture_ids[f.size()] = static_cast<std::uint32_t>(id);
const auto status = pp::renderer::gl::delete_opengl_texture_objects( pp::legacy::gl_texture::delete_texture_objects(
texture_ids, texture_ids,
pp::renderer::gl::OpenGlTexture2DDeleteDispatch { "TextureCube::destroy()");
.delete_textures = delete_opengl_textures,
});
if (!status.ok())
LOG("TextureCube::destroy() failed because: %s", status.message);
}); });
m_cubetex_id = 0; m_cubetex_id = 0;
m_faces.fill(0); m_faces.fill(0);
@@ -276,13 +202,9 @@ void TextureCube::destroy() noexcept
void TextureCube::bind() const noexcept void TextureCube::bind() const noexcept
{ {
assert(App::I->is_render_thread()); assert(App::I->is_render_thread());
const auto status = pp::renderer::gl::bind_opengl_texture_cube( pp::legacy::gl_texture::bind_texture_cube(
static_cast<std::uint32_t>(m_cubetex_id), static_cast<std::uint32_t>(m_cubetex_id),
pp::renderer::gl::OpenGlTexture2DBindDispatch { "TextureCube::bind()");
.bind_texture = bind_opengl_texture,
});
if (!status.ok())
LOG("TextureCube::bind() failed because: %s", status.message);
} }
bool TextureManager::load(const char* path, bool generate_mipmaps) bool TextureManager::load(const char* path, bool generate_mipmaps)
@@ -344,7 +266,7 @@ Image Texture2D::get_image() const noexcept
.pixels = ret.m_data.get(), .pixels = ret.m_data.get(),
}, },
pp::renderer::gl::OpenGlTexture2DReadbackDispatch { pp::renderer::gl::OpenGlTexture2DReadbackDispatch {
.bind_texture = bind_opengl_texture, .bind_texture = pp::legacy::gl_texture::bind_opengl_texture,
.gen_framebuffers = gen_opengl_framebuffers, .gen_framebuffers = gen_opengl_framebuffers,
.get_integer = query_opengl_integer, .get_integer = query_opengl_integer,
.bind_framebuffer = bind_opengl_framebuffer, .bind_framebuffer = bind_opengl_framebuffer,
@@ -413,7 +335,7 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
destroy(); destroy();
const auto component_type = pp::renderer::gl::texture_upload_type_for_internal_format( const auto component_type = pp::renderer::gl::texture_upload_type_for_internal_format(
static_cast<std::uint32_t>(internal_format)); static_cast<std::uint32_t>(internal_format));
const auto texture = pp::renderer::gl::allocate_opengl_texture_2d( const auto texture = pp::legacy::gl_texture::allocate_texture_2d(
pp::renderer::gl::OpenGlTexture2DAllocation { pp::renderer::gl::OpenGlTexture2DAllocation {
.width = width, .width = width,
.height = height, .height = height,
@@ -422,13 +344,8 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
.component_type = component_type, .component_type = component_type,
.data = data, .data = data,
}, },
pp::renderer::gl::OpenGlTexture2DAllocationDispatch { "Texture2D::create()");
.gen_textures = gen_opengl_textures, if (texture == 0U) {
.bind_texture = bind_opengl_texture,
.tex_image_2d = upload_opengl_texture_2d,
});
if (!texture.ok()) {
LOG("Texture2D::create() failed because: %s", texture.status().message);
return; return;
} }
@@ -436,7 +353,7 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
m_height = height; m_height = height;
m_format = format; m_format = format;
m_iformat = internal_format; m_iformat = internal_format;
m_tex = static_cast<GLuint>(texture.value()); m_tex = static_cast<GLuint>(texture);
}); });
return true; return true;
} }
@@ -458,14 +375,9 @@ void Texture2D::create_mipmaps()
{ {
App::I->render_task([this] App::I->render_task([this]
{ {
const auto status = pp::renderer::gl::generate_opengl_texture_2d_mipmaps( if (!pp::legacy::gl_texture::generate_texture_2d_mipmaps(
static_cast<std::uint32_t>(m_tex), static_cast<std::uint32_t>(m_tex),
pp::renderer::gl::OpenGlTexture2DMipmapDispatch { "Texture2D::create_mipmaps()")) {
.bind_texture = bind_opengl_texture,
.generate_mipmap = generate_opengl_mipmap,
});
if (!status.ok()) {
LOG("Texture2D::create_mipmaps() failed because: %s", status.message);
return; return;
} }
has_mips = true; has_mips = true;
@@ -515,13 +427,9 @@ void Texture2D::destroy()
{ {
App::I->render_task_async([id = m_tex] App::I->render_task_async([id = m_tex]
{ {
const auto status = pp::renderer::gl::delete_opengl_texture_2d( pp::legacy::gl_texture::delete_texture_2d(
static_cast<std::uint32_t>(id), static_cast<std::uint32_t>(id),
pp::renderer::gl::OpenGlTexture2DDeleteDispatch { "Texture2D::destroy()");
.delete_textures = delete_opengl_textures,
});
if (!status.ok())
LOG("Texture2D::destroy() failed because: %s", status.message);
}); });
m_tex = 0; m_tex = 0;
} }
@@ -530,32 +438,24 @@ void Texture2D::destroy()
void Texture2D::bind() const void Texture2D::bind() const
{ {
assert(App::I->is_render_thread()); assert(App::I->is_render_thread());
const auto status = pp::renderer::gl::bind_opengl_texture_2d( pp::legacy::gl_texture::bind_texture_2d(
static_cast<std::uint32_t>(m_tex), static_cast<std::uint32_t>(m_tex),
pp::renderer::gl::OpenGlTexture2DBindDispatch { "Texture2D::bind()");
.bind_texture = bind_opengl_texture,
});
if (!status.ok())
LOG("Texture2D::bind() failed because: %s", status.message);
} }
void Texture2D::unbind() const void Texture2D::unbind() const
{ {
assert(App::I->is_render_thread()); assert(App::I->is_render_thread());
const auto status = pp::renderer::gl::bind_opengl_texture_2d( pp::legacy::gl_texture::bind_texture_2d(
0U, 0U,
pp::renderer::gl::OpenGlTexture2DBindDispatch { "Texture2D::unbind()");
.bind_texture = bind_opengl_texture,
});
if (!status.ok())
LOG("Texture2D::unbind() failed because: %s", status.message);
} }
void Texture2D::update(const uint8_t* data) void Texture2D::update(const uint8_t* data)
{ {
App::I->render_task([this, data] App::I->render_task([this, data]
{ {
const auto status = pp::renderer::gl::update_opengl_texture_2d( pp::legacy::gl_texture::update_texture_2d(
pp::renderer::gl::OpenGlTexture2DUpdate { pp::renderer::gl::OpenGlTexture2DUpdate {
.texture_id = static_cast<std::uint32_t>(m_tex), .texture_id = static_cast<std::uint32_t>(m_tex),
.width = m_width, .width = m_width,
@@ -564,12 +464,7 @@ void Texture2D::update(const uint8_t* data)
.component_type = pp::renderer::gl::unsigned_byte_component_type(), .component_type = pp::renderer::gl::unsigned_byte_component_type(),
.data = data, .data = data,
}, },
pp::renderer::gl::OpenGlTexture2DUpdateDispatch { "Texture2D::update()");
.bind_texture = bind_opengl_texture,
.tex_sub_image_2d = update_opengl_texture_2d_region,
});
if (!status.ok())
LOG("Texture2D::update() failed because: %s", status.message);
}); });
} }