Narrow retained canvas stroke execution helpers
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
|
||||
@@ -46,12 +47,100 @@ struct LegacyCanvasStrokeCommitResult {
|
||||
int committed_faces = 0;
|
||||
};
|
||||
|
||||
struct LegacyCanvasStrokeCommitCopyExtent {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline std::size_t legacy_canvas_stroke_commit_step_count(
|
||||
const pp::paint_renderer::CanvasStrokeCommitSequencePlan& sequence) noexcept
|
||||
{
|
||||
return std::min(sequence.step_count, sequence.steps.size());
|
||||
}
|
||||
|
||||
[[nodiscard]] inline std::size_t legacy_canvas_stroke_commit_texture_binding_count(
|
||||
const pp::paint_renderer::CanvasStrokeCommitSequencePlan& sequence) noexcept
|
||||
{
|
||||
return std::min(sequence.texture_binding_count, sequence.texture_bindings.size());
|
||||
}
|
||||
|
||||
[[nodiscard]] inline int legacy_canvas_stroke_commit_texture_slot(
|
||||
const pp::paint_renderer::CanvasStrokeCommitSequencePlan& sequence,
|
||||
pp::paint_renderer::CanvasStrokeCommitTextureRole role) noexcept
|
||||
{
|
||||
const auto binding_count = legacy_canvas_stroke_commit_texture_binding_count(sequence);
|
||||
for (std::size_t binding_index = 0; binding_index < binding_count; ++binding_index) {
|
||||
const auto& binding = sequence.texture_bindings[binding_index];
|
||||
if (binding.role == role) {
|
||||
return static_cast<int>(binding.slot);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
template <typename SetActiveTextureUnit, typename BindTextureRole, typename BindSamplerRole>
|
||||
inline void bind_legacy_canvas_stroke_commit_inputs(
|
||||
const pp::paint_renderer::CanvasStrokeCommitSequencePlan& sequence,
|
||||
SetActiveTextureUnit&& set_active_texture_unit,
|
||||
BindTextureRole&& bind_texture_role,
|
||||
BindSamplerRole&& bind_sampler_role)
|
||||
{
|
||||
const auto binding_count = legacy_canvas_stroke_commit_texture_binding_count(sequence);
|
||||
for (std::size_t binding_index = 0; binding_index < binding_count; ++binding_index) {
|
||||
const auto& binding = sequence.texture_bindings[binding_index];
|
||||
set_active_texture_unit(static_cast<int>(binding.slot));
|
||||
bind_texture_role(binding.role);
|
||||
bind_sampler_role(binding.role, static_cast<int>(binding.slot));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SetupShader, typename DrawPlane>
|
||||
inline void execute_legacy_canvas_stroke_commit_erase(
|
||||
SetupShader&& setup_shader,
|
||||
DrawPlane&& draw_plane)
|
||||
{
|
||||
setup_shader();
|
||||
draw_plane();
|
||||
}
|
||||
|
||||
template <typename SetupShader, typename DrawPlane>
|
||||
inline void execute_legacy_canvas_stroke_commit_paint(
|
||||
SetupShader&& setup_shader,
|
||||
DrawPlane&& draw_plane)
|
||||
{
|
||||
setup_shader();
|
||||
draw_plane();
|
||||
}
|
||||
|
||||
template <typename SetupShader, typename SetActiveTextureUnit, typename BindLayerScratch, typename CopyFramebufferToTexture>
|
||||
inline void copy_legacy_canvas_stroke_commit_to_dilate_source(
|
||||
const pp::paint_renderer::CanvasStrokeCommitSequencePlan& sequence,
|
||||
SetupShader&& setup_shader,
|
||||
SetActiveTextureUnit&& set_active_texture_unit,
|
||||
BindLayerScratch&& bind_layer_scratch,
|
||||
CopyFramebufferToTexture&& copy_framebuffer_to_texture,
|
||||
LegacyCanvasStrokeCommitCopyExtent extent)
|
||||
{
|
||||
const auto layer_scratch_slot = legacy_canvas_stroke_commit_texture_slot(
|
||||
sequence,
|
||||
pp::paint_renderer::CanvasStrokeCommitTextureRole::layer_scratch);
|
||||
if (layer_scratch_slot < 0 || extent.width <= 0 || extent.height <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setup_shader();
|
||||
set_active_texture_unit(layer_scratch_slot);
|
||||
bind_layer_scratch();
|
||||
copy_framebuffer_to_texture(0, 0, 0, 0, extent.width, extent.height);
|
||||
}
|
||||
|
||||
template <typename DrawPlane>
|
||||
inline void execute_legacy_canvas_stroke_commit_dilate(DrawPlane&& draw_plane)
|
||||
{
|
||||
draw_plane();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool legacy_canvas_stroke_commit_callbacks_ready(
|
||||
const LegacyCanvasStrokeCommitCallbacks& callbacks) noexcept
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user