Share retained GL runtime dispatch adapters
This commit is contained in:
14
src/font.cpp
14
src/font.cpp
@@ -2,6 +2,7 @@
|
||||
#include "log.h"
|
||||
#include "font.h"
|
||||
#include "legacy_gl_mesh_dispatch.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "shader.h"
|
||||
#include "asset.h"
|
||||
#include "util.h"
|
||||
@@ -24,20 +25,9 @@ namespace {
|
||||
return static_cast<GLint>(pp::renderer::gl::texture_format_for_channel_count(1U).pixel_format);
|
||||
}
|
||||
|
||||
void activate_texture_adapter(std::uint32_t texture_unit) noexcept
|
||||
{
|
||||
glActiveTexture(static_cast<GLenum>(texture_unit));
|
||||
}
|
||||
|
||||
void activate_text_texture_unit(std::uint32_t unit_index)
|
||||
{
|
||||
const auto status = pp::renderer::gl::activate_opengl_texture_unit(
|
||||
unit_index,
|
||||
pp::renderer::gl::OpenGlActiveTextureDispatch {
|
||||
.active_texture = activate_texture_adapter,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("Text active texture dispatch failed because: %s", status.message);
|
||||
pp::legacy::ui_gl::activate_texture_unit(unit_index, "Text");
|
||||
}
|
||||
|
||||
[[nodiscard]] std::span<const pp::renderer::gl::OpenGlVertexAttribute> text_mesh_vertex_attributes() noexcept
|
||||
|
||||
20
src/hmd.cpp
20
src/hmd.cpp
@@ -1,30 +1,14 @@
|
||||
#include "pch.h"
|
||||
#include "hmd.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "log.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include <array>
|
||||
|
||||
namespace {
|
||||
|
||||
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 apply_hmd_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_viewport(
|
||||
pp::renderer::gl::OpenGlViewportRect {
|
||||
.x = x,
|
||||
.y = y,
|
||||
.width = width,
|
||||
.height = height,
|
||||
},
|
||||
pp::renderer::gl::OpenGlViewportDispatch {
|
||||
.viewport = set_opengl_viewport,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("HMD viewport dispatch failed because: %s", status.message);
|
||||
pp::legacy::ui_gl::apply_viewport(x, y, width, height, "HMD");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,21 @@ inline const char* query_opengl_indexed_string(std::uint32_t name, std::uint32_t
|
||||
glGetStringi(static_cast<GLenum>(name), static_cast<GLuint>(index)));
|
||||
}
|
||||
|
||||
inline std::uint32_t query_opengl_error() noexcept
|
||||
{
|
||||
return static_cast<std::uint32_t>(glGetError());
|
||||
}
|
||||
|
||||
inline bool has_opengl_debug_message_callback() noexcept
|
||||
{
|
||||
return glDebugMessageCallback != nullptr;
|
||||
}
|
||||
|
||||
inline void install_opengl_debug_message_callback(GLDEBUGPROC callback, const void* user_param) noexcept
|
||||
{
|
||||
glDebugMessageCallback(callback, user_param);
|
||||
}
|
||||
|
||||
inline pp::renderer::gl::OpenGlRuntimeInfoDispatch runtime_info_dispatch() noexcept
|
||||
{
|
||||
return pp::renderer::gl::OpenGlRuntimeInfoDispatch {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "app_core/document_platform_io.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "log.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
@@ -59,11 +60,6 @@ void invoke_picked_path_if_selected(
|
||||
callback(path);
|
||||
}
|
||||
|
||||
void enable_gl_capability(std::uint32_t state) noexcept
|
||||
{
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
// DEBT-0017: fallback for platforms that do not inject PlatformServices yet.
|
||||
class LegacyPlatformServices final : public pp::platform::PlatformServices {
|
||||
public:
|
||||
@@ -249,8 +245,8 @@ public:
|
||||
|
||||
void bind_default_render_target() override
|
||||
{
|
||||
glBindFramebuffer(
|
||||
static_cast<GLenum>(pp::renderer::gl::framebuffer_target()),
|
||||
pp::legacy::ui_gl::bind_opengl_framebuffer(
|
||||
pp::renderer::gl::framebuffer_target(),
|
||||
pp::renderer::gl::default_framebuffer_id());
|
||||
}
|
||||
|
||||
@@ -268,7 +264,7 @@ public:
|
||||
#if defined(__OSX__)
|
||||
const auto status = pp::renderer::gl::apply_opengl_render_platform_hints(
|
||||
pp::renderer::gl::OpenGlRenderPlatformHintDispatch {
|
||||
.enable = enable_gl_capability,
|
||||
.enable = pp::legacy::ui_gl::enable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL legacy render platform hints failed: %s", status.message);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "platform_windows/windows_platform_services.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "legacy_gl_runtime_dispatch.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "platform_api/platform_policy.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
@@ -84,11 +86,6 @@ void handle_gl_callback(
|
||||
}
|
||||
}
|
||||
|
||||
void enable_gl_capability(std::uint32_t state) noexcept
|
||||
{
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
void show_cursor(bool visible)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(main_task_mutex);
|
||||
@@ -313,9 +310,7 @@ public:
|
||||
void acquire_render_context() override
|
||||
{
|
||||
async_lock();
|
||||
glBindFramebuffer(
|
||||
static_cast<GLenum>(pp::renderer::gl::framebuffer_target()),
|
||||
static_cast<GLuint>(pp::renderer::gl::default_framebuffer_id()));
|
||||
bind_default_render_target();
|
||||
}
|
||||
|
||||
void release_render_context() override
|
||||
@@ -330,8 +325,8 @@ public:
|
||||
|
||||
void bind_default_render_target() override
|
||||
{
|
||||
glBindFramebuffer(
|
||||
static_cast<GLenum>(pp::renderer::gl::framebuffer_target()),
|
||||
pp::legacy::ui_gl::bind_opengl_framebuffer(
|
||||
pp::renderer::gl::framebuffer_target(),
|
||||
pp::renderer::gl::default_framebuffer_id());
|
||||
}
|
||||
|
||||
@@ -344,7 +339,7 @@ public:
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_render_platform_hints(
|
||||
pp::renderer::gl::OpenGlRenderPlatformHintDispatch {
|
||||
.enable = enable_gl_capability,
|
||||
.enable = pp::legacy::ui_gl::enable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL render platform hints failed: %s", status.message);
|
||||
@@ -352,15 +347,15 @@ public:
|
||||
|
||||
void install_render_debug_callback() override
|
||||
{
|
||||
if (!glDebugMessageCallback)
|
||||
if (!pp::legacy::gl_runtime::has_opengl_debug_message_callback())
|
||||
return;
|
||||
|
||||
// colors: http://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &render_debug_console_info);
|
||||
glDebugMessageCallback(handle_gl_callback, nullptr);
|
||||
pp::legacy::gl_runtime::install_opengl_debug_message_callback(handle_gl_callback, nullptr);
|
||||
const auto status = pp::renderer::gl::apply_opengl_debug_output_states(
|
||||
pp::renderer::gl::OpenGlDebugOutputStateDispatch {
|
||||
.enable = enable_gl_capability,
|
||||
.enable = pp::legacy::ui_gl::enable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL debug output states failed: %s", status.message);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <poly2tri.h>
|
||||
#include "app.h"
|
||||
#include "legacy_gl_framebuffer_dispatch.h"
|
||||
#include "legacy_gl_runtime_dispatch.h"
|
||||
#include "legacy_gl_sampler_dispatch.h"
|
||||
#include "legacy_gl_shader_dispatch.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
@@ -631,7 +632,7 @@ std::string str_replace(const std::string& string, const std::string& search, co
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char* gl2str(GLenum err)
|
||||
static const char* gl2str(std::uint32_t err)
|
||||
{
|
||||
return pp::renderer::gl::opengl_error_name(err);
|
||||
}
|
||||
@@ -652,8 +653,8 @@ double now_seconds()
|
||||
|
||||
void check_OpenGLError(const char* stmt, const char* fname, int line)
|
||||
{
|
||||
GLenum err;
|
||||
while ((err = glGetError()) != pp::renderer::gl::no_error_code())
|
||||
std::uint32_t err = 0U;
|
||||
while ((err = pp::legacy::gl_runtime::query_opengl_error()) != pp::renderer::gl::no_error_code())
|
||||
{
|
||||
LOG("OpenGL error %08x (%s), at %s:%i - for %s", err, gl2str(err), fname, line, stmt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user