| 534 | } |
| 535 | |
| 536 | void SetMaterialProgramAttributes(HMaterial material, const dmGraphics::VertexAttribute* attributes, uint32_t attributes_count) |
| 537 | { |
| 538 | // Don't need to do all this work if we don't have any custom attributes coming in |
| 539 | if (attributes == 0 || attributes_count == 0) |
| 540 | { |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | bool update_attributes = false; |
| 545 | |
| 546 | for (int i = 0; i < attributes_count; ++i) |
| 547 | { |
| 548 | const dmGraphics::VertexAttribute& graphics_attribute_in = attributes[i]; |
| 549 | uint8_t index = GetMaterialAttributeIndex(material, graphics_attribute_in.m_NameHash); |
| 550 | if (index == INVALID_MATERIAL_ATTRIBUTE_INDEX) |
| 551 | { |
| 552 | continue; |
| 553 | } |
| 554 | |
| 555 | dmGraphics::VertexAttributeInfo& info = material->m_VertexAttributeInfos[index]; |
| 556 | info.m_DataType = graphics_attribute_in.m_DataType; |
| 557 | info.m_Normalize = graphics_attribute_in.m_Normalize; |
| 558 | info.m_ElementCount = dmGraphics::VectorTypeToElementCount(graphics_attribute_in.m_VectorType); |
| 559 | info.m_VectorType = graphics_attribute_in.m_VectorType; |
| 560 | info.m_SemanticType = graphics_attribute_in.m_SemanticType; |
| 561 | info.m_CoordinateSpace = graphics_attribute_in.m_CoordinateSpace; |
| 562 | info.m_StepFunction = material->m_InstancingSupported ? graphics_attribute_in.m_StepFunction : dmGraphics::VERTEX_STEP_FUNCTION_VERTEX; |
| 563 | info.m_ValueVectorType = graphics_attribute_in.m_VectorType; |
| 564 | |
| 565 | update_attributes = true; |
| 566 | } |
| 567 | |
| 568 | // If the incoming attributes don't match any of the attributes from the shader, we don't need to do anything more |
| 569 | if (!update_attributes) |
| 570 | { |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | // Need to readjust value indices since the layout could have changed |
| 575 | uint32_t value_byte_size = 0; |
| 576 | for (int i = 0; i < material->m_VertexAttributeInfos.Size(); ++i) |
| 577 | { |
| 578 | dmRender::MaterialAttribute& material_attribute = material->m_MaterialAttributes[i]; |
| 579 | material_attribute.m_ValueIndex = value_byte_size; |
| 580 | |
| 581 | dmGraphics::Type graphics_type = dmGraphics::GetGraphicsType(material->m_VertexAttributeInfos[i].m_DataType); |
| 582 | value_byte_size += dmGraphics::GetTypeSize(graphics_type) * material->m_VertexAttributeInfos[i].m_ElementCount; |
| 583 | } |
| 584 | |
| 585 | material->m_MaterialAttributeValues.SetCapacity(value_byte_size); |
| 586 | material->m_MaterialAttributeValues.SetSize(value_byte_size); |
| 587 | UpdateVertexAttributeValuePointers(material); |
| 588 | |
| 589 | const uint32_t name_buffer_size = 128; |
| 590 | char name_buffer[name_buffer_size]; |
| 591 | |
| 592 | // And one more pass to set the new values from the incoming vertex declaration |
| 593 | for (int i = 0; i < attributes_count; ++i) |