Blender V5.3
draw_model.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "gpu_shader_compat.hh"
12
13#include "draw_shader_shared.hh"
14
15namespace draw {
16
17struct ID {
18 uint raw_id;
19
20 template<int view_count> uint view_id() const
21 {
23 return raw_id & ~(0xFFFFFFFFu << ((view_count > 32) ? 6 :
24 (view_count > 16) ? 5 :
25 (view_count > 8) ? 4 :
26 (view_count > 4) ? 3 :
27 (view_count > 2) ? 2 :
28 (view_count > 1) ? 1 :
29 0));
30 }
31
32 template<int view_count> uint resource_id() const
33 {
34 return raw_id >> ((view_count > 32) ? 6 :
35 (view_count > 16) ? 5 :
36 (view_count > 8) ? 4 :
37 (view_count > 4) ? 3 :
38 (view_count > 2) ? 2 :
39 (view_count > 1) ? 1 :
40 0);
41 }
42};
43
44template uint ID::view_id<1>() const;
45template uint ID::view_id<64>() const;
46template uint ID::resource_id<1>() const;
47template uint ID::resource_id<64>() const;
48
49struct Resource {
50 [[storage(DRW_RESOURCE_ID_SLOT, read)]] const uint (&res_id_buf)[];
51
52 /* `instance_index` must be the `[[instance_index]]` entry point parameter. */
54 {
55 uint raw = res_id_buf[instance_index];
56 return {raw};
57 }
58};
59
62
63 /* `instance_index` must be the `[[instance_index]]` entry point parameter. */
65 {
67 }
68
69 /* `instance_index` must be the `[[instance_index]]` entry point parameter. */
74};
75
76struct Model {
78
79 /* `resource_id` should be the result of `draw::ID::resource_id()` or manually indexed. */
80 ObjectMatrices get(uint resource_id) const
81 {
82 return drw_matrix_buf[resource_id];
83 }
84};
85
86struct Infos {
88
89 /* `resource_id` should be the result of `draw::ID::resource_id()` or manually indexed. */
90 ObjectInfos get(uint resource_id) const
91 {
92 return drw_infos[resource_id];
93 }
94};
95
96struct Attributes {
98
99 float4 get(ObjectInfos infos, const uint attr_hash) const
100 {
101 uint index = infos.object_attrs_offset;
102 for (uint i = 0; i < infos.object_attrs_len; i++, index++) {
104 if (attr.hash_code == attr_hash) {
105 return float4(attr.data_x, attr.data_y, attr.data_z, attr.data_w);
106 }
107 }
108 return float4(0.0f);
109 }
110};
111
112} // namespace draw
#define DRW_RESOURCE_ID_SLOT
#define DRW_OBJ_INFOS_SLOT
#define DRW_OBJ_ATTR_SLOT
#define DRW_OBJ_MAT_SLOT
#define instance_index
#define storage(slot, qualifiers)
#define index(i)
float4 get(ObjectInfos infos, const uint attr_hash) const
const ObjectAttribute(& drw_attrs)[]
uint view_id() const
uint resource_id() const
ObjectInfos get(uint resource_id) const
const ObjectInfos(& drw_infos)[]
ObjectMatrices get(uint resource_id) const
const ObjectMatrices(& drw_matrix_buf)[]
uint get_custom_id(int instance_index) const
ID get(int instance_index) const
const uint2(& res_id_with_custom_id_buf)[]
ID get(int instance_index) const
const uint(& res_id_buf)[]