Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/drivers/gles3/storage/mesh_storage.h
10000 views
1
/**************************************************************************/
2
/* mesh_storage.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#ifdef GLES3_ENABLED
34
35
#include "core/templates/local_vector.h"
36
#include "core/templates/rid_owner.h"
37
#include "core/templates/self_list.h"
38
#include "drivers/gles3/shaders/skeleton.glsl.gen.h"
39
#include "servers/rendering/storage/mesh_storage.h"
40
#include "servers/rendering/storage/utilities.h"
41
42
#include "platform_gl.h"
43
44
namespace GLES3 {
45
46
struct MeshInstance;
47
48
struct Mesh {
49
struct Surface {
50
struct Attrib {
51
bool enabled;
52
bool integer;
53
GLint size;
54
GLenum type;
55
GLboolean normalized;
56
GLsizei stride;
57
uint32_t offset;
58
};
59
RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS;
60
uint64_t format = 0;
61
62
GLuint vertex_buffer = 0;
63
GLuint attribute_buffer = 0;
64
GLuint skin_buffer = 0;
65
uint32_t vertex_count = 0;
66
uint32_t vertex_buffer_size = 0;
67
uint32_t attribute_buffer_size = 0;
68
uint32_t skin_buffer_size = 0;
69
70
// Cache vertex arrays so they can be created
71
struct Version {
72
uint32_t input_mask = 0;
73
GLuint vertex_array = 0;
74
75
Attrib attribs[RS::ARRAY_MAX];
76
};
77
78
SpinLock version_lock; //needed to access versions
79
Version *versions = nullptr; //allocated on demand
80
uint32_t version_count = 0;
81
82
GLuint index_buffer = 0;
83
uint32_t index_count = 0;
84
uint32_t index_buffer_size = 0;
85
86
struct Wireframe {
87
GLuint index_buffer = 0;
88
uint32_t index_count = 0;
89
uint32_t index_buffer_size = 0;
90
};
91
92
Wireframe *wireframe = nullptr;
93
94
struct LOD {
95
float edge_length = 0.0;
96
uint32_t index_count = 0;
97
uint32_t index_buffer_size = 0;
98
GLuint index_buffer = 0;
99
};
100
101
LOD *lods = nullptr;
102
uint32_t lod_count = 0;
103
104
AABB aabb;
105
106
Vector<AABB> bone_aabbs;
107
108
// Transform used in runtime bone AABBs compute.
109
// As bone AABBs are saved in Mesh space, but bones animation is in Skeleton space.
110
Transform3D mesh_to_skeleton_xform;
111
112
Vector4 uv_scale;
113
114
struct BlendShape {
115
GLuint vertex_buffer = 0;
116
GLuint vertex_array = 0;
117
};
118
119
BlendShape *blend_shapes = nullptr;
120
GLuint skeleton_vertex_array = 0;
121
122
RID material;
123
};
124
125
uint32_t blend_shape_count = 0;
126
RS::BlendShapeMode blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED;
127
128
Surface **surfaces = nullptr;
129
uint32_t surface_count = 0;
130
131
bool has_bone_weights = false;
132
133
AABB aabb;
134
AABB custom_aabb;
135
uint64_t skeleton_aabb_version = 0;
136
137
Vector<RID> material_cache;
138
139
List<MeshInstance *> instances;
140
141
RID shadow_mesh;
142
HashSet<Mesh *> shadow_owners;
143
144
String path;
145
146
Dependency dependency;
147
};
148
149
/* Mesh Instance */
150
151
struct MeshInstance {
152
Mesh *mesh = nullptr;
153
RID skeleton;
154
struct Surface {
155
GLuint vertex_buffers[2] = { 0, 0 };
156
GLuint vertex_arrays[2] = { 0, 0 };
157
GLuint vertex_buffer = 0;
158
int vertex_stride_cache = 0;
159
int vertex_size_cache = 0;
160
int vertex_normal_offset_cache = 0;
161
int vertex_tangent_offset_cache = 0;
162
uint64_t format_cache = 0;
163
164
Mesh::Surface::Version *versions = nullptr; //allocated on demand
165
uint32_t version_count = 0;
166
};
167
LocalVector<Surface> surfaces;
168
LocalVector<float> blend_weights;
169
170
List<MeshInstance *>::Element *I = nullptr; //used to erase itself
171
uint64_t skeleton_version = 0;
172
bool dirty = false;
173
bool weights_dirty = false;
174
SelfList<MeshInstance> weight_update_list;
175
SelfList<MeshInstance> array_update_list;
176
Transform2D canvas_item_transform_2d;
177
MeshInstance() :
178
weight_update_list(this), array_update_list(this) {}
179
};
180
181
/* MultiMesh */
182
183
struct MultiMesh {
184
RID mesh;
185
int instances = 0;
186
RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
187
bool uses_colors = false;
188
bool uses_custom_data = false;
189
int visible_instances = -1;
190
AABB aabb;
191
AABB custom_aabb;
192
bool aabb_dirty = false;
193
bool buffer_set = false;
194
uint32_t stride_cache = 0;
195
uint32_t color_offset_cache = 0;
196
uint32_t custom_data_offset_cache = 0;
197
198
Vector<float> data_cache; //used if individual setting is used
199
bool *data_cache_dirty_regions = nullptr;
200
uint32_t data_cache_used_dirty_regions = 0;
201
202
GLuint buffer = 0;
203
204
bool dirty = false;
205
MultiMesh *dirty_list = nullptr;
206
207
RendererMeshStorage::MultiMeshInterpolator interpolator;
208
209
Dependency dependency;
210
};
211
212
struct Skeleton {
213
bool use_2d = false;
214
int size = 0;
215
int height = 0;
216
LocalVector<float> data;
217
218
bool dirty = false;
219
Skeleton *dirty_list = nullptr;
220
Transform2D base_transform_2d;
221
222
GLuint transforms_texture = 0;
223
224
uint64_t version = 1;
225
226
Dependency dependency;
227
};
228
229
class MeshStorage : public RendererMeshStorage {
230
private:
231
static MeshStorage *singleton;
232
233
struct {
234
SkeletonShaderGLES3 shader;
235
RID shader_version;
236
} skeleton_shader;
237
238
/* Mesh */
239
240
mutable RID_Owner<Mesh, true> mesh_owner;
241
242
void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint64_t p_input_mask, MeshInstance::Surface *mis = nullptr);
243
void _mesh_surface_clear(Mesh *mesh, int p_surface);
244
245
/* Mesh Instance API */
246
247
mutable RID_Owner<MeshInstance> mesh_instance_owner;
248
249
void _mesh_instance_clear(MeshInstance *mi);
250
void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
251
void _mesh_instance_remove_surface(MeshInstance *mi, int p_surface);
252
void _blend_shape_bind_mesh_instance_buffer(MeshInstance *p_mi, uint32_t p_surface);
253
SelfList<MeshInstance>::List dirty_mesh_instance_weights;
254
SelfList<MeshInstance>::List dirty_mesh_instance_arrays;
255
256
/* MultiMesh */
257
258
mutable RID_Owner<MultiMesh, true> multimesh_owner;
259
260
MultiMesh *multimesh_dirty_list = nullptr;
261
262
_FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
263
_FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
264
_FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
265
_FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
266
267
/* Skeleton */
268
269
mutable RID_Owner<Skeleton, true> skeleton_owner;
270
271
_FORCE_INLINE_ void _skeleton_make_dirty(Skeleton *skeleton);
272
void _compute_skeleton(MeshInstance *p_mi, Skeleton *p_sk, uint32_t p_surface);
273
274
Skeleton *skeleton_dirty_list = nullptr;
275
276
public:
277
static MeshStorage *get_singleton();
278
279
MeshStorage();
280
virtual ~MeshStorage();
281
282
/* MESH API */
283
284
Mesh *get_mesh(RID p_rid) { return mesh_owner.get_or_null(p_rid); }
285
bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); }
286
287
virtual RID mesh_allocate() override;
288
virtual void mesh_initialize(RID p_rid) override;
289
virtual void mesh_free(RID p_rid) override;
290
291
virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override;
292
virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
293
294
virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override;
295
296
virtual int mesh_get_blend_shape_count(RID p_mesh) const override;
297
298
virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override;
299
virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override;
300
301
virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
302
virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
303
virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
304
virtual void mesh_surface_update_index_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
305
306
virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override;
307
virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const override;
308
309
virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override;
310
virtual int mesh_get_surface_count(RID p_mesh) const override;
311
312
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override;
313
virtual AABB mesh_get_custom_aabb(RID p_mesh) const override;
314
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;
315
316
virtual void mesh_set_path(RID p_mesh, const String &p_path) override;
317
virtual String mesh_get_path(RID p_mesh) const override;
318
319
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;
320
321
virtual void mesh_clear(RID p_mesh) override;
322
virtual void mesh_surface_remove(RID p_mesh, int p_surface) override;
323
virtual void mesh_debug_usage(List<RS::MeshInfo> *r_info) override {}
324
325
_FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) {
326
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
327
ERR_FAIL_NULL_V(mesh, nullptr);
328
r_surface_count = mesh->surface_count;
329
if (r_surface_count == 0) {
330
return nullptr;
331
}
332
if (mesh->material_cache.is_empty()) {
333
mesh->material_cache.resize(mesh->surface_count);
334
for (uint32_t i = 0; i < r_surface_count; i++) {
335
mesh->material_cache.write[i] = mesh->surfaces[i]->material;
336
}
337
}
338
339
return mesh->material_cache.ptr();
340
}
341
342
_FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
343
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
344
ERR_FAIL_NULL_V(mesh, nullptr);
345
ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
346
347
return mesh->surfaces[p_surface_index];
348
}
349
350
_FORCE_INLINE_ RID mesh_get_shadow_mesh(RID p_mesh) {
351
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
352
ERR_FAIL_NULL_V(mesh, RID());
353
354
return mesh->shadow_mesh;
355
}
356
357
_FORCE_INLINE_ RS::PrimitiveType mesh_surface_get_primitive(void *p_surface) {
358
Mesh::Surface *surface = reinterpret_cast<Mesh::Surface *>(p_surface);
359
return surface->primitive;
360
}
361
362
_FORCE_INLINE_ bool mesh_surface_has_lod(void *p_surface) const {
363
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
364
return s->lod_count > 0;
365
}
366
367
_FORCE_INLINE_ uint32_t mesh_surface_get_vertices_drawn_count(void *p_surface) const {
368
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
369
return s->index_count ? s->index_count : s->vertex_count;
370
}
371
372
_FORCE_INLINE_ uint32_t mesh_surface_get_lod(void *p_surface, float p_model_scale, float p_distance_threshold, float p_mesh_lod_threshold, uint32_t &r_index_count) const {
373
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
374
ERR_FAIL_NULL_V(s, 0);
375
376
int32_t current_lod = -1;
377
r_index_count = s->index_count;
378
379
for (uint32_t i = 0; i < s->lod_count; i++) {
380
float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold;
381
if (screen_size > p_mesh_lod_threshold) {
382
break;
383
}
384
current_lod = i;
385
}
386
if (current_lod == -1) {
387
return 0;
388
} else {
389
r_index_count = s->lods[current_lod].index_count;
390
return current_lod + 1;
391
}
392
}
393
394
_FORCE_INLINE_ GLuint mesh_surface_get_index_buffer(void *p_surface, uint32_t p_lod) const {
395
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
396
397
if (p_lod == 0) {
398
return s->index_buffer;
399
} else {
400
return s->lods[p_lod - 1].index_buffer;
401
}
402
}
403
404
_FORCE_INLINE_ GLuint mesh_surface_get_index_buffer_wireframe(void *p_surface) const {
405
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
406
407
if (s->wireframe) {
408
return s->wireframe->index_buffer;
409
}
410
411
return 0;
412
}
413
414
_FORCE_INLINE_ GLenum mesh_surface_get_index_type(void *p_surface) const {
415
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
416
417
return (s->vertex_count <= 65536 && s->vertex_count > 0) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
418
}
419
420
// Use this to cache Vertex Array Objects so they are only generated once
421
_FORCE_INLINE_ void mesh_surface_get_vertex_arrays_and_format(void *p_surface, uint64_t p_input_mask, GLuint &r_vertex_array_gl) {
422
Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
423
424
s->version_lock.lock();
425
426
// There will never be more than 3 or 4 versions, so iterating is the fastest way.
427
428
for (uint32_t i = 0; i < s->version_count; i++) {
429
if (s->versions[i].input_mask != p_input_mask) {
430
continue;
431
}
432
// We have this version, hooray.
433
r_vertex_array_gl = s->versions[i].vertex_array;
434
s->version_lock.unlock();
435
return;
436
}
437
438
uint32_t version = s->version_count;
439
s->version_count++;
440
s->versions = (Mesh::Surface::Version *)memrealloc(s->versions, sizeof(Mesh::Surface::Version) * s->version_count);
441
442
_mesh_surface_generate_version_for_input_mask(s->versions[version], s, p_input_mask);
443
444
r_vertex_array_gl = s->versions[version].vertex_array;
445
446
s->version_lock.unlock();
447
}
448
449
/* MESH INSTANCE API */
450
451
MeshInstance *get_mesh_instance(RID p_rid) { return mesh_instance_owner.get_or_null(p_rid); }
452
bool owns_mesh_instance(RID p_rid) { return mesh_instance_owner.owns(p_rid); }
453
454
virtual RID mesh_instance_create(RID p_base) override;
455
virtual void mesh_instance_free(RID p_rid) override;
456
virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override;
457
virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override;
458
virtual void mesh_instance_check_for_update(RID p_mesh_instance) override;
459
virtual void mesh_instance_set_canvas_item_transform(RID p_mesh_instance, const Transform2D &p_transform) override;
460
virtual void update_mesh_instances() override;
461
462
// TODO: considering hashing versions with multimesh buffer RID.
463
// Doing so would allow us to avoid specifying multimesh buffer pointers every frame and may improve performance.
464
_FORCE_INLINE_ void mesh_instance_surface_get_vertex_arrays_and_format(RID p_mesh_instance, uint32_t p_surface_index, uint64_t p_input_mask, GLuint &r_vertex_array_gl) {
465
MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
466
ERR_FAIL_NULL(mi);
467
Mesh *mesh = mi->mesh;
468
ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
469
470
MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
471
Mesh::Surface *s = mesh->surfaces[p_surface_index];
472
473
s->version_lock.lock();
474
475
//there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
476
477
for (uint32_t i = 0; i < mis->version_count; i++) {
478
if (mis->versions[i].input_mask != p_input_mask) {
479
continue;
480
}
481
//we have this version, hooray
482
r_vertex_array_gl = mis->versions[i].vertex_array;
483
s->version_lock.unlock();
484
return;
485
}
486
487
uint32_t version = mis->version_count;
488
mis->version_count++;
489
mis->versions = (Mesh::Surface::Version *)memrealloc(mis->versions, sizeof(Mesh::Surface::Version) * mis->version_count);
490
491
_mesh_surface_generate_version_for_input_mask(mis->versions[version], s, p_input_mask, mis);
492
493
r_vertex_array_gl = mis->versions[version].vertex_array;
494
495
s->version_lock.unlock();
496
}
497
498
/* MULTIMESH API */
499
500
MultiMesh *get_multimesh(RID p_rid) { return multimesh_owner.get_or_null(p_rid); }
501
bool owns_multimesh(RID p_rid) { return multimesh_owner.owns(p_rid); }
502
503
virtual RID _multimesh_allocate() override;
504
virtual void _multimesh_initialize(RID p_rid) override;
505
virtual void _multimesh_free(RID p_rid) override;
506
virtual void _multimesh_allocate_data(RID p_multimesh, int p_instances, RS::MultimeshTransformFormat p_transform_format, bool p_use_colors = false, bool p_use_custom_data = false, bool p_use_indirect = false) override;
507
virtual int _multimesh_get_instance_count(RID p_multimesh) const override;
508
509
virtual void _multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
510
virtual void _multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
511
virtual void _multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
512
virtual void _multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
513
virtual void _multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
514
515
virtual RID _multimesh_get_mesh(RID p_multimesh) const override;
516
virtual void _multimesh_set_custom_aabb(RID p_multimesh, const AABB &p_aabb) override;
517
virtual AABB _multimesh_get_custom_aabb(RID p_multimesh) const override;
518
virtual AABB _multimesh_get_aabb(RID p_multimesh) override;
519
520
virtual Transform3D _multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
521
virtual Transform2D _multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
522
virtual Color _multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
523
virtual Color _multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
524
virtual void _multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
525
virtual RID _multimesh_get_command_buffer_rd_rid(RID p_multimesh) const override;
526
virtual RID _multimesh_get_buffer_rd_rid(RID p_multimesh) const override;
527
virtual Vector<float> _multimesh_get_buffer(RID p_multimesh) const override;
528
529
virtual void _multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
530
virtual int _multimesh_get_visible_instances(RID p_multimesh) const override;
531
532
virtual MultiMeshInterpolator *_multimesh_get_interpolator(RID p_multimesh) const override;
533
534
void _update_dirty_multimeshes();
535
536
_FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
537
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
538
ERR_FAIL_NULL_V(multimesh, RS::MULTIMESH_TRANSFORM_3D);
539
return multimesh->xform_format;
540
}
541
542
_FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
543
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
544
ERR_FAIL_NULL_V(multimesh, false);
545
return multimesh->uses_colors;
546
}
547
548
_FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
549
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
550
ERR_FAIL_NULL_V(multimesh, false);
551
return multimesh->uses_custom_data;
552
}
553
554
_FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
555
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
556
ERR_FAIL_NULL_V(multimesh, 0);
557
if (multimesh->visible_instances >= 0) {
558
return multimesh->visible_instances;
559
}
560
return multimesh->instances;
561
}
562
563
_FORCE_INLINE_ GLuint multimesh_get_gl_buffer(RID p_multimesh) const {
564
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
565
ERR_FAIL_NULL_V(multimesh, 0);
566
return multimesh->buffer;
567
}
568
569
_FORCE_INLINE_ uint32_t multimesh_get_stride(RID p_multimesh) const {
570
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
571
ERR_FAIL_NULL_V(multimesh, 0);
572
return multimesh->stride_cache;
573
}
574
575
_FORCE_INLINE_ uint32_t multimesh_get_color_offset(RID p_multimesh) const {
576
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
577
ERR_FAIL_NULL_V(multimesh, 0);
578
return multimesh->color_offset_cache;
579
}
580
581
_FORCE_INLINE_ uint32_t multimesh_get_custom_data_offset(RID p_multimesh) const {
582
MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
583
ERR_FAIL_NULL_V(multimesh, 0);
584
return multimesh->custom_data_offset_cache;
585
}
586
587
/* SKELETON API */
588
589
Skeleton *get_skeleton(RID p_rid) { return skeleton_owner.get_or_null(p_rid); }
590
bool owns_skeleton(RID p_rid) { return skeleton_owner.owns(p_rid); }
591
592
virtual RID skeleton_allocate() override;
593
virtual void skeleton_initialize(RID p_rid) override;
594
virtual void skeleton_free(RID p_rid) override;
595
596
virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override;
597
virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override;
598
virtual int skeleton_get_bone_count(RID p_skeleton) const override;
599
virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override;
600
virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override;
601
virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override;
602
virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override;
603
604
virtual void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override;
605
606
void _update_dirty_skeletons();
607
608
_FORCE_INLINE_ bool skeleton_is_valid(RID p_skeleton) {
609
return skeleton_owner.get_or_null(p_skeleton) != nullptr;
610
}
611
};
612
613
} // namespace GLES3
614
615
#endif // GLES3_ENABLED
616
617