Removed world from renderer and moved depth-calculation code to modeljob

This commit is contained in:
Tleety
2016-01-19 15:41:17 +01:00
parent 982837052a
commit 893ef38237
4 changed files with 14 additions and 25 deletions
+3
View File
@@ -28,6 +28,9 @@ struct ModelJob : RenderJob
Matrix = matrix;
Color = modelComponent["Color"];
Entity = modelComponent.EntityID;
glm::vec3 abspos = Transform::AbsolutePosition(world, modelComponent.EntityID);
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
Depth = worldpos.z;
World = world;
};
+2 -4
View File
@@ -22,9 +22,8 @@
class Renderer : public IRenderer
{
public:
Renderer(EventBroker* eventBroker, World* world)
Renderer(EventBroker* eventBroker)
: m_EventBroker(eventBroker)
, m_World(world)
{ }
virtual void Initialize() override;
@@ -36,7 +35,6 @@ public:
private:
//----------------------Variables----------------------//
EventBroker* m_EventBroker;
World* m_World;
Texture* m_ErrorTexture;
Texture* m_WhiteTexture;
@@ -62,7 +60,7 @@ private:
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(RenderScene& scene);
void SortRenderJobsByDepth(RenderScene &scene);
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
//--------------------ShaderPrograms-------------------//
ShaderProgram* m_BasicForwardProgram;
+8 -19
View File
@@ -98,9 +98,8 @@ void Renderer::Draw(RenderFrame& frame)
m_PickingPass->ClearPicking();
for (auto scene : frame.RenderScenes){
m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras.
FillDepth(*scene);
SortRenderJobsByDepth(*scene);
m_PickingPass->Draw(*scene);
m_LightCullingPass->GenerateNewFrustum(*scene);
m_LightCullingPass->FillLightList(*scene);
@@ -147,6 +146,13 @@ void Renderer::InitializeTextures()
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
}
void Renderer::SortRenderJobsByDepth(RenderScene *scene)
{
//Sort all forward jobs so transparency is good.
scene->ForwardJobs.sort(Renderer::DepthSort);
}
void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type)
{
glGenTextures(1, texture);
@@ -165,21 +171,4 @@ void Renderer::InitializeRenderPasses()
m_PickingPass = new PickingPass(this, m_EventBroker);
m_LightCullingPass = new LightCullingPass(this);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass);
}
//Temp func
void Renderer::FillDepth(RenderScene& scene)
{
for (auto job : scene.ForwardJobs) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if(! modelJob) {
return;
}
glm::vec3 abspos = Transform::AbsolutePosition(modelJob->World, modelJob->Entity);
glm::vec3 worldpos = glm::vec3(scene.Camera->ViewMatrix() * glm::vec4(abspos, 1));
modelJob->Depth = worldpos.z;
}
scene.ForwardJobs.sort(Renderer::DepthSort);
}
+1 -2
View File
@@ -64,8 +64,7 @@ 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 Octrees
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);