Blender V4.3
overlay_particle.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "DRW_render.hh"
10
12
13#include "DNA_particle_types.h"
14
15#include "BKE_pointcache.h"
16
17#include "ED_particle.hh"
18
19#include "overlay_private.hh"
20
21/* -------------------------------------------------------------------- */
54
56{
57 OVERLAY_PrivateData *pd = vedata->stl->pd;
58 const DRWContextState *draw_ctx = DRW_context_state_get();
59 Scene *scene_orig = (Scene *)DEG_get_original_id(&draw_ctx->scene->id);
60
61 /* Usually the edit structure is created by Particle Edit Mode Toggle
62 * operator, but sometimes it's invoked after tagging hair as outdated
63 * (for example, when toggling edit mode). That makes it impossible to
64 * create edit structure for until after next dependency graph evaluation.
65 *
66 * Ideally, the edit structure will be created here already via some
67 * dependency graph callback or so, but currently trying to make it nicer
68 * only causes bad level calls and breaks design from the past.
69 */
70 Object *ob_orig = DEG_get_original_object(ob);
71 PTCacheEdit *edit = PE_create_current(draw_ctx->depsgraph, scene_orig, ob_orig);
72 if (edit == nullptr) {
73 /* Happens when trying to edit particles in EMITTER mode without
74 * having them cached.
75 */
76 return;
77 }
78 /* NOTE: We need to pass evaluated particle system, which we need
79 * to find first.
80 */
81 ParticleSystem *psys = static_cast<ParticleSystem *>(ob->particlesystem.first);
82 LISTBASE_FOREACH (ParticleSystem *, psys_orig, &ob_orig->particlesystem) {
83 if (PE_get_current_from_psys(psys_orig) == edit) {
84 break;
85 }
86 psys = psys->next;
87 }
88 if (psys == nullptr) {
89 printf("Error getting evaluated particle system for edit.\n");
90 return;
91 }
92
93 blender::gpu::Batch *geom;
94 {
97 }
98
100 geom = DRW_cache_particles_get_edit_inner_points(ob, psys, edit);
101 DRW_shgroup_call(pd->edit_particle_point_grp, geom, nullptr);
102 }
103
105 geom = DRW_cache_particles_get_edit_tip_points(ob, psys, edit);
106 DRW_shgroup_call(pd->edit_particle_point_grp, geom, nullptr);
107 }
108}
109
111{
112 OVERLAY_PassList *psl = vedata->psl;
113 OVERLAY_FramebufferList *fbl = vedata->fbl;
114
115 if (DRW_state_is_fbo()) {
117 }
118
120}
121
124/* -------------------------------------------------------------------- */
153
155{
156 OVERLAY_PrivateData *pd = vedata->stl->pd;
157
160 continue;
161 }
162
163 ParticleSettings *part = psys->part;
164 int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
165
166 if (part->type == PART_HAIR) {
167 /* Hairs should have been rendered by the render engine. */
168 continue;
169 }
170
171 if (!ELEM(draw_as, PART_DRAW_NOT, PART_DRAW_OB, PART_DRAW_GR)) {
172 blender::gpu::Batch *geom = DRW_cache_particles_get_dots(ob, psys);
173 blender::gpu::Batch *shape = nullptr;
174 DRWShadingGroup *grp;
175
176 /* TODO(fclem): Here would be a good place for preemptive culling. */
177
178 /* NOTE(fclem): Is color even useful in our modern context? */
179 Material *ma = BKE_object_material_get_eval(ob, part->omat);
180 float color[4] = {0.6f, 0.6f, 0.6f, part->draw_size};
181 if (ma != nullptr) {
182 copy_v3_v3(color, &ma->r);
183 }
184
185 switch (draw_as) {
186 default:
187 case PART_DRAW_DOT:
189 DRW_shgroup_uniform_vec4_copy(grp, "ucolor", color);
190 DRW_shgroup_call(grp, geom, nullptr);
191 break;
192 case PART_DRAW_AXIS:
193 case PART_DRAW_CIRC:
194 case PART_DRAW_CROSS:
196 DRW_shgroup_uniform_vec4_copy(grp, "ucolor", color);
197 shape = DRW_cache_particles_get_prim(draw_as);
198 DRW_shgroup_call_instances_with_attrs(grp, nullptr, shape, geom);
199 break;
200 }
201 }
202 }
203}
204
206{
207 OVERLAY_PassList *psl = vedata->psl;
208
210}
211
struct Material * BKE_object_material_get_eval(struct Object *ob, short act)
#define LISTBASE_FOREACH(type, var, list)
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define ELEM(...)
ID * DEG_get_original_id(ID *id)
Object * DEG_get_original_object(Object *object)
@ PART_DRAW_CIRC
@ PART_DRAW_CROSS
@ PART_DRAW_AXIS
@ PART_DRAW_NOT
@ PART_DRAW_GR
@ PART_DRAW_OB
@ PART_DRAW_REND
@ PART_DRAW_DOT
@ PART_HAIR
@ SCE_SELECT_POINT
@ SCE_SELECT_END
@ PE_BRUSH_WEIGHT
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
#define DRW_shgroup_call(shgroup, geom, ob)
PTCacheEdit * PE_get_current_from_psys(ParticleSystem *psys)
ParticleEditSettings * PE_settings(Scene *scene)
PTCacheEdit * PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
struct GPUShader GPUShader
#define printf
blender::gpu::Batch * DRW_cache_particles_get_prim(int type)
blender::gpu::Batch * DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
blender::gpu::Batch * DRW_cache_particles_get_edit_strands(Object *object, ParticleSystem *psys, PTCacheEdit *edit, bool use_weight)
blender::gpu::Batch * DRW_cache_particles_get_edit_tip_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
blender::gpu::Batch * DRW_cache_particles_get_edit_inner_points(Object *object, ParticleSystem *psys, PTCacheEdit *edit)
DRW_Global G_draw
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
const DRWContextState * DRW_context_state_get()
bool DRW_state_is_fbo()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
void DRW_shgroup_call_instances_with_attrs(DRWShadingGroup *shgroup, const Object *ob, blender::gpu::Batch *geom, blender::gpu::Batch *inst_attributes)
DRWShadingGroup * DRW_shgroup_create_sub(DRWShadingGroup *shgroup)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
void DRW_draw_pass(DRWPass *pass)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
static ulong state[N]
void OVERLAY_particle_draw(OVERLAY_Data *vedata)
void OVERLAY_edit_particle_cache_init(OVERLAY_Data *vedata)
void OVERLAY_particle_cache_init(OVERLAY_Data *vedata)
void OVERLAY_edit_particle_cache_populate(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_particle_cache_populate(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_edit_particle_draw(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_edit_particle_point()
GPUShader * OVERLAY_shader_particle_shape()
GPUShader * OVERLAY_shader_edit_particle_strand()
GPUShader * OVERLAY_shader_particle_dot()
Depsgraph * depsgraph
GPUTexture * weight_ramp
GPUUniformBuf * block_ubo
GPUTexture * ramp
void * first
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
GPUFrameBuffer * overlay_default_fb
DRWPass * edit_particle_ps
struct OVERLAY_PrivateData::@232 edit_particle
DRWShadingGroup * edit_particle_point_grp
DRWShadingGroup * edit_particle_strand_grp
DRWShadingGroup * particle_dots_grp
DRWShadingGroup * particle_shapes_grp
OVERLAY_PrivateData * pd
ListBase particlesystem
struct ParticleSystem * next