Skip to content

Commit

Permalink
Store ArrayMesh path in RenderingServer for use in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
clayjohn committed Nov 14, 2023
1 parent 5945768 commit ead36fd
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 6 deletions.
4 changes: 3 additions & 1 deletion drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ void RasterizerSceneGLES3::_geometry_instance_add_surface_with_material(Geometry

GLES3::Mesh::Surface *s = reinterpret_cast<GLES3::Mesh::Surface *>(sdcache->surface);
if (p_material->shader_data->uses_tangent && !(s->format & RS::ARRAY_FORMAT_TANGENT)) {
WARN_PRINT_ED("Attempting to use a shader that requires tangents with a mesh that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an `ARRAY_TANGENT` array (when using ArrayMesh) or call `generate_tangents()` (when using SurfaceTool).");
String shader_path = p_material->shader_data->path.is_empty() ? "" : "(" + p_material->shader_data->path + ")";
String mesh_path = mesh_storage->mesh_get_path(p_mesh).is_empty() ? "" : "(" + mesh_storage->mesh_get_path(p_mesh) + ")";
WARN_PRINT_ED(vformat("Attempting to use a shader %s that requires tangents with a mesh %s that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an `ARRAY_TANGENT` array (when using ArrayMesh) or call `generate_tangents()` (when using SurfaceTool).", shader_path, mesh_path));
}
}

Expand Down
14 changes: 14 additions & 0 deletions drivers/gles3/storage/mesh_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,20 @@ AABB MeshStorage::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
return aabb;
}

void MeshStorage::mesh_set_path(RID p_mesh, const String &p_path) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);

mesh->path = p_path;
}

String MeshStorage::mesh_get_path(RID p_mesh) const {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL_V(mesh, String());

return mesh->path;
}

void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);
Expand Down
7 changes: 6 additions & 1 deletion drivers/gles3/storage/mesh_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ struct Mesh {
RID shadow_mesh;
HashSet<Mesh *> shadow_owners;

String path;

Dependency dependency;
};

Expand Down Expand Up @@ -292,8 +294,11 @@ class MeshStorage : public RendererMeshStorage {

virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override;
virtual AABB mesh_get_custom_aabb(RID p_mesh) const override;

virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;

virtual void mesh_set_path(RID p_mesh, const String &p_path) override;
virtual String mesh_get_path(RID p_mesh) const override;

virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;
virtual void mesh_clear(RID p_mesh) override;

Expand Down
2 changes: 2 additions & 0 deletions scene/resources/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ void ArrayMesh::_create_if_empty() const {
mesh = RS::get_singleton()->mesh_create();
RS::get_singleton()->mesh_set_blend_shape_mode(mesh, (RS::BlendShapeMode)blend_shape_mode);
RS::get_singleton()->mesh_set_blend_shape_count(mesh, blend_shapes.size());
RS::get_singleton()->mesh_set_path(mesh, get_path());
}
}

Expand Down Expand Up @@ -1666,6 +1667,7 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) {
// we can create it with a single call, which is a lot more efficient and thread friendly
mesh = RS::get_singleton()->mesh_create_from_surfaces(surface_data, blend_shapes.size());
RS::get_singleton()->mesh_set_blend_shape_mode(mesh, (RS::BlendShapeMode)blend_shape_mode);
RS::get_singleton()->mesh_set_path(mesh, get_path());
}

surfaces.clear();
Expand Down
5 changes: 4 additions & 1 deletion servers/rendering/dummy/storage/mesh_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ class MeshStorage : public RendererMeshStorage {

virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) override {}
virtual AABB mesh_get_custom_aabb(RID p_mesh) const override { return AABB(); }

virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override { return AABB(); }

virtual void mesh_set_path(RID p_mesh, const String &p_path) override {}
virtual String mesh_get_path(RID p_mesh) const override { return String(); }

virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override {}
virtual void mesh_clear(RID p_mesh) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3722,7 +3722,9 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet

uint64_t format = RendererRD::MeshStorage::get_singleton()->mesh_surface_get_format(sdcache->surface);
if (p_material->shader_data->uses_tangent && !(format & RS::ARRAY_FORMAT_TANGENT)) {
WARN_PRINT_ED("Attempting to use a shader that requires tangents with a mesh that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an `ARRAY_TANGENT` array (when using ArrayMesh) or call `generate_tangents()` (when using SurfaceTool).");
String shader_path = p_material->shader_data->path.is_empty() ? "" : "(" + p_material->shader_data->path + ")";
String mesh_path = mesh_storage->mesh_get_path(p_mesh).is_empty() ? "" : "(" + mesh_storage->mesh_get_path(p_mesh) + ")";
WARN_PRINT_ED(vformat("Attempting to use a shader %s that requires tangents with a mesh %s that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an `ARRAY_TANGENT` array (when using ArrayMesh) or call `generate_tangents()` (when using SurfaceTool).", shader_path, mesh_path));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,9 @@ void RenderForwardMobile::_geometry_instance_add_surface_with_material(GeometryI

uint64_t format = RendererRD::MeshStorage::get_singleton()->mesh_surface_get_format(sdcache->surface);
if (p_material->shader_data->uses_tangent && !(format & RS::ARRAY_FORMAT_TANGENT)) {
WARN_PRINT_ED("Attempting to use a shader that requires tangents with a mesh that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an `ARRAY_TANGENT` array (when using ArrayMesh) or call `generate_tangents()` (when using SurfaceTool).");
String shader_path = p_material->shader_data->path.is_empty() ? "" : "(" + p_material->shader_data->path + ")";
String mesh_path = mesh_storage->mesh_get_path(p_mesh).is_empty() ? "" : "(" + mesh_storage->mesh_get_path(p_mesh) + ")";
WARN_PRINT_ED(vformat("Attempting to use a shader %s that requires tangents with a mesh %s that doesn't contain tangents. Ensure that meshes are imported with the 'ensure_tangents' option. If creating your own meshes, add an `ARRAY_TANGENT` array (when using ArrayMesh) or call `generate_tangents()` (when using SurfaceTool).", shader_path, mesh_path));
}
}

Expand Down
14 changes: 14 additions & 0 deletions servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,20 @@ AABB MeshStorage::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
return aabb;
}

void MeshStorage::mesh_set_path(RID p_mesh, const String &p_path) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);

mesh->path = p_path;
}

String MeshStorage::mesh_get_path(RID p_mesh) const {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL_V(mesh, String());

return mesh->path;
}

void MeshStorage::mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) {
Mesh *mesh = mesh_owner.get_or_null(p_mesh);
ERR_FAIL_NULL(mesh);
Expand Down
5 changes: 5 additions & 0 deletions servers/rendering/renderer_rd/storage_rd/mesh_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class MeshStorage : public RendererMeshStorage {
RID shadow_mesh;
HashSet<Mesh *> shadow_owners;

String path;

Dependency dependency;
};

Expand Down Expand Up @@ -373,6 +375,9 @@ class MeshStorage : public RendererMeshStorage {
virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) override;
virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) override;

virtual void mesh_set_path(RID p_mesh, const String &p_path) override;
virtual String mesh_get_path(RID p_mesh) const override;

virtual void mesh_clear(RID p_mesh) override;

virtual bool mesh_needs_instance(RID p_mesh, bool p_has_skeleton) override;
Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/rendering_server_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class RenderingServerDefault : public RenderingServer {
FUNC2(mesh_set_custom_aabb, RID, const AABB &)
FUNC1RC(AABB, mesh_get_custom_aabb, RID)

FUNC2(mesh_set_path, RID, const String &)
FUNC1RC(String, mesh_get_path, RID)

FUNC2(mesh_set_shadow_mesh, RID, RID)

FUNC1(mesh_clear, RID)
Expand Down
4 changes: 3 additions & 1 deletion servers/rendering/storage/mesh_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class RendererMeshStorage {

virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) = 0;
virtual AABB mesh_get_custom_aabb(RID p_mesh) const = 0;

virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton = RID()) = 0;

virtual void mesh_set_path(RID p_mesh, const String &p_path) = 0;
virtual String mesh_get_path(RID p_mesh) const = 0;

virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) = 0;

virtual void mesh_clear(RID p_mesh) = 0;
Expand Down
3 changes: 3 additions & 0 deletions servers/rendering_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ class RenderingServer : public Object {
virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) = 0;
virtual AABB mesh_get_custom_aabb(RID p_mesh) const = 0;

virtual void mesh_set_path(RID p_mesh, const String &p_path) = 0;
virtual String mesh_get_path(RID p_mesh) const = 0;

virtual void mesh_set_shadow_mesh(RID p_mesh, RID p_shadow_mesh) = 0;

virtual void mesh_clear(RID p_mesh) = 0;
Expand Down

0 comments on commit ead36fd

Please sign in to comment.