Route UI leaf render state through GL dispatch
This commit is contained in:
152
src/legacy_ui_gl_dispatch.h
Normal file
152
src/legacy_ui_gl_dispatch.h
Normal file
@@ -0,0 +1,152 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "log.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
namespace pp::legacy::ui_gl {
|
||||
|
||||
inline void enable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
inline void disable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
glDisable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
inline void clear_opengl_buffer(std::uint32_t mask) noexcept
|
||||
{
|
||||
glClear(static_cast<GLbitfield>(mask));
|
||||
}
|
||||
|
||||
inline void set_opengl_clear_color(float r, float g, float b, float a) noexcept
|
||||
{
|
||||
glClearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
inline 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));
|
||||
}
|
||||
|
||||
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 get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept
|
||||
{
|
||||
GLint raw_values[4] {};
|
||||
glGetIntegerv(static_cast<GLenum>(name), raw_values);
|
||||
values[0] = static_cast<std::int32_t>(raw_values[0]);
|
||||
values[1] = static_cast<std::int32_t>(raw_values[1]);
|
||||
values[2] = static_cast<std::int32_t>(raw_values[2]);
|
||||
values[3] = static_cast<std::int32_t>(raw_values[3]);
|
||||
}
|
||||
|
||||
inline void get_opengl_float(std::uint32_t name, float* values) noexcept
|
||||
{
|
||||
glGetFloatv(static_cast<GLenum>(name), values);
|
||||
}
|
||||
|
||||
inline std::array<std::int32_t, 4> query_viewport(const char* context)
|
||||
{
|
||||
std::array<std::int32_t, 4> viewport {};
|
||||
get_opengl_integer(pp::renderer::gl::viewport_query(), viewport.data());
|
||||
(void)context;
|
||||
return viewport;
|
||||
}
|
||||
|
||||
inline std::array<float, 4> query_clear_color(const char* context)
|
||||
{
|
||||
std::array<float, 4> color {};
|
||||
get_opengl_float(pp::renderer::gl::color_clear_value_query(), color.data());
|
||||
(void)context;
|
||||
return color;
|
||||
}
|
||||
|
||||
inline void set_capability(std::uint32_t state, bool enabled, const char* context)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_capability(
|
||||
state,
|
||||
enabled,
|
||||
pp::renderer::gl::OpenGlCapabilityDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("%s capability dispatch failed because: %s", context, status.message);
|
||||
}
|
||||
|
||||
inline void set_blend_enabled(bool enabled, const char* context)
|
||||
{
|
||||
set_capability(pp::renderer::gl::blend_state(), enabled, context);
|
||||
}
|
||||
|
||||
inline void apply_viewport(
|
||||
std::int32_t x,
|
||||
std::int32_t y,
|
||||
std::int32_t width,
|
||||
std::int32_t height,
|
||||
const char* context)
|
||||
{
|
||||
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("%s viewport dispatch failed because: %s", context, status.message);
|
||||
}
|
||||
|
||||
inline void clear_color_buffer(std::array<float, 4> color, const char* context)
|
||||
{
|
||||
const auto status = pp::renderer::gl::clear_opengl_render_target(
|
||||
pp::renderer::gl::OpenGlDefaultClear {
|
||||
.color = color,
|
||||
.mask = pp::renderer::gl::framebuffer_color_buffer_mask(),
|
||||
},
|
||||
pp::renderer::gl::OpenGlClearDispatch {
|
||||
.clear_color = set_opengl_clear_color,
|
||||
.clear = clear_opengl_buffer,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("%s clear dispatch failed because: %s", context, status.message);
|
||||
}
|
||||
|
||||
inline void set_clear_color(std::array<float, 4> color, const char* context)
|
||||
{
|
||||
const auto status = pp::renderer::gl::clear_opengl_render_target(
|
||||
pp::renderer::gl::OpenGlDefaultClear {
|
||||
.color = color,
|
||||
.mask = pp::renderer::gl::framebuffer_color_buffer_mask(),
|
||||
},
|
||||
pp::renderer::gl::OpenGlClearDispatch {
|
||||
.clear_color = set_opengl_clear_color,
|
||||
.clear = [](std::uint32_t) noexcept {},
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("%s clear-color dispatch failed because: %s", context, status.message);
|
||||
}
|
||||
|
||||
inline void unbind_texture_2d(const char* context)
|
||||
{
|
||||
const auto status = pp::renderer::gl::bind_opengl_texture_2d(
|
||||
0U,
|
||||
pp::renderer::gl::OpenGlTexture2DBindDispatch {
|
||||
.bind_texture = bind_opengl_texture,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("%s texture bind dispatch failed because: %s", context, status.message);
|
||||
}
|
||||
|
||||
} // namespace pp::legacy::ui_gl
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_border.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
|
||||
Plane NodeBorder::m_plane;
|
||||
@@ -63,22 +63,20 @@ void NodeBorder::draw()
|
||||
{
|
||||
ShaderManager::use(kShader::Color);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
|
||||
const auto blend_state = pp::renderer::gl::blend_state();
|
||||
|
||||
if (m_color.a > 0.f)
|
||||
{
|
||||
m_color.a < 1.f ? glEnable(blend_state) : glDisable(blend_state);
|
||||
pp::legacy::ui_gl::set_blend_enabled(m_color.a < 1.f, "NodeBorder");
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
|
||||
m_plane.draw_fill();
|
||||
glDisable(blend_state);
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeBorder");
|
||||
}
|
||||
|
||||
if (m_thinkness > 0 && m_border_color.a > 0.f)
|
||||
{
|
||||
//glLineWidth(m_thinkness);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
|
||||
m_border_color.a < 1.f ? glEnable(blend_state) : glDisable(blend_state);
|
||||
pp::legacy::ui_gl::set_blend_enabled(m_border_color.a < 1.f, "NodeBorder");
|
||||
m_plane.draw_stroke();
|
||||
glDisable(blend_state);
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeBorder");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "pch.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_colorwheel.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
@@ -90,7 +91,7 @@ void NodeColorWheel::loaded()
|
||||
|
||||
void NodeColorWheel::draw()
|
||||
{
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeColorWheel");
|
||||
ShaderManager::use(kShader::ColorHue);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp * glm::eulerAngleZ(glm::radians(-90.f)));
|
||||
ShaderManager::u_int(kShaderUniform::Direction, 0); // set horizontal
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_image.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
@@ -102,7 +103,7 @@ void NodeImage::draw()
|
||||
auto& sampler = m_use_mipmaps ? m_sampler_mips : m_sampler;
|
||||
sampler.bind(0);
|
||||
|
||||
glEnable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(true, "NodeImage");
|
||||
if (m_use_atlas)
|
||||
{
|
||||
ShaderManager::use(kShader::Atlas);
|
||||
@@ -117,7 +118,7 @@ void NodeImage::draw()
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp * glm::scale(glm::vec3(m_scale, 1.f)));
|
||||
m_plane.draw_fill();
|
||||
sampler.unbind();
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeImage");
|
||||
}
|
||||
|
||||
bool NodeImage::set_image(const std::string& path)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_image_texture.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
#include "node_image.h"
|
||||
|
||||
@@ -19,14 +19,14 @@ void NodeImageTexture::clone_copy(Node* dest) const
|
||||
|
||||
void NodeImageTexture::draw()
|
||||
{
|
||||
tex ? tex->bind() : glBindTexture(pp::renderer::gl::texture_2d_target(), 0);
|
||||
tex ? tex->bind() : pp::legacy::ui_gl::unbind_texture_2d("NodeImageTexture");
|
||||
auto& sampler = tex && tex->has_mips ? NodeImage::m_sampler_mips : NodeImage::m_sampler;
|
||||
sampler.bind(0);
|
||||
glEnable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(true, "NodeImageTexture");
|
||||
ShaderManager::use(kShader::Texture);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
|
||||
NodeImage::m_plane.draw_fill();
|
||||
sampler.unbind();
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeImageTexture");
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "node_panel_animation.h"
|
||||
#include "app_core/document_animation.h"
|
||||
#include "legacy_document_animation_services.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_button.h"
|
||||
#include "node_button_custom.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "canvas.h"
|
||||
|
||||
Node* NodePanelAnimation::clone_instantiate() const
|
||||
@@ -308,7 +308,7 @@ void NodeAnimationTimeline::draw()
|
||||
{
|
||||
parent::draw();
|
||||
ShaderManager::use(kShader::Color);
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeAnimationTimeline");
|
||||
|
||||
float step = 35.f;
|
||||
glm::vec2 cur_pos = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_scroll.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "event.h"
|
||||
#include "shader.h"
|
||||
|
||||
@@ -111,7 +111,7 @@ void NodeScroll::draw()
|
||||
|
||||
if (rect.w > 0 && rect.z > 0)
|
||||
{
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeScroll");
|
||||
ShaderManager::use(kShader::Color);
|
||||
|
||||
if (m_direction == kScrollDirection::Vertical)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_text.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
|
||||
Node* NodeText::clone_instantiate() const
|
||||
@@ -174,9 +174,9 @@ void NodeText::draw()
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj * pos);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
|
||||
glEnable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(true, "NodeText");
|
||||
m_text_mesh.draw();
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeText");
|
||||
}
|
||||
|
||||
void NodeText::handle_resize(glm::vec2 old_size, glm::vec2 new_size, float zoom)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "app.h"
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_text_input.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "node_border.h"
|
||||
|
||||
Node* NodeTextInput::clone_instantiate() const
|
||||
@@ -220,13 +220,13 @@ void NodeTextInput::draw()
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_proj * pos);
|
||||
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
|
||||
glEnable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(true, "NodeTextInput");
|
||||
m_text_mesh.draw();
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeTextInput");
|
||||
|
||||
if (m_cursor_visible)
|
||||
{
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeTextInput");
|
||||
glm::mat4 cur_pos = glm::translate(glm::vec3(m_pos + m_off + xy(m_text_mesh.cur_box), 0));
|
||||
glm::mat4 cur_scale = glm::scale(glm::vec3(zw(m_text_mesh.cur_box), 1));
|
||||
glm::mat4 cur_pivot = glm::translate(glm::vec3(0.5, 0.5, 0));
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "log.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "node_viewport.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
#include "app.h"
|
||||
|
||||
@@ -10,29 +13,31 @@ void NodeViewport::draw()
|
||||
glm::mat4 cam = glm::lookAt(glm::vec3(sinf(angle) * 10, 0, -10), glm::vec3(0, 0, 0), glm::vec3(0, -1, 0));
|
||||
glm::mat4 proj = glm::perspective<float>(glm::radians(45.f), m_clip.z / m_clip.w, .1f, 100);
|
||||
|
||||
GLint vp[4];
|
||||
GLfloat cc[4];
|
||||
glGetIntegerv(pp::renderer::gl::viewport_query(), vp);
|
||||
glGetFloatv(pp::renderer::gl::color_clear_value_query(), cc);
|
||||
const auto vp = pp::legacy::ui_gl::query_viewport("NodeViewport");
|
||||
const auto cc = pp::legacy::ui_gl::query_clear_color("NodeViewport");
|
||||
|
||||
glClearColor(1, 0, 0, 1);
|
||||
glClear(pp::renderer::gl::framebuffer_color_buffer_mask());
|
||||
pp::legacy::ui_gl::clear_color_buffer({ 1.f, 0.f, 0.f, 1.f }, "NodeViewport");
|
||||
auto box = m_clip * root()->m_zoom;
|
||||
glm::ivec4 c = (glm::ivec4)glm::vec4(box.x, (int)(vp[3] - box.y - box.w), box.z, box.w);
|
||||
glViewport(c.x + App::I->off_x, c.y + App::I->off_y, c.z, c.w);
|
||||
pp::legacy::ui_gl::apply_viewport(
|
||||
static_cast<std::int32_t>(c.x + App::I->off_x),
|
||||
static_cast<std::int32_t>(c.y + App::I->off_y),
|
||||
c.z,
|
||||
c.w,
|
||||
"NodeViewport");
|
||||
TextureManager::get(m_tex_id).bind();
|
||||
m_sampler->bind(0);
|
||||
glEnable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(true, "NodeViewport");
|
||||
ShaderManager::use(kShader::Texture);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, proj * cam);
|
||||
m_faces->draw_fill();
|
||||
m_sampler->unbind();
|
||||
TextureManager::get(m_tex_id).unbind();
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
pp::legacy::ui_gl::set_blend_enabled(false, "NodeViewport");
|
||||
|
||||
glViewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
pp::legacy::ui_gl::apply_viewport(vp[0], vp[1], vp[2], vp[3], "NodeViewport");
|
||||
pp::legacy::ui_gl::set_clear_color(cc, "NodeViewport");
|
||||
}
|
||||
Node* NodeViewport::clone_instantiate() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user