Blender  V3.3
eevee_sync.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation.
3  */
4 
12 #pragma once
13 
14 #include "BKE_duplilist.h"
15 #include "BLI_ghash.h"
16 #include "BLI_map.hh"
17 #include "DNA_object_types.h"
18 #include "DRW_render.h"
19 #include "GPU_material.h"
20 
21 #include "eevee_shader_shared.hh"
22 
23 namespace blender::eevee {
24 
25 class Instance;
26 
27 /* -------------------------------------------------------------------- */
34 struct ObjectKey {
42  int id[MAX_DUPLI_RECUR];
45 #ifdef DEBUG
46  char name[64];
47 #endif
48  ObjectKey() : ob(nullptr), parent(nullptr){};
49 
50  ObjectKey(Object *ob_, Object *parent_, int id_[MAX_DUPLI_RECUR], bool use_particle_hair_)
51  : ob(ob_), parent(parent_), use_particle_hair(use_particle_hair_)
52  {
53  if (id_) {
54  memcpy(id, id_, sizeof(id));
55  }
56  else {
57  memset(id, 0, sizeof(id));
58  }
59  /* Compute hash on creation so we avoid the cost of it for every sync. */
62  for (int i = 0; i < MAX_DUPLI_RECUR; i++) {
63  if (id[i] != 0) {
65  }
66  else {
67  break;
68  }
69  }
70 #ifdef DEBUG
71  STRNCPY(name, ob->id.name);
72 #endif
73  }
74 
76  : ObjectKey(ob, parent, dupli ? dupli->persistent_id : nullptr, false){};
77 
80 
81  uint64_t hash() const
82  {
83  return hash_value;
84  }
85 
86  bool operator<(const ObjectKey &k) const
87  {
88  if (ob != k.ob) {
89  return (ob < k.ob);
90  }
91  if (parent != k.parent) {
92  return (parent < k.parent);
93  }
96  }
97  return memcmp(id, k.id, sizeof(id)) < 0;
98  }
99 
100  bool operator==(const ObjectKey &k) const
101  {
102  if (ob != k.ob) {
103  return false;
104  }
105  if (parent != k.parent) {
106  return false;
107  }
109  return false;
110  }
111  return memcmp(id, k.id, sizeof(id)) == 0;
112  }
113 };
114 
117 /* -------------------------------------------------------------------- */
122 struct ObjectHandle : public DrawData {
124 
126  {
127  if (recalc != 0) {
128  recalc = 0;
129  }
130  }
131 };
132 
133 struct WorldHandle : public DrawData {
135  {
136  if (recalc != 0) {
137  recalc = 0;
138  }
139  }
140 };
141 
142 class SyncModule {
143  private:
144  Instance &inst_;
145 
146  public:
147  SyncModule(Instance &inst) : inst_(inst){};
149 
152 
153  void sync_mesh(Object *ob, ObjectHandle &ob_handle);
154  void sync_gpencil(Object *ob, ObjectHandle &ob_handle);
155  void sync_curves(Object *ob, ObjectHandle &ob_handle, ModifierData *modifier_data = nullptr);
156 };
157 
160 } // 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:579
#define STRNCPY(dst, src)
Definition: BLI_string.h:483
Object is a sort of wrapper for general info.
#define MAX_DUPLI_RECUR
A running instance of the engine.
ObjectHandle & sync_object(Object *ob)
Definition: eevee_sync.cc:36
void sync_gpencil(Object *ob, ObjectHandle &ob_handle)
Definition: eevee_sync.cc:253
WorldHandle & sync_world(::World *world)
Definition: eevee_sync.cc:57
void sync_mesh(Object *ob, ObjectHandle &ob_handle)
Definition: eevee_sync.cc:105
SyncModule(Instance &inst)
Definition: eevee_sync.hh:147
void sync_curves(Object *ob, ObjectHandle &ob_handle, ModifierData *modifier_data=nullptr)
Definition: eevee_sync.cc:294
World world
struct Object * DRW_object_get_dupli_parent(const Object *UNUSED(ob))
Definition: draw_manager.c:264
struct DupliObject * DRW_object_get_dupli(const Object *UNUSED(ob))
Definition: draw_manager.c:269
unsigned __int64 uint64_t
Definition: stdint.h:90
int recalc
Definition: DNA_ID.h:40
char name[66]
Definition: DNA_ID.h:378
ObjectKey(Object *ob_, Object *parent_, int id_[MAX_DUPLI_RECUR], bool use_particle_hair_)
Definition: eevee_sync.hh:50
uint64_t hash() const
Definition: eevee_sync.hh:81
int id[MAX_DUPLI_RECUR]
Definition: eevee_sync.hh:42
bool operator<(const ObjectKey &k) const
Definition: eevee_sync.hh:86
bool operator==(const ObjectKey &k) const
Definition: eevee_sync.hh:100
ObjectKey(Object *ob, DupliObject *dupli, Object *parent)
Definition: eevee_sync.hh:75