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#ifndef MESH_STORAGE_DUMMY_H
32#define MESH_STORAGE_DUMMY_H
33
34#include "core/templates/local_vector.h"
35#include "core/templates/rid_owner.h"
36#include "servers/rendering/storage/mesh_storage.h"
37
38namespace RendererDummy {
39
40class MeshStorage : public RendererMeshStorage {
41private:
42 static MeshStorage *singleton;
43
44 struct DummyMesh {
45 Vector<RS::SurfaceData> surfaces;
46 int blend_shape_count;
47 RS::BlendShapeMode blend_shape_mode;
48 PackedFloat32Array blend_shape_values;
49 };
50
51 mutable RID_Owner<DummyMesh> mesh_owner;
52
53public:
54 static MeshStorage *get_singleton() {
55 return singleton;
56 };
57
58 MeshStorage();
59 ~MeshStorage();
60
61 /* MESH API */
62
63 bool owns_mesh(RID p_rid) { return mesh_owner.owns(p_rid); };
64
65 virtual RID mesh_allocate() override;
66 virtual void mesh_initialize(RID p_rid) override;
67 virtual void mesh_free(RID p_rid) override;
68
69 virtual void mesh_set_blend_shape_count(RID p_mesh, int p_blend_shape_count) override {}
70 virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override { return false; }
71
72 virtual void mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface) override {
73 DummyMesh *m = mesh_owner.get_or_null(p_mesh);
74 ERR_FAIL_COND(!m);
75 m->surfaces.push_back(RS::SurfaceData());
76 RS::SurfaceData *s = &m->surfaces.write[m->surfaces.size() - 1];
77 s->format = p_surface.format;
78 s->primitive = p_surface.primitive;
79 s->vertex_data = p_surface.vertex_data;
80 s->attribute_data = p_surface.attribute_data;
81 s->vertex_count = p_surface.vertex_count;
82 s->index_data = p_surface.index_data;
83 s->index_count = p_surface.index_count;
84 s->aabb = p_surface.aabb;
85 s->skin_data = p_surface.skin_data;
86 }
87
88 virtual int mesh_get_blend_shape_count(RID p_mesh) const override { return 0; }
89
90 virtual void mesh_set_blend_shape_mode(RID p_mesh, RS::BlendShapeMode p_mode) override {}
91 virtual RS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const override { return RS::BLEND_SHAPE_MODE_NORMALIZED; }
92
93 virtual void mesh_surface_update_vertex_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
94 virtual void mesh_surface_update_attribute_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
95 virtual void mesh_surface_update_skin_region(RID p_mesh, int p_surface, int p_offset, const Vector<uint8_t> &p_data) override {}
96
97 virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) override {}
98 virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const override { return RID(); }
99
100 virtual RS::SurfaceData mesh_get_surface(RID p_mesh, int p_surface) const override {
101 DummyMesh *m = mesh_owner.get_or_null(p_mesh);
102 ERR_FAIL_COND_V(!m, RS::SurfaceData());
103 ERR_FAIL_INDEX_V(p_surface, m->surfaces.size(), RS::SurfaceData());
104 RS::SurfaceData s = m->surfaces[p_surface];
105 return s;
106 }
107
108 virtual int mesh_get_surface_count(RID p_mesh) const override {
109 DummyMesh *m = mesh_owner.get_or_null(p_mesh);
110 ERR_FAIL_COND_V(!m, 0);
111 return m->surfaces.size();
112 }
113
114 virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override {}
115 virtual AABB mesh_get_custom_aabb(RID p_mesh) const override { return AABB(); }
116
117 virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override { return AABB(); }
118 virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override {}
119 virtual void mesh_clear(RID p_mesh) override;
120
121 /* MESH INSTANCE */
122
123 virtual RID mesh_instance_create(RID p_base) override { return RID(); }
124 virtual void mesh_instance_free(RID p_rid) override {}
125
126 virtual void mesh_instance_set_skeleton(RID p_mesh_instance, RID p_skeleton) override {}
127 virtual void mesh_instance_set_blend_shape_weight(RID p_mesh_instance, int p_shape, float p_weight) override {}
128 virtual void mesh_instance_check_for_update(RID p_mesh_instance) override {}
129 virtual void mesh_instance_set_canvas_item_transform(RID p_mesh_instance, const Transform2D &p_transform) override {}
130 virtual void update_mesh_instances() override {}
131
132 /* MULTIMESH API */
133
134 virtual RID multimesh_allocate() override { return RID(); }
135 virtual void multimesh_initialize(RID p_rid) override {}
136 virtual void multimesh_free(RID p_rid) override {}
137
138 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 {}
139 virtual int multimesh_get_instance_count(RID p_multimesh) const override { return 0; }
140
141 virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) override {}
142 virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform3D &p_transform) override {}
143 virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) override {}
144 virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) override {}
145 virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) override {}
146
147 virtual RID multimesh_get_mesh(RID p_multimesh) const override { return RID(); }
148 virtual AABB multimesh_get_aabb(RID p_multimesh) const override { return AABB(); }
149
150 virtual Transform3D multimesh_instance_get_transform(RID p_multimesh, int p_index) const override { return Transform3D(); }
151 virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const override { return Transform2D(); }
152 virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const override { return Color(); }
153 virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const override { return Color(); }
154 virtual void multimesh_set_buffer(RID p_multimesh, const Vector<float> &p_buffer) override {}
155 virtual Vector<float> multimesh_get_buffer(RID p_multimesh) const override { return Vector<float>(); }
156
157 virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) override {}
158 virtual int multimesh_get_visible_instances(RID p_multimesh) const override { return 0; }
159
160 /* SKELETON API */
161
162 virtual RID skeleton_allocate() override { return RID(); }
163 virtual void skeleton_initialize(RID p_rid) override {}
164 virtual void skeleton_free(RID p_rid) override {}
165 virtual void skeleton_allocate_data(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) override {}
166 virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) override {}
167 virtual int skeleton_get_bone_count(RID p_skeleton) const override { return 0; }
168 virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform3D &p_transform) override {}
169 virtual Transform3D skeleton_bone_get_transform(RID p_skeleton, int p_bone) const override { return Transform3D(); }
170 virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) override {}
171 virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const override { return Transform2D(); }
172
173 virtual void skeleton_update_dependency(RID p_base, DependencyTracker *p_instance) override {}
174
175 /* OCCLUDER */
176
177 void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) {}
178};
179
180} // namespace RendererDummy
181
182#endif // MESH_STORAGE_DUMMY_H
183