| 437 | } |
| 438 | |
| 439 | void RenderSystem::CopyTextureImageData( |
| 440 | const DstImageDescriptor& dstImageDesc, |
| 441 | const Extent3D& extent, |
| 442 | const Format format, |
| 443 | const void* data, |
| 444 | std::size_t rowStride) |
| 445 | { |
| 446 | /* Check if image buffer must be converted */ |
| 447 | const auto numTexels = (extent.width * extent.height * extent.depth); |
| 448 | const auto& srcTexFormat = GetFormatAttribs(format); |
| 449 | auto srcFormatSize = DataTypeSize(srcTexFormat.dataType) * ImageFormatSize(srcTexFormat.format); |
| 450 | auto srcImageSize = (numTexels * srcFormatSize); |
| 451 | const auto dstPitch = (extent.width * srcFormatSize); |
| 452 | |
| 453 | if (srcTexFormat.format != dstImageDesc.format || srcTexFormat.dataType != dstImageDesc.dataType) |
| 454 | { |
| 455 | /* Check if padding must be removed */ |
| 456 | ByteBuffer unpaddedData; |
| 457 | if (rowStride != 0 && dstPitch != rowStride) |
| 458 | { |
| 459 | unpaddedData = GenerateEmptyByteBuffer(srcImageSize, false); |
| 460 | CopyRowAlignedData(unpaddedData.get(), data, srcImageSize, dstPitch, rowStride); |
| 461 | data = unpaddedData.get(); |
| 462 | } |
| 463 | |
| 464 | /* Determine destination image size */ |
| 465 | auto dstFormatSize = DataTypeSize(dstImageDesc.dataType) * ImageFormatSize(dstImageDesc.format); |
| 466 | auto dstImageSize = (numTexels * dstFormatSize); |
| 467 | |
| 468 | /* Validate input size */ |
| 469 | AssertImageDataSize(dstImageDesc.dataSize, dstImageSize); |
| 470 | |
| 471 | /* Convert mapped data into requested format */ |
| 472 | auto tempData = ConvertImageBuffer( |
| 473 | SrcImageDescriptor{ srcTexFormat.format, srcTexFormat.dataType, data, srcImageSize }, |
| 474 | dstImageDesc.format, dstImageDesc.dataType, GetConfiguration().threadCount |
| 475 | ); |
| 476 | |
| 477 | /* Copy temporary data into output buffer */ |
| 478 | ::memcpy(dstImageDesc.data, tempData.get(), dstImageSize); |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | /* Validate input size */ |
| 483 | AssertImageDataSize(dstImageDesc.dataSize, srcImageSize); |
| 484 | |
| 485 | /* Copy mapped data directly into the output buffer */ |
| 486 | if (rowStride != 0 && dstPitch != rowStride) |
| 487 | CopyRowAlignedData(dstImageDesc.data, data, srcImageSize, dstPitch, rowStride); |
| 488 | else |
| 489 | ::memcpy(dstImageDesc.data, data, srcImageSize); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | |
| 494 | } // /namespace LLGL |
nothing calls this directly
no test coverage detected