Initial Grease Pencil 3.0 stage #106848
|
@ -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(
|
||||
|
||||
int frame, blender::FunctionRef<void(GreasePencilDrawing &)> function)
|
||||
{
|
||||
|
|
|
@ -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
Falk David
commented
Add tests for 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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -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);
|
||||
Hans Goudey
commented
Pretty sure null-terminated goes without saying for Pretty sure null-terminated goes without saying for `char *` pointers in DNA, I don't think it's worth mentioning here
Sergey Sharybin
commented
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.
Hans Goudey
commented
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);
|
||||
|
|
Loading…
Reference in New Issue
I believe it's standard to
std::move
from aT &&
Is there a need for overloads for
T &
andT &&
? What's the benefit of that?