Implements #95967. Currently the `MPoly` struct is 12 bytes, and stores the index of a face's first corner and the number of corners/verts/edges. Polygons and corners are always created in order by Blender, meaning each face's corners will be after the previous face's corners. We can take advantage of this fact and eliminate the redundancy in mesh face storage by only storing a single integer corner offset for each face. The size of the face is then encoded by the offset of the next face. The size of a single integer is 4 bytes, so this reduces memory usage by 3 times. The same method is used for `CurvesGeometry`, so Blender already has an abstraction to simplify using these offsets called `OffsetIndices`. This class is used to easily retrieve a range of corner indices for each face. This also gives the opportunity for sharing some logic with curves. Another benefit of the change is that the offsets and sizes stored in `MPoly` can no longer disagree with each other. Storing faces in the order of their corners can simplify some code too. Face/polygon variables now use the `IndexRange` type, which comes with quite a few utilities that can simplify code. Some: - The offset integer array has to be one longer than the face count to avoid a branch for every face, which means the data is no longer part of the mesh's `CustomData`. - We lose the ability to "reference" an original mesh's offset array until more reusable CoW from #104478 is committed. That will be added in a separate commit. - Since they aren't part of `CustomData`, poly offsets often have to be copied manually. - To simplify using `OffsetIndices` in many places, some functions and structs in headers were moved to only compile in C++. - All meshes created by Blender use the same order for faces and face corners, but just in case, meshes with mismatched order are fixed by versioning code. - `MeshPolygon.totloop` is no longer editable in RNA. This API break is necessary here unfortunately. It should be worth it in 3.6, since that's the best way to allow loading meshes from 4.0, which is important for an LTS version. Pull Request: https://projects.blender.org/blender/blender/pulls/105938
91 lines
2.2 KiB
C++
91 lines
2.2 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright 2022 Blender Foundation. */
|
|
|
|
/** \file
|
|
* \ingroup draw
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
/* Needed for BKE_ccg.h. */
|
|
#include "BLI_assert.h"
|
|
#include "BLI_bitmap.h"
|
|
#include "BLI_offset_indices.hh"
|
|
#include "BLI_span.hh"
|
|
|
|
#include "BKE_ccg.h"
|
|
|
|
struct PBVHAttrReq;
|
|
struct GPUBatch;
|
|
struct PBVHNode;
|
|
struct PBVHBatches;
|
|
struct PBVHGPUFormat;
|
|
struct GSet;
|
|
struct DMFlagMat;
|
|
struct Mesh;
|
|
struct MLoopTri;
|
|
struct CustomData;
|
|
struct SubdivCCG;
|
|
struct BMesh;
|
|
|
|
struct PBVH_GPU_Args {
|
|
int pbvh_type;
|
|
|
|
BMesh *bm;
|
|
const Mesh *me;
|
|
const float (*vert_positions)[3];
|
|
blender::OffsetIndices<int> polys;
|
|
blender::Span<int> corner_verts;
|
|
blender::Span<int> corner_edges;
|
|
int mesh_verts_num, mesh_faces_num, mesh_grids_num;
|
|
CustomData *vdata, *ldata, *pdata;
|
|
const float (*vert_normals)[3];
|
|
|
|
const char *active_color;
|
|
const char *render_color;
|
|
|
|
int face_sets_color_seed, face_sets_color_default;
|
|
int *face_sets; /* for PBVH_FACES and PBVH_GRIDS */
|
|
|
|
SubdivCCG *subdiv_ccg;
|
|
const DMFlagMat *grid_flag_mats;
|
|
const int *grid_indices;
|
|
CCGKey ccg_key;
|
|
CCGElem **grids;
|
|
void **gridfaces;
|
|
BLI_bitmap **grid_hidden;
|
|
|
|
int *prim_indices;
|
|
int totprim;
|
|
|
|
const bool *hide_poly;
|
|
|
|
int node_verts_num;
|
|
|
|
const MLoopTri *mlooptri;
|
|
PBVHNode *node;
|
|
|
|
/* BMesh. */
|
|
GSet *bm_unique_vert, *bm_other_verts, *bm_faces;
|
|
int cd_mask_layer;
|
|
};
|
|
|
|
void DRW_pbvh_node_update(PBVHBatches *batches, PBVH_GPU_Args *args);
|
|
void DRW_pbvh_update_pre(PBVHBatches *batches, PBVH_GPU_Args *args);
|
|
|
|
void DRW_pbvh_node_gpu_flush(PBVHBatches *batches);
|
|
PBVHBatches *DRW_pbvh_node_create(PBVH_GPU_Args *args);
|
|
void DRW_pbvh_node_free(PBVHBatches *batches);
|
|
GPUBatch *DRW_pbvh_tris_get(PBVHBatches *batches,
|
|
PBVHAttrReq *attrs,
|
|
int attrs_num,
|
|
PBVH_GPU_Args *args,
|
|
int *r_prim_count,
|
|
bool do_coarse_grids);
|
|
GPUBatch *DRW_pbvh_lines_get(PBVHBatches *batches,
|
|
PBVHAttrReq *attrs,
|
|
int attrs_num,
|
|
PBVH_GPU_Args *args,
|
|
int *r_prim_count,
|
|
bool do_coarse_grids);
|