Refactor: Grease Pencil: Port rendering to new draw manager
Pull Request: https://projects.blender.org/blender/blender/pulls/130337
This commit is contained in:
committed by
Clément Foucault
parent
e44ae763bc
commit
b0c0c2708d
@@ -331,7 +331,8 @@ GPENCIL_tLayer *grease_pencil_layer_cache_add(GPENCIL_PrivateData *pd,
|
||||
pd, grease_pencil, onion_id, &layer_alpha);
|
||||
|
||||
/* Create the new layer descriptor. */
|
||||
GPENCIL_tLayer *tgp_layer = static_cast<GPENCIL_tLayer *>(BLI_memblock_alloc(pd->gp_layer_pool));
|
||||
int64_t id = pd->gp_layer_pool->append_and_get_index({});
|
||||
GPENCIL_tLayer *tgp_layer = &(*pd->gp_layer_pool)[id];
|
||||
BLI_LINKS_APPEND(&tgp_ob->layers, tgp_layer);
|
||||
tgp_layer->layer_id = *grease_pencil.get_layer_index(layer);
|
||||
tgp_layer->is_onion = onion_id != 0;
|
||||
@@ -404,26 +405,27 @@ GPENCIL_tLayer *grease_pencil_layer_cache_add(GPENCIL_PrivateData *pd,
|
||||
pd->use_signed_fb = true;
|
||||
}
|
||||
|
||||
tgp_layer->blend_ps = DRW_pass_create("GPencil Blend Layer", state);
|
||||
|
||||
GPUShader *sh = GPENCIL_shader_layer_blend_get();
|
||||
DRWShadingGroup *grp = DRW_shgroup_create(sh, tgp_layer->blend_ps);
|
||||
DRW_shgroup_uniform_int_copy(grp, "blendMode", layer.blend_mode);
|
||||
DRW_shgroup_uniform_float_copy(grp, "blendOpacity", layer_opacity);
|
||||
DRW_shgroup_uniform_texture_ref(grp, "colorBuf", &pd->color_layer_tx);
|
||||
DRW_shgroup_uniform_texture_ref(grp, "revealBuf", &pd->reveal_layer_tx);
|
||||
DRW_shgroup_uniform_texture_ref(grp, "maskBuf", (is_masked) ? &pd->mask_tx : &pd->dummy_tx);
|
||||
DRW_shgroup_stencil_mask(grp, 0xFF);
|
||||
DRW_shgroup_call_procedural_triangles(grp, nullptr, 1);
|
||||
if (tgp_layer->blend_ps == nullptr) {
|
||||
tgp_layer->blend_ps = std::make_unique<PassSimple>("GPencil Blend Layer");
|
||||
}
|
||||
PassSimple &pass = *tgp_layer->blend_ps;
|
||||
pass.init();
|
||||
pass.state_set(state);
|
||||
pass.shader_set(GPENCIL_shader_layer_blend_get());
|
||||
pass.push_constant("blendMode", int(layer.blend_mode));
|
||||
pass.push_constant("blendOpacity", layer_opacity);
|
||||
pass.bind_texture("colorBuf", &pd->color_layer_tx);
|
||||
pass.bind_texture("revealBuf", &pd->reveal_layer_tx);
|
||||
pass.bind_texture("maskBuf", (is_masked) ? &pd->mask_tx : &pd->dummy_tx);
|
||||
pass.state_stencil(0xFF, 0xFF, 0xFF);
|
||||
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
|
||||
if (layer.blend_mode == GP_LAYER_BLEND_HARDLIGHT) {
|
||||
/* We cannot do custom blending on Multi-Target frame-buffers.
|
||||
* Workaround by doing 2 passes. */
|
||||
grp = DRW_shgroup_create(sh, tgp_layer->blend_ps);
|
||||
DRW_shgroup_state_disable(grp, DRW_STATE_BLEND_MUL);
|
||||
DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ADD_FULL);
|
||||
DRW_shgroup_uniform_int_copy(grp, "blendMode", 999);
|
||||
DRW_shgroup_call_procedural_triangles(grp, nullptr, 1);
|
||||
pass.state_set((state & ~DRW_STATE_BLEND_MUL) | DRW_STATE_BLEND_ADD_FULL);
|
||||
pass.push_constant("blendMode", 999);
|
||||
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
|
||||
}
|
||||
|
||||
pd->use_layer_fb = true;
|
||||
@@ -431,6 +433,12 @@ GPENCIL_tLayer *grease_pencil_layer_cache_add(GPENCIL_PrivateData *pd,
|
||||
|
||||
/* Geometry pass */
|
||||
{
|
||||
if (tgp_layer->geom_ps == nullptr) {
|
||||
tgp_layer->geom_ps = std::make_unique<PassSimple>("GPencil Layer");
|
||||
}
|
||||
|
||||
PassSimple &pass = *tgp_layer->geom_ps;
|
||||
|
||||
GPUTexture *depth_tex = (is_in_front) ? pd->dummy_tx : pd->scene_depth_tx;
|
||||
GPUTexture **mask_tex = (is_masked) ? &pd->mask_tx : &pd->dummy_tx;
|
||||
|
||||
@@ -440,32 +448,29 @@ GPENCIL_tLayer *grease_pencil_layer_cache_add(GPENCIL_PrivateData *pd,
|
||||
/* Always write stencil. Only used as optimization for blending. */
|
||||
state |= DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS;
|
||||
|
||||
tgp_layer->geom_ps = DRW_pass_create("GPencil Layer", state);
|
||||
|
||||
GPUShader *sh = GPENCIL_shader_geometry_get();
|
||||
DRWShadingGroup *grp = tgp_layer->base_shgrp = DRW_shgroup_create(sh, tgp_layer->geom_ps);
|
||||
|
||||
DRW_shgroup_uniform_texture(grp, "gpSceneDepthTexture", depth_tex);
|
||||
DRW_shgroup_uniform_texture_ref(grp, "gpMaskTexture", mask_tex);
|
||||
DRW_shgroup_uniform_vec3_copy(grp, "gpNormal", tgp_ob->plane_normal);
|
||||
DRW_shgroup_uniform_bool_copy(grp, "gpStrokeOrder3d", tgp_ob->is_drawmode3d);
|
||||
DRW_shgroup_uniform_float_copy(grp, "gpThicknessScale", tgp_ob->object_scale);
|
||||
pass.state_set(state);
|
||||
pass.shader_set(GPENCIL_shader_geometry_get());
|
||||
pass.bind_texture("gpSceneDepthTexture", depth_tex);
|
||||
pass.bind_texture("gpMaskTexture", mask_tex);
|
||||
pass.push_constant("gpNormal", tgp_ob->plane_normal);
|
||||
pass.push_constant("gpStrokeOrder3d", tgp_ob->is_drawmode3d);
|
||||
pass.push_constant("gpThicknessScale", tgp_ob->object_scale);
|
||||
/* Replaced by a modifier in GPv3. */
|
||||
DRW_shgroup_uniform_float_copy(grp, "gpThicknessOffset", 0.0f);
|
||||
DRW_shgroup_uniform_float_copy(grp, "gpThicknessWorldScale", thickness_scale);
|
||||
DRW_shgroup_uniform_float_copy(grp, "gpVertexColorOpacity", vert_col_opacity);
|
||||
pass.push_constant("gpThicknessOffset", 0.0f);
|
||||
pass.push_constant("gpThicknessWorldScale", thickness_scale);
|
||||
pass.push_constant("gpVertexColorOpacity", vert_col_opacity);
|
||||
|
||||
/* If random color type, need color by layer. */
|
||||
float gpl_color[4];
|
||||
float4 gpl_color;
|
||||
copy_v4_v4(gpl_color, layer_tint);
|
||||
if (pd->v3d_color_type == V3D_SHADING_RANDOM_COLOR) {
|
||||
grease_pencil_layer_random_color_get(ob, layer, gpl_color);
|
||||
gpl_color[3] = 1.0f;
|
||||
}
|
||||
DRW_shgroup_uniform_vec4_copy(grp, "gpLayerTint", gpl_color);
|
||||
pass.push_constant("gpLayerTint", gpl_color);
|
||||
|
||||
DRW_shgroup_uniform_float_copy(grp, "gpLayerOpacity", layer_alpha);
|
||||
DRW_shgroup_stencil_mask(grp, 0xFF);
|
||||
pass.push_constant("gpLayerOpacity", layer_alpha);
|
||||
pass.state_stencil(0xFF, 0xFF, 0xFF);
|
||||
}
|
||||
|
||||
return tgp_layer;
|
||||
|
||||
@@ -451,7 +451,7 @@ static void gpencil_view_layer_data_free(void *storage)
|
||||
BLI_memblock_destroy(vldata->gp_material_pool, gpencil_material_pool_free);
|
||||
BLI_memblock_destroy(vldata->gp_maskbit_pool, nullptr);
|
||||
BLI_memblock_destroy(vldata->gp_object_pool, nullptr);
|
||||
BLI_memblock_destroy(vldata->gp_layer_pool, nullptr);
|
||||
delete vldata->gp_layer_pool;
|
||||
delete vldata->gp_vfx_pool;
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ GPENCIL_ViewLayerData *GPENCIL_view_layer_data_ensure()
|
||||
(*vldata)->gp_material_pool = BLI_memblock_create(sizeof(GPENCIL_MaterialPool));
|
||||
(*vldata)->gp_maskbit_pool = BLI_memblock_create(BLI_BITMAP_SIZE(GP_MAX_MASKBITS));
|
||||
(*vldata)->gp_object_pool = BLI_memblock_create(sizeof(GPENCIL_tObject));
|
||||
(*vldata)->gp_layer_pool = BLI_memblock_create(sizeof(GPENCIL_tLayer));
|
||||
(*vldata)->gp_layer_pool = new GPENCIL_tLayer_Pool();
|
||||
(*vldata)->gp_vfx_pool = new GPENCIL_tVfx_Pool();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,13 @@ struct bGPDstroke;
|
||||
#define GP_MAX_MASKBITS 256
|
||||
|
||||
struct GPENCIL_tVfx;
|
||||
struct GPENCIL_tLayer;
|
||||
|
||||
using PassSimple = blender::draw::PassSimple;
|
||||
/* NOTE: These do not preserve the PassSimple memory across frames.
|
||||
* If that becomes a bottleneck, these containers can be improved. */
|
||||
using GPENCIL_tVfx_Pool = blender::draw::detail::SubPassVector<GPENCIL_tVfx>;
|
||||
using GPENCIL_tLayer_Pool = blender::draw::detail::SubPassVector<GPENCIL_tLayer>;
|
||||
|
||||
/* *********** Draw Data *********** */
|
||||
typedef struct GPENCIL_MaterialPool {
|
||||
@@ -80,7 +85,7 @@ struct GPENCIL_ViewLayerData {
|
||||
/* GPENCIL_tObject */
|
||||
struct BLI_memblock *gp_object_pool;
|
||||
/* GPENCIL_tLayer */
|
||||
struct BLI_memblock *gp_layer_pool;
|
||||
GPENCIL_tLayer_Pool *gp_layer_pool;
|
||||
/* GPENCIL_tVfx */
|
||||
GPENCIL_tVfx_Pool *gp_vfx_pool;
|
||||
/* GPENCIL_MaterialPool */
|
||||
@@ -94,7 +99,6 @@ struct GPENCIL_ViewLayerData {
|
||||
/* *********** GPencil *********** */
|
||||
|
||||
struct GPENCIL_tVfx {
|
||||
using PassSimple = blender::draw::PassSimple;
|
||||
/** Single linked-list. */
|
||||
struct GPENCIL_tVfx *next = nullptr;
|
||||
std::unique_ptr<PassSimple> vfx_ps = std::make_unique<PassSimple>("vfx");
|
||||
@@ -106,11 +110,9 @@ typedef struct GPENCIL_tLayer {
|
||||
/** Single linked-list. */
|
||||
struct GPENCIL_tLayer *next;
|
||||
/** Geometry pass (draw all strokes). */
|
||||
DRWPass *geom_ps;
|
||||
std::unique_ptr<PassSimple> geom_ps;
|
||||
/** Blend pass to composite onto the target buffer (blends modes). NULL if not needed. */
|
||||
DRWPass *blend_ps;
|
||||
/** First shading group created for this layer. Contains all uniforms. */
|
||||
DRWShadingGroup *base_shgrp;
|
||||
std::unique_ptr<PassSimple> blend_ps;
|
||||
/** Layer id of the mask. */
|
||||
BLI_bitmap *mask_bits;
|
||||
BLI_bitmap *mask_invert_bits;
|
||||
@@ -137,7 +139,7 @@ typedef struct GPENCIL_tObject {
|
||||
/* Used for stroke thickness scaling. */
|
||||
float object_scale;
|
||||
/* Normal used for shading. Based on view angle. */
|
||||
float plane_normal[3];
|
||||
float3 plane_normal;
|
||||
/* Used for drawing depth merge pass. */
|
||||
float plane_mat[4][4];
|
||||
|
||||
@@ -184,13 +186,15 @@ typedef struct GPENCIL_TextureList {
|
||||
} GPENCIL_TextureList;
|
||||
|
||||
struct GPENCIL_Instance {
|
||||
blender::draw::PassSimple smaa_edge_ps = {"smaa_edge"};
|
||||
blender::draw::PassSimple smaa_weight_ps = {"smaa_weight"};
|
||||
blender::draw::PassSimple smaa_resolve_ps = {"smaa_resolve"};
|
||||
PassSimple smaa_edge_ps = {"smaa_edge"};
|
||||
PassSimple smaa_weight_ps = {"smaa_weight"};
|
||||
PassSimple smaa_resolve_ps = {"smaa_resolve"};
|
||||
/* Composite the object depth to the default depth buffer to occlude overlays. */
|
||||
blender::draw::PassSimple merge_depth_ps = {"merge_depth_ps"};
|
||||
PassSimple merge_depth_ps = {"merge_depth_ps"};
|
||||
/* Invert mask buffer content. */
|
||||
blender::draw::PassSimple mask_invert_ps = {"mask_invert_ps"};
|
||||
PassSimple mask_invert_ps = {"mask_invert_ps"};
|
||||
|
||||
blender::draw::View view = {"GPView"};
|
||||
|
||||
float4x4 object_bound_mat;
|
||||
};
|
||||
@@ -210,7 +214,7 @@ struct GPENCIL_Data {
|
||||
typedef struct GPENCIL_PrivateData {
|
||||
/* Pointers copied from GPENCIL_ViewLayerData. */
|
||||
struct BLI_memblock *gp_object_pool;
|
||||
struct BLI_memblock *gp_layer_pool;
|
||||
GPENCIL_tLayer_Pool *gp_layer_pool;
|
||||
GPENCIL_tVfx_Pool *gp_vfx_pool;
|
||||
struct BLI_memblock *gp_material_pool;
|
||||
struct BLI_memblock *gp_light_pool;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "GPU_uniform_buffer.hh"
|
||||
|
||||
#include "draw_manager.hh"
|
||||
#include "draw_view.hh"
|
||||
|
||||
#include "gpencil_engine.h"
|
||||
|
||||
#include "DEG_depsgraph_query.hh"
|
||||
@@ -79,7 +81,7 @@ void GPENCIL_engine_init(void *ved)
|
||||
BLI_memblock_clear(vldata->gp_light_pool, gpencil_light_pool_free);
|
||||
BLI_memblock_clear(vldata->gp_material_pool, gpencil_material_pool_free);
|
||||
BLI_memblock_clear(vldata->gp_object_pool, nullptr);
|
||||
BLI_memblock_clear(vldata->gp_layer_pool, nullptr);
|
||||
vldata->gp_layer_pool->clear();
|
||||
vldata->gp_vfx_pool->clear();
|
||||
BLI_memblock_clear(vldata->gp_maskbit_pool, nullptr);
|
||||
|
||||
@@ -370,9 +372,11 @@ static bool use_layer_in_render(const GreasePencil &grease_pencil,
|
||||
return true;
|
||||
}
|
||||
|
||||
static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData *pd,
|
||||
GPENCIL_TextureList *txl,
|
||||
Object *ob)
|
||||
static GPENCIL_tObject *grease_pencil_object_cache_populate(
|
||||
GPENCIL_PrivateData *pd,
|
||||
GPENCIL_TextureList *txl,
|
||||
Object *ob,
|
||||
blender::draw::ResourceHandle res_handle)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::ed::greasepencil;
|
||||
@@ -395,14 +399,14 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
GPUTexture *tex_stroke = txl->dummy_texture;
|
||||
|
||||
blender::gpu::Batch *iter_geom = nullptr;
|
||||
DRWShadingGroup *grp;
|
||||
PassSimple *last_pass = nullptr;
|
||||
int vfirst = 0;
|
||||
int vcount = 0;
|
||||
|
||||
const auto drawcall_flush = [&]() {
|
||||
const auto drawcall_flush = [&](PassSimple &pass) {
|
||||
#if !DISABLE_BATCHING
|
||||
if (iter_geom != nullptr) {
|
||||
DRW_shgroup_call_range(grp, ob, iter_geom, vfirst, vcount);
|
||||
pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
|
||||
}
|
||||
#endif
|
||||
iter_geom = nullptr;
|
||||
@@ -411,15 +415,15 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
};
|
||||
|
||||
const auto drawcall_add =
|
||||
[&](blender::gpu::Batch *draw_geom, const int v_first, const int v_count) {
|
||||
[&](PassSimple &pass, blender::gpu::Batch *draw_geom, const int v_first, const int v_count) {
|
||||
#if DISABLE_BATCHING
|
||||
DRW_shgroup_call_range(grp, ob, geom, v_first, v_count);
|
||||
pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
|
||||
return;
|
||||
#endif
|
||||
int last = vfirst + vcount;
|
||||
/* Interrupt draw-call grouping if the sequence is not consecutive. */
|
||||
if ((draw_geom != iter_geom) || (v_first - last > 0)) {
|
||||
drawcall_flush();
|
||||
drawcall_flush(pass);
|
||||
}
|
||||
iter_geom = draw_geom;
|
||||
if (vfirst == -1) {
|
||||
@@ -474,10 +478,12 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
continue;
|
||||
}
|
||||
|
||||
drawcall_flush();
|
||||
|
||||
GPENCIL_tLayer *tgp_layer = grease_pencil_layer_cache_add(
|
||||
pd, ob, layer, info.onion_id, is_layer_used_as_mask, tgp_ob);
|
||||
PassSimple &pass = *tgp_layer->geom_ps;
|
||||
last_pass = &pass;
|
||||
|
||||
drawcall_flush(pass);
|
||||
|
||||
const bool use_lights = pd->use_lighting &&
|
||||
((layer.base.flag & GP_LAYER_TREE_NODE_USE_LIGHTS) != 0) &&
|
||||
@@ -489,15 +495,14 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
GPUUniformBuf *ubo_mat;
|
||||
gpencil_material_resources_get(matpool, 0, nullptr, nullptr, &ubo_mat);
|
||||
|
||||
grp = tgp_layer->base_shgrp;
|
||||
DRW_shgroup_uniform_block(grp, "gp_lights", lights_ubo);
|
||||
DRW_shgroup_uniform_block(grp, "gp_materials", ubo_mat);
|
||||
DRW_shgroup_uniform_texture(grp, "gpFillTexture", tex_fill);
|
||||
DRW_shgroup_uniform_texture(grp, "gpStrokeTexture", tex_stroke);
|
||||
DRW_shgroup_uniform_int_copy(grp, "gpMaterialOffset", mat_ofs);
|
||||
pass.bind_ubo("gp_lights", lights_ubo);
|
||||
pass.bind_ubo("gp_materials", ubo_mat);
|
||||
pass.bind_texture("gpFillTexture", tex_fill);
|
||||
pass.bind_texture("gpStrokeTexture", tex_stroke);
|
||||
pass.push_constant("gpMaterialOffset", int(mat_ofs));
|
||||
/* Since we don't use the sbuffer in GPv3, this is always 0. */
|
||||
DRW_shgroup_uniform_float_copy(grp, "gpStrokeIndexOffset", 0.0f);
|
||||
DRW_shgroup_uniform_vec2_copy(grp, "viewportSize", DRW_viewport_size_get());
|
||||
pass.push_constant("gpStrokeIndexOffset", 0.0f);
|
||||
pass.push_constant("viewportSize", float2(DRW_viewport_size_get()));
|
||||
|
||||
const VArray<int> stroke_materials = *attributes.lookup_or_default<int>(
|
||||
"material_index", bke::AttrDomain::Curve, 0);
|
||||
@@ -545,39 +550,38 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
(new_tex_stroke && (new_tex_stroke != tex_stroke));
|
||||
|
||||
if (resource_changed) {
|
||||
drawcall_flush();
|
||||
drawcall_flush(pass);
|
||||
|
||||
grp = DRW_shgroup_create_sub(grp);
|
||||
if (new_ubo_mat != ubo_mat) {
|
||||
DRW_shgroup_uniform_block(grp, "gp_materials", new_ubo_mat);
|
||||
pass.bind_ubo("gp_materials", new_ubo_mat);
|
||||
ubo_mat = new_ubo_mat;
|
||||
}
|
||||
if (new_tex_fill) {
|
||||
DRW_shgroup_uniform_texture(grp, "gpFillTexture", new_tex_fill);
|
||||
pass.bind_texture("gpFillTexture", new_tex_fill);
|
||||
tex_fill = new_tex_fill;
|
||||
}
|
||||
if (new_tex_stroke) {
|
||||
DRW_shgroup_uniform_texture(grp, "gpStrokeTexture", new_tex_stroke);
|
||||
pass.bind_texture("gpStrokeTexture", new_tex_stroke);
|
||||
tex_stroke = new_tex_stroke;
|
||||
}
|
||||
}
|
||||
|
||||
blender::gpu::Batch *geom = draw::DRW_cache_grease_pencil_get(pd->scene, ob);
|
||||
if (iter_geom != geom) {
|
||||
drawcall_flush();
|
||||
drawcall_flush(pass);
|
||||
|
||||
blender::gpu::VertBuf *position_tx = draw::DRW_cache_grease_pencil_position_buffer_get(
|
||||
pd->scene, ob);
|
||||
blender::gpu::VertBuf *color_tx = draw::DRW_cache_grease_pencil_color_buffer_get(pd->scene,
|
||||
ob);
|
||||
DRW_shgroup_buffer_texture(grp, "gp_pos_tx", position_tx);
|
||||
DRW_shgroup_buffer_texture(grp, "gp_col_tx", color_tx);
|
||||
pass.bind_texture("gp_pos_tx", position_tx);
|
||||
pass.bind_texture("gp_col_tx", color_tx);
|
||||
}
|
||||
|
||||
if (show_fill) {
|
||||
const int v_first = t_offset * 3;
|
||||
const int v_count = num_triangles_per_stroke[pos] * 3;
|
||||
drawcall_add(geom, v_first, v_count);
|
||||
drawcall_add(pass, geom, v_first, v_count);
|
||||
}
|
||||
|
||||
t_offset += num_triangles_per_stroke[pos];
|
||||
@@ -585,14 +589,16 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
|
||||
if (show_stroke) {
|
||||
const int v_first = t_offset * 3;
|
||||
const int v_count = num_vertices_per_stroke[pos] * 2 * 3;
|
||||
drawcall_add(geom, v_first, v_count);
|
||||
drawcall_add(pass, geom, v_first, v_count);
|
||||
}
|
||||
|
||||
t_offset += num_vertices_per_stroke[pos] * 2;
|
||||
});
|
||||
}
|
||||
|
||||
drawcall_flush();
|
||||
if (last_pass) {
|
||||
drawcall_flush(*last_pass);
|
||||
}
|
||||
|
||||
return tgp_ob;
|
||||
}
|
||||
@@ -609,7 +615,11 @@ void GPENCIL_cache_populate(void *ved, Object *ob)
|
||||
}
|
||||
|
||||
if (ob->data && (ob->type == OB_GREASE_PENCIL) && (ob->dt >= OB_SOLID)) {
|
||||
GPENCIL_tObject *tgp_ob = grease_pencil_object_cache_populate(pd, txl, ob);
|
||||
blender::draw::Manager *manager = DRW_manager_get();
|
||||
blender::draw::ObjectRef ob_ref = DRW_object_ref_get(ob);
|
||||
blender::draw::ResourceHandle res_handle = manager->unique_handle(ob_ref);
|
||||
|
||||
GPENCIL_tObject *tgp_ob = grease_pencil_object_cache_populate(pd, txl, ob, res_handle);
|
||||
gpencil_vfx_cache_populate(
|
||||
vedata,
|
||||
ob,
|
||||
@@ -725,9 +735,12 @@ static void GPENCIL_draw_scene_depth_only(void *ved)
|
||||
GPU_framebuffer_bind(dfbl->depth_only_fb);
|
||||
}
|
||||
|
||||
blender::draw::Manager *manager = DRW_manager_get();
|
||||
blender::draw::View view("GPDepthOnlyView", DRW_view_get_active());
|
||||
|
||||
LISTBASE_FOREACH (GPENCIL_tObject *, ob, &pd->tobjects) {
|
||||
LISTBASE_FOREACH (GPENCIL_tLayer *, layer, &ob->layers) {
|
||||
DRW_draw_pass(layer->geom_ps);
|
||||
manager->submit(*layer->geom_ps, view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -735,11 +748,15 @@ static void GPENCIL_draw_scene_depth_only(void *ved)
|
||||
GPU_framebuffer_bind(dfbl->default_fb);
|
||||
}
|
||||
|
||||
pd->gp_object_pool = pd->gp_layer_pool = pd->gp_maskbit_pool = nullptr;
|
||||
pd->gp_object_pool = pd->gp_maskbit_pool = nullptr;
|
||||
pd->gp_vfx_pool = nullptr;
|
||||
pd->gp_layer_pool = nullptr;
|
||||
}
|
||||
|
||||
static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL_tLayer *layer)
|
||||
static void gpencil_draw_mask(GPENCIL_Data *vedata,
|
||||
blender::draw::View &view,
|
||||
GPENCIL_tObject *ob,
|
||||
GPENCIL_tLayer *layer)
|
||||
{
|
||||
GPENCIL_Instance *inst = vedata->instance;
|
||||
blender::draw::Manager *manager = DRW_manager_get();
|
||||
@@ -779,7 +796,7 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL
|
||||
continue;
|
||||
}
|
||||
|
||||
DRW_draw_pass(mask_layer->geom_ps);
|
||||
manager->submit(*mask_layer->geom_ps, view);
|
||||
}
|
||||
|
||||
if (!inverted) {
|
||||
@@ -790,7 +807,9 @@ static void gpencil_draw_mask(GPENCIL_Data *vedata, GPENCIL_tObject *ob, GPENCIL
|
||||
DRW_stats_group_end();
|
||||
}
|
||||
|
||||
static void GPENCIL_draw_object(GPENCIL_Data *vedata, GPENCIL_tObject *ob)
|
||||
static void GPENCIL_draw_object(GPENCIL_Data *vedata,
|
||||
blender::draw::View &view,
|
||||
GPENCIL_tObject *ob)
|
||||
{
|
||||
GPENCIL_Instance *inst = vedata->instance;
|
||||
blender::draw::Manager *manager = DRW_manager_get();
|
||||
@@ -812,7 +831,7 @@ static void GPENCIL_draw_object(GPENCIL_Data *vedata, GPENCIL_tObject *ob)
|
||||
|
||||
LISTBASE_FOREACH (GPENCIL_tLayer *, layer, &ob->layers) {
|
||||
if (layer->mask_bits) {
|
||||
gpencil_draw_mask(vedata, ob, layer);
|
||||
gpencil_draw_mask(vedata, view, ob, layer);
|
||||
}
|
||||
|
||||
if (layer->blend_ps) {
|
||||
@@ -823,11 +842,11 @@ static void GPENCIL_draw_object(GPENCIL_Data *vedata, GPENCIL_tObject *ob)
|
||||
GPU_framebuffer_bind(fb_object);
|
||||
}
|
||||
|
||||
DRW_draw_pass(layer->geom_ps);
|
||||
manager->submit(*layer->geom_ps, view);
|
||||
|
||||
if (layer->blend_ps) {
|
||||
GPU_framebuffer_bind(fb_object);
|
||||
DRW_draw_pass(layer->blend_ps);
|
||||
manager->submit(*layer->blend_ps);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -841,7 +860,7 @@ static void GPENCIL_draw_object(GPENCIL_Data *vedata, GPENCIL_tObject *ob)
|
||||
|
||||
if (pd->scene_fb) {
|
||||
GPU_framebuffer_bind(pd->scene_fb);
|
||||
manager->submit(inst->merge_depth_ps);
|
||||
manager->submit(inst->merge_depth_ps, view);
|
||||
}
|
||||
|
||||
DRW_stats_group_end();
|
||||
@@ -863,7 +882,7 @@ static void GPENCIL_fast_draw_start(GPENCIL_Data *vedata)
|
||||
}
|
||||
}
|
||||
|
||||
static void GPENCIL_fast_draw_end(GPENCIL_Data *vedata)
|
||||
static void GPENCIL_fast_draw_end(GPENCIL_Data *vedata, blender::draw::View &view)
|
||||
{
|
||||
GPENCIL_PrivateData *pd = vedata->stl->pd;
|
||||
GPENCIL_FramebufferList *fbl = vedata->fbl;
|
||||
@@ -878,7 +897,7 @@ static void GPENCIL_fast_draw_end(GPENCIL_Data *vedata)
|
||||
}
|
||||
/* Draw the sbuffer stroke(s). */
|
||||
LISTBASE_FOREACH (GPENCIL_tObject *, ob, &pd->sbuffer_tobjects) {
|
||||
GPENCIL_draw_object(vedata, ob);
|
||||
GPENCIL_draw_object(vedata, view, ob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -920,20 +939,24 @@ void GPENCIL_draw_scene(void *ved)
|
||||
GPU_framebuffer_multi_clear(fbl->gpencil_fb, clear_cols);
|
||||
}
|
||||
|
||||
blender::draw::View &view = vedata->instance->view;
|
||||
view.sync(DRW_view_get_active());
|
||||
|
||||
LISTBASE_FOREACH (GPENCIL_tObject *, ob, &pd->tobjects) {
|
||||
GPENCIL_draw_object(vedata, ob);
|
||||
GPENCIL_draw_object(vedata, view, ob);
|
||||
}
|
||||
|
||||
if (pd->do_fast_drawing) {
|
||||
GPENCIL_fast_draw_end(vedata);
|
||||
GPENCIL_fast_draw_end(vedata, view);
|
||||
}
|
||||
|
||||
if (pd->scene_fb) {
|
||||
GPENCIL_antialiasing_draw(vedata);
|
||||
}
|
||||
|
||||
pd->gp_object_pool = pd->gp_layer_pool = pd->gp_maskbit_pool = nullptr;
|
||||
pd->gp_object_pool = pd->gp_maskbit_pool = nullptr;
|
||||
pd->gp_vfx_pool = nullptr;
|
||||
pd->gp_layer_pool = nullptr;
|
||||
}
|
||||
|
||||
static void GPENCIL_engine_free()
|
||||
|
||||
@@ -55,7 +55,10 @@ VERTEX_OUT(gpencil_geometry_noperspective_iface)
|
||||
VERTEX_SOURCE("gpencil_vert.glsl")
|
||||
FRAGMENT_SOURCE("gpencil_frag.glsl")
|
||||
DEPTH_WRITE(DepthWrite::ANY)
|
||||
ADDITIONAL_INFO(draw_gpencil)
|
||||
ADDITIONAL_INFO(draw_view)
|
||||
ADDITIONAL_INFO(draw_modelmat_new)
|
||||
ADDITIONAL_INFO(draw_resource_handle_new)
|
||||
ADDITIONAL_INFO(draw_gpencil_new)
|
||||
GPU_SHADER_CREATE_END()
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user