Extract stroke dirty bounds planning
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "paint_renderer/compositor.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <array>
|
||||
@@ -13,6 +14,7 @@ struct LegacyStrokeSampleExecutionRequest {
|
||||
std::string_view context;
|
||||
glm::vec2 target_size {};
|
||||
std::span<const vertex_t> vertices;
|
||||
std::span<const pp::paint_renderer::CanvasStrokePoint> sample_points;
|
||||
bool copy_stroke_destination = false;
|
||||
std::function<void()> bind_destination_texture;
|
||||
std::function<void(int, int, int, int, int, int)> copy_framebuffer_to_destination_texture;
|
||||
@@ -49,25 +51,28 @@ struct LegacyStrokeSampleExecutionResult {
|
||||
request.bind_destination_texture();
|
||||
}
|
||||
|
||||
glm::vec2 bb_min(request.target_size);
|
||||
glm::vec2 bb_max(0.0f, 0.0f);
|
||||
for (const auto& vertex : request.vertices) {
|
||||
bb_min = glm::max({ 0.0f, 0.0f }, glm::min(bb_min, xy(vertex.pos)));
|
||||
bb_max = glm::min(request.target_size, glm::max(bb_max, xy(vertex.pos)));
|
||||
const auto sample_bounds = pp::paint_renderer::plan_canvas_stroke_sample_bounds(
|
||||
pp::paint_renderer::CanvasStrokeSampleBoundsRequest {
|
||||
.extent = pp::renderer::Extent2D {
|
||||
.width = static_cast<std::uint32_t>(request.target_size.x),
|
||||
.height = static_cast<std::uint32_t>(request.target_size.y),
|
||||
},
|
||||
.vertices = request.sample_points,
|
||||
});
|
||||
if (!sample_bounds.has_pixels) {
|
||||
if (request.copy_stroke_destination) {
|
||||
request.unbind_destination_texture();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const auto bb_sz = bb_max - bb_min;
|
||||
const glm::vec2 pad(1.0f);
|
||||
const glm::ivec2 target_extent(request.target_size);
|
||||
result.copy_position = glm::clamp(
|
||||
glm::floor(bb_min) - pad,
|
||||
glm::vec2(0.0f),
|
||||
request.target_size);
|
||||
result.copy_size = glm::clamp(
|
||||
glm::ceil(bb_sz) + pad * 2.0f,
|
||||
glm::vec2(0.0f),
|
||||
glm::vec2(target_extent - result.copy_position));
|
||||
result.dirty_bounds = glm::vec4(result.copy_position, result.copy_position + result.copy_size);
|
||||
result.copy_position = glm::ivec2(sample_bounds.copy_region.x, sample_bounds.copy_region.y);
|
||||
result.copy_size = glm::ivec2(sample_bounds.copy_region.width, sample_bounds.copy_region.height);
|
||||
result.dirty_bounds = glm::vec4(
|
||||
sample_bounds.dirty_bounds.min_x,
|
||||
sample_bounds.dirty_bounds.min_y,
|
||||
sample_bounds.dirty_bounds.max_x,
|
||||
sample_bounds.dirty_bounds.max_y);
|
||||
|
||||
if (request.copy_stroke_destination) {
|
||||
request.copy_framebuffer_to_destination_texture(
|
||||
|
||||
Reference in New Issue
Block a user