From acb65377cdd31d8add121179e290d90bc03597d0 Mon Sep 17 00:00:00 2001 From: Clay Date: Thu, 12 Oct 2023 22:01:41 +0200 Subject: [PATCH] Cleanup instances of using uint32_t for mesh formats And tidy up some leftovers from the attribute compression PR --- editor/import/resource_importer_obj.cpp | 2 +- editor/import/resource_importer_scene.cpp | 6 +++--- scene/resources/material.h | 2 -- scene/resources/primitive_meshes.cpp | 2 +- scene/resources/surface_tool.cpp | 8 ++++---- servers/rendering_server.cpp | 14 +++++++------- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 4379a1aae40..97b0a1b4ca7 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -486,7 +486,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, co mesh.instantiate(); mesh->set_name(m->get_name()); for (int i = 0; i < m->get_surface_count(); i++) { - mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i)); + mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i), String(), m->surface_get_format(i)); } ImporterMeshInstance3D *mi = memnew(ImporterMeshInstance3D); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 7c2a26533e9..33c2b0e2389 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -391,7 +391,7 @@ void _rescale_importer_mesh(Vector3 p_scale, Ref p_mesh, bool is_s Dictionary lods; String name; Ref mat; - int fmt_compress_flags = 0; + uint64_t fmt_compress_flags = 0; }; Vector surf_data_by_mesh; @@ -403,7 +403,7 @@ void _rescale_importer_mesh(Vector3 p_scale, Ref p_mesh, bool is_s for (int surf_idx = 0; surf_idx < surf_count; surf_idx++) { Mesh::PrimitiveType prim = p_mesh->get_surface_primitive_type(surf_idx); - const int fmt_compress_flags = p_mesh->get_surface_format(surf_idx); + const uint64_t fmt_compress_flags = p_mesh->get_surface_format(surf_idx); Array arr = p_mesh->get_surface_arrays(surf_idx); String name = p_mesh->get_surface_name(surf_idx); Dictionary lods; @@ -450,7 +450,7 @@ void _rescale_importer_mesh(Vector3 p_scale, Ref p_mesh, bool is_s const Array arr = surf_data_by_mesh[surf_idx].arr; const Array bsarr = surf_data_by_mesh[surf_idx].bsarr; const Dictionary lods = surf_data_by_mesh[surf_idx].lods; - const int fmt_compress_flags = surf_data_by_mesh[surf_idx].fmt_compress_flags; + const uint64_t fmt_compress_flags = surf_data_by_mesh[surf_idx].fmt_compress_flags; const String name = surf_data_by_mesh[surf_idx].name; const Ref mat = surf_data_by_mesh[surf_idx].mat; diff --git a/scene/resources/material.h b/scene/resources/material.h index a631f775988..1c698cb1044 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -351,8 +351,6 @@ private: } }; - size_t sss = sizeof(MaterialKey); - struct ShaderData { RID shader; int users = 0; diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 6c66fca254d..b3237107435 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -181,7 +181,7 @@ TypedArray PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) c BitField PrimitiveMesh::surface_get_format(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, 1, 0); - uint32_t mesh_format = RS::ARRAY_FORMAT_VERTEX | RS::ARRAY_FORMAT_NORMAL | RS::ARRAY_FORMAT_TANGENT | RS::ARRAY_FORMAT_TEX_UV | RS::ARRAY_FORMAT_INDEX; + uint64_t mesh_format = RS::ARRAY_FORMAT_VERTEX | RS::ARRAY_FORMAT_NORMAL | RS::ARRAY_FORMAT_TANGENT | RS::ARRAY_FORMAT_TEX_UV | RS::ARRAY_FORMAT_INDEX; if (add_uv2) { mesh_format |= RS::ARRAY_FORMAT_TEX_UV2; } diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 4560ce51cef..73baba6c939 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -729,11 +729,11 @@ Ref SurfaceTool::commit(const Ref &p_existing, uint64_t p_ Array a = commit_to_arrays(); - uint32_t compress_flags = (p_compress_flags >> RS::ARRAY_COMPRESS_FLAGS_BASE) << RS::ARRAY_COMPRESS_FLAGS_BASE; - static const uint32_t shift[RS::ARRAY_CUSTOM_COUNT] = { Mesh::ARRAY_FORMAT_CUSTOM0_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM1_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM2_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM3_SHIFT }; + uint64_t compress_flags = (p_compress_flags >> RS::ARRAY_COMPRESS_FLAGS_BASE) << RS::ARRAY_COMPRESS_FLAGS_BASE; + static const uint64_t shift[RS::ARRAY_CUSTOM_COUNT] = { Mesh::ARRAY_FORMAT_CUSTOM0_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM1_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM2_SHIFT, Mesh::ARRAY_FORMAT_CUSTOM3_SHIFT }; for (int i = 0; i < RS::ARRAY_CUSTOM_COUNT; i++) { if (last_custom_format[i] != CUSTOM_MAX) { - compress_flags |= last_custom_format[i] << shift[i]; + compress_flags |= uint64_t(last_custom_format[i]) << shift[i]; } } @@ -819,7 +819,7 @@ void SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays return; } - int lformat = 0; + uint64_t lformat = 0; if (varr.size()) { lformat |= RS::ARRAY_FORMAT_VERTEX; } diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index c5adb6cdf61..2e7c4933856 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -907,7 +907,7 @@ Error RenderingServer::_surface_set_data(Array p_arrays, uint64_t p_format, uint uint32_t RenderingServer::mesh_surface_get_format_offset(BitField p_format, int p_vertex_len, int p_array_index) const { ERR_FAIL_INDEX_V(p_array_index, ARRAY_MAX, 0); - p_format = int64_t(p_format) & ~ARRAY_FORMAT_INDEX; + p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX; uint32_t offsets[ARRAY_MAX]; uint32_t vstr; uint32_t ntstr; @@ -918,7 +918,7 @@ uint32_t RenderingServer::mesh_surface_get_format_offset(BitField p } uint32_t RenderingServer::mesh_surface_get_format_vertex_stride(BitField p_format, int p_vertex_len) const { - p_format = int64_t(p_format) & ~ARRAY_FORMAT_INDEX; + p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX; uint32_t offsets[ARRAY_MAX]; uint32_t vstr; uint32_t ntstr; @@ -929,18 +929,18 @@ uint32_t RenderingServer::mesh_surface_get_format_vertex_stride(BitField p_format, int p_vertex_len) const { - p_format = int64_t(p_format) & ~ARRAY_FORMAT_INDEX; + p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX; uint32_t offsets[ARRAY_MAX]; uint32_t vstr; uint32_t ntstr; uint32_t astr; uint32_t sstr; mesh_surface_make_offsets_from_format(p_format, p_vertex_len, 0, offsets, vstr, ntstr, astr, sstr); - return vstr; + return ntstr; } uint32_t RenderingServer::mesh_surface_get_format_attribute_stride(BitField p_format, int p_vertex_len) const { - p_format = int64_t(p_format) & ~ARRAY_FORMAT_INDEX; + p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX; uint32_t offsets[ARRAY_MAX]; uint32_t vstr; uint32_t ntstr; @@ -950,7 +950,7 @@ uint32_t RenderingServer::mesh_surface_get_format_attribute_stride(BitField p_format, int p_vertex_len) const { - p_format = int64_t(p_format) & ~ARRAY_FORMAT_INDEX; + p_format = uint64_t(p_format) & ~ARRAY_FORMAT_INDEX; uint32_t offsets[ARRAY_MAX]; uint32_t vstr; uint32_t ntstr; @@ -1662,7 +1662,7 @@ TypedArray RenderingServer::mesh_surface_get_blend_shape_arrays(RID p_mes uint32_t normal_elem_size; uint32_t attrib_elem_size; uint32_t skin_elem_size; - //CLAY + mesh_surface_make_offsets_from_format(bs_format, sd.vertex_count, 0, bs_offsets, vertex_elem_size, normal_elem_size, attrib_elem_size, skin_elem_size); int divisor = (vertex_elem_size + normal_elem_size) * sd.vertex_count;