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

Function WriteMeshAttributes

engine/gamesys/src/gamesys/components/comp_model.cpp:821–856  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

819 }
820
821 static uint8_t* WriteMeshAttributes(dmRender::HRenderContext render_context, MeshRenderItem* render_item, dmGraphics::VertexStepFunction step_function, dmGraphics::VertexAttributeInfos* attribute_infos, uint8_t* write_ptr, uint32_t vertex_count)
822 {
823 dmVMath::Matrix4 normal_matrix = dmRender::GetNormalMatrix(render_context, render_item->m_World);
824
825 const float* world_matrix_channels[] = { (float*) &render_item->m_World };
826 const float* normal_matrix_channels[] = { (float*) &normal_matrix };
827 const float* texture_transform_2d_channels[] = { dmRig::TEXTURE_TRANSFORM_2D_IDENTITY };
828
829 #define UNPACK_ATTRIBUTE_PTR(name) \
830 (render_item->m_Mesh->name.m_Count ? render_item->m_Mesh->name.m_Data : 0)
831 const float* uv_channels[] = { UNPACK_ATTRIBUTE_PTR(m_Texcoord0), UNPACK_ATTRIBUTE_PTR(m_Texcoord1), };
832 const float* color_channels[] = { UNPACK_ATTRIBUTE_PTR(m_Colors) };
833 const float* position_channels[] = { UNPACK_ATTRIBUTE_PTR(m_Positions) };
834 const float* normal_channels[] = { UNPACK_ATTRIBUTE_PTR(m_Normals) };
835 const float* tangent_channels[] = { UNPACK_ATTRIBUTE_PTR(m_Tangents) };
836 #undef UNPACK_ATTRIBUTE_PTR
837
838 uint32_t uv_channels_count = (uv_channels[0] ? 1 : 0) + (uv_channels[1] ? 1 : 0);
839
840 dmGraphics::WriteAttributeParams params = {};
841 dmRig::SetMeshWriteAttributeParams(&params,
842 attribute_infos,
843 step_function,
844 world_matrix_channels,
845 normal_matrix_channels,
846 0, // World space positions are not supported by local space materials
847 position_channels,
848 normal_channels,
849 tangent_channels,
850 color_channels,
851 texture_transform_2d_channels,
852 uv_channels,
853 uv_channels_count);
854
855 return dmGraphics::WriteAttributes(write_ptr, 0, vertex_count, params);
856 }
857
858 static void SetMeshAttributeRenderData(ModelWorld* world, ModelComponent* component, dmRender::HRenderContext render_context, const dmGraphics::VertexAttributeInfos* material_infos, const dmGraphics::VertexAttributeInfos* attribute_infos, MeshRenderItem* render_item, dmGraphics::VertexAttribute* model_attributes, uint32_t model_attribute_count, MeshAttributeRenderData* rd)
859 {

Callers 2

Calls 3

GetNormalMatrixFunction · 0.85
WriteAttributesFunction · 0.85

Tested by

no test coverage detected