| 1564 | } |
| 1565 | |
| 1566 | ALResult Tr2TextureAL::UpdateSubresource( const Tr2TextureSubresource& region, const void* source, uint32_t pitch, uint32_t depthPitch, Tr2RenderContextAL& renderContext ) |
| 1567 | { |
| 1568 | if( !IsValid() ) |
| 1569 | { |
| 1570 | return E_INVALIDCALL; |
| 1571 | } |
| 1572 | if( !renderContext.IsValid() ) |
| 1573 | { |
| 1574 | return E_INVALIDARG; |
| 1575 | } |
| 1576 | |
| 1577 | if( HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE_OFTEN ) ) |
| 1578 | { |
| 1579 | return E_INVALIDCALL; |
| 1580 | } |
| 1581 | if( !HasFlag( m_cpuUsage, Tr2CpuUsage::WRITE ) && !IsWritable( m_gpuUsage ) ) |
| 1582 | { |
| 1583 | return E_INVALIDCALL; |
| 1584 | } |
| 1585 | |
| 1586 | if( !region.IsValidForBitmap( m_desc ) ) |
| 1587 | { |
| 1588 | return E_INVALIDARG; |
| 1589 | } |
| 1590 | if( !region.IsSingleSubresource() ) |
| 1591 | { |
| 1592 | return E_INVALIDARG; |
| 1593 | } |
| 1594 | |
| 1595 | void* dest; |
| 1596 | uint32_t destPitch; |
| 1597 | FORWARD_HR( MapForWriting( region, dest, destPitch, renderContext ) ); |
| 1598 | |
| 1599 | auto clamped = region; |
| 1600 | clamped.ClampToTexture( m_desc ); |
| 1601 | |
| 1602 | auto bpp = Tr2RenderContextEnum::GetBytesPerPixel( m_desc.GetFormat() ); |
| 1603 | auto width = clamped.m_box.GetWidth(); |
| 1604 | width *= bpp; |
| 1605 | auto depthSlice = static_cast<const uint8_t*>( source ); |
| 1606 | |
| 1607 | for( uint32_t j = clamped.m_box.front; j != clamped.m_box.back; ++j ) |
| 1608 | { |
| 1609 | auto src = depthSlice; |
| 1610 | for( uint32_t i = clamped.m_box.top; i != clamped.m_box.bottom; ++i ) |
| 1611 | { |
| 1612 | memcpy( dest, src, width ); |
| 1613 | dest = static_cast<uint8_t*>( dest ) + destPitch; |
| 1614 | src += pitch; |
| 1615 | } |
| 1616 | depthSlice += depthPitch; |
| 1617 | } |
| 1618 | UnmapForWriting( renderContext ); |
| 1619 | |
| 1620 | return S_OK; |
| 1621 | } |
| 1622 | |
| 1623 |
nothing calls this directly
no test coverage detected