Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
4 changed files with 28 additions and 11 deletions
Showing only changes of commit 4949aa74ee - Show all commits

View File

@ -225,6 +225,9 @@ void legacy_gpencil_to_grease_pencil(GreasePencil &grease_pencil, bGPdata &gpd);
} // namespace greasepencil
/**
* A single point for a stroke that is currently being drawn.
*/
struct StrokePoint {
float3 position;
float radius;
@ -232,16 +235,30 @@ struct StrokePoint {
float4 color;
};
class GreasePencilDrawingRuntime {
public:
mutable SharedCache<Vector<uint3>> triangles_cache;
/**
/**
* Stroke cache for a stroke that is currently being drawn.
*/
Vector<StrokePoint> stroke_cache = {};
Vector<uint3> stroke_triangle_cache = {};
int stroke_mat = 0;
struct StrokeCache {
Vector<StrokePoint> points = {};
Vector<uint3> triangles = {};
int mat = 0;
void clear()
{
this->points.clear_and_shrink();
this->triangles.clear_and_shrink();
this->mat = 0;
}
};
class GreasePencilDrawingRuntime {
public:
/**
* Triangle cache for all the strokes in the drawing.
*/
mutable SharedCache<Vector<uint3>> triangles_cache;
StrokeCache stroke_cache;
};
class GreasePencilRuntime {

View File

@ -740,12 +740,12 @@ void GreasePencilDrawing::tag_positions_changed()
bool GreasePencilDrawing::has_stroke_buffer()
{
return this->runtime->stroke_cache.size() > 0;
return this->runtime->stroke_cache.points.size() > 0;
}
blender::Span<blender::bke::StrokePoint> GreasePencilDrawing::stroke_buffer()
{
return this->runtime->stroke_cache.as_span();
return this->runtime->stroke_cache.points.as_span();
}
/** \} */

View File

@ -363,7 +363,7 @@ static void grease_pencil_batches_ensure(GreasePencil &grease_pencil, int cfra)
IndexRange verts_range = IndexRange(verts_start_offset, num_verts);
MutableSpan<GreasePencilStrokeVert> verts_slice = verts.slice(verts_range);
MutableSpan<GreasePencilColorVert> cols_slice = cols.slice(verts_range);
const int material_nr = drawing.runtime->stroke_mat;
const int material_nr = drawing.runtime->stroke_cache.mat;
verts_slice.first().mat = -1;
for (const int i : IndexRange(points.size())) {

View File

@ -64,7 +64,7 @@ struct PaintOperationExecutor {
StrokePoint new_point{proj_pos, stroke_extension.pressure * 100.0f, 1.0f, float4(1.0f)};
drawing.runtime->stroke_cache.append(std::move(new_point));
drawing.runtime->stroke_cache.points.append(std::move(new_point));
BKE_grease_pencil_batch_cache_dirty_tag(&grease_pencil, BKE_GREASEPENCIL_BATCH_DIRTY_ALL);
}
@ -151,7 +151,7 @@ void PaintOperation::on_stroke_done(const bContext &C)
return true;
});
drawing_eval.runtime->stroke_cache.clear_and_shrink();
drawing_eval.runtime->stroke_cache.clear();
drawing_orig.tag_positions_changed();
radii.finish();