Skip to content

Commit ac85e05

Browse files
committed
Added generateModel to renderer
1 parent bf0695c commit ac85e05

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Documentation Status](https://readthedocs.org/projects/igneous/badge/?version=latest)](https://igneous.readthedocs.io/en/latest/?badge=latest)
66
[![Join the chat at https://discord.gg/CCUwTar](https://img.shields.io/badge/chat-on_discord-7389D8.svg?logo=discord&logoColor=ffffff&labelColor=6A7EC2)](https://discord.gg/CCUwTar)
77
[![Join the chat at https://www.reddit.com/r/igneous/](https://img.shields.io/badge/chat-on_reddit-FF5700.svg?logo=reddit&logoColor=ffffff&labelColor=FF4500)](https://www.reddit.com/r/igneous/)
8+
[![Track on https://trello.com/b/05omR9Mj/igneous](https://img.shields.io/badge/track-on_trello-007BC2.svg?logo=trello&logoColor=ffffff&labelColor=026AA7)](https://trello.com/b/05omR9Mj/igneous)
89

910
Igneous is an open source game engine written in C++.
1011

igneous/include/igneous/renderer/renderer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace renderer
2121
bgfx::ProgramHandle loadProgram(const char* vs, const char* fs);
2222

2323
ModelHandle loadModel(std::string path, bgfx::ProgramHandle program);
24+
ModelHandle generateModel(std::vector<std::pair<unsigned int, unsigned int>> modelSizes, void* modelData, bgfx::VertexDecl vertexDecl, bgfx::ProgramHandle program);
2425

2526
void render();
2627
void screenshot();

igneous/src/renderer/renderer.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ namespace renderer
275275

276276
ModelHandle loadModel(std::string path, bgfx::ProgramHandle program)
277277
{
278+
if (models.count(path))
279+
{
280+
return models.at(path);
281+
}
278282
std::ifstream file(path, std::ios::in | std::ios::binary);
279283
if (file.fail())
280284
{
@@ -363,6 +367,33 @@ namespace renderer
363367
model->meshes = meshes;
364368
model->program = program;
365369

370+
models[path] = model;
371+
return model;
372+
}
373+
374+
ModelHandle generateModel(std::vector<std::pair<unsigned int, unsigned int>> modelSizes, void* modelData, bgfx::VertexDecl vertexDecl, bgfx::ProgramHandle program)
375+
{
376+
std::vector<Mesh> meshes;
377+
uint32_t amountRead = 0;
378+
for (auto meshSize : modelSizes)
379+
{
380+
unsigned int numVerticies = meshSize.first;
381+
unsigned int numIndicies = meshSize.second;
382+
uint32_t verticiesSize = (uint32_t)numVerticies * (uint32_t)vertexDecl.getStride();
383+
uint32_t indiciesSize = (uint32_t)numIndicies * sizeof(uint16_t);
384+
Mesh mesh;
385+
mesh.vbh = bgfx::createVertexBuffer(bgfx::makeRef((uint8_t*)modelData + amountRead, verticiesSize), vertexDecl);
386+
amountRead += verticiesSize;
387+
mesh.ibh = bgfx::createIndexBuffer(bgfx::makeRef((uint8_t*)modelData + amountRead, indiciesSize));
388+
amountRead += indiciesSize;
389+
390+
meshes.push_back(mesh);
391+
}
392+
393+
Model* model = new Model;
394+
model->meshes = meshes;
395+
model->program = program;
396+
366397
return model;
367398
}
368399

0 commit comments

Comments
 (0)