MCPcopy Create free account
hub / github.com/Apress/Ray-Tracing-Gems-II / ExportToFile

Method ExportToFile

Chapter_27/Core/PixelBuffer.cpp:381–403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

379}
380
381void PixelBuffer::ExportToFile( const std::wstring& FilePath )
382{
383 // Create the buffer. We will release it after all is done.
384 ReadbackBuffer TempBuffer;
385 TempBuffer.Create(L"Temporary Readback Buffer", m_Width * m_Height, (uint32_t)BytesPerPixel(m_Format));
386
387 CommandContext::ReadbackTexture2D(TempBuffer, *this);
388
389 // Retrieve a CPU-visible pointer to the buffer memory. Map the whole range for reading.
390 void* Memory = TempBuffer.Map();
391
392 // Open the file and write the header followed by the texel data.
393 std::ofstream OutFile(FilePath, std::ios::out | std::ios::binary);
394 OutFile.write((const char*)&m_Format, 4);
395 OutFile.write((const char*)&m_Width, 4); // Pitch
396 OutFile.write((const char*)&m_Width, 4);
397 OutFile.write((const char*)&m_Height, 4);
398 OutFile.write((const char*)Memory, TempBuffer.GetBufferSize());
399 OutFile.close();
400
401 // No values were written to the buffer, so use a null range when unmapping.
402 TempBuffer.Unmap();
403}

Callers

nothing calls this directly

Calls 7

BytesPerPixelFunction · 0.85
GetBufferSizeMethod · 0.80
CreateMethod · 0.45
MapMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
UnmapMethod · 0.45

Tested by

no test coverage detected