Welcome to mirror list, hosted at ThFree Co, Russian Federation.

draw_resource.hh « intern « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9761c83f964cc179d4ebcfd463e7388ea1e1f055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2022 Blender Foundation. */

#pragma once

/** \file
 * \ingroup draw
 *
 * Component / Object level resources like object attributes, matrices, visibility etc...
 * Each of them are reference by resource index (#ResourceHandle).
 */

#include "BKE_duplilist.h"
#include "DNA_object_types.h"

#include "draw_shader_shared.h"

namespace blender::draw {

/* -------------------------------------------------------------------- */
/** \name ObjectMatrices
 * \{ */

void ObjectMatrices::sync(const Object &object)
{
  model = object->obmat;
  model_inverse = object->imat;
}

void ObjectMatrices::sync(const float4x4 &object_mat)
{
  model = object_mat;
  model_inverse = object_mat.inverted();
}

/** \} */

/* -------------------------------------------------------------------- */
/** \name ObjectInfos
 * \{ */

void ObjectInfos::sync(const draw::ObjectRef ref, bool is_active_object)
{
  color = ref.object.color;
  index = ref.object.index;
  SET_FLAG_FROM_TEST(flag, is_active_object, DRW_OBJECT_ACTIVE);
  SET_FLAG_FROM_TEST(flag, ref.object.base_flag & BASE_SELECTED, DRW_OBJECT_SELECTED);
  SET_FLAG_FROM_TEST(flag, ref.object.base_flag & BASE_FROM_DUPLI, DRW_OBJECT_FROM_DUPLI);
  SET_FLAG_FROM_TEST(flag, ref.object.base_flag & BASE_FROM_SET, DRW_OBJECT_FROM_SET);
  SET_FLAG_FROM_TEST(flag, ref.object.transflag & OB_NEG_SCALE, DRW_OBJECT_NEGATIVE_SCALE);

  if (ref.dupli == nullptr) {
    /* TODO(fclem): this is rather costly to do at runtime. Maybe we can
     * put it in ob->runtime and make depsgraph ensure it is up to date. */
    random = BLI_hash_int_2d(BLI_hash_string(ref.object.id.name + 2), 0) * (1.0f / 0xFFFFFFFF);
  }
  else {
    random = ref.dupli.random_id * (1.0f / 0xFFFFFFFF);
  }
  /* Default values. Set if needed. */
  random = 0.0f;

  if (ref.object.data == nullptr) {
    orco_add = float3(0.0f);
    orco_mul = float3(1.0f);
    return;
  }

  switch (GS(ref.object.data->name)) {
    case ID_VO: {
      BoundBox &bbox = *BKE_volume_boundbox_get(object);
      orco_add = (float3(bbox.vec[6]) + float3(bbox.vec[0])) * 0.5f; /* Center. */
      orco_mul = float3(bbox.vec[6]) - float3(bbox.vec[0]);          /* Size. */
      break;
    }
    case ID_ME: {
      BKE_mesh_texspace_get((Mesh *)ref.object.data, orco_add, orco_mul);
      break;
    }
    case ID_CU_LEGACY: {
      Curve &cu = *(Curve *)ref.object.data;
      BKE_curve_texspace_ensure(&cu);
      orco_add = cu.loc;
      orco_mul = cu.size;
      break;
    }
    case ID_MB: {
      MetaBall &mb = *(MetaBall *)ref.object.data;
      orco_add = mb.loc;
      orco_mul = mb.size;
      break;
    }
    default:
      orco_add = float3(0.0f);
      orco_mul = float3(1.0f);
      break;
  }
}

/** \} */

/* -------------------------------------------------------------------- */
/** \name ObjectBounds
 * \{ */

void ObjectBounds::sync(const Object &ob)
{
  const BoundBox *bbox = BKE_object_boundbox_get(ob);
  if (bbox == nullptr) {
    bounding_sphere.w = -1.0f; /* Disable test. */
    return;
  }
  bounding_corners[0] = bbox->vec[0];
  bounding_corners[1] = bbox->vec[4];
  bounding_corners[2] = bbox->vec[3];
  bounding_corners[3] = bbox->vec[1];
  bounding_sphere.w = 0.0f; /* Enable test. */
}

/** \} */

};  // namespace blender::draw