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
3 changed files with 53 additions and 4 deletions
Showing only changes of commit 14f4073efc - Show all commits

View File

@ -16,6 +16,7 @@
#include "BLI_math_vector_types.hh"
#include "BLI_memarena.h"
#include "BLI_memory_utils.hh"
#include "BLI_polyfill_2d.h"
#include "BLI_span.hh"
#include "BLI_stack.hh"
@ -440,12 +441,47 @@ blender::Span<blender::bke::StrokePoint> GreasePencilDrawing::stroke_buffer()
/* GreasePencil API */
static void grease_pencil_grow_drawing_array_by(GreasePencil &self, const int added_capacity)
{
BLI_assert(added_capacity > 0);
const int new_drawing_array_size = self.drawing_array_size + added_capacity;
GreasePencilDrawingOrReference **new_drawing_array =
reinterpret_cast<GreasePencilDrawingOrReference **>(
MEM_cnew_array<GreasePencilDrawingOrReference *>(new_drawing_array_size, __func__));
blender::uninitialized_relocate_n(
self.drawing_array, self.drawing_array_size, new_drawing_array);
self.drawing_array = new_drawing_array;
self.drawing_array_size = new_drawing_array_size;
}
blender::Span<GreasePencilDrawingOrReference *> GreasePencil::drawings() const
{
return blender::Span<GreasePencilDrawingOrReference *>{this->drawing_array,
this->drawing_array_size};
}
blender::MutableSpan<GreasePencilDrawingOrReference *> GreasePencil::drawings_for_write()
{
return blender::MutableSpan<GreasePencilDrawingOrReference *>{this->drawing_array,
this->drawing_array_size};
}
void GreasePencil::add_empty_drawings(int n)
{
using namespace blender;
BLI_assert(n > 0);
const int prev_size = this->drawings().size();
grease_pencil_grow_drawing_array_by(*this, n);
MutableSpan<GreasePencilDrawingOrReference *> new_drawings =
this->drawings_for_write().drop_front(prev_size);
for (const int i : IndexRange(new_drawings.size())) {
new_drawings[i] = reinterpret_cast<GreasePencilDrawingOrReference *>(
MEM_new<GreasePencilDrawing>(__func__));
}
}
void GreasePencil::foreach_visible_drawing(

I believe it's standard to std::move from a T &&

Is there a need for overloads for T & and T &&? What's the benefit of that?

I believe it's standard to `std::move` from a `T &&` Is there a need for overloads for `T &` and `T &&`? What's the benefit of that?
int frame, blender::FunctionRef<void(GreasePencilDrawing &)> function)
{

View File

@ -33,9 +33,20 @@ TEST(gpencil, create_grease_pencil_id)
{
GreasePencilIDTestContext ctx;
GreasePencil *grease_pencil = static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
EXPECT_EQ(grease_pencil->drawings().size(), 0);
EXPECT_EQ(grease_pencil->root_group().total_num_children(), 0);
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
EXPECT_EQ(grease_pencil.drawings().size(), 0);
EXPECT_EQ(grease_pencil.root_group().total_num_children(), 0);
}
/* --------------------------------------------------------------------------------------------- */
filedescriptor marked this conversation as resolved Outdated

Add tests for load_layer_tree_from_storage and save_layer_tree_to_storage.

Add tests for `load_layer_tree_from_storage` and `save_layer_tree_to_storage`.
/* Drawing Array Tests. */
TEST(gpencil, add_empty_drawings)
{
GreasePencilIDTestContext ctx;
GreasePencil &grease_pencil = *static_cast<GreasePencil *>(BKE_id_new(ctx.bmain, ID_GP, "GP"));
grease_pencil.add_empty_drawings(3);
EXPECT_EQ(grease_pencil.drawings().size(), 3);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -21,7 +21,7 @@ struct StrokePoint;
namespace gpencil {
class Layer;
class LayerGroup;
}
} // namespace gpencil
} // namespace blender::bke
using GreasePencilRuntimeHandle = blender::bke::GreasePencilRuntime;
using GreasePencilDrawingRuntimeHandle = blender::bke::GreasePencilDrawingRuntime;
@ -179,6 +179,8 @@ typedef struct GreasePencil {
#ifdef __cplusplus
blender::Span<GreasePencilDrawingOrReference *> drawings() const;
blender::MutableSpan<GreasePencilDrawingOrReference *> drawings_for_write();
void add_empty_drawings(int n);

Pretty sure null-terminated goes without saying for char * pointers in DNA, I don't think it's worth mentioning here

Pretty sure null-terminated goes without saying for `char *` pointers in DNA, I don't think it's worth mentioning here

Not sure about dynamic names for strings. It is not something typically used in the DNA.

Not sure about dynamic names for strings. It is not something typically used in the DNA.

It's been done more recently I think. It's properly integrated with RNA now too, to avoid that boilerplate. It's nice not to have to worry about choosing a future-proof length.

It's been done more recently I think. It's properly integrated with RNA now too, to avoid that boilerplate. It's nice not to have to worry about choosing a future-proof length.
void foreach_visible_drawing(int frame,
blender::FunctionRef<void(GreasePencilDrawing &)> function);
void read_drawing_array(BlendDataReader *reader);