Now sort models according to depth.

This commit is contained in:
Tleety
2016-01-11 14:12:54 +01:00
parent 0cf8d26557
commit 3c5966d174
5 changed files with 30 additions and 2 deletions
+3
View File
@@ -9,6 +9,7 @@
#include "Camera.h"
#include "RenderQueue.h"
#include "Model.h"
#include "../Core/World.h"
class IRenderer
{
@@ -34,6 +35,8 @@ public:
virtual void Update(double dt) = 0;
virtual void Draw(RenderQueueCollection& rq) = 0;
World* m_World; //Temp world, untill viktor merge.
protected:
Rectangle m_Resolution = Rectangle::Rectangle(1280, 720);
bool m_Fullscreen = false;
+4 -1
View File
@@ -23,7 +23,7 @@
class Renderer : public IRenderer
{
public:
Renderer(EventBroker* eventBroker)
Renderer(EventBroker* eventBroker)
: m_EventBroker(eventBroker)
{ }
@@ -61,6 +61,9 @@ private:
//void PickingPass(RenderQueueCollection& rq);
void DrawScreenQuad(GLuint textureToDraw);
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
void FillDepth(RenderQueueCollection& rq);
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
//--------------------ShaderPrograms-------------------//
ShaderProgram* m_BasicForwardProgram;
@@ -89,6 +89,12 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
model = ResourceManager::Load<Model>("Models/Core/Error.obj");
}
auto transformC = world->GetComponent(modelC.EntityID, "Transform");
if(&transformC == nullptr)
{
return;
}
for (auto texGroup : model->TextureGroups) {
ModelJob job;
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
+15 -1
View File
@@ -90,6 +90,8 @@ void Renderer::Update(double dt)
void Renderer::Draw(RenderQueueCollection& rq)
{
FillDepth(rq);
m_PickingPass->Draw(rq);
//DrawScreenQuad(m_PickingPass->PickingTexture());
m_LightCullingPass->FillLightList(rq);
@@ -148,4 +150,16 @@ void Renderer::InitializeRenderPasses()
m_PickingPass = new PickingPass(this, m_EventBroker);
m_LightCullingPass = new LightCullingPass(this);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass);
}
}
void Renderer::FillDepth(RenderQueueCollection& rq)
{
for(auto job : rq.Forward)
{
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
glm::vec3 pos = m_World->GetComponent(modelJob->Entity, "Transform")["Position"];
glm::vec3 worldpos = glm::vec3((m_Camera->ViewMatrix() * modelJob->ModelMatrix) * glm::vec4(pos, 1));
job->Depth = worldpos.z;
}
rq.Forward.Sort();
}
+2
View File
@@ -55,6 +55,8 @@ Game::Game(int argc, char* argv[])
EntityFileParser fp(file);
fp.MergeEntities(m_World);
}
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
m_Renderer->m_World = m_World;
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker);