Share retained utility GL dispatch bridges
This commit is contained in:
119
src/util.cpp
119
src/util.cpp
@@ -3,93 +3,12 @@
|
||||
#include "util.h"
|
||||
#include <poly2tri.h>
|
||||
#include "app.h"
|
||||
#include "legacy_gl_framebuffer_dispatch.h"
|
||||
#include "legacy_gl_sampler_dispatch.h"
|
||||
#include "legacy_gl_shader_dispatch.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::uint8_t is_opengl_enabled(std::uint32_t state) noexcept
|
||||
{
|
||||
return static_cast<std::uint8_t>(glIsEnabled(static_cast<GLenum>(state)));
|
||||
}
|
||||
|
||||
void query_opengl_integer(std::uint32_t name, std::int32_t* value) noexcept
|
||||
{
|
||||
glGetIntegerv(static_cast<GLenum>(name), reinterpret_cast<GLint*>(value));
|
||||
}
|
||||
|
||||
void query_opengl_float(std::uint32_t name, float* value) noexcept
|
||||
{
|
||||
glGetFloatv(static_cast<GLenum>(name), value);
|
||||
}
|
||||
|
||||
void set_opengl_active_texture(std::uint32_t texture_unit) noexcept
|
||||
{
|
||||
glActiveTexture(static_cast<GLenum>(texture_unit));
|
||||
}
|
||||
|
||||
void enable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
void disable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
glDisable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept
|
||||
{
|
||||
glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
|
||||
}
|
||||
|
||||
void set_opengl_clear_color(float r, float g, float b, float a) noexcept
|
||||
{
|
||||
glClearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
void bind_opengl_framebuffer(std::uint32_t target, std::uint32_t framebuffer) noexcept
|
||||
{
|
||||
glBindFramebuffer(static_cast<GLenum>(target), static_cast<GLuint>(framebuffer));
|
||||
}
|
||||
|
||||
void use_opengl_program(std::uint32_t program) noexcept
|
||||
{
|
||||
glUseProgram(static_cast<GLuint>(program));
|
||||
}
|
||||
|
||||
void bind_opengl_texture(std::uint32_t target, std::uint32_t texture) noexcept
|
||||
{
|
||||
glBindTexture(static_cast<GLenum>(target), static_cast<GLuint>(texture));
|
||||
}
|
||||
|
||||
void bind_opengl_sampler(std::uint32_t unit, std::uint32_t sampler) noexcept
|
||||
{
|
||||
glBindSampler(static_cast<GLuint>(unit), static_cast<GLuint>(sampler));
|
||||
}
|
||||
|
||||
void copy_opengl_tex_sub_image_2d(
|
||||
std::uint32_t target,
|
||||
std::int32_t level,
|
||||
std::int32_t destination_x,
|
||||
std::int32_t destination_y,
|
||||
std::int32_t source_x,
|
||||
std::int32_t source_y,
|
||||
std::int32_t width,
|
||||
std::int32_t height) noexcept
|
||||
{
|
||||
glCopyTexSubImage2D(
|
||||
static_cast<GLenum>(target),
|
||||
static_cast<GLint>(level),
|
||||
static_cast<GLint>(destination_x),
|
||||
static_cast<GLint>(destination_y),
|
||||
static_cast<GLint>(source_x),
|
||||
static_cast<GLint>(source_y),
|
||||
static_cast<GLsizei>(width),
|
||||
static_cast<GLsizei>(height));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
std::vector<vertex_t> poly_remove_duplicate<vertex_t>(const std::vector<vertex_t>& v, const float tollerance)
|
||||
{
|
||||
@@ -761,9 +680,7 @@ bool copy_framebuffer_to_texture_target(
|
||||
.width = width,
|
||||
.height = height,
|
||||
},
|
||||
pp::renderer::gl::OpenGlTexture2DFramebufferCopyDispatch {
|
||||
.copy_tex_sub_image_2d = copy_opengl_tex_sub_image_2d,
|
||||
});
|
||||
pp::legacy::gl_framebuffer::framebuffer_to_texture_copy_dispatch());
|
||||
if (!status.ok()) {
|
||||
LOG("OpenGL framebuffer-to-texture copy failed: %s", status.message);
|
||||
return false;
|
||||
@@ -866,10 +783,10 @@ void gl_state::save()
|
||||
|
||||
const auto snapshot = pp::renderer::gl::snapshot_opengl_state(
|
||||
pp::renderer::gl::OpenGlStateSnapshotDispatch {
|
||||
.is_enabled = is_opengl_enabled,
|
||||
.get_integer = query_opengl_integer,
|
||||
.get_float = query_opengl_float,
|
||||
.active_texture = set_opengl_active_texture,
|
||||
.is_enabled = pp::legacy::ui_gl::is_opengl_state_enabled,
|
||||
.get_integer = pp::legacy::gl_framebuffer::query_opengl_integer,
|
||||
.get_float = pp::legacy::ui_gl::get_opengl_float,
|
||||
.active_texture = pp::legacy::ui_gl::activate_opengl_texture,
|
||||
});
|
||||
if (!snapshot.ok()) {
|
||||
LOG("OpenGL state snapshot failed: %s", snapshot.status().message);
|
||||
@@ -920,15 +837,15 @@ void gl_state::restore()
|
||||
const auto status = pp::renderer::gl::restore_opengl_state(
|
||||
state,
|
||||
pp::renderer::gl::OpenGlStateRestoreDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
.viewport = set_opengl_viewport,
|
||||
.clear_color = set_opengl_clear_color,
|
||||
.bind_framebuffer = bind_opengl_framebuffer,
|
||||
.use_program = use_opengl_program,
|
||||
.active_texture = set_opengl_active_texture,
|
||||
.bind_texture = bind_opengl_texture,
|
||||
.bind_sampler = bind_opengl_sampler,
|
||||
.enable = pp::legacy::ui_gl::enable_opengl_state,
|
||||
.disable = pp::legacy::ui_gl::disable_opengl_state,
|
||||
.viewport = pp::legacy::ui_gl::set_opengl_viewport,
|
||||
.clear_color = pp::legacy::ui_gl::set_opengl_clear_color,
|
||||
.bind_framebuffer = pp::legacy::ui_gl::bind_opengl_framebuffer,
|
||||
.use_program = pp::legacy::gl_shader::use_opengl_program,
|
||||
.active_texture = pp::legacy::ui_gl::activate_opengl_texture,
|
||||
.bind_texture = pp::legacy::ui_gl::bind_opengl_texture,
|
||||
.bind_sampler = pp::legacy::gl_sampler::bind_opengl_sampler,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL state restore failed: %s", status.message);
|
||||
|
||||
Reference in New Issue
Block a user