Merge remote-tracking branch 'origin/master' into Menu
# Conflicts: # include/Engine/Rendering/DrawFinalPass.h # include/Engine/Rendering/RenderQueue.h # resources/Schema/Components.xsd # resources/Schema/Entities/QualityAssurance.xml # resources/Schema/Entities/RenderingWorld.xml # resources/Shaders/Sprite.vert.glsl # src/Engine/Rendering/DrawFinalPass.cpp # src/Engine/Rendering/Model.cpp # src/Engine/Rendering/RenderSystem.cpp # src/Engine/Rendering/Renderer.cpp # src/Game/Game.cpp
This commit is contained in:
@@ -5,26 +5,77 @@ Model::Model(std::string fileName)
|
||||
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
|
||||
m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
|
||||
|
||||
for (auto& group : m_RawModel->MaterialGroups) {
|
||||
if (!group.TexturePath.empty()) {
|
||||
group.Texture = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.TexturePath, false));
|
||||
}
|
||||
if (!group.NormalMapPath.empty()) {
|
||||
group.NormalMap = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.NormalMapPath, false));
|
||||
}
|
||||
if (!group.SpecularMapPath.empty()) {
|
||||
group.SpecularMap = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.SpecularMapPath, false));
|
||||
}
|
||||
if (!group.IncandescenceMapPath.empty()) {
|
||||
group.IncandescenceMap = std::shared_ptr<Texture>(CommonFunctions::LoadTexture(group.IncandescenceMapPath, false));
|
||||
}
|
||||
for (auto& materialProperty : m_RawModel->m_Materials) {
|
||||
switch (materialProperty.type) {
|
||||
case RawModel::MaterialType::SingleTextures:
|
||||
{
|
||||
RawModel::MaterialSingleTextures* materialSingleTexture = static_cast<RawModel::MaterialSingleTextures*>(materialProperty.material);
|
||||
if (!materialSingleTexture->ColorMap.TexturePath.empty()) {
|
||||
materialSingleTexture->ColorMap.Texture = std::shared_ptr<Texture>(ResourceManager::LoadfixTexture>(materialSingleTexture->ColorMap.TexturePath));
|
||||
}
|
||||
if (!materialSingleTexture->NormalMap.TexturePath.empty()) {
|
||||
materialSingleTexture->NormalMap.Texture = std::shared_ptr<Texture>(ResourceManager::LoadfixTexture>(materialSingleTexture->NormalMap.TexturePath));
|
||||
}
|
||||
if (!materialSingleTexture->SpecularMap.TexturePath.empty()) {
|
||||
materialSingleTexture->SpecularMap.Texture = std::shared_ptr<Texture>(ResourceManager::LoadfixTexture>(materialSingleTexture->SpecularMap.TexturePath));
|
||||
}
|
||||
if (!materialSingleTexture->IncandescenceMap.TexturePath.empty()) {
|
||||
materialSingleTexture->IncandescenceMap.Texture = std::shared_ptr<Texture>(ResourceManager::LoadfixTexture>(materialSingleTexture->IncandescenceMap.TexturePath));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RawModel::MaterialType::SplatMapping:
|
||||
{
|
||||
RawModel::MaterialSplatMapping* materialSplatMapping = static_cast<RawModel::MaterialSplatMapping*>(materialProperty.material);
|
||||
if (!materialSplatMapping->SplatMap.TexturePath.empty()) {
|
||||
materialSplatMapping->SplatMap.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(materialSplatMapping->SplatMap.TexturePath));
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->ColorMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
}
|
||||
else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->NormalMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
} else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->SpecularMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
}
|
||||
else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
for (auto& texture : materialSplatMapping->IncandescenceMaps)
|
||||
{
|
||||
if (!texture.TexturePath.empty()) {
|
||||
texture.Texture = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(texture.TexturePath));
|
||||
}
|
||||
else {
|
||||
texture.Texture = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate GL buffers
|
||||
GLuint buffer;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->m_Vertices.size() * sizeof(RawModel::Vertex), &m_RawModel->m_Vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * m_RawModel->VertexSize(), m_RawModel->Vertices(), GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &ElementBuffer);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
|
||||
@@ -35,7 +86,13 @@ Model::Model(std::string fileName)
|
||||
GLERROR("GLEW: BufferFail4");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer);
|
||||
std::vector<int> structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||
std::vector<int> structSizes;
|
||||
if (m_RawModel->IsSkinned()) {
|
||||
structSizes = { 3, 3, 3, 3, 2, 4, 4 };
|
||||
} else {
|
||||
structSizes = { 3, 3, 3, 3, 2 };
|
||||
}
|
||||
|
||||
int stride = 0;
|
||||
for (int size : structSizes) {
|
||||
stride += size;
|
||||
@@ -49,8 +106,10 @@ Model::Model(std::string fileName)
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
if (m_RawModel->IsSkinned()) {
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
|
||||
}
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
@@ -59,11 +118,24 @@ Model::Model(std::string fileName)
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
glEnableVertexAttribArray(4);
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
if (m_RawModel->IsSkinned()) {
|
||||
glEnableVertexAttribArray(5);
|
||||
glEnableVertexAttribArray(6);
|
||||
}
|
||||
GLERROR("GLEW: BufferFail5");
|
||||
|
||||
//CreateBuffers();
|
||||
|
||||
glm::vec3 mini(INFINITY);
|
||||
glm::vec3 maxi(-INFINITY);
|
||||
|
||||
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) {
|
||||
const auto& v = m_RawModel->Vertices()[i];
|
||||
mini = glm::min(mini, v.Position);
|
||||
maxi = glm::max(maxi, v.Position);
|
||||
}
|
||||
|
||||
m_Box = AABB(maxi, mini);
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
|
||||
Reference in New Issue
Block a user