Blender V4.3
eevee_sync.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#pragma once
13
14#include "BKE_duplilist.hh"
15#include "BLI_ghash.h"
16#include "BLI_map.hh"
18#include "DNA_object_types.h"
19#include "DRW_render.hh"
20#include "GPU_material.hh"
21
23
24namespace blender::eevee {
25
26class Instance;
27
28/* -------------------------------------------------------------------- */
34
35class ObjectKey {
37 uint64_t hash_value_ = 0;
39 Object *ob_ = nullptr;
41 Object *parent_ = nullptr;
43 int id_[MAX_DUPLI_RECUR];
45 int sub_key_ = 0;
46
47 public:
48 ObjectKey() = default;
49
50 ObjectKey(Object *ob, int sub_key = 0)
51 {
53 hash_value_ = BLI_ghashutil_ptrhash(ob_);
54
55 if (DupliObject *dupli = DRW_object_get_dupli(ob)) {
56 parent_ = DRW_object_get_dupli_parent(ob);
57 hash_value_ = BLI_ghashutil_combine_hash(hash_value_, BLI_ghashutil_ptrhash(parent_));
58 for (int i : IndexRange(MAX_DUPLI_RECUR)) {
59 id_[i] = dupli->persistent_id[i];
60 if (id_[i] == INT_MAX) {
61 break;
62 }
63 hash_value_ = BLI_ghashutil_combine_hash(hash_value_, BLI_ghashutil_inthash(id_[i]));
64 }
65 }
66
67 if (sub_key != 0) {
68 sub_key_ = sub_key;
69 hash_value_ = BLI_ghashutil_combine_hash(hash_value_, BLI_ghashutil_inthash(sub_key_));
70 }
71 }
72
73 uint64_t hash() const
74 {
75 return hash_value_;
76 }
77
78 bool operator<(const ObjectKey &k) const
79 {
80 if (hash_value_ != k.hash_value_) {
81 return hash_value_ < k.hash_value_;
82 }
83 if (ob_ != k.ob_) {
84 return (ob_ < k.ob_);
85 }
86 if (parent_ != k.parent_) {
87 return (parent_ < k.parent_);
88 }
89 if (sub_key_ != k.sub_key_) {
90 return (sub_key_ < k.sub_key_);
91 }
92 if (parent_) {
93 for (int i : IndexRange(MAX_DUPLI_RECUR)) {
94 if (id_[i] < k.id_[i]) {
95 return true;
96 }
97 if (id_[i] == INT_MAX) {
98 break;
99 }
100 }
101 }
102 return false;
103 }
104
105 bool operator==(const ObjectKey &k) const
106 {
107 if (hash_value_ != k.hash_value_) {
108 return false;
109 }
110 if (ob_ != k.ob_) {
111 return false;
112 }
113 if (parent_ != k.parent_) {
114 return false;
115 }
116 if (sub_key_ != k.sub_key_) {
117 return false;
118 }
119 if (parent_) {
120 for (int i : IndexRange(MAX_DUPLI_RECUR)) {
121 if (id_[i] != k.id_[i]) {
122 return false;
123 }
124 if (id_[i] == INT_MAX) {
125 break;
126 }
127 }
128 }
129 return true;
130 }
131};
132
134
135/* -------------------------------------------------------------------- */
139
141 unsigned int recalc;
142};
143
147
148struct WorldHandle : public BaseHandle {};
149
150struct SceneHandle : public BaseHandle {};
151
153 private:
154 Instance &inst_;
155
156 Map<ObjectKey, ObjectHandle> ob_handles = {};
157
158 public:
159 SyncModule(Instance &inst) : inst_(inst){};
161
162 ObjectHandle &sync_object(const ObjectRef &ob_ref);
163 WorldHandle sync_world(const ::World &world);
164
165 void sync_mesh(Object *ob,
166 ObjectHandle &ob_handle,
167 ResourceHandle res_handle,
168 const ObjectRef &ob_ref);
169 bool sync_sculpt(Object *ob,
170 ObjectHandle &ob_handle,
171 ResourceHandle res_handle,
172 const ObjectRef &ob_ref);
173 void sync_point_cloud(Object *ob,
174 ObjectHandle &ob_handle,
175 ResourceHandle res_handle,
176 const ObjectRef &ob_ref);
177 void sync_volume(Object *ob,
178 ObjectHandle &ob_handle,
179 ResourceHandle res_handle,
180 const ObjectRef &ob_ref);
181 void sync_curves(Object *ob,
182 ObjectHandle &ob_handle,
183 ResourceHandle res_handle,
184 const ObjectRef &ob_ref,
185 ModifierData *modifier_data = nullptr,
186 ParticleSystem *particle_sys = nullptr);
187};
188
191
193
194} // namespace blender::eevee
size_t BLI_ghashutil_combine_hash(size_t hash_a, size_t hash_b)
unsigned int BLI_ghashutil_ptrhash(const void *key)
#define BLI_ghashutil_inthash(key)
Definition BLI_ghash.h:580
Object * DEG_get_original_object(Object *object)
Object is a sort of wrapper for general info.
#define MAX_DUPLI_RECUR
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between world
A running instance of the engine.
uint64_t hash() const
Definition eevee_sync.hh:73
bool operator<(const ObjectKey &k) const
Definition eevee_sync.hh:78
bool operator==(const ObjectKey &k) const
ObjectKey(Object *ob, int sub_key=0)
Definition eevee_sync.hh:50
void sync_point_cloud(Object *ob, ObjectHandle &ob_handle, ResourceHandle res_handle, const ObjectRef &ob_ref)
ObjectHandle & sync_object(const ObjectRef &ob_ref)
Definition eevee_sync.cc:37
void sync_mesh(Object *ob, ObjectHandle &ob_handle, ResourceHandle res_handle, const ObjectRef &ob_ref)
Definition eevee_sync.cc:91
void sync_volume(Object *ob, ObjectHandle &ob_handle, ResourceHandle res_handle, const ObjectRef &ob_ref)
SyncModule(Instance &inst)
void sync_curves(Object *ob, ObjectHandle &ob_handle, ResourceHandle res_handle, const ObjectRef &ob_ref, ModifierData *modifier_data=nullptr, ParticleSystem *particle_sys=nullptr)
WorldHandle sync_world(const ::World &world)
Definition eevee_sync.cc:52
bool sync_sculpt(Object *ob, ObjectHandle &ob_handle, ResourceHandle res_handle, const ObjectRef &ob_ref)
Object * DRW_object_get_dupli_parent(const Object *)
DupliObject * DRW_object_get_dupli(const Object *)
FunctionRef< void(ObjectHandle, ModifierData &, ParticleSystem &)> HairHandleCallback
void foreach_hair_particle_handle(Object *ob, ObjectHandle ob_handle, HairHandleCallback callback)
unsigned __int64 uint64_t
Definition stdint.h:90