Sfoglia il codice sorgente

Clean up blend shape support in GLES2 and GLES3.

Juan Linietsky 6 anni fa
parent
commit
3f681b0681

+ 20 - 0
core/error_macros.h

@@ -310,6 +310,16 @@ extern bool _err_error_exists;
 		_err_error_exists = false;                                                              \
 	}
 
+#define ERR_PRINT_ONCE(m_string)                                          \
+	{                                                                     \
+		static bool first_print = true;                                   \
+		if (first_print) {                                                \
+			_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
+			_err_error_exists = false;                                    \
+			first_print = false;                                          \
+		}                                                                 \
+	}
+
 /** Print a warning string.
  */
 
@@ -325,6 +335,16 @@ extern bool _err_error_exists;
 		_err_error_exists = false;                                                                                   \
 	}
 
+#define WARN_PRINT_ONCE(m_string)                                                              \
+	{                                                                                          \
+		static bool first_print = true;                                                        \
+		if (first_print) {                                                                     \
+			_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
+			_err_error_exists = false;                                                         \
+			first_print = false;                                                               \
+		}                                                                                      \
+	}
+
 #define WARN_DEPRECATED                                                                                                                                   \
 	{                                                                                                                                                     \
 		static volatile bool warning_shown = false;                                                                                                       \

+ 21 - 15
drivers/gles2/rasterizer_storage_gles2.cpp

@@ -30,12 +30,12 @@
 
 #include "rasterizer_storage_gles2.h"
 
+#include "core/engine.h"
 #include "core/math/transform.h"
 #include "core/project_settings.h"
 #include "rasterizer_canvas_gles2.h"
 #include "rasterizer_scene_gles2.h"
 #include "servers/visual/shader_language.h"
-
 GLuint RasterizerStorageGLES2::system_fbo = 0;
 
 /* TEXTURE API */
@@ -1308,19 +1308,11 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const {
 			actions->uniforms = &p_shader->uniforms;
 
 			if (p_shader->spatial.uses_screen_texture && p_shader->spatial.uses_depth_texture) {
-				static bool show_warning = true; //show warning only once
-				if (show_warning) {
-					ERR_PRINT("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2");
-					show_warning = false;
-				}
+				ERR_PRINT_ONCE("Using both SCREEN_TEXTURE and DEPTH_TEXTURE is not supported in GLES2");
 			}
 
 			if (p_shader->spatial.uses_depth_texture && !config.support_depth_texture) {
-				static bool show_warning = true; //show warning only once
-				if (show_warning) {
-					ERR_PRINT("Using DEPTH_TEXTURE is not permitted on this hardware, operation will fail.");
-					show_warning = false;
-				}
+				ERR_PRINT_ONCE("Using DEPTH_TEXTURE is not permitted on this hardware, operation will fail.");
 			}
 		} break;
 
@@ -2266,9 +2258,14 @@ void RasterizerStorageGLES2::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
 
 	surface->aabb = p_aabb;
 	surface->max_bone = p_bone_aabbs.size();
-
+#ifdef TOOLS_ENABLED
+	surface->blend_shape_data = p_blend_shapes;
+	if (surface->blend_shape_data.size()) {
+		ERR_PRINT_ONCE("Blend shapes are not supported in OpenGL ES 2.0");
+	}
 	surface->data = array;
 	surface->index_data = p_index_array;
+#endif
 
 	surface->total_data_size += surface->array_byte_size + surface->index_array_byte_size;
 
@@ -2338,12 +2335,12 @@ void RasterizerStorageGLES2::mesh_set_blend_shape_count(RID p_mesh, int p_amount
 	ERR_FAIL_COND(p_amount < 0);
 
 	mesh->blend_shape_count = p_amount;
+	mesh->instance_change_notify(true, false);
 }
 
 int RasterizerStorageGLES2::mesh_get_blend_shape_count(RID p_mesh) const {
 	const Mesh *mesh = mesh_owner.getornull(p_mesh);
 	ERR_FAIL_COND_V(!mesh, 0);
-
 	return mesh->blend_shape_count;
 }
 
@@ -2429,7 +2426,9 @@ PoolVector<uint8_t> RasterizerStorageGLES2::mesh_surface_get_array(RID p_mesh, i
 	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), PoolVector<uint8_t>());
 
 	Surface *surface = mesh->surfaces[p_surface];
-
+#ifndef TOOLS_ENABLED
+	ERR_PRINT("OpenGL ES 2.0 does not allow retrieving mesh array data");
+#endif
 	return surface->data;
 }
 
@@ -2469,7 +2468,14 @@ AABB RasterizerStorageGLES2::mesh_surface_get_aabb(RID p_mesh, int p_surface) co
 }
 
 Vector<PoolVector<uint8_t> > RasterizerStorageGLES2::mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const {
-	return Vector<PoolVector<uint8_t> >();
+	const Mesh *mesh = mesh_owner.getornull(p_mesh);
+	ERR_FAIL_COND_V(!mesh, Vector<PoolVector<uint8_t> >());
+	ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Vector<PoolVector<uint8_t> >());
+#ifndef TOOLS_ENABLED
+	ERR_PRINT("OpenGL ES 2.0 does not allow retrieving mesh array data");
+#endif
+
+	return mesh->surfaces[p_surface]->blend_shape_data;
 }
 Vector<AABB> RasterizerStorageGLES2::mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const {
 	const Mesh *mesh = mesh_owner.getornull(p_mesh);

+ 1 - 0
drivers/gles2/rasterizer_storage_gles2.h

@@ -635,6 +635,7 @@ public:
 
 		PoolVector<uint8_t> data;
 		PoolVector<uint8_t> index_data;
+		Vector<PoolVector<uint8_t> > blend_shape_data;
 
 		int total_data_size;
 

+ 1 - 0
drivers/gles3/rasterizer_storage_gles3.cpp

@@ -3634,6 +3634,7 @@ void RasterizerStorageGLES3::mesh_set_blend_shape_count(RID p_mesh, int p_amount
 	ERR_FAIL_COND(p_amount < 0);
 
 	mesh->blend_shape_count = p_amount;
+	mesh->instance_change_notify(true, false);
 }
 int RasterizerStorageGLES3::mesh_get_blend_shape_count(RID p_mesh) const {
 

+ 2 - 0
editor/import/editor_scene_importer_gltf.cpp

@@ -892,9 +892,11 @@ Error EditorSceneImporterGLTF::_parse_meshes(GLTFState &state) {
 				primitive = primitives2[mode];
 			}
 
+			ERR_FAIL_COND_V(!a.has("POSITION"), ERR_PARSE_ERROR);
 			if (a.has("POSITION")) {
 				array[Mesh::ARRAY_VERTEX] = _decode_accessor_as_vec3(state, a["POSITION"], true);
 			}
+
 			if (a.has("NORMAL")) {
 				array[Mesh::ARRAY_NORMAL] = _decode_accessor_as_vec3(state, a["NORMAL"], true);
 			}

+ 3 - 0
servers/visual/visual_server_scene.cpp

@@ -445,6 +445,9 @@ void VisualServerScene::instance_set_base(RID p_instance, RID p_base) {
 
 				InstanceGeometryData *geom = memnew(InstanceGeometryData);
 				instance->base_data = geom;
+				if (instance->base_type == VS::INSTANCE_MESH) {
+					instance->blend_values.resize(VSG::storage->mesh_get_blend_shape_count(p_base));
+				}
 			} break;
 			case VS::INSTANCE_REFLECTION_PROBE: {