Now sort models according to depth.
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "RenderQueue.h"
|
#include "RenderQueue.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
#include "../Core/World.h"
|
||||||
|
|
||||||
class IRenderer
|
class IRenderer
|
||||||
{
|
{
|
||||||
@@ -34,6 +35,8 @@ public:
|
|||||||
virtual void Update(double dt) = 0;
|
virtual void Update(double dt) = 0;
|
||||||
virtual void Draw(RenderQueueCollection& rq) = 0;
|
virtual void Draw(RenderQueueCollection& rq) = 0;
|
||||||
|
|
||||||
|
World* m_World; //Temp world, untill viktor merge.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Rectangle m_Resolution = Rectangle::Rectangle(1280, 720);
|
Rectangle m_Resolution = Rectangle::Rectangle(1280, 720);
|
||||||
bool m_Fullscreen = false;
|
bool m_Fullscreen = false;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
class Renderer : public IRenderer
|
class Renderer : public IRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Renderer(EventBroker* eventBroker)
|
Renderer(EventBroker* eventBroker)
|
||||||
: m_EventBroker(eventBroker)
|
: m_EventBroker(eventBroker)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -61,6 +61,9 @@ private:
|
|||||||
//void PickingPass(RenderQueueCollection& rq);
|
//void PickingPass(RenderQueueCollection& rq);
|
||||||
void DrawScreenQuad(GLuint textureToDraw);
|
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);
|
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
|
||||||
//--------------------ShaderPrograms-------------------//
|
//--------------------ShaderPrograms-------------------//
|
||||||
ShaderProgram* m_BasicForwardProgram;
|
ShaderProgram* m_BasicForwardProgram;
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
|
|||||||
model = ResourceManager::Load<Model>("Models/Core/Error.obj");
|
model = ResourceManager::Load<Model>("Models/Core/Error.obj");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto transformC = world->GetComponent(modelC.EntityID, "Transform");
|
||||||
|
if(&transformC == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto texGroup : model->TextureGroups) {
|
for (auto texGroup : model->TextureGroups) {
|
||||||
ModelJob job;
|
ModelJob job;
|
||||||
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
|
job.TextureID = (texGroup.Texture) ? texGroup.Texture->ResourceID : 0;
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ void Renderer::Update(double dt)
|
|||||||
|
|
||||||
void Renderer::Draw(RenderQueueCollection& rq)
|
void Renderer::Draw(RenderQueueCollection& rq)
|
||||||
{
|
{
|
||||||
|
FillDepth(rq);
|
||||||
|
|
||||||
m_PickingPass->Draw(rq);
|
m_PickingPass->Draw(rq);
|
||||||
//DrawScreenQuad(m_PickingPass->PickingTexture());
|
//DrawScreenQuad(m_PickingPass->PickingTexture());
|
||||||
m_LightCullingPass->FillLightList(rq);
|
m_LightCullingPass->FillLightList(rq);
|
||||||
@@ -148,4 +150,16 @@ void Renderer::InitializeRenderPasses()
|
|||||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||||
m_LightCullingPass = new LightCullingPass(this);
|
m_LightCullingPass = new LightCullingPass(this);
|
||||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass);
|
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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ Game::Game(int argc, char* argv[])
|
|||||||
EntityFileParser fp(file);
|
EntityFileParser fp(file);
|
||||||
fp.MergeEntities(m_World);
|
fp.MergeEntities(m_World);
|
||||||
}
|
}
|
||||||
|
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
|
||||||
|
m_Renderer->m_World = m_World;
|
||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
|
|||||||
Reference in New Issue
Block a user