Lots of things done

This commit is contained in:
Ayumiwii
2016-01-08 16:42:59 +01:00
parent c133223bac
commit 3467315aef
15 changed files with 312 additions and 22 deletions
+52 -8
View File
@@ -16,18 +16,32 @@ void DrawScenePass::InitializeShaderPrograms()
{
//Gör så att shaders är en resource, tex som texture classen. Konstruktorn måste vara privat.
m_BasicForwardProgram = ResourceManager::Load<ShaderProgram>("#BasicForwardProgram");
m_BasicForwardProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/BasicForward.vert.glsl")));
m_BasicForwardProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/BasicForward.frag.glsl")));
m_BasicForwardProgram->Compile();
m_BasicForwardProgram->Link();
m_CoolDeathAnimProgram = ResourceManager::Load<ShaderProgram>("#CoolDeathAnimProgram");
m_CoolDeathAnimProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/CoolDeathAnim.vert.glsl")));
m_CoolDeathAnimProgram->AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/CoolDeathAnim.geom.glsl")));
m_CoolDeathAnimProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/CoolDeathAnim.frag.glsl")));
m_CoolDeathAnimProgram->Compile();
m_CoolDeathAnimProgram->Link();
}
void DrawScenePass::Draw(RenderQueueCollection& rq)
{
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (TimeDeath > 2.f) {
TimeDeath = 0.f;
}
Origin = glm::vec3(0.f, 0.0f, 0.f);
TimeDeath = TimeDeath + 0.01f;
EndDeath = EndDeath + 0.05f;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLERROR("Renderer::Draw PickingPass");
DrawScenePassState state;
@@ -35,17 +49,47 @@ void DrawScenePass::Draw(RenderQueueCollection& rq)
//TODO: Render: Add code for more jobs than modeljobs.
for (auto &job : rq.Forward) {
auto coolDeathAnimationJob = std::dynamic_pointer_cast<CoolDeathAnimationJob>(job);
if (coolDeathAnimationJob) {
GLuint ShaderHandle = m_CoolDeathAnimProgram->GetHandle(); //---
//---
m_CoolDeathAnimProgram->Bind();
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(coolDeathAnimationJob->ModelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(coolDeathAnimationJob->Color));
glUniform3fv(glGetUniformLocation(ShaderHandle, "OriginPos"), 1, glm::value_ptr(Origin));
glUniform1f(glGetUniformLocation(ShaderHandle, "TimeSinceDeath"), TimeDeath);
glUniform1f(glGetUniformLocation(ShaderHandle, "EndOfDeath"), EndDeath);
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
if (coolDeathAnimationJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, coolDeathAnimationJob->DiffuseTexture->m_Texture);
} else {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glBindVertexArray(coolDeathAnimationJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, coolDeathAnimationJob->Model->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, coolDeathAnimationJob->EndIndex - coolDeathAnimationJob->StartIndex + 1, GL_UNSIGNED_INT, 0, coolDeathAnimationJob->StartIndex);
continue;
}
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) {
GLuint ShaderHandle = m_BasicForwardProgram->GetHandle();
GLuint ShaderHandle = m_BasicForwardProgram->GetHandle(); //---
GLERROR("1");
//---
m_BasicForwardProgram->Bind();
GLERROR("2.1");
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->ModelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
GLERROR("2");
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
if (modelJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0);
@@ -54,11 +98,11 @@ void DrawScenePass::Draw(RenderQueueCollection& rq)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
GLERROR("3");
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);
GLERROR("4");
continue;
}
}
+39 -13
View File
@@ -90,21 +90,47 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
}
for (auto texGroup : model->TextureGroups) {
ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color;
auto deathComp = world->HasComponent(modelC.EntityID, "CoolDeathAnim");
if (!deathComp) {
ModelJob job;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
job.Entity = modelC.EntityID;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color;
renderQueue->Add(job);
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
job.Entity = modelC.EntityID;
renderQueue->Add(job);
}
else {
CoolDeathAnimationJob job;
job.TimeSinceDeath = 1.f;
job.EndOfDeath = 15.f;
job.OriginPos = glm::vec3(1000.f, 2.f, 0.f);
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
job.DiffuseTexture = texGroup.Texture.get();
job.NormalTexture = texGroup.NormalMap.get();
job.SpecularTexture = texGroup.SpecularMap.get();
job.Model = model;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
job.Entity = modelC.EntityID;
renderQueue->Add(job);
}
}
}
}
+9
View File
@@ -76,6 +76,15 @@ void Renderer::InitializeShaders()
m_DrawScreenQuadProgram->Compile();
m_DrawScreenQuadProgram->Link();
m_CoolDeathAnimProgram = ResourceManager::Load<ShaderProgram>("#CoolDeathAnimProgram");
//m_CoolDeathAnimProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/CoolDeathAnim.vert.glsl")));
//m_CoolDeathAnimProgram->AddShader(std::shared_ptr<Shader>(new GeometryShader("Shaders/CoolDeathAnim.geom.glsl")));
//m_CoolDeathAnimProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/CoolDeathAnim.frag.glsl")));
//m_CoolDeathAnimProgram->Compile();
//m_CoolDeathAnimProgram->Link();
//m_CalculateFrustumProgram = ResourceManager::Load<ShaderProgram>("#CalculateFrustumProgram");
//m_CalculateFrustumProgram.AddShader(std::shared_ptr<Shader>(new ComputeShader("Shaders/GridFrustum.comp.glsl")));
//m_CalculateFrustumProgram.Compile();