Share retained texture dispatch bridge
This commit is contained in:
242
src/legacy_gl_texture_dispatch.h
Normal file
242
src/legacy_gl_texture_dispatch.h
Normal 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
|
||||
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
|
||||
|
||||
153
src/texture.cpp
153
src/texture.cpp
@@ -3,78 +3,13 @@
|
||||
#include "texture.h"
|
||||
#include "util.h"
|
||||
#include "app.h"
|
||||
#include "legacy_gl_texture_dispatch.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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
|
||||
{
|
||||
glGenFramebuffers(static_cast<GLsizei>(count), reinterpret_cast<GLuint*>(ids));
|
||||
@@ -227,24 +162,19 @@ bool TextureCube::create(int resolution) noexcept
|
||||
destroy();
|
||||
m_resolution = resolution;
|
||||
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 {
|
||||
.resolution = m_resolution,
|
||||
.internal_format = static_cast<std::int32_t>(format.internal_format),
|
||||
.pixel_format = format.pixel_format,
|
||||
.component_type = pp::renderer::gl::unsigned_byte_component_type(),
|
||||
},
|
||||
pp::renderer::gl::OpenGlTextureCubeAllocationDispatch {
|
||||
.gen_textures = gen_opengl_textures,
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.tex_image_2d = upload_opengl_texture_2d,
|
||||
});
|
||||
if (!texture.ok())
|
||||
"TextureCube::create()");
|
||||
if (texture == 0U)
|
||||
{
|
||||
LOG("TextureCube::create() failed because: %s", texture.status().message);
|
||||
return;
|
||||
}
|
||||
m_cubetex_id = static_cast<GLuint>(texture.value());
|
||||
m_cubetex_id = static_cast<GLuint>(texture);
|
||||
});
|
||||
return m_cubetex_id != 0;
|
||||
}
|
||||
@@ -259,13 +189,9 @@ void TextureCube::destroy() noexcept
|
||||
for (std::size_t i = 0U; i < f.size(); ++i)
|
||||
texture_ids[i] = static_cast<std::uint32_t>(f[i]);
|
||||
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,
|
||||
pp::renderer::gl::OpenGlTexture2DDeleteDispatch {
|
||||
.delete_textures = delete_opengl_textures,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("TextureCube::destroy() failed because: %s", status.message);
|
||||
"TextureCube::destroy()");
|
||||
});
|
||||
m_cubetex_id = 0;
|
||||
m_faces.fill(0);
|
||||
@@ -276,13 +202,9 @@ void TextureCube::destroy() noexcept
|
||||
void TextureCube::bind() const noexcept
|
||||
{
|
||||
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),
|
||||
pp::renderer::gl::OpenGlTexture2DBindDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("TextureCube::bind() failed because: %s", status.message);
|
||||
"TextureCube::bind()");
|
||||
}
|
||||
|
||||
bool TextureManager::load(const char* path, bool generate_mipmaps)
|
||||
@@ -344,7 +266,7 @@ Image Texture2D::get_image() const noexcept
|
||||
.pixels = ret.m_data.get(),
|
||||
},
|
||||
pp::renderer::gl::OpenGlTexture2DReadbackDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.bind_texture = pp::legacy::gl_texture::bind_opengl_texture,
|
||||
.gen_framebuffers = gen_opengl_framebuffers,
|
||||
.get_integer = query_opengl_integer,
|
||||
.bind_framebuffer = bind_opengl_framebuffer,
|
||||
@@ -413,7 +335,7 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
|
||||
destroy();
|
||||
const auto component_type = pp::renderer::gl::texture_upload_type_for_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 {
|
||||
.width = width,
|
||||
.height = height,
|
||||
@@ -422,13 +344,8 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
|
||||
.component_type = component_type,
|
||||
.data = data,
|
||||
},
|
||||
pp::renderer::gl::OpenGlTexture2DAllocationDispatch {
|
||||
.gen_textures = gen_opengl_textures,
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.tex_image_2d = upload_opengl_texture_2d,
|
||||
});
|
||||
if (!texture.ok()) {
|
||||
LOG("Texture2D::create() failed because: %s", texture.status().message);
|
||||
"Texture2D::create()");
|
||||
if (texture == 0U) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -436,7 +353,7 @@ bool Texture2D::create(int width, int height, GLint internal_format, GLint forma
|
||||
m_height = height;
|
||||
m_format = format;
|
||||
m_iformat = internal_format;
|
||||
m_tex = static_cast<GLuint>(texture.value());
|
||||
m_tex = static_cast<GLuint>(texture);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -458,14 +375,9 @@ void Texture2D::create_mipmaps()
|
||||
{
|
||||
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),
|
||||
pp::renderer::gl::OpenGlTexture2DMipmapDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.generate_mipmap = generate_opengl_mipmap,
|
||||
});
|
||||
if (!status.ok()) {
|
||||
LOG("Texture2D::create_mipmaps() failed because: %s", status.message);
|
||||
"Texture2D::create_mipmaps()")) {
|
||||
return;
|
||||
}
|
||||
has_mips = true;
|
||||
@@ -515,13 +427,9 @@ void Texture2D::destroy()
|
||||
{
|
||||
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),
|
||||
pp::renderer::gl::OpenGlTexture2DDeleteDispatch {
|
||||
.delete_textures = delete_opengl_textures,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("Texture2D::destroy() failed because: %s", status.message);
|
||||
"Texture2D::destroy()");
|
||||
});
|
||||
m_tex = 0;
|
||||
}
|
||||
@@ -530,32 +438,24 @@ void Texture2D::destroy()
|
||||
void Texture2D::bind() const
|
||||
{
|
||||
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),
|
||||
pp::renderer::gl::OpenGlTexture2DBindDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("Texture2D::bind() failed because: %s", status.message);
|
||||
"Texture2D::bind()");
|
||||
}
|
||||
|
||||
void Texture2D::unbind() const
|
||||
{
|
||||
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("Texture2D::unbind() failed because: %s", status.message);
|
||||
"Texture2D::unbind()");
|
||||
}
|
||||
|
||||
void Texture2D::update(const uint8_t* 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 {
|
||||
.texture_id = static_cast<std::uint32_t>(m_tex),
|
||||
.width = m_width,
|
||||
@@ -564,12 +464,7 @@ void Texture2D::update(const uint8_t* data)
|
||||
.component_type = pp::renderer::gl::unsigned_byte_component_type(),
|
||||
.data = data,
|
||||
},
|
||||
pp::renderer::gl::OpenGlTexture2DUpdateDispatch {
|
||||
.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);
|
||||
"Texture2D::update()");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user