Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup instances of using uint32_t for mesh formats #83211

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/import/resource_importer_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions editor/import/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void _rescale_importer_mesh(Vector3 p_scale, Ref<ImporterMesh> p_mesh, bool is_s
Dictionary lods;
String name;
Ref<Material> mat;
int fmt_compress_flags = 0;
uint64_t fmt_compress_flags = 0;
};

Vector<LocalSurfData> surf_data_by_mesh;
Expand All @@ -403,7 +403,7 @@ void _rescale_importer_mesh(Vector3 p_scale, Ref<ImporterMesh> 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;
Expand Down Expand Up @@ -450,7 +450,7 @@ void _rescale_importer_mesh(Vector3 p_scale, Ref<ImporterMesh> 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<Material> mat = surf_data_by_mesh[surf_idx].mat;

Expand Down
2 changes: 0 additions & 2 deletions scene/resources/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ class BaseMaterial3D : public Material {
}
};

size_t sss = sizeof(MaterialKey);

struct ShaderData {
RID shader;
int users = 0;
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/primitive_meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ TypedArray<Array> PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) c
BitField<Mesh::ArrayFormat> 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;
}
Expand Down
8 changes: 4 additions & 4 deletions scene/resources/surface_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,11 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &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];
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions servers/rendering_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArrayFormat> 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;
Expand All @@ -918,7 +918,7 @@ uint32_t RenderingServer::mesh_surface_get_format_offset(BitField<ArrayFormat> p
}

uint32_t RenderingServer::mesh_surface_get_format_vertex_stride(BitField<ArrayFormat> 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;
Expand All @@ -929,18 +929,18 @@ uint32_t RenderingServer::mesh_surface_get_format_vertex_stride(BitField<ArrayFo
}

uint32_t RenderingServer::mesh_surface_get_format_normal_tangent_stride(BitField<ArrayFormat> 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<ArrayFormat> 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;
Expand All @@ -950,7 +950,7 @@ uint32_t RenderingServer::mesh_surface_get_format_attribute_stride(BitField<Arra
return astr;
}
uint32_t RenderingServer::mesh_surface_get_format_skin_stride(BitField<ArrayFormat> 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;
Expand Down Expand Up @@ -1662,7 +1662,7 @@ TypedArray<Array> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋


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;
Expand Down
Loading