Skip to content

Commit cf9e6ed

Browse files
committed
option to flip screenshot image
1 parent e798485 commit cf9e6ed

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

include/nbl/ext/ScreenShot/ScreenShot.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,27 @@ namespace nbl
150150

151151
auto destinationBoundMemory = destinationBuffer->getBoundMemory();
152152
destinationBoundMemory->mapMemoryRange(video::IDriverMemoryAllocation::EMCAF_READ, { 0u, memoryRequirements.vulkanReqs.size });
153-
auto texelBuffer = core::make_smart_refctd_ptr<asset::CCustomAllocatorCPUBuffer<core::null_allocator<uint8_t>>>(memoryRequirements.vulkanReqs.size, destinationBoundMemory->getMappedPointer(), core::adopt_memory);
154153

155-
image->setBufferAndRegions(std::move(texelBuffer), regions);
154+
auto correctedScreenShotTexelBuffer = core::make_smart_refctd_ptr<asset::ICPUBuffer>(memoryRequirements.vulkanReqs.size);
155+
bool flipImage = true;
156+
if(flipImage)
157+
{
158+
auto extent = gpuImage->getMipSize(0u);
159+
uint32_t rowByteSize = extent.x * asset::getTexelOrBlockBytesize(gpuImage->getCreationParameters().format);
160+
for(uint32_t y = 0; y < extent.y; ++y)
161+
{
162+
uint32_t flipped_y = extent.y - y - 1;
163+
memcpy(reinterpret_cast<uint8_t*>(correctedScreenShotTexelBuffer->getPointer()) + rowByteSize * y, reinterpret_cast<uint8_t*>(destinationBoundMemory->getMappedPointer()) + rowByteSize * flipped_y, rowByteSize);
164+
}
165+
}
166+
else
167+
{
168+
memcpy(correctedScreenShotTexelBuffer->getPointer(), destinationBoundMemory->getMappedPointer(), memoryRequirements.vulkanReqs.size);
169+
}
170+
171+
destinationBoundMemory->unmapMemory();
172+
173+
image->setBufferAndRegions(std::move(correctedScreenShotTexelBuffer), regions);
156174

157175
while (mapPointerGetterFence->waitCPU(1000ull, mapPointerGetterFence->canDeferredFlush()) == video::EDFR_TIMEOUT_EXPIRED) {}
158176

@@ -231,7 +249,6 @@ namespace nbl
231249
if (!status)
232250
status = tryToWrite(imageView.get());
233251

234-
destinationBoundMemory->unmapMemory();
235252
return status;
236253

237254
}

0 commit comments

Comments
 (0)