void StagingTexture2D::WriteTexels(u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) { // Optimal path: same dimensions, same stride. ASSERT((x + width) <= m_width && (y + height) <= m_height); bool use_optimal_path = x == 0 && width == m_width && m_row_stride == data_stride; u32 block_width = Util::GetBlockWidth(m_format); if (block_width > 1) { x = std::max(0u, (x + block_width - 1) / block_width); y = std::max(0u, (y + block_width - 1) / block_width); width = std::max(1u, (width + block_width - 1) / block_width); height = std::max(1u, (height + block_width - 1) / block_width); } char* dst_ptr = GetRowPointer(y); if (use_optimal_path) { std::memcpy(dst_ptr, data, m_row_stride * height); return; } u32 copy_size = std::min(width * m_texel_size, data_stride); const char* src_ptr = reinterpret_cast<const char*>(data); for (u32 row = 0; row < height; row++) { std::memcpy(dst_ptr + (x * m_texel_size), src_ptr, copy_size); dst_ptr += m_row_stride; src_ptr += data_stride; } }
void StagingTexture2D::WriteTexels(u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_stride) { char* dst_ptr = GetRowPointer(y); // Optimal path: same dimensions, same stride. _assert_((x + width) <= m_width && (y + height) <= m_height); if (x == 0 && width == m_width && m_row_stride == data_stride) { memcpy(dst_ptr, data, m_row_stride * height); return; } u32 copy_size = std::min(width * m_texel_size, data_stride); const char* src_ptr = reinterpret_cast<const char*>(data); for (u32 row = 0; row < height; row++) { memcpy(dst_ptr + (x * m_texel_size), src_ptr, copy_size); dst_ptr += m_row_stride; src_ptr += data_stride; } }