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

draw_resource.cc « intern « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 689df4edb31dc8c14aeedc8800f928ca9fbf7c81 (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
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2022 Blender Foundation. */

/** \file
 * \ingroup draw
 */

#include "DNA_particle_types.h"
#include "RNA_access.h"
#include "RNA_path.h"
#include "RNA_types.h"

#include "draw_handle.hh"
#include "draw_manager.hh"
#include "draw_shader_shared.h"

/* -------------------------------------------------------------------- */
/** \name ObjectAttributes
 * \{ */

/**
 * Extract object attribute from RNA property.
 * Returns true if the attribute was correctly extracted.
 * This function mirrors lookup_property in cycles/blender/blender_object.cpp
 */
bool ObjectAttribute::id_property_lookup(ID *id, const char *name)
{
  PointerRNA ptr, id_ptr;
  PropertyRNA *prop;

  if (id == nullptr) {
    return false;
  }

  RNA_id_pointer_create(id, &id_ptr);

  if (!RNA_path_resolve(&id_ptr, name, &ptr, &prop)) {
    return false;
  }

  if (prop == nullptr) {
    return false;
  }

  PropertyType type = RNA_property_type(prop);
  int array_len = RNA_property_array_length(&ptr, prop);

  if (array_len == 0) {
    float value;

    if (type == PROP_FLOAT) {
      value = RNA_property_float_get(&ptr, prop);
    }
    else if (type == PROP_INT) {
      value = RNA_property_int_get(&ptr, prop);
    }
    else {
      return false;
    }

    *reinterpret_cast<float4 *>(&data_x) = float4(value, value, value, 1.0f);
    return true;
  }

  if (type == PROP_FLOAT && array_len <= 4) {
    *reinterpret_cast<float4 *>(&data_x) = float4(0.0f, 0.0f, 0.0f, 1.0f);
    RNA_property_float_get_array(&ptr, prop, &data_x);
    return true;
  }
  return false;
}

/**
 * Go through all possible source of the given object uniform attribute.
 * Returns true if the attribute was correctly filled.
 * This function mirrors lookup_instance_property in cycles/blender/blender_object.cpp
 */
bool ObjectAttribute::sync(const blender::draw::ObjectRef &ref, const GPUUniformAttr &attr)
{
  hash_code = attr.hash_code;

  /* If requesting instance data, check the parent particle system and object. */
  if (attr.use_dupli) {
    if ((ref.dupli_object != nullptr) && (ref.dupli_object->particle_system != nullptr)) {
      ParticleSettings *settings = ref.dupli_object->particle_system->part;
      if (this->id_property_lookup((ID *)settings, attr.name_id_prop) ||
          this->id_property_lookup((ID *)settings, attr.name)) {
        return true;
      }
    }
    if (this->id_property_lookup((ID *)ref.dupli_parent, attr.name_id_prop) ||
        this->id_property_lookup((ID *)ref.dupli_parent, attr.name)) {
      return true;
    }
  }

  /* Check the object and mesh. */
  if (ref.object != nullptr) {
    if (this->id_property_lookup((ID *)ref.object, attr.name_id_prop) ||
        this->id_property_lookup((ID *)ref.object, attr.name) ||
        this->id_property_lookup((ID *)ref.object->data, attr.name_id_prop) ||
        this->id_property_lookup((ID *)ref.object->data, attr.name)) {
      return true;
    }
  }
  return false;
}

/** \} */