MCPcopy Create free account
hub / github.com/TheRealMJP/Shadows / WriteToFile

Method WriteToFile

Shadows/SampleFramework11/Model.cpp:670–750  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

668}
669
670void Model::WriteToFile(const wchar* path, ID3D11Device* device, ID3D11DeviceContext* context)
671{
672 // If the file exists, delete it
673 if(FileExists(path))
674 Win32Call(DeleteFile(path));
675
676 // Create the file
677 HANDLE fileHandle = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
678 if(fileHandle == INVALID_HANDLE_VALUE)
679 Win32Call(false);
680
681 // Write out the number of meshes
682 DWORD bytesWritten = 0;
683 uint32 numMeshes = static_cast<uint32>(meshes.size());
684 SerializeWrite(fileHandle, numMeshes);
685
686 // Write out the meshes
687 for(uint32 meshIdx = 0; meshIdx < meshes.size(); ++meshIdx)
688 {
689 Mesh& mesh = meshes[meshIdx];
690
691 // Write the mesh vertex data
692 uint32 vbSize = mesh.numVertices * mesh.vertexStride;
693 SerializeWrite(fileHandle, vbSize);
694
695 StagingBuffer stagingVB;
696 stagingVB.Initialize(device, vbSize);
697 context->CopyResource(stagingVB.Buffer, mesh.vertexBuffer);
698 const void* vertexData = stagingVB.Map(context);
699 Win32Call(WriteFile(fileHandle, vertexData, vbSize, &bytesWritten, NULL));
700 stagingVB.Unmap(context);
701
702 // Write the mesh index buffer data
703 uint32 ibSize = mesh.numIndices * (mesh.indexType == Mesh::Index16Bit ? 2 : 4);
704 SerializeWrite(fileHandle, ibSize);
705
706 StagingBuffer stagingIB;
707 stagingIB.Initialize(device, ibSize);
708 context->CopyResource(stagingIB.Buffer, mesh.indexBuffer);
709 const void* indexData = stagingIB.Map(context);
710 Win32Call(WriteFile(fileHandle, indexData, stagingIB.Size, &bytesWritten, NULL));
711 stagingIB.Unmap(context);
712
713 // Write out the other mesh members
714 SerializeWriteVector(fileHandle, mesh.meshParts);
715 SerializeWriteVector(fileHandle, mesh.inputElements);
716 SerializeWrite(fileHandle, mesh.vertexStride);
717 SerializeWrite(fileHandle, mesh.numVertices);
718 SerializeWrite(fileHandle, mesh.numIndices);
719
720 uint32 ibType = static_cast<uint32>(mesh.indexType);
721 SerializeWrite(fileHandle, ibType);
722
723 // Write out the input element names
724 uint32 numInputElements = static_cast<uint32>(mesh.inputElementNames.size());
725 SerializeWrite(fileHandle, numInputElements);
726 for(uint32 i = 0; i < numInputElements; ++i)
727 SerializeWriteString(fileHandle, mesh.inputElementNames[i]);

Callers

nothing calls this directly

Calls 8

FileExistsFunction · 0.85
Win32CallFunction · 0.85
SerializeWriteFunction · 0.85
SerializeWriteVectorFunction · 0.85
SerializeWriteStringFunction · 0.85
MapMethod · 0.80
UnmapMethod · 0.80
InitializeMethod · 0.45

Tested by

no test coverage detected