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