MCPcopy Create free account
hub / github.com/defold/defold / WriteVertexDataByAttributes

Function WriteVertexDataByAttributes

engine/rig/src/rig.cpp:1276–1331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1274 }
1275
1276 static uint8_t* WriteVertexDataByAttributes(const dmRigDDF::Mesh* mesh, const float* positions_world, const float* positions_local, const float* normals, const float* tangents, const dmGraphics::VertexAttributeInfos* attribute_infos, uint32_t vertex_stride, const dmVMath::Matrix4& world_matrix, const dmVMath::Matrix4& normal_matrix, uint8_t* out_write_ptr)
1277 {
1278 const float* uv0 = mesh->m_Texcoord0.m_Count ? mesh->m_Texcoord0.m_Data : 0;
1279 const float* uv1 = mesh->m_Texcoord1.m_Count ? mesh->m_Texcoord1.m_Data : 0;
1280 const float* colors = mesh->m_Colors.m_Count ? mesh->m_Colors.m_Data : 0;
1281
1282 assert(mesh->m_Indices.m_Count > 0);
1283
1284 uint32_t* indices32 = 0;
1285 uint16_t* indices16 = 0;
1286 uint32_t num_indices;
1287 if (mesh->m_IndicesFormat == dmRigDDF::INDEXBUFFER_FORMAT_32)
1288 {
1289 indices32 = (uint32_t*)mesh->m_Indices.m_Data;
1290 num_indices = mesh->m_Indices.m_Count / 4;
1291 }
1292 else
1293 {
1294 indices16 = (uint16_t*)mesh->m_Indices.m_Data;
1295 num_indices = mesh->m_Indices.m_Count / 2;
1296 }
1297
1298 const float* uv_channels[] = { uv0, uv1 };
1299 uint32_t uv_channels_count = (uv0 ? 1 : 0) + (uv1 ? 1 : 0);
1300
1301 const float* world_matrix_channels[] = { (float*) &world_matrix };
1302 const float* normal_matrix_channels[] = { (float*) &normal_matrix };
1303 const float* position_world_channels[] = { positions_world };
1304 const float* position_local_channels[] = { positions_local };
1305 const float* normals_channels[] = { normals };
1306 const float* tangents_channels[] = { tangents };
1307 const float* colors_channels[] = { colors };
1308 const float* texture_transform_2d_channels[] = { TEXTURE_TRANSFORM_2D_IDENTITY };
1309
1310 dmGraphics::WriteAttributeParams params = {};
1311 SetMeshWriteAttributeParams(&params,
1312 attribute_infos,
1313 dmGraphics::VERTEX_STEP_FUNCTION_VERTEX,
1314 world_matrix_channels,
1315 normal_matrix_channels,
1316 position_world_channels,
1317 position_local_channels,
1318 normals_channels,
1319 tangents_channels,
1320 colors_channels,
1321 texture_transform_2d_channels,
1322 uv_channels,
1323 uv_channels_count);
1324
1325 for (uint32_t i = 0; i < num_indices; ++i)
1326 {
1327 uint32_t idx = indices32?indices32[i]:indices16[i];
1328 out_write_ptr = dmGraphics::WriteAttributes(out_write_ptr, idx, 1, params);
1329 }
1330 return out_write_ptr;
1331 }
1332
1333 static RigModelVertex* WriteVertexData(const dmRigDDF::Mesh* mesh, const float* positions, const float* normals, const float* tangents, RigModelVertex* out_write_ptr)

Callers 1

Calls 3

WriteAttributesFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected