| 730 | return data != nullptr; |
| 731 | } |
| 732 | bool ObjectManager::LoadBufferFromModel(BufferObject* buf, const std::string& str) |
| 733 | { |
| 734 | ed::Logger::Get().Log("Loading buffer data from a 3D model"); |
| 735 | |
| 736 | ed::eng::Model mdl; |
| 737 | bool ret = mdl.LoadFromFile(str); |
| 738 | |
| 739 | if (ret) { |
| 740 | int vertCount = 0; |
| 741 | for (auto mesh : mdl.Meshes) |
| 742 | vertCount += mesh.Vertices.size(); |
| 743 | int bufSize = vertCount * 4 * sizeof(float); |
| 744 | |
| 745 | buf->Size = bufSize; |
| 746 | buf->Data = realloc(buf->Data, bufSize); |
| 747 | |
| 748 | int index = 0; |
| 749 | float* fData = (float*)buf->Data; |
| 750 | for (auto mesh : mdl.Meshes) |
| 751 | for (auto vert : mesh.Vertices) { |
| 752 | fData[index + 0] = vert.Position.x; |
| 753 | fData[index + 1] = vert.Position.y; |
| 754 | fData[index + 2] = vert.Position.z; |
| 755 | fData[index + 3] = 1.0f; |
| 756 | index += 4; |
| 757 | } |
| 758 | |
| 759 | glBindBuffer(GL_UNIFORM_BUFFER, buf->ID); |
| 760 | glBufferData(GL_UNIFORM_BUFFER, buf->Size, buf->Data, GL_STATIC_DRAW); // upload data |
| 761 | glBindBuffer(GL_UNIFORM_BUFFER, 0); |
| 762 | } |
| 763 | |
| 764 | return ret; |
| 765 | } |
| 766 | bool ObjectManager::LoadBufferFromFile(BufferObject* buf, const std::string& str) |
| 767 | { |
| 768 | ed::Logger::Get().Log("Loading buffer data from a file"); |
no test coverage detected