Blender V4.3
draw_resource.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
14#include "BLI_math_base.h"
15#include "BLI_math_matrix.hh"
16
17#include "BKE_curve.hh"
18#include "BKE_duplilist.hh"
19#include "BKE_mesh.h"
20#include "BKE_object.hh"
21#include "BKE_volume.hh"
22#include "BLI_hash.h"
23#include "DNA_curve_types.h"
24#include "DNA_layer_types.h"
25#include "DNA_meta_types.h"
26#include "DNA_object_types.h"
27
28#include "draw_handle.hh"
29#include "draw_manager.hh"
30#include "draw_shader_shared.hh"
31
32/* -------------------------------------------------------------------- */
36inline void ObjectMatrices::sync(const Object &object)
37{
38 model = object.object_to_world();
39 model_inverse = object.world_to_object();
40}
41
42inline void ObjectMatrices::sync(const float4x4 &model_matrix)
43{
44 model = model_matrix;
46}
47
48inline std::ostream &operator<<(std::ostream &stream, const ObjectMatrices &matrices)
49{
50 stream << "ObjectMatrices(" << std::endl;
51 stream << "model=" << matrices.model << ", " << std::endl;
52 stream << "model_inverse=" << matrices.model_inverse << ")" << std::endl;
53 return stream;
54}
55
58/* -------------------------------------------------------------------- */
63
64inline void ObjectInfos::sync()
65{
68
70}
71
72inline void ObjectInfos::sync(const blender::draw::ObjectRef ref, bool is_active_object)
73{
77
78 LightLinking *light_linking = (ref.dupli_parent) != nullptr ? ref.dupli_parent->light_linking :
79 ref.object->light_linking;
80 if (light_linking) {
83 }
84
85 bool is_holdout = (ref.object->base_flag & BASE_HOLDOUT) ||
87
88 ob_color = ref.object->color;
89 index = ref.object->index;
100
101 if (ref.dupli_object == nullptr) {
102 /* TODO(fclem): this is rather costly to do at draw time. Maybe we can
103 * put it in ob->runtime and make depsgraph ensure it is up to date. */
104 random = BLI_hash_int_2d(BLI_hash_string(ref.object->id.name + 2), 0) *
105 (1.0f / (float)0xFFFFFFFF);
106 }
107 else {
108 random = ref.dupli_object->random_id * (1.0f / (float)0xFFFFFFFF);
109 }
110
111 if (ref.object->data == nullptr) {
112 orco_add = float3(0.0f);
113 orco_mul = float3(1.0f);
114 return;
115 }
116
117 switch (GS(reinterpret_cast<ID *>(ref.object->data)->name)) {
118 case ID_VO: {
119 std::optional<const blender::Bounds<float3>> bounds = BKE_volume_min_max(
120 static_cast<const Volume *>(ref.object->data));
121 if (bounds) {
123 orco_mul = (bounds->max - bounds->min) * 0.5f;
124 }
125 else {
126 orco_add = float3(0.0f);
127 orco_mul = float3(1.0f);
128 }
129 break;
130 }
131 case ID_ME: {
132 BKE_mesh_texspace_get(static_cast<Mesh *>(ref.object->data), orco_add, orco_mul);
133 break;
134 }
135 case ID_CU_LEGACY: {
136 Curve &cu = *static_cast<Curve *>(ref.object->data);
140 break;
141 }
142 case ID_MB: {
143 MetaBall &mb = *static_cast<MetaBall *>(ref.object->data);
146 break;
147 }
148 default:
149 orco_add = float3(0.0f);
150 orco_mul = float3(1.0f);
151 break;
152 }
153}
154
155inline std::ostream &operator<<(std::ostream &stream, const ObjectInfos &infos)
156{
157 stream << "ObjectInfos(";
159 stream << "skipped)" << std::endl;
160 return stream;
161 }
162 stream << "orco_add=" << infos.orco_add << ", ";
163 stream << "orco_mul=" << infos.orco_mul << ", ";
164 stream << "ob_color=" << infos.ob_color << ", ";
165 stream << "index=" << infos.index << ", ";
166 stream << "random=" << infos.random << ", ";
167 stream << "flag=" << infos.flag << ")" << std::endl;
168 return stream;
169}
170
173/* -------------------------------------------------------------------- */
177inline void ObjectBounds::sync()
178{
179#ifndef NDEBUG
180 /* Initialize to NaN for easier debugging of uninitialized data usage. */
186#endif
187 bounding_sphere.w = -1.0f; /* Disable test. */
188}
189
190inline void ObjectBounds::sync(const Object &ob, float inflate_bounds)
191{
192 const std::optional<blender::Bounds<float3>> bounds = BKE_object_boundbox_get(&ob);
193 if (!bounds) {
194#ifndef NDEBUG
195 /* Initialize to NaN for easier debugging of uninitialized data usage. */
201#endif
202 bounding_sphere.w = -1.0f; /* Disable test. */
203 return;
204 }
205 BoundBox bbox;
207 *reinterpret_cast<float3 *>(&bounding_corners[0]) = bbox.vec[0];
208 *reinterpret_cast<float3 *>(&bounding_corners[1]) = bbox.vec[4];
209 *reinterpret_cast<float3 *>(&bounding_corners[2]) = bbox.vec[3];
210 *reinterpret_cast<float3 *>(&bounding_corners[3]) = bbox.vec[1];
211 bounding_sphere.w = 0.0f; /* Enable test. */
212
213 if (inflate_bounds != 0.0f) {
214 BLI_assert(inflate_bounds >= 0.0f);
215 float p = inflate_bounds;
216 float n = -inflate_bounds;
217 bounding_corners[0] += float4(n, n, n, 0.0f);
218 bounding_corners[1] += float4(p, n, n, 0.0f);
219 bounding_corners[2] += float4(n, p, n, 0.0f);
220 bounding_corners[3] += float4(n, n, p, 0.0f);
221 }
222}
223
224inline void ObjectBounds::sync(const float3 &center, const float3 &size)
225{
226 *reinterpret_cast<float3 *>(&bounding_corners[0]) = center - size;
227 *reinterpret_cast<float3 *>(&bounding_corners[1]) = center + float3(+size.x, -size.y, -size.z);
228 *reinterpret_cast<float3 *>(&bounding_corners[2]) = center + float3(-size.x, +size.y, -size.z);
229 *reinterpret_cast<float3 *>(&bounding_corners[3]) = center + float3(-size.x, -size.y, +size.z);
230 bounding_sphere.w = 0.0; /* Enable test. */
231}
232
233inline std::ostream &operator<<(std::ostream &stream, const ObjectBounds &bounds)
234{
235 stream << "ObjectBounds(";
236 if (bounds.bounding_sphere.w == -1.0f) {
237 stream << "skipped)" << std::endl;
238 return stream;
239 }
240 stream << std::endl;
241 stream << ".bounding_corners[0]"
242 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[0]) << std::endl;
243 stream << ".bounding_corners[1]"
244 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[1]) << std::endl;
245 stream << ".bounding_corners[2]"
246 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[2]) << std::endl;
247 stream << ".bounding_corners[3]"
248 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[3]) << std::endl;
249 stream << ".sphere=(pos=" << float3(bounds.bounding_sphere)
250 << ", rad=" << bounds.bounding_sphere.w << std::endl;
251 stream << ")" << std::endl;
252 return stream;
253}
254
void BKE_curve_texspace_ensure(Curve *cu)
Definition curve.cc:500
void BKE_mesh_texspace_get(Mesh *mesh, float r_texspace_location[3], float r_texspace_size[3])
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
std::optional< blender::Bounds< blender::float3 > > BKE_object_boundbox_get(const Object *ob)
Volume data-block.
std::optional< blender::Bounds< blender::float3 > > BKE_volume_min_max(const Volume *volume)
#define BLI_assert(a)
Definition BLI_assert.h:50
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash.h:71
BLI_INLINE unsigned int BLI_hash_int_2d(unsigned int kx, unsigned int ky)
Definition BLI_hash.h:55
#define NAN_FLT
#define ENUM_OPERATORS(_type, _max)
#define SET_FLAG_FROM_TEST(value, test, flag)
@ ID_VO
@ ID_CU_LEGACY
@ ID_ME
@ ID_MB
@ BASE_FROM_DUPLI
@ BASE_FROM_SET
@ BASE_HOLDOUT
Object is a sort of wrapper for general info.
@ OB_HOLDOUT
@ OB_NEG_SCALE
#define BASE_SELECTED(v3d, base)
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
std::ostream & operator<<(std::ostream &stream, const ObjectMatrices &matrices)
@ OBJECT_NO_INFO
@ OBJECT_SELECTED
@ OBJECT_FROM_DUPLI
@ OBJECT_ACTIVE
@ OBJECT_FROM_SET
@ OBJECT_HOLDOUT
@ OBJECT_NEGATIVE_SCALE
draw_view in_light_buf[] float
#define GS(x)
Definition iris.cc:202
CartesianBasis invert(const CartesianBasis &basis)
T midpoint(const T &a, const T &b)
VecBase< float, 4 > float4
float vec[8][3]
float texspace_size[3]
float texspace_location[3]
unsigned int random_id
Definition DNA_ID.h:413
char name[66]
Definition DNA_ID.h:425
LightLinkingRuntime runtime
float texspace_size[3]
float texspace_location[3]
float4 bounding_corners[4]
eObjectInfoFlag flag
packed_float3 orco_add
uint light_and_shadow_set_membership
packed_float3 orco_mul
short transflag
short base_flag
short visibility_flag
LightLinking * light_linking
float color[4]
DupliObject * dupli_object