mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibGL: Fix scissor box coordinate system
We were working with (0, 0) being the top-left of the render target, but `glScissor` documentation states that this should be the bottom-left instead.
This commit is contained in:
parent
e967d31a98
commit
930782a155
1 changed files with 8 additions and 3 deletions
|
@ -54,6 +54,11 @@ static FloatVector4 to_vec4(Gfx::RGBA32 rgba)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Gfx::IntRect scissor_box_to_window_coordinates(Gfx::IntRect const& scissor_box, Gfx::IntRect const& window_rect)
|
||||||
|
{
|
||||||
|
return scissor_box.translated(0, window_rect.height() - 2 * scissor_box.y() - scissor_box.height());
|
||||||
|
}
|
||||||
|
|
||||||
static constexpr void setup_blend_factors(GLenum mode, FloatVector4& constant, float& src_alpha, float& dst_alpha, float& src_color, float& dst_color)
|
static constexpr void setup_blend_factors(GLenum mode, FloatVector4& constant, float& src_alpha, float& dst_alpha, float& src_color, float& dst_color)
|
||||||
{
|
{
|
||||||
constant = { 0.0f, 0.0f, 0.0f, 0.0f };
|
constant = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
@ -185,7 +190,7 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re
|
||||||
// Calculate block-based bounds
|
// Calculate block-based bounds
|
||||||
auto render_bounds = render_target.rect();
|
auto render_bounds = render_target.rect();
|
||||||
if (options.scissor_enabled)
|
if (options.scissor_enabled)
|
||||||
render_bounds.intersect(options.scissor_box);
|
render_bounds.intersect(scissor_box_to_window_coordinates(options.scissor_box, render_target.rect()));
|
||||||
int const block_padding = RASTERIZER_BLOCK_SIZE - 1;
|
int const block_padding = RASTERIZER_BLOCK_SIZE - 1;
|
||||||
// clang-format off
|
// clang-format off
|
||||||
int const bx0 = max(render_bounds.left(), min(min(v0.x(), v1.x()), v2.x())) / RASTERIZER_BLOCK_SIZE;
|
int const bx0 = max(render_bounds.left(), min(min(v0.x(), v1.x()), v2.x())) / RASTERIZER_BLOCK_SIZE;
|
||||||
|
@ -576,7 +581,7 @@ void SoftwareRasterizer::clear_color(const FloatVector4& color)
|
||||||
|
|
||||||
if (m_options.scissor_enabled) {
|
if (m_options.scissor_enabled) {
|
||||||
auto fill_rect = m_render_target->rect();
|
auto fill_rect = m_render_target->rect();
|
||||||
fill_rect.intersect(m_options.scissor_box);
|
fill_rect.intersect(scissor_box_to_window_coordinates(m_options.scissor_box, fill_rect));
|
||||||
Gfx::Painter painter { *m_render_target };
|
Gfx::Painter painter { *m_render_target };
|
||||||
painter.fill_rect(fill_rect, fill_color);
|
painter.fill_rect(fill_rect, fill_color);
|
||||||
return;
|
return;
|
||||||
|
@ -590,7 +595,7 @@ void SoftwareRasterizer::clear_depth(float depth)
|
||||||
wait_for_all_threads();
|
wait_for_all_threads();
|
||||||
|
|
||||||
if (m_options.scissor_enabled) {
|
if (m_options.scissor_enabled) {
|
||||||
m_depth_buffer->clear(m_options.scissor_box, depth);
|
m_depth_buffer->clear(scissor_box_to_window_coordinates(m_options.scissor_box, m_render_target->rect()), depth);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue