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
8 changed files with 116 additions and 10 deletions
Showing only changes of commit 1d67ad4d7e - Show all commits

View File

@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
filedescriptor marked this conversation as resolved Outdated

Needs copyright.

Needs copyright.
#pragma once
#include "DNA_grease_pencil_types.h"
/** \file
* \ingroup bke
* \brief Low-level operations for grease pencil that cannot be defined in the C++ header yet.
*/
#ifdef __cplusplus
extern "C" {
#endif
enum {
BKE_GREASEPENCIL_BATCH_DIRTY_ALL = 0,
};
extern void (*BKE_grease_pencil_batch_cache_dirty_tag_cb)(GreasePencil *grease_pencil, int mode);
extern void (*BKE_grease_pencil_batch_cache_free_cb)(GreasePencil *grease_pencil);
void BKE_grease_pencil_batch_cache_dirty_tag(GreasePencil *grease_pencil, int mode);
void BKE_grease_pencil_batch_cache_free(GreasePencil *grease_pencil);
#ifdef __cplusplus
}
#endif

View File

@ -390,6 +390,7 @@ set(SRC
BKE_gpencil_geom_legacy.h
BKE_gpencil_modifier_legacy.h
BKE_gpencil_update_cache_legacy.h
BKE_grease_pencil.h
BKE_grease_pencil.hh
BKE_icons.h
BKE_idprop.h

View File

@ -95,10 +95,12 @@ static void grease_pencil_free_data(ID *id)
GreasePencil *grease_pencil = (GreasePencil *)id;
BKE_animdata_free(&grease_pencil->id, false);
MEM_SAFE_FREE(grease_pencil->material_array);
grease_pencil->free_drawing_array();
grease_pencil->free_layer_tree_storage();
MEM_SAFE_FREE(grease_pencil->material_array);
BKE_grease_pencil_batch_cache_free(grease_pencil);
MEM_delete(grease_pencil->runtime);
grease_pencil->runtime = nullptr;
@ -228,6 +230,20 @@ IDTypeInfo IDType_ID_GP = {
/*lib_override_apply_post*/ nullptr,
};
namespace blender::bke::gpencil {
LayerGroup &TreeNode::as_group()
{
return *static_cast<LayerGroup *>(this);
}
Layer &TreeNode::as_layer()
{
return *static_cast<Layer *>(this);
}
} // namespace blender::bke::gpencil
void *BKE_grease_pencil_add(Main *bmain, const char *name)
{
GreasePencil *grease_pencil = static_cast<GreasePencil *>(BKE_id_new(bmain, ID_GP, name));
@ -276,20 +292,26 @@ BoundBox *BKE_grease_pencil_boundbox_get(Object *ob)
return ob->runtime.bb;
}
namespace blender::bke::gpencil {
/* Draw Cache */

This should only consider the current frame.

This should only consider the current frame.
LayerGroup &TreeNode::as_group()
void (*BKE_grease_pencil_batch_cache_dirty_tag_cb)(GreasePencil *grease_pencil,
int mode) = nullptr;
void (*BKE_grease_pencil_batch_cache_free_cb)(GreasePencil *grease_pencil) = nullptr;
void BKE_grease_pencil_batch_cache_dirty_tag(GreasePencil *grease_pencil, int mode)
{
return *static_cast<LayerGroup *>(this);
if (grease_pencil->runtime && grease_pencil->runtime->batch_cache) {
BKE_grease_pencil_batch_cache_dirty_tag_cb(grease_pencil, mode);
filedescriptor marked this conversation as resolved Outdated

Make sure to not overwrite min and max but account any value already present. E.g. use math::min_max(...).

Make sure to not overwrite `min` and `max` but account any value already present. E.g. use `math::min_max(...)`.
}
}
Layer &TreeNode::as_layer()
void BKE_grease_pencil_batch_cache_free(GreasePencil *grease_pencil)
{
return *static_cast<Layer *>(this);
if (grease_pencil->runtime && grease_pencil->runtime->batch_cache) {
BKE_grease_pencil_batch_cache_free_cb(grease_pencil);
}
}
} // namespace blender::bke::gpencil
blender::Span<GreasePencilDrawingOrReference *> GreasePencil::drawings() const
{
return blender::Span<GreasePencilDrawingOrReference *>{this->drawing_array,

View File

@ -31,6 +31,7 @@
#include "BKE_effect.h"
#include "BKE_gpencil_legacy.h"
#include "BKE_gpencil_modifier_legacy.h"
#include "BKE_grease_pencil.h"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_lattice.h"
@ -321,6 +322,8 @@ void BKE_object_batch_cache_dirty_tag(Object *ob)
break;
case OB_GREASE_PENCIL:
filedescriptor marked this conversation as resolved Outdated

Remove todo.

Remove todo.
/* TODO: tag batches. */
BKE_grease_pencil_batch_cache_dirty_tag((struct GreasePencil *)ob->data,
BKE_GREASEPENCIL_BATCH_DIRTY_ALL);
break;
default:
break;

View File

@ -6,6 +6,7 @@
#include "DNA_curve_types.h"
#include "DNA_curves_types.h"
#include "DNA_grease_pencil_types.h"
#include "DNA_lattice_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
@ -3298,6 +3299,8 @@ void drw_batch_cache_validate(Object *ob)
case OB_VOLUME:
DRW_volume_batch_cache_validate((Volume *)ob->data);
break;
case OB_GREASE_PENCIL:
DRW_grease_pencil_batch_cache_validate((GreasePencil *)ob->data);
default:
break;
}

View File

@ -22,6 +22,7 @@ struct Mesh;
struct PointCloud;
struct Volume;
struct bGPdata;
struct GreasePencil;
#include "BKE_mesh_types.h"
@ -63,6 +64,10 @@ void DRW_volume_batch_cache_dirty_tag(struct Volume *volume, int mode);
void DRW_volume_batch_cache_validate(struct Volume *volume);
void DRW_volume_batch_cache_free(struct Volume *volume);
void DRW_grease_pencil_batch_cache_dirty_tag(struct GreasePencil *grase_pencil, int mode);
void DRW_grease_pencil_batch_cache_validate(struct GreasePencil *grase_pencil);
void DRW_grease_pencil_batch_cache_free(struct GreasePencil *grase_pencil);
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -7,6 +7,7 @@
*/
#include "BKE_curves.hh"
#include "BKE_grease_pencil.h"
#include "BKE_grease_pencil.hh"
#include "BLI_task.hh"
@ -18,6 +19,8 @@
#include "GPU_batch.h"
#include "draw_cache_impl.h"
#include "../engines/gpencil/gpencil_defines.h"
namespace blender::draw {
@ -116,7 +119,7 @@ static GreasePencilBatchCache *grease_pencil_batch_cache_init(GreasePencil &grea
return cache;
}
static void grese_pencil_batch_cache_clear(GreasePencil &grease_pencil)
static void grease_pencil_batch_cache_clear(GreasePencil &grease_pencil)
{
BLI_assert(grease_pencil.runtime != nullptr);
GreasePencilBatchCache *cache = static_cast<GreasePencilBatchCache *>(
@ -140,7 +143,7 @@ static GreasePencilBatchCache *grease_pencil_batch_cache_get(GreasePencil &greas
GreasePencilBatchCache *cache = static_cast<GreasePencilBatchCache *>(
grease_pencil.runtime->batch_cache);
if (!grease_pencil_batch_cache_valid(grease_pencil)) {
grese_pencil_batch_cache_clear(grease_pencil);
grease_pencil_batch_cache_clear(grease_pencil);
return grease_pencil_batch_cache_init(grease_pencil, cfra);
}
@ -298,6 +301,43 @@ static void grease_pencil_batches_ensure(GreasePencil &grease_pencil, int cfra)
} // namespace blender::draw
void DRW_grease_pencil_batch_cache_dirty_tag(GreasePencil *grease_pencil, int mode)
{
using namespace blender::draw;

Add details about TODO. Something that helps others to pick up a task, or to understand that specific case is not expected to be yet working.

Add details about TODO. Something that helps others to pick up a task, or to understand that specific case is not expected to be yet working.
BLI_assert(grease_pencil->runtime != nullptr);
GreasePencilBatchCache *cache = static_cast<GreasePencilBatchCache *>(
grease_pencil->runtime->batch_cache);
if (cache == nullptr) {
return;
}
switch (mode) {
case BKE_GREASEPENCIL_BATCH_DIRTY_ALL:
cache->is_dirty = true;
break;
default:
BLI_assert_unreachable();
}
}
void DRW_grease_pencil_batch_cache_validate(GreasePencil *grease_pencil)
{
using namespace blender::draw;
BLI_assert(grease_pencil->runtime != nullptr);
if (!grease_pencil_batch_cache_valid(*grease_pencil)) {
grease_pencil_batch_cache_clear(*grease_pencil);
/* TODO: pass correct frame here? */
grease_pencil_batch_cache_init(*grease_pencil, 0);
}
}
void DRW_grease_pencil_batch_cache_free(GreasePencil *grease_pencil)
{
using namespace blender::draw;
grease_pencil_batch_cache_clear(*grease_pencil);
MEM_delete(static_cast<GreasePencilBatchCache *>(grease_pencil->runtime->batch_cache));
grease_pencil->runtime->batch_cache = nullptr;
}
GPUBatch *DRW_cache_grease_pencil_get(Object *ob, int cfra)
{
using namespace blender::draw;

View File

@ -25,6 +25,7 @@
#include "BKE_editmesh.h"
#include "BKE_global.h"
#include "BKE_gpencil_legacy.h"
#include "BKE_grease_pencil.h"
#include "BKE_lattice.h"
#include "BKE_main.h"
#include "BKE_mball.h"
@ -3052,6 +3053,9 @@ void DRW_engines_register(void)
BKE_volume_batch_cache_dirty_tag_cb = DRW_volume_batch_cache_dirty_tag;
BKE_volume_batch_cache_free_cb = DRW_volume_batch_cache_free;
BKE_grease_pencil_batch_cache_dirty_tag_cb = DRW_grease_pencil_batch_cache_dirty_tag;
BKE_grease_pencil_batch_cache_free_cb = DRW_grease_pencil_batch_cache_free;
BKE_subsurf_modifier_free_gpu_cache_cb = DRW_subdiv_cache_free;
}
}