Async load works, using exceptions for special resources.

This commit is contained in:
William Moberg
2016-01-14 16:27:45 +01:00
parent 9f185a1e35
commit 71047b08ec
13 changed files with 160 additions and 181 deletions
+19 -8
View File
@@ -1,24 +1,35 @@
#include "Rendering/Model.h"
Model::Model(std::string fileName)
: RawModel(fileName)
{
}
//Load the RawModel asyncronously, this will be done on a separate thread in the background.
m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
//If it is null, the model is not done yet, so tell resourceManager to try constructing me again later.
if (m_RawModel == nullptr) {
throw StillLoadingException();
}
void Model::GlCommands()
{
//Call the base class method.
RawModel::GlCommands();
for (auto& group : m_RawModel->TextureGroups) {
if (!group.TexturePath.empty()) {
group.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.TexturePath));
}
if (!group.NormalMapPath.empty()) {
group.NormalMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.NormalMapPath));
}
if (!group.SpecularMapPath.empty()) {
group.SpecularMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.SpecularMapPath));
}
}
// Generate GL buffers
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, m_Vertices.size() * sizeof(Vertex), &m_Vertices[0], GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, m_RawModel->m_Vertices.size() * sizeof(RawModel::Vertex), &m_RawModel->m_Vertices[0], GL_STATIC_DRAW);
glGenBuffers(1, &ElementBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_Indices.size() * sizeof(unsigned int), &m_Indices[0], GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_RawModel->m_Indices.size() * sizeof(unsigned int), &m_RawModel->m_Indices[0], GL_STATIC_DRAW);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);