Now supporting multiple material per mesh. Simon changed glDrawElementsBaseVertex to glDrawElements in DrawFinalPass.cpp Hallelulijah!

This commit is contained in:
antc13
2016-01-19 17:40:34 +01:00
parent 2a3009212a
commit 3826142e94
15 changed files with 359 additions and 230 deletions
+3 -3
View File
@@ -291,21 +291,21 @@ void EditorSystem::createWidget()
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
m_World->AttachComponent(m_WidgetPlaneX, "Model");
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh";
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube";
m_WidgetY = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetY, "Transform");
m_World->AttachComponent(m_WidgetY, "Model");
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
m_World->AttachComponent(m_WidgetPlaneY, "Model");
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh";
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube";
m_WidgetZ = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetZ, "Transform");
m_World->AttachComponent(m_WidgetZ, "Model");
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh";
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube";
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetOrigin, "Transform");
m_World->AttachComponent(m_WidgetOrigin, "Model");
+1 -3
View File
@@ -56,9 +56,7 @@ void DrawFinalPass::Draw(RenderScene& scene)
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
continue;
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
}
}
GLERROR("DrawFinalPass::Draw: END");
+1 -1
View File
@@ -7,7 +7,7 @@ DrawFinalPassState::DrawFinalPassState()
Enable(GL_BLEND);
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Enable(GL_DEPTH_TEST);
Enable(GL_CULL_FACE);
Disable(GL_CULL_FACE); //Should be enabled, fix it johan and andreas.
ClearColor(glm::vec4(200.f / 255, 0.f / 255, 200.f / 255, 0.f));
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
+121 -15
View File
@@ -1,12 +1,19 @@
#include "Rendering\RawModelCustom.h"
#include "Rendering/RawModelCustom.h"
RawModel::RawModel(std::string fileName)
RawModel::RawModel(std::string& fileName)
{
ReadMeshFile(fileName);
ReadMaterialFile(fileName);
}
void RawModel::ReadMeshFile(std::string filePath)
{
char* fileData;
std::ifstream in(fileName.c_str(), std::ios_base::binary | std::ios_base::ate);
filePath += ".mesh";
std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate);
if (!in.is_open()) {
throw Resource::FailedLoadingException("Open file failed");
throw Resource::FailedLoadingException("Open mesh file failed");
}
unsigned int fileByteSize = in.tellg();
in.seekg(0, std::ios_base::beg);
@@ -21,23 +28,13 @@ RawModel::RawModel(std::string fileName)
ReadMesh(offset, fileData, fileByteSize);
}
delete fileData;
MaterialGroup mat;
mat.StartIndex = 0;
mat.EndIndex = m_Indices.size() - 1;
MaterialGroups.push_back(mat);
}
void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
{
#ifdef BOOST_LITTLE_ENDIAN
unsigned int test;
test = *(unsigned int*)fileData;
unsigned int* test2;
test2 = (unsigned int*)fileData;
m_Vertices.resize(test);
m_Vertices.resize(*(unsigned int*)(fileData + offset));
offset += sizeof(unsigned int);
test = *(unsigned int*)(fileData + offset);
m_Indices.resize(*(unsigned int*)(fileData + offset));
offset += sizeof(unsigned int);
#else
@@ -78,6 +75,115 @@ void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& f
#endif
}
void RawModel::ReadMaterialFile(std::string filePath)
{
char* fileData;
filePath += ".mtrl";
std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate);
if (!in.is_open()) {
throw Resource::FailedLoadingException("Open material file failed");
}
unsigned int fileByteSize = in.tellg();
in.seekg(0, std::ios_base::beg);
fileData = new char[fileByteSize];
in.read(fileData, fileByteSize);
in.close();
unsigned int offset = 0;
if (fileByteSize > 0) {
ReadMaterials(offset, fileData, fileByteSize);
}
delete fileData;
}
void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
{
#ifdef BOOST_LITTLE_ENDIAN
unsigned int* numMaterials = (unsigned int*)(fileData);
MaterialGroups.reserve(*numMaterials);
offset += sizeof(unsigned int);
for (int i = 0; i < *numMaterials; i++) {
ReadMaterialSingle(offset, fileData, fileByteSize);
}
#else
#endif
}
void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
{
MaterialGroup newMaterial;
#ifdef BOOST_LITTLE_ENDIAN
if (offset + sizeof(unsigned int) * 4 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material texture names length failed");
}
unsigned int* nameLengths = (unsigned int*)(fileData + offset);
offset += sizeof(unsigned int) * 4;
if (offset + sizeof(float) * 2 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material specular and reflection values failed");
}
newMaterial.SpecularExponent = *(float*)(fileData + offset);
offset += sizeof(float);
newMaterial.ReflectionFactor = *(float*)(fileData + offset);
offset += sizeof(float);
if (offset + sizeof(unsigned int) * 2 > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material start and end index values failed");
}
newMaterial.StartIndex = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
newMaterial.EndIndex = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
if (nameLengths[0] > 0) {
if (offset + nameLengths[0] > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material texture path failed");
}
newMaterial.TexturePath = (fileData + offset);
offset += nameLengths[0];
}
if (nameLengths[1] > 0) {
if (offset + nameLengths[1] > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material NormalMap path failed");
}
newMaterial.NormalMapPath = (fileData + offset);
offset += nameLengths[1];
}
if (nameLengths[2] > 0) {
if (offset + nameLengths[2] > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material SpecularMap path failed");
}
newMaterial.SpecularMapPath = (fileData + offset);
offset += nameLengths[2];
}
if (nameLengths[3] > 0) {
if (offset + nameLengths[3] > fileByteSize) {
throw Resource::FailedLoadingException("Reading Material IncandescenceMap path failed");
}
newMaterial.IncandescenceMapPath = (fileData + offset);
offset += nameLengths[3];
}
#else
#endif
MaterialGroups.push_back(newMaterial);
}
RawModel::~RawModel()
{
+2 -2
View File
@@ -95,10 +95,10 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
model = ResourceManager::Load<::Model, true>(resource);
} catch (const Resource::StillLoadingException&) {
//continue;
model = ResourceManager::Load<::Model>("Models/coolCube.mesh");
model = ResourceManager::Load<::Model>("Models/coolCube");
} catch (const std::exception&) {
try {
model = ResourceManager::Load<::Model>("Models/coolCube.mesh");
model = ResourceManager::Load<::Model>("Models/coolCube");
} catch (const std::exception&) {
continue;
}
+4 -4
View File
@@ -101,10 +101,10 @@ void Renderer::Draw(RenderFrame& frame)
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
FillDepth(*scene);
m_PickingPass->Draw(*scene);
m_LightCullingPass->GenerateNewFrustum(*scene);
m_LightCullingPass->FillLightList(*scene);
m_LightCullingPass->CullLights(*scene);
//m_PickingPass->Draw(*scene);
//m_LightCullingPass->GenerateNewFrustum(*scene);
//m_LightCullingPass->FillLightList(*scene);
//m_LightCullingPass->CullLights(*scene);
m_DrawFinalPass->Draw(*scene);
//m_DrawScenePass->Draw(rq);