Fixed a bugg with RenderState.
Renderstate now also handles the Frambuffer binding.
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
class PickingPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
PickingPassState();
|
||||
PickingPassState(GLuint frameBuffer);
|
||||
~PickingPassState();
|
||||
private:
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -14,9 +14,10 @@ public:
|
||||
bool CullFace(GLenum GlFaceToCull);
|
||||
bool ClearColor(glm::vec4 color);
|
||||
bool Clear(GLbitfield mask);
|
||||
bool BindBuffer(GLint buffer);
|
||||
private:
|
||||
std::vector<GLenum> m_Enables;
|
||||
float m_preClearColor[4];
|
||||
GLenum m_preCullFace;
|
||||
int m_preBuffer;
|
||||
};
|
||||
#endif
|
||||
@@ -52,8 +52,8 @@ private:
|
||||
Model* m_UnitQuad;
|
||||
Model* m_UnitSphere;
|
||||
|
||||
PickingPass* m_PickingPass;
|
||||
DrawScenePass* m_DrawScenePass;
|
||||
PickingPass* m_PickingPass;
|
||||
|
||||
//----------------------Functions----------------------//
|
||||
void InitializeWindow();
|
||||
|
||||
@@ -10,7 +10,6 @@ DrawScenePass::DrawScenePass(IRenderer* renderer)
|
||||
void DrawScenePass::InitializeTextures()
|
||||
{
|
||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
||||
|
||||
}
|
||||
|
||||
void DrawScenePass::InitializeShaderPrograms()
|
||||
@@ -24,10 +23,12 @@ void DrawScenePass::InitializeShaderPrograms()
|
||||
|
||||
void DrawScenePass::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
GLERROR("Renderer::Draw PickingPass");
|
||||
|
||||
DrawScenePassState state;
|
||||
|
||||
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
|
||||
DrawScenePassState::DrawScenePassState()
|
||||
{
|
||||
GLERROR("---");
|
||||
BindBuffer(0);
|
||||
GLERROR("---");
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
CullFace(GL_BACK);
|
||||
ClearColor(glm::vec4(255.f / 255, 163.f / 255, 176.f / 255, 0.f));
|
||||
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@@ -44,14 +44,12 @@ void PickingPass::InitializeShaderPrograms()
|
||||
void PickingPass::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
m_PickingColorsToEntity.clear();
|
||||
m_PickingBuffer.Bind();
|
||||
PickingPassState state;
|
||||
PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle());
|
||||
|
||||
int r = 1;
|
||||
int g = 0;
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
|
||||
|
||||
GLuint ShaderHandle = m_PickingProgram.GetHandle();
|
||||
m_PickingProgram.Bind();
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
#include "Rendering/PickingPassState.h"
|
||||
|
||||
|
||||
PickingPassState::PickingPassState()
|
||||
PickingPassState::PickingPassState(GLuint frameBuffer)
|
||||
{
|
||||
|
||||
GLERROR("---2");
|
||||
BindBuffer(frameBuffer);
|
||||
GLERROR("---3");
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
CullFace(GL_BACK);
|
||||
|
||||
glm::vec4 clearColor = glm::vec4(0.f);
|
||||
ClearColor(clearColor);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
RenderState::RenderState()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RenderState::Enable(GLenum GLEnable)
|
||||
@@ -30,12 +31,11 @@ bool RenderState::CullFace(GLenum GLCullFace)
|
||||
|
||||
GLint a;
|
||||
glGetIntegerv(GL_CULL_FACE_MODE, &a);
|
||||
if(a == GL_BACK)
|
||||
if(a != GL_BACK)
|
||||
{
|
||||
//LOG_INFO("Setting Cullface to back, unessesary since this is already default.");
|
||||
glCullFace(GLCullFace);
|
||||
}
|
||||
m_preCullFace = a;
|
||||
glCullFace(GLCullFace);
|
||||
if (GLERROR("RenderState::CullFace"))
|
||||
{
|
||||
return false;
|
||||
@@ -62,20 +62,50 @@ bool RenderState::Clear(GLbitfield mask)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenderState::BindBuffer(GLint buffer)
|
||||
{
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &m_preBuffer);
|
||||
if (buffer == m_preBuffer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
|
||||
if (GLERROR("RenderState::BindBuffer"))
|
||||
{
|
||||
printf("BufferID: %i\npreBufferID: %i\n", buffer, m_preBuffer);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderState::~RenderState()
|
||||
{
|
||||
GLERROR("RenderState::~RenderState Pre");
|
||||
GLint n_buffer = -1;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &n_buffer);
|
||||
|
||||
//Set cullface to default
|
||||
glCullFace(m_preCullFace);
|
||||
if (glIsEnabled(GL_CULL_FACE)) {
|
||||
glCullFace(GL_BACK);
|
||||
}
|
||||
GLERROR("RenderState::~RenderState glCullFace");
|
||||
|
||||
//Set color to default
|
||||
glClearColor(m_preClearColor[0], m_preClearColor[1], m_preClearColor[2], m_preClearColor[3]);
|
||||
GLERROR("RenderState::~RenderState glClearColor");
|
||||
|
||||
//Disable Enables
|
||||
for (auto i : m_Enables)
|
||||
{
|
||||
glDisable(i);
|
||||
}
|
||||
GLERROR("RenderState::~RenderState glDisable");
|
||||
|
||||
if(m_preBuffer != 0)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
m_Enables.clear();
|
||||
GLERROR("RenderState::~RenderState glBindFramebuffer");
|
||||
}
|
||||
|
||||
|
||||
@@ -151,58 +151,61 @@ void Renderer::Update(double dt)
|
||||
void Renderer::Draw(RenderQueueCollection& rq)
|
||||
{
|
||||
//TODO: Renderer: Kanske borde vara längst upp i update.
|
||||
GLERROR("Renderer::Draw Pre");
|
||||
m_PickingPass->Draw(rq);
|
||||
GLERROR("Renderer::Draw PickingPass");
|
||||
//DrawScreenQuad(m_PickingPass->PickingTexture());
|
||||
//CullLights();
|
||||
|
||||
//DrawScene(rq);
|
||||
m_DrawScenePass->Draw(rq);
|
||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
||||
glfwSwapBuffers(m_Window);
|
||||
}
|
||||
|
||||
void Renderer::DrawScene(RenderQueueCollection& rq)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
//TODO: Render: Clean up draw code
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
GLuint ShaderHandle = m_BasicForwardProgram.GetHandle();
|
||||
|
||||
m_BasicForwardProgram.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(modelJob->ModelMatrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
|
||||
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
GLERROR("DrawScene Error");
|
||||
}
|
||||
//
|
||||
//void Renderer::DrawScene(RenderQueueCollection& rq)
|
||||
//{
|
||||
// glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
//
|
||||
// //TODO: Render: Clean up draw code
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
// glEnable(GL_CULL_FACE);
|
||||
// glCullFace(GL_BACK);
|
||||
//
|
||||
// glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
//
|
||||
// //TODO: Render: Add code for more jobs than modeljobs.
|
||||
// for (auto &job : rq.Forward) {
|
||||
// auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
// if (modelJob) {
|
||||
// GLuint ShaderHandle = m_BasicForwardProgram.GetHandle();
|
||||
//
|
||||
// m_BasicForwardProgram.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(modelJob->ModelMatrix));
|
||||
// glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||
// glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
|
||||
// glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
//
|
||||
// //TODO: Renderer: bättre textur felhantering samt fler texturer stöd
|
||||
// if (modelJob->DiffuseTexture != nullptr) {
|
||||
// glActiveTexture(GL_TEXTURE0);
|
||||
// glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
// } else {
|
||||
// glActiveTexture(GL_TEXTURE0);
|
||||
// glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
// }
|
||||
//
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// GLERROR("DrawScene Error");
|
||||
//}
|
||||
|
||||
void Renderer::DrawScreenQuad(GLuint textureToDraw)
|
||||
{
|
||||
@@ -304,8 +307,8 @@ void Renderer::InitializeSSBOs()
|
||||
|
||||
void Renderer::InitializeRenderPasses()
|
||||
{
|
||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||
m_DrawScenePass = new DrawScenePass(this);
|
||||
m_PickingPass = new PickingPass(this, m_EventBroker);
|
||||
}
|
||||
|
||||
void Renderer::CalculateFrustum()
|
||||
|
||||
+2
-1
@@ -73,8 +73,9 @@ void Game::Tick()
|
||||
m_Renderer->Update(dt);
|
||||
|
||||
m_RenderQueueFactory->Update(m_World);
|
||||
GLERROR("Game::Tick m_RenderQueueFactory->Update");
|
||||
m_Renderer->Draw(m_RenderQueueFactory->RenderQueues());
|
||||
|
||||
GLERROR("Game::Tick m_Renderer->Draw");
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user