Move app render state mapping to renderer gl

This commit is contained in:
2026-06-02 07:01:07 +02:00
parent 3930f39b14
commit 217450e161
6 changed files with 90 additions and 14 deletions

View File

@@ -97,6 +97,11 @@ namespace {
return static_cast<GLenum>(pp::renderer::gl::depth_test_state());
}
[[nodiscard]] GLenum scissor_test_state() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::scissor_test_state());
}
[[nodiscard]] GLenum program_point_size_state() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::program_point_size_state());
@@ -132,6 +137,36 @@ namespace {
return static_cast<GLint>(pp::renderer::gl::rgba8_internal_format());
}
[[nodiscard]] GLenum linear_texture_filter() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::linear_texture_filter());
}
[[nodiscard]] GLenum nearest_texture_filter() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::nearest_texture_filter());
}
[[nodiscard]] GLenum repeat_texture_wrap() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::repeat_texture_wrap());
}
[[nodiscard]] GLenum framebuffer_target() noexcept
{
return static_cast<GLenum>(pp::renderer::gl::framebuffer_target());
}
[[nodiscard]] GLuint default_framebuffer_id() noexcept
{
return static_cast<GLuint>(pp::renderer::gl::default_framebuffer_id());
}
[[nodiscard]] GLbitfield framebuffer_color_buffer_mask() noexcept
{
return static_cast<GLbitfield>(pp::renderer::gl::framebuffer_color_buffer_mask());
}
}
std::thread App::render_thread;
std::thread::id App::render_thread_id;
@@ -256,7 +291,7 @@ bool App::request_close()
void App::clear()
{
glClearColor(.1f, .1f, .1f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glClear(framebuffer_color_buffer_mask());
}
void App::initAssets()
@@ -265,9 +300,9 @@ void App::initAssets()
FontManager::init();
LOG("initializing assets create sampler");
sampler.create(GL_NEAREST);
sampler_stencil.create(GL_LINEAR, GL_REPEAT);
sampler_linear.create(GL_LINEAR);
sampler.create(nearest_texture_filter());
sampler_stencil.create(linear_texture_filter(), repeat_texture_wrap());
sampler_linear.create(linear_texture_filter());
m_face_plane.create<1>(2, 2);
sphere.create<8, 8>(1);
LOG("initializing assets load uvs texture");
@@ -587,7 +622,7 @@ void App::async_start()
android_async_lock();
#elif _WIN32
async_lock();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(framebuffer_target(), default_framebuffer_id());
#elif __LINUX__ || __WEB__
glfwMakeContextCurrent(glfw_window);
#endif
@@ -686,13 +721,13 @@ void App::draw(float dt)
uirtt.bindFramebuffer();
uirtt.clear();
glViewport(0, 0, uirtt.getWidth(), uirtt.getHeight());
glEnable(GL_SCISSOR_TEST);
glEnable(scissor_test_state());
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
layout[main_id]->m_children[i]->watch(observer);
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
layout_designer[main_id]->m_children[i]->watch(observer);
//msgbox->watch(observer);
glDisable(GL_SCISSOR_TEST);
glDisable(scissor_test_state());
uirtt.unbindFramebuffer();
}
@@ -701,16 +736,16 @@ void App::draw(float dt)
#if __IOS__
[ios_view->glview bindDrawable];
#else
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(framebuffer_target(), default_framebuffer_id());
#endif
glViewport(off_x, off_y, (GLsizei)width, (GLsizei)height);
glEnable(GL_SCISSOR_TEST);
glEnable(scissor_test_state());
for (int i = 0; i < layout[main_id]->m_children.size(); i++)
layout[main_id]->m_children[i]->watch(observer);
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
layout_designer[main_id]->m_children[i]->watch(observer);
//msgbox->watch(observer);
glDisable(GL_SCISSOR_TEST);
glDisable(scissor_test_state());
}
redraw = false;
@@ -1012,7 +1047,7 @@ void App::ui_thread_tick()
update(0);
render_task([this]
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(framebuffer_target(), default_framebuffer_id());
clear();
draw(0);
async_swap();
@@ -1114,7 +1149,7 @@ void App::ui_thread_main()
update(t_frame);
render_task([this, t_frame]
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(framebuffer_target(), default_framebuffer_id());
clear();
draw(t_frame);
async_swap();

View File

@@ -33,6 +33,7 @@ constexpr std::uint32_t gl_debug_severity_notification = 0x826BU;
constexpr std::uint32_t gl_src_alpha = 0x0302U;
constexpr std::uint32_t gl_one_minus_src_alpha = 0x0303U;
constexpr std::uint32_t gl_line_smooth = 0x0B20U;
constexpr std::uint32_t gl_scissor_test = 0x0C11U;
constexpr std::uint32_t gl_depth_test = 0x0B71U;
constexpr std::uint32_t gl_func_add = 0x8006U;
constexpr std::uint32_t gl_max = 0x8008U;
@@ -86,6 +87,7 @@ constexpr std::uint32_t gl_texture_wrap_s = 0x2802U;
constexpr std::uint32_t gl_texture_wrap_t = 0x2803U;
constexpr std::uint32_t gl_texture_wrap_r = 0x8072U;
constexpr std::uint32_t gl_texture_border_color = 0x1004U;
constexpr std::uint32_t gl_repeat = 0x2901U;
constexpr std::uint32_t gl_clamp_to_edge = 0x812FU;
constexpr std::uint32_t gl_pixel_pack_buffer = 0x88EBU;
constexpr std::uint32_t gl_pixel_unpack_buffer = 0x88ECU;
@@ -277,6 +279,11 @@ std::uint32_t framebuffer_complete_status() noexcept
return gl_framebuffer_complete;
}
std::uint32_t default_framebuffer_id() noexcept
{
return 0U;
}
const char* framebuffer_status_name(std::uint32_t status) noexcept
{
switch (status) {
@@ -465,6 +472,11 @@ std::uint32_t depth_test_state() noexcept
return gl_depth_test;
}
std::uint32_t scissor_test_state() noexcept
{
return gl_scissor_test;
}
std::uint32_t program_point_size_state() noexcept
{
return gl_program_point_size;
@@ -500,6 +512,21 @@ std::uint32_t rgba8_internal_format() noexcept
return gl_rgba8;
}
std::uint32_t linear_texture_filter() noexcept
{
return gl_linear;
}
std::uint32_t nearest_texture_filter() noexcept
{
return gl_nearest;
}
std::uint32_t repeat_texture_wrap() noexcept
{
return gl_repeat;
}
std::uint32_t texture_cube_map_target() noexcept
{
return gl_texture_cube_map;

View File

@@ -67,6 +67,7 @@ struct OpenGlReadbackFormat {
[[nodiscard]] std::uint32_t framebuffer_color_attachment() noexcept;
[[nodiscard]] std::uint32_t framebuffer_depth_attachment() noexcept;
[[nodiscard]] std::uint32_t framebuffer_complete_status() noexcept;
[[nodiscard]] std::uint32_t default_framebuffer_id() noexcept;
[[nodiscard]] const char* framebuffer_status_name(std::uint32_t status) noexcept;
[[nodiscard]] std::uint32_t framebuffer_color_buffer_mask() noexcept;
[[nodiscard]] std::uint32_t framebuffer_depth_buffer_mask() noexcept;
@@ -97,6 +98,7 @@ struct OpenGlReadbackFormat {
[[nodiscard]] std::uint32_t renderer_string_name() noexcept;
[[nodiscard]] std::uint32_t shading_language_version_string_name() noexcept;
[[nodiscard]] std::uint32_t depth_test_state() noexcept;
[[nodiscard]] std::uint32_t scissor_test_state() noexcept;
[[nodiscard]] std::uint32_t program_point_size_state() noexcept;
[[nodiscard]] std::uint32_t line_smooth_state() noexcept;
[[nodiscard]] std::uint32_t source_alpha_blend_factor() noexcept;
@@ -104,6 +106,9 @@ struct OpenGlReadbackFormat {
[[nodiscard]] std::uint32_t add_blend_equation() noexcept;
[[nodiscard]] std::uint32_t max_blend_equation() noexcept;
[[nodiscard]] std::uint32_t rgba8_internal_format() noexcept;
[[nodiscard]] std::uint32_t linear_texture_filter() noexcept;
[[nodiscard]] std::uint32_t nearest_texture_filter() noexcept;
[[nodiscard]] std::uint32_t repeat_texture_wrap() noexcept;
[[nodiscard]] std::uint32_t texture_cube_map_target() noexcept;
[[nodiscard]] std::uint32_t cube_map_allocation_face_texture_target(std::uint32_t face_index) noexcept;
[[nodiscard]] std::span<const std::uint32_t> panopainter_cube_face_texture_targets() noexcept;