| 459 | } |
| 460 | |
| 461 | const Tr2ConstantBufferAL* Tr2RaytracingMeshArea::GetGeometryConstants( Tr2RaytracingMesh& mesh, Tr2RenderContext& renderContext ) const |
| 462 | { |
| 463 | TriGeometryResLodData* lod = mesh.GetCurrentLodData(); |
| 464 | if( !lod || m_areaIndex >= lod->m_areas.size() ) |
| 465 | { |
| 466 | return nullptr; //No mesh data or area index out of bounds |
| 467 | } |
| 468 | std::scoped_lock lock( s_geometryConstantsMutex ); |
| 469 | |
| 470 | if( !lod->m_areas[m_areaIndex].m_rtGeometryConstants.IsValid() ) |
| 471 | { |
| 472 | if( SUCCEEDED( lod->m_areas[m_areaIndex].m_rtGeometryConstants.Create( sizeof( TriRtGeometryConstants ), renderContext.GetPrimaryRenderContext() ) ) ) |
| 473 | { |
| 474 | TriRtGeometryConstants* data; |
| 475 | if( SUCCEEDED( lod->m_areas[m_areaIndex].m_rtGeometryConstants.Lock( (void**)&data, renderContext ) ) ) |
| 476 | { |
| 477 | *data = TriRtGeometryConstants{}; |
| 478 | |
| 479 | Tr2VertexDefinition def; |
| 480 | Tr2EffectStateManager::GetVertexDeclarationElements( lod->m_mesh->m_vertexDeclarationHandle, def ); |
| 481 | for( auto it = begin( def.m_items ); it != end( def.m_items ); ++it ) |
| 482 | { |
| 483 | if( it->m_usage == Tr2VertexDefinition::POSITION && it->m_usageIndex == 0 && it->m_stream == 0 ) |
| 484 | { |
| 485 | data->positionOffset = it->m_offset + lod->m_vertexAllocation.GetOffset(); |
| 486 | data->positionType = it->m_dataType; |
| 487 | |
| 488 | uint32_t type = data->positionType; |
| 489 | CCP_ASSERT_M( |
| 490 | type == Tr2VertexDefinition::DataType::FLOAT32_3, |
| 491 | "position type has to be FLOAT32_3!" ); |
| 492 | } |
| 493 | |
| 494 | if( it->m_usage == Tr2VertexDefinition::NORMAL && it->m_usageIndex == 0 && it->m_stream == 0 ) |
| 495 | { |
| 496 | data->normalOffset = it->m_offset + lod->m_vertexAllocation.GetOffset(); |
| 497 | data->normalType = it->m_dataType; |
| 498 | |
| 499 | uint32_t type = data->normalType; |
| 500 | CCP_ASSERT_M( |
| 501 | type == Tr2VertexDefinition::DataType::FLOAT16_3 || |
| 502 | type == Tr2VertexDefinition::DataType::FLOAT32_3, |
| 503 | "normal type has to be FLOAT16_3 or FLOAT32_3!" ); |
| 504 | } |
| 505 | |
| 506 | if( it->m_usage == Tr2VertexDefinition::TANGENT && it->m_usageIndex == 0 && it->m_stream == 0 ) |
| 507 | { |
| 508 | data->tangentOffset = it->m_offset + lod->m_vertexAllocation.GetOffset(); |
| 509 | data->tangentType = it->m_dataType; |
| 510 | |
| 511 | uint32_t type = data->tangentType; |
| 512 | CCP_ASSERT_M( |
| 513 | type == Tr2VertexDefinition::DataType::FLOAT16_3 || |
| 514 | type == Tr2VertexDefinition::DataType::FLOAT32_3 || |
| 515 | type == Tr2VertexDefinition::DataType::UBYTE_4_NORM || |
| 516 | type == Tr2VertexDefinition::DataType::USHORT_4_NORM || |
| 517 | type == Tr2VertexDefinition::DataType::SHORT_4_NORM, |
| 518 | "tangent type has to be FLOAT16_3 or FLOAT32_3 or UBYTE_4_NORM or USHORT_4_NORM or SHORT_4_NORM!" ); |