mesh_storage.h 20 KB

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