Share retained texture dispatch bridge
This commit is contained in:
139
src/rtt.cpp
139
src/rtt.cpp
@@ -4,17 +4,13 @@
|
||||
#include "util.h"
|
||||
#include "app.h"
|
||||
#include "legacy_gl_renderbuffer_dispatch.h"
|
||||
#include "legacy_gl_texture_dispatch.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] GLenum texture_2d_target() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::texture_2d_target());
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum framebuffer_target() noexcept
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
|
||||
@@ -362,13 +292,9 @@ void RTT::destroy()
|
||||
if (texID)
|
||||
{
|
||||
//unbindTexture();
|
||||
const auto status = pp::renderer::gl::delete_opengl_texture_2d(
|
||||
pp::legacy::gl_texture::delete_texture_2d(
|
||||
static_cast<std::uint32_t>(texID),
|
||||
pp::renderer::gl::OpenGlTexture2DDeleteDispatch {
|
||||
.delete_textures = delete_opengl_textures,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("RTT::destroy texture delete failed because: %s", status.message);
|
||||
"RTT::destroy texture delete");
|
||||
//LOG("TEX rtt destroy %d", texID)
|
||||
}
|
||||
if (fboID)
|
||||
@@ -492,7 +418,7 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
|
||||
|
||||
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 {
|
||||
.width = width,
|
||||
.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)),
|
||||
.data = nullptr,
|
||||
},
|
||||
pp::renderer::gl::OpenGlTexture2DAllocationDispatch {
|
||||
.gen_textures = gen_opengl_textures,
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.tex_image_2d = set_opengl_texture_2d_image,
|
||||
});
|
||||
if (!texture.ok())
|
||||
"RTT::create texture allocation");
|
||||
if (texture == 0U)
|
||||
{
|
||||
LOG("RTT::create texture allocation failed because: %s", texture.status().message);
|
||||
status = 0;
|
||||
return;
|
||||
}
|
||||
texID = static_cast<GLuint>(texture.value());
|
||||
texID = static_cast<GLuint>(texture);
|
||||
//LOG("TEX rtt create %d", texID);
|
||||
}
|
||||
else
|
||||
@@ -521,16 +442,11 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
|
||||
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),
|
||||
pp::renderer::gl::default_render_target_texture_parameters(),
|
||||
pp::renderer::gl::OpenGlTexture2DParameterDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.tex_parameter_f = set_opengl_texture_parameter_f,
|
||||
});
|
||||
if (!parameter_status.ok())
|
||||
"RTT::create texture parameter setup"))
|
||||
{
|
||||
LOG("RTT::create texture parameter setup failed because: %s", parameter_status.message);
|
||||
status = 0;
|
||||
return;
|
||||
}
|
||||
@@ -734,23 +650,18 @@ bool RTT::updateRgba8(int x, int y, int width, int height, const void* data) noe
|
||||
if (!valid() || data == nullptr)
|
||||
return false;
|
||||
|
||||
const auto status = pp::renderer::gl::update_opengl_texture_2d(
|
||||
pp::renderer::gl::OpenGlTexture2DUpdate {
|
||||
.texture_id = texID,
|
||||
.x = x,
|
||||
if (!pp::legacy::gl_texture::update_texture_2d(
|
||||
pp::renderer::gl::OpenGlTexture2DUpdate {
|
||||
.texture_id = texID,
|
||||
.x = x,
|
||||
.y = y,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.pixel_format = pp::renderer::gl::rgba_pixel_format(),
|
||||
.component_type = pp::renderer::gl::unsigned_byte_component_type(),
|
||||
.data = data,
|
||||
},
|
||||
pp::renderer::gl::OpenGlTexture2DUpdateDispatch {
|
||||
.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);
|
||||
.component_type = pp::renderer::gl::unsigned_byte_component_type(),
|
||||
.data = data,
|
||||
},
|
||||
"RTT::updateRgba8()")) {
|
||||
return false;
|
||||
}
|
||||
unbindTexture();
|
||||
@@ -835,25 +746,17 @@ float * RTT::createBufferFloat() const noexcept
|
||||
void RTT::bindTexture()
|
||||
{
|
||||
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),
|
||||
pp::renderer::gl::OpenGlTexture2DBindDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("RTT::bindTexture() failed because: %s", status.message);
|
||||
"RTT::bindTexture()");
|
||||
}
|
||||
|
||||
void RTT::unbindTexture()
|
||||
{
|
||||
assert(App::I->is_render_thread());
|
||||
const auto status = pp::renderer::gl::bind_opengl_texture_2d(
|
||||
pp::legacy::gl_texture::bind_texture_2d(
|
||||
0U,
|
||||
pp::renderer::gl::OpenGlTexture2DBindDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("RTT::unbindTexture() failed because: %s", status.message);
|
||||
"RTT::unbindTexture()");
|
||||
}
|
||||
|
||||
Image RTT::get_image() const noexcept
|
||||
|
||||
Reference in New Issue
Block a user