Blender V4.5
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
13
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 "DRW_render.hh"
29#include "draw_handle.hh"
30#include "draw_shader_shared.hh"
31
32/* -------------------------------------------------------------------- */
35
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
57
58/* -------------------------------------------------------------------- */
61
62inline void ObjectInfos::sync()
63{
66
68}
69
70inline void ObjectInfos::sync(const blender::draw::ObjectRef ref,
71 bool is_active_object,
72 bool is_active_edit_mode)
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;
101
102 if (ref.object->shadow_terminator_normal_offset > 0.0f) {
103 using namespace blender::math;
106 reduce_max(to_scale(ref.object->object_to_world()));
107 }
108 else {
111 }
112
113 if (ref.dupli_object == nullptr) {
114 /* TODO(fclem): this is rather costly to do at draw time. Maybe we can
115 * put it in ob->runtime and make depsgraph ensure it is up to date. */
117 (1.0f / (float)0xFFFFFFFF);
118 }
119 else {
120 random = ref.dupli_object->random_id * (1.0f / (float)0xFFFFFFFF);
121 }
122
123 if (ref.object->data == nullptr) {
124 orco_add = float3(0.0f);
125 orco_mul = float3(1.0f);
126 return;
127 }
128
129 switch (GS(reinterpret_cast<ID *>(ref.object->data)->name)) {
130 case ID_VO: {
131 std::optional<const blender::Bounds<float3>> bounds = BKE_volume_min_max(
133 if (bounds) {
135 orco_mul = (bounds->max - bounds->min) * 0.5f;
136 }
137 else {
138 orco_add = float3(0.0f);
139 orco_mul = float3(1.0f);
140 }
141 break;
142 }
143 case ID_ME: {
146 break;
147 }
148 case ID_CU_LEGACY: {
153 break;
154 }
155 case ID_MB: {
159 break;
160 }
161 default:
162 orco_add = float3(0.0f);
163 orco_mul = float3(1.0f);
164 break;
165 }
166}
167
168inline std::ostream &operator<<(std::ostream &stream, const ObjectInfos &infos)
169{
170 stream << "ObjectInfos(";
172 stream << "skipped)" << std::endl;
173 return stream;
174 }
175 stream << "orco_add=" << infos.orco_add << ", ";
176 stream << "orco_mul=" << infos.orco_mul << ", ";
177 stream << "ob_color=" << infos.ob_color << ", ";
178 stream << "index=" << infos.index << ", ";
179 stream << "random=" << infos.random << ", ";
180 stream << "flag=" << infos.flag << ")" << std::endl;
181 return stream;
182}
183
185
186/* -------------------------------------------------------------------- */
189
190inline void ObjectBounds::sync()
191{
192#ifndef NDEBUG
193 /* Initialize to NaN for easier debugging of uninitialized data usage. */
199#endif
200 bounding_sphere.w = -1.0f; /* Disable test. */
201}
202
203inline void ObjectBounds::sync(const Object &ob, float inflate_bounds)
204{
205 const std::optional<blender::Bounds<float3>> bounds = BKE_object_boundbox_get(&ob);
206 if (!bounds) {
207#ifndef NDEBUG
208 /* Initialize to NaN for easier debugging of uninitialized data usage. */
214#endif
215 bounding_sphere.w = -1.0f; /* Disable test. */
216 return;
217 }
218 BoundBox bbox;
220 *reinterpret_cast<float3 *>(&bounding_corners[0]) = bbox.vec[0];
221 *reinterpret_cast<float3 *>(&bounding_corners[1]) = bbox.vec[4];
222 *reinterpret_cast<float3 *>(&bounding_corners[2]) = bbox.vec[3];
223 *reinterpret_cast<float3 *>(&bounding_corners[3]) = bbox.vec[1];
224 bounding_sphere.w = 0.0f; /* Enable test. */
225
226 if (inflate_bounds != 0.0f) {
227 BLI_assert(inflate_bounds >= 0.0f);
228 float p = inflate_bounds;
229 float n = -inflate_bounds;
230 bounding_corners[0] += float4(n, n, n, 0.0f);
231 bounding_corners[1] += float4(p, n, n, 0.0f);
232 bounding_corners[2] += float4(n, p, n, 0.0f);
233 bounding_corners[3] += float4(n, n, p, 0.0f);
234 }
235}
236
237inline void ObjectBounds::sync(const float3 &center, const float3 &size)
238{
239 *reinterpret_cast<float3 *>(&bounding_corners[0]) = center - size;
240 *reinterpret_cast<float3 *>(&bounding_corners[1]) = center + float3(+size.x, -size.y, -size.z);
241 *reinterpret_cast<float3 *>(&bounding_corners[2]) = center + float3(-size.x, +size.y, -size.z);
242 *reinterpret_cast<float3 *>(&bounding_corners[3]) = center + float3(-size.x, -size.y, +size.z);
243 bounding_sphere.w = 0.0; /* Enable test. */
244}
245
246inline std::ostream &operator<<(std::ostream &stream, const ObjectBounds &bounds)
247{
248 stream << "ObjectBounds(";
249 if (bounds.bounding_sphere.w == -1.0f) {
250 stream << "skipped)" << std::endl;
251 return stream;
252 }
253 stream << std::endl;
254 stream << ".bounding_corners[0]"
255 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[0]) << std::endl;
256 stream << ".bounding_corners[1]"
257 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[1]) << std::endl;
258 stream << ".bounding_corners[2]"
259 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[2]) << std::endl;
260 stream << ".bounding_corners[3]"
261 << *reinterpret_cast<const float3 *>(&bounds.bounding_corners[3]) << std::endl;
262 stream << ".sphere=(pos=" << float3(bounds.bounding_sphere)
263 << ", rad=" << bounds.bounding_sphere.w << std::endl;
264 stream << ")" << std::endl;
265 return stream;
266}
267
void BKE_curve_texspace_ensure(Curve *cu)
Definition curve.cc:506
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:46
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash.h:67
BLI_INLINE unsigned int BLI_hash_int_2d(unsigned int kx, unsigned int ky)
Definition BLI_hash.h:51
#define NAN_FLT
#define SET_FLAG_FROM_TEST(value, test, flag)
struct ID ID
@ ID_VO
@ ID_CU_LEGACY
@ ID_ME
@ ID_MB
struct Curve Curve
@ BASE_FROM_DUPLI
@ BASE_FROM_SET
@ BASE_HOLDOUT
struct MetaBall MetaBall
Object is a sort of wrapper for general info.
@ OB_NEG_SCALE
@ OB_HOLDOUT
struct LightLinking LightLinking
struct BoundBox BoundBox
#define BASE_SELECTED(v3d, base)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
reduce_max(value.rgb)") DEFINE_VALUE("REDUCE(lhs
Mesh & DRW_object_get_data_for_drawing(const Object &object)
std::ostream & operator<<(std::ostream &stream, const ObjectMatrices &matrices)
@ OBJECT_NO_INFO
@ OBJECT_SELECTED
@ OBJECT_FROM_DUPLI
@ OBJECT_ACTIVE
@ OBJECT_ACTIVE_EDIT_MODE
@ OBJECT_FROM_SET
@ OBJECT_HOLDOUT
@ OBJECT_NEGATIVE_SCALE
#define GS(a)
CartesianBasis invert(const CartesianBasis &basis)
T midpoint(const T &a, const T &b)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 3 > float3
float vec[8][3]
float texspace_size[3]
float texspace_location[3]
unsigned int random_id
char name[66]
Definition DNA_ID.h:415
LightLinkingRuntime runtime
float texspace_size[3]
float texspace_location[3]
float4 bounding_corners[4]
eObjectInfoFlag flag
packed_float3 orco_add
float shadow_terminator_normal_offset
uint light_and_shadow_set_membership
float shadow_terminator_geometry_offset
packed_float3 orco_mul
short transflag
short base_flag
short visibility_flag
float shadow_terminator_geometry_offset
LightLinking * light_linking
float color[4]
float shadow_terminator_normal_offset
DupliObject * dupli_object