| 750 | } |
| 751 | |
| 752 | void Model::ReadFromFile(const wchar* path, ID3D11Device* device) |
| 753 | { |
| 754 | wstring directory = GetDirectoryFromFilePath(path); |
| 755 | |
| 756 | // Open the file |
| 757 | HANDLE fileHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 758 | if(fileHandle == INVALID_HANDLE_VALUE) |
| 759 | Win32Call(false); |
| 760 | |
| 761 | // Read in the number of meshes |
| 762 | uint32 numMeshes = 0; |
| 763 | SerializeRead(fileHandle, numMeshes); |
| 764 | |
| 765 | meshes.resize(numMeshes); |
| 766 | for(uint32 meshIdx = 0; meshIdx < numMeshes; ++meshIdx) |
| 767 | { |
| 768 | Mesh& mesh = meshes[meshIdx]; |
| 769 | |
| 770 | // Read in the vertex data |
| 771 | uint32 vbSize = 0; |
| 772 | SerializeRead(fileHandle, vbSize); |
| 773 | |
| 774 | UINT8* vbData = new UINT8[vbSize]; |
| 775 | DWORD bytesRead = 0; |
| 776 | Win32Call(ReadFile(fileHandle, vbData, vbSize, &bytesRead, NULL)); |
| 777 | |
| 778 | D3D11_BUFFER_DESC vbDesc; |
| 779 | vbDesc.ByteWidth = vbSize; |
| 780 | vbDesc.CPUAccessFlags = 0; |
| 781 | vbDesc.StructureByteStride = 0; |
| 782 | vbDesc.MiscFlags = 0; |
| 783 | vbDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; |
| 784 | vbDesc.Usage = D3D11_USAGE_IMMUTABLE; |
| 785 | |
| 786 | D3D11_SUBRESOURCE_DATA srData; |
| 787 | srData.pSysMem = vbData; |
| 788 | srData.SysMemPitch = 0; |
| 789 | srData.SysMemSlicePitch = 0; |
| 790 | DXCall(device->CreateBuffer(&vbDesc, &srData, &mesh.vertexBuffer)); |
| 791 | |
| 792 | delete [] vbData; |
| 793 | |
| 794 | // Read in the index data |
| 795 | uint32 ibSize = 0; |
| 796 | SerializeRead(fileHandle, ibSize); |
| 797 | |
| 798 | UINT8* ibData = new UINT8[ibSize]; |
| 799 | Win32Call(ReadFile(fileHandle, ibData, ibSize, &bytesRead, NULL)); |
| 800 | |
| 801 | D3D11_BUFFER_DESC ibDesc; |
| 802 | ibDesc.ByteWidth = ibSize; |
| 803 | ibDesc.CPUAccessFlags = 0; |
| 804 | ibDesc.StructureByteStride = 0; |
| 805 | ibDesc.MiscFlags = 0; |
| 806 | ibDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; |
| 807 | ibDesc.Usage = D3D11_USAGE_IMMUTABLE; |
| 808 | |
| 809 | srData.pSysMem = ibData; |
nothing calls this directly
no test coverage detected