Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_uv.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2021 Blender Foundation. All rights reserved. */ | * Copyright 2021 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup draw | * \ingroup draw | ||||
| */ | */ | ||||
| #include "BLI_math_vector_types.hh" | |||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "draw_subdivision.h" | #include "draw_subdivision.h" | ||||
| #include "extract_mesh.hh" | #include "extract_mesh.hh" | ||||
| namespace blender::draw { | namespace blender::draw { | ||||
| /* ---------------------------------------------------------------------- */ | /* ---------------------------------------------------------------------- */ | ||||
| /** \name Extract UV layers | /** \name Extract UV layers | ||||
| * \{ */ | * \{ */ | ||||
| /* Initialize the vertex format to be used for UVs. Return true if any UV layer is | /* Initialize the vertex format to be used for UVs. Return true if any UV layer is | ||||
| * found, false otherwise. */ | * found, false otherwise. */ | ||||
| static bool mesh_extract_uv_format_init(GPUVertFormat *format, | static bool mesh_extract_uv_format_init(GPUVertFormat *format, | ||||
| MeshBatchCache *cache, | MeshBatchCache *cache, | ||||
| CustomData *cd_ldata, | CustomData *cd_ldata, | ||||
| eMRExtractType extract_type, | eMRExtractType extract_type, | ||||
| uint32_t &r_uv_layers) | uint32_t &r_uv_layers) | ||||
| { | { | ||||
| GPU_vertformat_deinterleave(format); | GPU_vertformat_deinterleave(format); | ||||
| uint32_t uv_layers = cache->cd_used.uv; | uint32_t uv_layers = cache->cd_used.uv; | ||||
| /* HACK to fix T68857 */ | /* HACK to fix T68857 */ | ||||
| if (extract_type == MR_EXTRACT_BMESH && cache->cd_used.edit_uv == 1) { | if (extract_type == MR_EXTRACT_BMESH && cache->cd_used.edit_uv == 1) { | ||||
| int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV); | int layer = CustomData_get_active_layer(cd_ldata, CD_PROP_FLOAT2); | ||||
| if (layer != -1) { | if (layer != -1) { | ||||
| uv_layers |= (1 << layer); | uv_layers |= (1 << layer); | ||||
| } | } | ||||
| } | } | ||||
| r_uv_layers = uv_layers; | r_uv_layers = uv_layers; | ||||
| for (int i = 0; i < MAX_MTFACE; i++) { | for (int i = 0; i < MAX_MTFACE; i++) { | ||||
| if (uv_layers & (1 << i)) { | if (uv_layers & (1 << i)) { | ||||
| char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME]; | char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME]; | ||||
| const char *layer_name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i); | const char *layer_name = CustomData_get_layer_name(cd_ldata, CD_PROP_FLOAT2, i); | ||||
| GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME); | GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME); | ||||
| /* UV layer name. */ | /* UV layer name. */ | ||||
| BLI_snprintf(attr_name, sizeof(attr_name), "a%s", attr_safe_name); | BLI_snprintf(attr_name, sizeof(attr_name), "a%s", attr_safe_name); | ||||
| GPU_vertformat_attr_add(format, attr_name, GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | GPU_vertformat_attr_add(format, attr_name, GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| /* Active render layer name. */ | /* Active render layer name. */ | ||||
| if (i == CustomData_get_render_layer(cd_ldata, CD_MLOOPUV)) { | if (i == CustomData_get_render_layer(cd_ldata, CD_PROP_FLOAT2)) { | ||||
| GPU_vertformat_alias_add(format, "a"); | GPU_vertformat_alias_add(format, "a"); | ||||
| } | } | ||||
| /* Active display layer name. */ | /* Active display layer name. */ | ||||
| if (i == CustomData_get_active_layer(cd_ldata, CD_MLOOPUV)) { | if (i == CustomData_get_active_layer(cd_ldata, CD_PROP_FLOAT2)) { | ||||
| GPU_vertformat_alias_add(format, "au"); | GPU_vertformat_alias_add(format, "au"); | ||||
| /* Alias to `pos` for edit uvs. */ | /* Alias to `pos` for edit uvs. */ | ||||
| GPU_vertformat_alias_add(format, "pos"); | GPU_vertformat_alias_add(format, "pos"); | ||||
| } | } | ||||
| /* Stencil mask uv layer name. */ | /* Stencil mask uv layer name. */ | ||||
| if (i == CustomData_get_stencil_layer(cd_ldata, CD_MLOOPUV)) { | if (i == CustomData_get_stencil_layer(cd_ldata, CD_PROP_FLOAT2)) { | ||||
| GPU_vertformat_alias_add(format, "mu"); | GPU_vertformat_alias_add(format, "mu"); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (format->attr_len == 0) { | if (format->attr_len == 0) { | ||||
| GPU_vertformat_attr_add(format, "dummy", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | GPU_vertformat_attr_add(format, "dummy", GPU_COMP_F32, 1, GPU_FETCH_FLOAT); | ||||
| return false; | return false; | ||||
| Show All 16 Lines | static void extract_uv_init(const MeshRenderData *mr, | ||||
| if (!mesh_extract_uv_format_init(&format, cache, cd_ldata, mr->extract_type, uv_layers)) { | if (!mesh_extract_uv_format_init(&format, cache, cd_ldata, mr->extract_type, uv_layers)) { | ||||
| /* VBO will not be used, only allocate minimum of memory. */ | /* VBO will not be used, only allocate minimum of memory. */ | ||||
| v_len = 1; | v_len = 1; | ||||
| } | } | ||||
| GPU_vertbuf_init_with_format(vbo, &format); | GPU_vertbuf_init_with_format(vbo, &format); | ||||
| GPU_vertbuf_data_alloc(vbo, v_len); | GPU_vertbuf_data_alloc(vbo, v_len); | ||||
| float(*uv_data)[2] = (float(*)[2])GPU_vertbuf_get_data(vbo); | float2 *uv_data = static_cast<float2 *>(GPU_vertbuf_get_data(vbo)); | ||||
| for (int i = 0; i < MAX_MTFACE; i++) { | for (int i = 0; i < MAX_MTFACE; i++) { | ||||
| if (uv_layers & (1 << i)) { | if (uv_layers & (1 << i)) { | ||||
| if (mr->extract_type == MR_EXTRACT_BMESH) { | if (mr->extract_type == MR_EXTRACT_BMESH) { | ||||
| int cd_ofs = CustomData_get_n_offset(cd_ldata, CD_MLOOPUV, i); | int cd_ofs = CustomData_get_n_offset(cd_ldata, CD_PROP_FLOAT2, i); | ||||
| BMIter f_iter; | BMIter f_iter; | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BM_ITER_MESH (efa, &f_iter, mr->bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (efa, &f_iter, mr->bm, BM_FACES_OF_MESH) { | ||||
| BMLoop *l_iter, *l_first; | BMLoop *l_iter, *l_first; | ||||
| l_iter = l_first = BM_FACE_FIRST_LOOP(efa); | l_iter = l_first = BM_FACE_FIRST_LOOP(efa); | ||||
| do { | do { | ||||
| MLoopUV *luv = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_ofs); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l_iter, cd_ofs); | ||||
| memcpy(uv_data, luv->uv, sizeof(*uv_data)); | memcpy(uv_data, luv, sizeof(*uv_data)); | ||||
| uv_data++; | uv_data++; | ||||
| } while ((l_iter = l_iter->next) != l_first); | } while ((l_iter = l_iter->next) != l_first); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| const MLoopUV *layer_data = (const MLoopUV *)CustomData_get_layer_n( | const float2 *layer_data = static_cast<float2 *>( | ||||
| cd_ldata, CD_MLOOPUV, i); | CustomData_get_layer_n(cd_ldata, CD_PROP_FLOAT2, i)); | ||||
| for (int ml_index = 0; ml_index < mr->loop_len; ml_index++, uv_data++, layer_data++) { | for (int ml_index = 0; ml_index < mr->loop_len; ml_index++, uv_data++, layer_data++) { | ||||
| memcpy(uv_data, layer_data->uv, sizeof(*uv_data)); | memcpy(uv_data, layer_data, sizeof(*uv_data)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void extract_uv_init_subdiv(const DRWSubdivCache *subdiv_cache, | static void extract_uv_init_subdiv(const DRWSubdivCache *subdiv_cache, | ||||
| const MeshRenderData * /*mr*/, | const MeshRenderData * /*mr*/, | ||||
| ▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines | |||||