mesh_storage.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. #ifndef MESH_STORAGE_GLES3_H
  31. #define MESH_STORAGE_GLES3_H
  32. #ifdef GLES3_ENABLED
  33. #include "../shaders/skeleton.glsl.gen.h"
  34. #include "core/templates/local_vector.h"
  35. #include "core/templates/rid_owner.h"
  36. #include "core/templates/self_list.h"
  37. #include "servers/rendering/storage/mesh_storage.h"
  38. #include "servers/rendering/storage/utilities.h"
  39. #include "platform_config.h"
  40. #ifndef OPENGL_INCLUDE_H
  41. #include <GLES3/gl3.h>
  42. #else
  43. #include OPENGL_INCLUDE_H
  44. #endif
  45. namespace GLES3 {
  46. struct MeshInstance;
  47. struct Mesh {
  48. struct Surface {
  49. struct Attrib {
  50. bool enabled;
  51. bool integer;
  52. GLint size;
  53. GLenum type;
  54. GLboolean normalized;
  55. GLsizei stride;
  56. uint32_t offset;
  57. };
  58. RS::PrimitiveType primitive = RS::PRIMITIVE_POINTS;
  59. uint32_t format = 0;
  60. GLuint vertex_buffer = 0;
  61. GLuint attribute_buffer = 0;
  62. GLuint skin_buffer = 0;
  63. uint32_t vertex_count = 0;
  64. uint32_t vertex_buffer_size = 0;
  65. uint32_t attribute_buffer_size = 0;
  66. uint32_t skin_buffer_size = 0;
  67. // Cache vertex arrays so they can be created
  68. struct Version {
  69. uint32_t input_mask = 0;
  70. GLuint vertex_array = 0;
  71. Attrib attribs[RS::ARRAY_MAX];
  72. };
  73. SpinLock version_lock; //needed to access versions
  74. Version *versions = nullptr; //allocated on demand
  75. uint32_t version_count = 0;
  76. GLuint index_buffer = 0;
  77. uint32_t index_count = 0;
  78. uint32_t index_buffer_size = 0;
  79. struct LOD {
  80. float edge_length = 0.0;
  81. uint32_t index_count = 0;
  82. uint32_t index_buffer_size = 0;
  83. GLuint index_buffer = 0;
  84. };
  85. LOD *lods = nullptr;
  86. uint32_t lod_count = 0;
  87. AABB aabb;
  88. Vector<AABB> bone_aabbs;
  89. struct BlendShape {
  90. GLuint vertex_buffer = 0;
  91. GLuint vertex_array = 0;
  92. };
  93. BlendShape *blend_shapes = nullptr;
  94. GLuint skeleton_vertex_array = 0;
  95. RID material;
  96. };
  97. uint32_t blend_shape_count = 0;
  98. RS::BlendShapeMode blend_shape_mode = RS::BLEND_SHAPE_MODE_NORMALIZED;
  99. Surface **surfaces = nullptr;
  100. uint32_t surface_count = 0;
  101. bool has_bone_weights = false;
  102. AABB aabb;
  103. AABB custom_aabb;
  104. uint64_t skeleton_aabb_version = 0;
  105. Vector<RID> material_cache;
  106. List<MeshInstance *> instances;
  107. RID shadow_mesh;
  108. HashSet<Mesh *> shadow_owners;
  109. Dependency dependency;
  110. };
  111. /* Mesh Instance */
  112. struct MeshInstance {
  113. Mesh *mesh = nullptr;
  114. RID skeleton;
  115. struct Surface {
  116. GLuint vertex_buffers[2] = { 0, 0 };
  117. GLuint vertex_arrays[2] = { 0, 0 };
  118. GLuint vertex_buffer = 0;
  119. int vertex_stride_cache = 0;
  120. int vertex_size_cache = 0;
  121. int vertex_normal_offset_cache = 0;
  122. int vertex_tangent_offset_cache = 0;
  123. uint32_t format_cache = 0;
  124. Mesh::Surface::Version *versions = nullptr; //allocated on demand
  125. uint32_t version_count = 0;
  126. };
  127. LocalVector<Surface> surfaces;
  128. LocalVector<float> blend_weights;
  129. List<MeshInstance *>::Element *I = nullptr; //used to erase itself
  130. uint64_t skeleton_version = 0;
  131. bool dirty = false;
  132. bool weights_dirty = false;
  133. SelfList<MeshInstance> weight_update_list;
  134. SelfList<MeshInstance> array_update_list;
  135. Transform2D canvas_item_transform_2d;
  136. MeshInstance() :
  137. weight_update_list(this), array_update_list(this) {}
  138. };
  139. /* MultiMesh */
  140. struct MultiMesh {
  141. RID mesh;
  142. int instances = 0;
  143. RS::MultimeshTransformFormat xform_format = RS::MULTIMESH_TRANSFORM_3D;
  144. bool uses_colors = false;
  145. bool uses_custom_data = false;
  146. int visible_instances = -1;
  147. AABB aabb;
  148. bool aabb_dirty = false;
  149. bool buffer_set = false;
  150. uint32_t stride_cache = 0;
  151. uint32_t color_offset_cache = 0;
  152. uint32_t custom_data_offset_cache = 0;
  153. Vector<float> data_cache; //used if individual setting is used
  154. bool *data_cache_dirty_regions = nullptr;
  155. uint32_t data_cache_used_dirty_regions = 0;
  156. GLuint buffer = 0;
  157. bool dirty = false;
  158. MultiMesh *dirty_list = nullptr;
  159. Dependency dependency;
  160. };
  161. struct Skeleton {
  162. bool use_2d = false;
  163. int size = 0;
  164. int height = 0;
  165. Vector<float> data;
  166. bool dirty = false;
  167. Skeleton *dirty_list = nullptr;
  168. Transform2D base_transform_2d;
  169. GLuint transforms_texture = 0;
  170. uint64_t version = 1;
  171. Dependency dependency;
  172. };
  173. class MeshStorage : public RendererMeshStorage {
  174. private:
  175. static MeshStorage *singleton;
  176. struct {
  177. SkeletonShaderGLES3 shader;
  178. RID shader_version;
  179. } skeleton_shader;
  180. /* Mesh */
  181. mutable RID_Owner<Mesh, true> mesh_owner;
  182. void _mesh_surface_generate_version_for_input_mask(Mesh::Surface::Version &v, Mesh::Surface *s, uint32_t p_input_mask, MeshInstance::Surface *mis = nullptr);
  183. /* Mesh Instance API */
  184. mutable RID_Owner<MeshInstance> mesh_instance_owner;
  185. void _mesh_instance_clear(MeshInstance *mi);
  186. void _mesh_instance_add_surface(MeshInstance *mi, Mesh *mesh, uint32_t p_surface);
  187. void _blend_shape_bind_mesh_instance_buffer(MeshInstance *p_mi, uint32_t p_surface);
  188. SelfList<MeshInstance>::List dirty_mesh_instance_weights;
  189. SelfList<MeshInstance>::List dirty_mesh_instance_arrays;
  190. /* MultiMesh */
  191. mutable RID_Owner<MultiMesh, true> multimesh_owner;
  192. MultiMesh *multimesh_dirty_list = nullptr;
  193. _FORCE_INLINE_ void _multimesh_make_local(MultiMesh *multimesh) const;
  194. _FORCE_INLINE_ void _multimesh_mark_dirty(MultiMesh *multimesh, int p_index, bool p_aabb);
  195. _FORCE_INLINE_ void _multimesh_mark_all_dirty(MultiMesh *multimesh, bool p_data, bool p_aabb);
  196. _FORCE_INLINE_ void _multimesh_re_create_aabb(MultiMesh *multimesh, const float *p_data, int p_instances);
  197. /* Skeleton */
  198. mutable RID_Owner<Skeleton, true> skeleton_owner;
  199. _FORCE_INLINE_ void _skeleton_make_dirty(Skeleton *skeleton);
  200. void _compute_skeleton(MeshInstance *p_mi, Skeleton *p_sk, uint32_t p_surface);
  201. Skeleton *skeleton_dirty_list = nullptr;
  202. public:
  203. static MeshStorage *get_singleton();
  204. MeshStorage();
  205. virtual ~MeshStorage();
  206. /* MESH API */
  207. Mesh *get_mesh(RID p_rid) { return mesh_owner.get_or_null(p_rid); };
  208. bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); };
  209. virtual RID mesh_allocate() override;
  210. virtual void mesh_initialize(RID p_rid) override;
  211. virtual void mesh_free(RID p_rid) override;
  212. virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override;
  213. virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
  214. virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override;
  215. virtual int mesh_get_blend_shape_count(RID p_mesh) const override;
  216. virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override;
  217. virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override;
  218. virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
  219. virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
  220. virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override;
  221. virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override;
  222. virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const override;
  223. virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override;
  224. virtual int mesh_get_surface_count(RID p_mesh) const override;
  225. virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override;
  226. virtual AABB mesh_get_custom_aabb(RID p_mesh) const override;
  227. virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;
  228. virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;
  229. virtual void mesh_clear(RID p_mesh) override;
  230. _FORCE_INLINE_ const RID *mesh_get_surface_count_and_materials(RID p_mesh, uint32_t &r_surface_count) {
  231. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  232. ERR_FAIL_COND_V(!mesh, nullptr);
  233. r_surface_count = mesh->surface_count;
  234. if (r_surface_count == 0) {
  235. return nullptr;
  236. }
  237. if (mesh->material_cache.is_empty()) {
  238. mesh->material_cache.resize(mesh->surface_count);
  239. for (uint32_t i = 0; i < r_surface_count; i++) {
  240. mesh->material_cache.write[i] = mesh->surfaces[i]->material;
  241. }
  242. }
  243. return mesh->material_cache.ptr();
  244. }
  245. _FORCE_INLINE_ void *mesh_get_surface(RID p_mesh, uint32_t p_surface_index) {
  246. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  247. ERR_FAIL_COND_V(!mesh, nullptr);
  248. ERR_FAIL_UNSIGNED_INDEX_V(p_surface_index, mesh->surface_count, nullptr);
  249. return mesh->surfaces[p_surface_index];
  250. }
  251. _FORCE_INLINE_ RID mesh_get_shadow_mesh(RID p_mesh) {
  252. Mesh *mesh = mesh_owner.get_or_null(p_mesh);
  253. ERR_FAIL_COND_V(!mesh, RID());
  254. return mesh->shadow_mesh;
  255. }
  256. _FORCE_INLINE_ RS::PrimitiveType mesh_surface_get_primitive(void *p_surface) {
  257. Mesh::Surface *surface = reinterpret_cast<Mesh::Surface *>(p_surface);
  258. return surface->primitive;
  259. }
  260. _FORCE_INLINE_ bool mesh_surface_has_lod(void *p_surface) const {
  261. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  262. return s->lod_count > 0;
  263. }
  264. _FORCE_INLINE_ uint32_t mesh_surface_get_vertices_drawn_count(void *p_surface) const {
  265. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  266. return s->index_count ? s->index_count : s->vertex_count;
  267. }
  268. _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 {
  269. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  270. ERR_FAIL_COND_V(!s, 0);
  271. int32_t current_lod = -1;
  272. r_index_count = s->index_count;
  273. for (uint32_t i = 0; i < s->lod_count; i++) {
  274. float screen_size = s->lods[i].edge_length * p_model_scale / p_distance_threshold;
  275. if (screen_size > p_mesh_lod_threshold) {
  276. break;
  277. }
  278. current_lod = i;
  279. }
  280. if (current_lod == -1) {
  281. return 0;
  282. } else {
  283. r_index_count = s->lods[current_lod].index_count;
  284. return current_lod + 1;
  285. }
  286. }
  287. _FORCE_INLINE_ GLuint mesh_surface_get_index_buffer(void *p_surface, uint32_t p_lod) const {
  288. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  289. if (p_lod == 0) {
  290. return s->index_buffer;
  291. } else {
  292. return s->lods[p_lod - 1].index_buffer;
  293. }
  294. }
  295. _FORCE_INLINE_ GLenum mesh_surface_get_index_type(void *p_surface) const {
  296. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  297. return (s->vertex_count <= 65536 && s->vertex_count > 0) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT;
  298. }
  299. // Use this to cache Vertex Array Objects so they are only generated once
  300. _FORCE_INLINE_ void mesh_surface_get_vertex_arrays_and_format(void *p_surface, uint32_t p_input_mask, GLuint &r_vertex_array_gl) {
  301. Mesh::Surface *s = reinterpret_cast<Mesh::Surface *>(p_surface);
  302. s->version_lock.lock();
  303. //there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
  304. for (uint32_t i = 0; i < s->version_count; i++) {
  305. if (s->versions[i].input_mask != p_input_mask) {
  306. continue;
  307. }
  308. //we have this version, hooray
  309. r_vertex_array_gl = s->versions[i].vertex_array;
  310. s->version_lock.unlock();
  311. return;
  312. }
  313. uint32_t version = s->version_count;
  314. s->version_count++;
  315. s->versions = (Mesh::Surface::Version *)memrealloc(s->versions, sizeof(Mesh::Surface::Version) * s->version_count);
  316. _mesh_surface_generate_version_for_input_mask(s->versions[version], s, p_input_mask);
  317. r_vertex_array_gl = s->versions[version].vertex_array;
  318. s->version_lock.unlock();
  319. }
  320. /* MESH INSTANCE API */
  321. MeshInstance *get_mesh_instance(RID p_rid) { return mesh_instance_owner.get_or_null(p_rid); };
  322. bool owns_mesh_instance(RID p_rid) { return mesh_instance_owner.owns(p_rid); };
  323. virtual RID mesh_instance_create(RID p_base) override;
  324. virtual void mesh_instance_free(RID p_rid) override;
  325. virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override;
  326. virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override;
  327. virtual void mesh_instance_check_for_update(RID p_mesh_instance) override;
  328. virtual void mesh_instance_set_canvas_item_transform(RID p_mesh_instance, const Transform2D &p_transform) override;
  329. virtual void update_mesh_instances() override;
  330. // TODO: considering hashing versions with multimesh buffer RID.
  331. // Doing so would allow us to avoid specifying multimesh buffer pointers every frame and may improve performance.
  332. _FORCE_INLINE_ void mesh_instance_surface_get_vertex_arrays_and_format(RID p_mesh_instance, uint32_t p_surface_index, uint32_t p_input_mask, GLuint &r_vertex_array_gl) {
  333. MeshInstance *mi = mesh_instance_owner.get_or_null(p_mesh_instance);
  334. ERR_FAIL_COND(!mi);
  335. Mesh *mesh = mi->mesh;
  336. ERR_FAIL_UNSIGNED_INDEX(p_surface_index, mesh->surface_count);
  337. MeshInstance::Surface *mis = &mi->surfaces[p_surface_index];
  338. Mesh::Surface *s = mesh->surfaces[p_surface_index];
  339. s->version_lock.lock();
  340. //there will never be more than, at much, 3 or 4 versions, so iterating is the fastest way
  341. for (uint32_t i = 0; i < mis->version_count; i++) {
  342. if (mis->versions[i].input_mask != p_input_mask) {
  343. continue;
  344. }
  345. //we have this version, hooray
  346. r_vertex_array_gl = mis->versions[i].vertex_array;
  347. s->version_lock.unlock();
  348. return;
  349. }
  350. uint32_t version = mis->version_count;
  351. mis->version_count++;
  352. mis->versions = (Mesh::Surface::Version *)memrealloc(mis->versions, sizeof(Mesh::Surface::Version) * mis->version_count);
  353. _mesh_surface_generate_version_for_input_mask(mis->versions[version], s, p_input_mask, mis);
  354. r_vertex_array_gl = mis->versions[version].vertex_array;
  355. s->version_lock.unlock();
  356. }
  357. /* MULTIMESH API */
  358. MultiMesh *get_multimesh(RID p_rid) { return multimesh_owner.get_or_null(p_rid); };
  359. bool owns_multimesh(RID p_rid) { return multimesh_owner.owns(p_rid); };
  360. virtual RID multimesh_allocate() override;
  361. virtual void multimesh_initialize(RID p_rid) override;
  362. virtual void multimesh_free(RID p_rid) override;
  363. 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) override;
  364. virtual int multimesh_get_instance_count(RID p_multimesh) const override;
  365. virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override;
  366. virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override;
  367. virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override;
  368. virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override;
  369. virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override;
  370. virtual RID multimesh_get_mesh(RID p_multimesh) const override;
  371. virtual AABB multimesh_get_aabb(RID p_multimesh) const override;
  372. virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override;
  373. virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override;
  374. virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override;
  375. virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override;
  376. virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override;
  377. virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const override;
  378. virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override;
  379. virtual int multimesh_get_visible_instances(RID p_multimesh) const override;
  380. void _update_dirty_multimeshes();
  381. _FORCE_INLINE_ RS::MultimeshTransformFormat multimesh_get_transform_format(RID p_multimesh) const {
  382. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  383. return multimesh->xform_format;
  384. }
  385. _FORCE_INLINE_ bool multimesh_uses_colors(RID p_multimesh) const {
  386. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  387. return multimesh->uses_colors;
  388. }
  389. _FORCE_INLINE_ bool multimesh_uses_custom_data(RID p_multimesh) const {
  390. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  391. return multimesh->uses_custom_data;
  392. }
  393. _FORCE_INLINE_ uint32_t multimesh_get_instances_to_draw(RID p_multimesh) const {
  394. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  395. if (multimesh->visible_instances >= 0) {
  396. return multimesh->visible_instances;
  397. }
  398. return multimesh->instances;
  399. }
  400. _FORCE_INLINE_ GLuint multimesh_get_gl_buffer(RID p_multimesh) const {
  401. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  402. return multimesh->buffer;
  403. }
  404. _FORCE_INLINE_ uint32_t multimesh_get_stride(RID p_multimesh) const {
  405. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  406. return multimesh->stride_cache;
  407. }
  408. _FORCE_INLINE_ uint32_t multimesh_get_color_offset(RID p_multimesh) const {
  409. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  410. return multimesh->color_offset_cache;
  411. }
  412. _FORCE_INLINE_ uint32_t multimesh_get_custom_data_offset(RID p_multimesh) const {
  413. MultiMesh *multimesh = multimesh_owner.get_or_null(p_multimesh);
  414. return multimesh->custom_data_offset_cache;
  415. }
  416. /* SKELETON API */
  417. Skeleton *get_skeleton(RID p_rid) { return skeleton_owner.get_or_null(p_rid); };
  418. bool owns_skeleton(RID p_rid) { return skeleton_owner.owns(p_rid); };
  419. virtual RID skeleton_allocate() override;
  420. virtual void skeleton_initialize(RID p_rid) override;
  421. virtual void skeleton_free(RID p_rid) override;
  422. virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override;
  423. virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override;
  424. virtual int skeleton_get_bone_count(RID p_skeleton) const override;
  425. virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override;
  426. virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override;
  427. virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override;
  428. virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override;
  429. virtual void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override;
  430. void _update_dirty_skeletons();
  431. _FORCE_INLINE_ bool skeleton_is_valid(RID p_skeleton) {
  432. return skeleton_owner.get_or_null(p_skeleton) != nullptr;
  433. }
  434. };
  435. } // namespace GLES3
  436. #endif // GLES3_ENABLED
  437. #endif // MESH_STORAGE_GLES3_H