Move render target clear mapping to renderer gl

This commit is contained in:
2026-06-02 06:38:32 +02:00
parent e00eec30d4
commit 02f14f1bf5
6 changed files with 51 additions and 12 deletions

View File

@@ -43,6 +43,8 @@ constexpr std::uint32_t gl_framebuffer_unsupported = 0x8CDDU;
constexpr std::uint32_t gl_framebuffer_undefined = 0x8219U;
constexpr std::uint32_t gl_framebuffer_incomplete_multisample = 0x8D56U;
constexpr std::uint32_t gl_color_buffer_bit = 0x00004000U;
constexpr std::uint32_t gl_depth_buffer_bit = 0x00000100U;
constexpr std::uint32_t gl_color_writemask = 0x0C23U;
constexpr std::uint32_t gl_texture_cube_map_positive_x = 0x8515U;
constexpr std::uint32_t gl_texture_cube_map_negative_x = 0x8516U;
constexpr std::uint32_t gl_texture_cube_map_positive_y = 0x8517U;
@@ -121,6 +123,11 @@ std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_for
}
}
std::uint32_t rgba_pixel_format() noexcept
{
return gl_rgba;
}
OpenGlPixelFormat texture_format_for_channel_count(std::uint32_t channel_count) noexcept
{
switch (channel_count) {
@@ -267,6 +274,16 @@ std::uint32_t framebuffer_color_buffer_mask() noexcept
return gl_color_buffer_bit;
}
std::uint32_t framebuffer_depth_buffer_mask() noexcept
{
return gl_depth_buffer_bit;
}
std::uint32_t color_write_mask_query() noexcept
{
return gl_color_writemask;
}
std::uint32_t framebuffer_blit_filter(bool linear) noexcept
{
return linear ? gl_linear : gl_nearest;

View File

@@ -43,6 +43,7 @@ struct OpenGlReadbackFormat {
OpenGlRuntime runtime) noexcept;
[[nodiscard]] std::uint32_t texture_upload_type_for_internal_format(std::uint32_t internal_format) noexcept;
[[nodiscard]] std::uint32_t rgba_pixel_format() noexcept;
[[nodiscard]] OpenGlPixelFormat texture_format_for_channel_count(std::uint32_t channel_count) noexcept;
[[nodiscard]] OpenGlReadbackFormat rgba8_readback_format() noexcept;
[[nodiscard]] OpenGlReadbackFormat rgba32f_readback_format() noexcept;
@@ -67,6 +68,8 @@ struct OpenGlReadbackFormat {
[[nodiscard]] std::uint32_t framebuffer_complete_status() 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;
[[nodiscard]] std::uint32_t color_write_mask_query() noexcept;
[[nodiscard]] std::uint32_t framebuffer_blit_filter(bool linear) noexcept;
[[nodiscard]] std::uint32_t index_type_for_index_size(std::uint32_t index_size_bytes) noexcept;
[[nodiscard]] std::uint32_t primitive_mode_for_fill_count(std::uint32_t vertex_or_index_count) noexcept;

View File

@@ -263,7 +263,16 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format,
glBindTexture(texture_2d_target(), texID);
if (tex == -1)
glTexImage2D(texture_2d_target(), 0, internal_format, width, height, 0, GL_RGBA, ifmt, 0);
glTexImage2D(
texture_2d_target(),
0,
internal_format,
width,
height,
0,
static_cast<GLenum>(pp::renderer::gl::rgba_pixel_format()),
ifmt,
0);
for (const auto parameter : pp::renderer::gl::default_render_target_texture_parameters())
{
glTexParameterf(
@@ -361,7 +370,9 @@ void RTT::clear(glm::vec4 color)
{
assert(App::I->is_render_thread());
glClearColor(color.r, color.g, color.b, color.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(static_cast<GLbitfield>(
pp::renderer::gl::framebuffer_color_buffer_mask()
| pp::renderer::gl::framebuffer_depth_buffer_mask()));
}
void RTT::clear_mask(glm::bool4 mask, glm::vec4 color)
@@ -369,12 +380,12 @@ void RTT::clear_mask(glm::bool4 mask, glm::vec4 color)
assert(App::I->is_render_thread());
// save old state
std::array<GLboolean, 4> old_mask;
glGetBooleanv(GL_COLOR_WRITEMASK, old_mask.data());
glGetBooleanv(static_cast<GLenum>(pp::renderer::gl::color_write_mask_query()), old_mask.data());
// clear with mask
glColorMask(mask.r, mask.g, mask.b, mask.a);
glClearColor(color.r, color.g, color.b, color.a);
glClear(GL_COLOR_BUFFER_BIT);
glClear(static_cast<GLbitfield>(pp::renderer::gl::framebuffer_color_buffer_mask()));
// restore old state
glColorMask(old_mask[0], old_mask[1], old_mask[2], old_mask[3]);