We only uses one depth buffer now
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
class DrawFinalPass
|
class DrawFinalPass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass);
|
DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, GLuint* depthBuffer);
|
||||||
~DrawFinalPass() { }
|
~DrawFinalPass() { }
|
||||||
void InitializeTextures();
|
void InitializeTextures();
|
||||||
void InitializeFrameBuffers();
|
void InitializeFrameBuffers();
|
||||||
@@ -59,7 +59,7 @@ private:
|
|||||||
GLuint m_SceneTexture;
|
GLuint m_SceneTexture;
|
||||||
GLuint m_BloomTextureLowRes;
|
GLuint m_BloomTextureLowRes;
|
||||||
GLuint m_SceneTextureLowRes;
|
GLuint m_SceneTextureLowRes;
|
||||||
GLuint m_DepthBuffer;
|
GLuint* m_DepthBuffer;
|
||||||
GLuint m_DepthBufferLowRes;
|
GLuint m_DepthBufferLowRes;
|
||||||
GLuint m_CubeMapTexture;
|
GLuint m_CubeMapTexture;
|
||||||
|
|
||||||
|
|||||||
@@ -33,15 +33,6 @@ public:
|
|||||||
~Texture2D();
|
~Texture2D();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Texture2DMultiSample : public ResourceType<GL_TEXTURE_2D_MULTISAMPLE>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Texture2DMultiSample(GLuint* resourceHandle, GLenum attachment)
|
|
||||||
: ResourceType(resourceHandle, attachment) { };
|
|
||||||
|
|
||||||
~Texture2DMultiSample();
|
|
||||||
};
|
|
||||||
|
|
||||||
class RenderBuffer : public ResourceType<GL_RENDERBUFFER>
|
class RenderBuffer : public ResourceType<GL_RENDERBUFFER>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -28,15 +28,13 @@ public:
|
|||||||
const ShaderProgram& PickingProgram() const { return *m_PickingProgram; }
|
const ShaderProgram& PickingProgram() const { return *m_PickingProgram; }
|
||||||
//const std::unordered_map<glm::ivec2, EntityID>& PickingColorsToEntity() const { return m_PickingColorsToEntity; }
|
//const std::unordered_map<glm::ivec2, EntityID>& PickingColorsToEntity() const { return m_PickingColorsToEntity; }
|
||||||
GLuint PickingTexture() const { return m_PickingTexture; }
|
GLuint PickingTexture() const { return m_PickingTexture; }
|
||||||
GLuint DepthBuffer() const { return m_DepthBuffer; }
|
GLuint* DepthBuffer() { return &m_DepthBuffer; }
|
||||||
const FrameBuffer& PickingBuffer() const { return m_PickingBuffer; }
|
const FrameBuffer& PickingBuffer() const { return m_PickingBuffer; }
|
||||||
|
|
||||||
|
|
||||||
PickData Pick(glm::vec2 screenCoord);
|
PickData Pick(glm::vec2 screenCoord);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
|
||||||
|
|
||||||
EventBroker* m_EventBroker;
|
EventBroker* m_EventBroker;
|
||||||
|
|
||||||
const IRenderer* m_Renderer;
|
const IRenderer* m_Renderer;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public:
|
|||||||
bool StencilFunc(GLenum func, GLint ref, GLuint mask);
|
bool StencilFunc(GLenum func, GLint ref, GLuint mask);
|
||||||
bool StencilMask(GLuint mask);
|
bool StencilMask(GLuint mask);
|
||||||
bool DepthMask(GLboolean flag);
|
bool DepthMask(GLboolean flag);
|
||||||
|
bool DepthFunc(GLenum func);
|
||||||
|
bool AlphaFunc(GLenum func, GLclampf thresholder);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::function<void(void)>> m_ResetFunctions;
|
std::vector<std::function<void(void)>> m_ResetFunctions;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace CommonFunctions
|
|||||||
{
|
{
|
||||||
Texture* LoadTexture(std::string path, bool threaded);
|
Texture* LoadTexture(std::string path, bool threaded);
|
||||||
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);
|
||||||
|
void GenerateMultiSampleTexture(GLuint* texture, int numSamples, glm::vec2 dimensions, GLint internalFormat);
|
||||||
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps);
|
void GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps);
|
||||||
void DeleteTexture(GLuint* texture);
|
void DeleteTexture(GLuint* texture);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -82,11 +82,11 @@ void DrawBloomPass::ClearBuffer()
|
|||||||
GLERROR("PRE");
|
GLERROR("PRE");
|
||||||
m_GaussianFrameBuffer_horiz.Bind();
|
m_GaussianFrameBuffer_horiz.Bind();
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_GaussianFrameBuffer_horiz.Unbind();
|
m_GaussianFrameBuffer_horiz.Unbind();
|
||||||
m_GaussianFrameBuffer_vert.Bind();
|
m_GaussianFrameBuffer_vert.Bind();
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_GaussianFrameBuffer_vert.Unbind();
|
m_GaussianFrameBuffer_vert.Unbind();
|
||||||
GLERROR("END");
|
GLERROR("END");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#include "Rendering/DrawFinalPass.h"
|
#include "Rendering/DrawFinalPass.h"
|
||||||
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass)
|
DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCullingPass, CubeMapPass* cubeMapPass, SSAOPass* ssaoPass, GLuint* depthBuffer)
|
||||||
: m_Renderer(renderer)
|
: m_Renderer(renderer)
|
||||||
, m_LightCullingPass(lightCullingPass)
|
, m_LightCullingPass(lightCullingPass)
|
||||||
, m_CubeMapPass(cubeMapPass)
|
, m_CubeMapPass(cubeMapPass)
|
||||||
, m_SSAOPass(ssaoPass)
|
, m_SSAOPass(ssaoPass)
|
||||||
|
, m_DepthBuffer(depthBuffer)
|
||||||
{
|
{
|
||||||
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
||||||
m_ShieldPixelRate = 8;
|
m_ShieldPixelRate = 8;
|
||||||
@@ -23,19 +24,13 @@ void DrawFinalPass::InitializeTextures()
|
|||||||
|
|
||||||
void DrawFinalPass::InitializeFrameBuffers()
|
void DrawFinalPass::InitializeFrameBuffers()
|
||||||
{
|
{
|
||||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
|
||||||
GLERROR("RenderBuffer generation");
|
|
||||||
|
|
||||||
|
|
||||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||||
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||||
CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||||
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4);
|
//GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_FLOAT, 4);
|
||||||
//GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT);
|
//GenerateTexture(&m_StencilTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_STENCIL, GL_STENCIL_INDEX8, GL_INT);
|
||||||
|
|
||||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(m_DepthBuffer, GL_DEPTH_STENCIL_ATTACHMENT)));
|
||||||
//m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
//m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
||||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||||
@@ -182,7 +177,6 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
|||||||
if (scene.ClearDepth) {
|
if (scene.ClearDepth) {
|
||||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
state->Disable(GL_DEPTH_TEST);
|
state->Disable(GL_DEPTH_TEST);
|
||||||
state->DepthMask(GL_FALSE);
|
|
||||||
}
|
}
|
||||||
//TODO: Do we need check for this or will it be per scene always?
|
//TODO: Do we need check for this or will it be per scene always?
|
||||||
glClearStencil(0x00);
|
glClearStencil(0x00);
|
||||||
@@ -273,7 +267,7 @@ void DrawFinalPass::ClearBuffer()
|
|||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
GLERROR("1");
|
GLERROR("1");
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
GLERROR("2");
|
GLERROR("2");
|
||||||
|
|
||||||
glDisable(GL_SCISSOR_TEST);
|
glDisable(GL_SCISSOR_TEST);
|
||||||
@@ -288,7 +282,7 @@ void DrawFinalPass::ClearBuffer()
|
|||||||
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||||
GLERROR("ViewPort,Scissor LowRes");
|
GLERROR("ViewPort,Scissor LowRes");
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_FinalPassFrameBuffer.Unbind();
|
m_FinalPassFrameBuffer.Unbind();
|
||||||
GLERROR("END");
|
GLERROR("END");
|
||||||
}
|
}
|
||||||
@@ -297,8 +291,6 @@ void DrawFinalPass::ClearBuffer()
|
|||||||
void DrawFinalPass::OnWindowResize()
|
void DrawFinalPass::OnWindowResize()
|
||||||
{
|
{
|
||||||
//InitializeFrameBuffers();
|
//InitializeFrameBuffers();
|
||||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
|
||||||
|
|
||||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||||
CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
|
|||||||
Enable(GL_BLEND);
|
Enable(GL_BLEND);
|
||||||
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
Enable(GL_DEPTH_TEST);
|
Enable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
DepthMask(GL_FALSE);
|
||||||
|
DepthFunc(GL_LEQUAL);
|
||||||
Enable(GL_CULL_FACE);
|
Enable(GL_CULL_FACE);
|
||||||
Enable(GL_STENCIL_TEST);
|
Enable(GL_STENCIL_TEST);
|
||||||
StencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
StencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
||||||
|
|||||||
@@ -16,12 +16,6 @@ Texture2D::~Texture2D()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2DMultiSample::~Texture2DMultiSample()
|
|
||||||
{
|
|
||||||
if (m_ResourceHandle != 0) {
|
|
||||||
glDeleteTextures(1, m_ResourceHandle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderBuffer::~RenderBuffer()
|
RenderBuffer::~RenderBuffer()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ PickingPass::~PickingPass()
|
|||||||
|
|
||||||
void PickingPass::InitializeTextures()
|
void PickingPass::InitializeTextures()
|
||||||
{
|
{
|
||||||
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
CommonFunctions::GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
||||||
|
|
||||||
GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
CommonFunctions::GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
|
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ void PickingPass::ClearPicking()
|
|||||||
|
|
||||||
m_PickingBuffer.Bind();
|
m_PickingBuffer.Bind();
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
m_PickingBuffer.Unbind();
|
m_PickingBuffer.Unbind();
|
||||||
GLERROR("END");
|
GLERROR("END");
|
||||||
}
|
}
|
||||||
@@ -407,16 +407,3 @@ PickData PickingPass::Pick(glm::vec2 screenCoord)
|
|||||||
pickData.World = pickInfo.World;
|
pickData.World = pickInfo.World;
|
||||||
return pickData;
|
return pickData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PickingPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
|
||||||
{
|
|
||||||
//TODO: Renderer: Make this in a sparate class
|
|
||||||
glGenTextures(1, texture);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapping);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, dimensions.x, dimensions.y, 0, format, type, nullptr);//TODO: Renderer: Fix the precision and Resolution
|
|
||||||
GLERROR("Texture initialization failed");
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ PickingPassState::PickingPassState(GLuint frameBuffer)
|
|||||||
//ClearColor(clearColor);
|
//ClearColor(clearColor);
|
||||||
//Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
//Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
GLERROR("END");
|
GLERROR("END");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PickingPassState::~PickingPassState()
|
PickingPassState::~PickingPassState()
|
||||||
|
|||||||
@@ -135,6 +135,26 @@ bool RenderState::DepthMask(GLboolean flag)
|
|||||||
return !GLERROR("DepthMask");
|
return !GLERROR("DepthMask");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderState::DepthFunc(GLenum func)
|
||||||
|
{
|
||||||
|
GLint original;
|
||||||
|
glGetIntegerv(GL_DEPTH_FUNC, &original);
|
||||||
|
m_ResetFunctions.push_back(std::bind(glDepthFunc, original));
|
||||||
|
glDepthFunc(func);
|
||||||
|
return !GLERROR("DepthFunc");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderState::AlphaFunc(GLenum func, GLclampf thresholder)
|
||||||
|
{
|
||||||
|
GLint originalFunc;
|
||||||
|
glGetIntegerv(GL_ALPHA_TEST_FUNC, &originalFunc);
|
||||||
|
GLint originalRef;
|
||||||
|
glGetIntegerv(GL_ALPHA_TEST_REF, &originalRef);
|
||||||
|
m_ResetFunctions.push_back(std::bind(glAlphaFunc, originalFunc, originalRef));
|
||||||
|
glAlphaFunc(func, thresholder);
|
||||||
|
return !GLERROR("AlphaFunc");
|
||||||
|
}
|
||||||
|
|
||||||
RenderState::~RenderState()
|
RenderState::~RenderState()
|
||||||
{
|
{
|
||||||
for (auto& f : boost::adaptors::reverse(m_ResetFunctions)) {
|
for (auto& f : boost::adaptors::reverse(m_ResetFunctions)) {
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ void Renderer::glfwFrameBufferCallback(GLFWwindow* window, int width, int height
|
|||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
Renderer* currentRenderer = m_WindowToRenderer[window];
|
Renderer* currentRenderer = m_WindowToRenderer[window];
|
||||||
currentRenderer->m_ViewportSize = Rectangle(width, height);
|
currentRenderer->m_ViewportSize = Rectangle(width, height);
|
||||||
|
currentRenderer->m_PickingPass->OnWindowResize();
|
||||||
currentRenderer->m_DrawFinalPass->OnWindowResize();
|
currentRenderer->m_DrawFinalPass->OnWindowResize();
|
||||||
currentRenderer->m_LightCullingPass->OnWindowResize();
|
currentRenderer->m_LightCullingPass->OnWindowResize();
|
||||||
currentRenderer->m_PickingPass->OnWindowResize();
|
|
||||||
currentRenderer->m_DrawBloomPass->OnWindowResize();
|
currentRenderer->m_DrawBloomPass->OnWindowResize();
|
||||||
currentRenderer->m_SSAOPass->OnWindowResize();
|
currentRenderer->m_SSAOPass->OnWindowResize();
|
||||||
}
|
}
|
||||||
@@ -136,17 +136,16 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
||||||
GLERROR("ClearBuffers");
|
GLERROR("ClearBuffers");
|
||||||
for (auto scene : frame.RenderScenes) {
|
for (auto scene : frame.RenderScenes) {
|
||||||
PerformanceTimer::StartTimer("Renderer-Depth");
|
PerformanceTimer::StartTimer("Renderer-PickingPass");
|
||||||
m_PickingPass->Draw(*scene);
|
m_PickingPass->Draw(*scene);
|
||||||
GLERROR("Drawing pickingpass");
|
GLERROR("Drawing pickingpass");
|
||||||
PerformanceTimer::StopTimer("Renderer-Depth");
|
PerformanceTimer::StopTimer("Renderer-PickingPass");
|
||||||
}
|
}
|
||||||
PerformanceTimer::StartTimer("Renderer-AO generation");
|
PerformanceTimer::StartTimer("Renderer-AO generation");
|
||||||
m_SSAOPass->Draw(m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera);
|
m_SSAOPass->Draw(*m_PickingPass->DepthBuffer(), frame.RenderScenes.front()->Camera);
|
||||||
PerformanceTimer::StopTimer("Renderer-AO generation");
|
PerformanceTimer::StopTimer("Renderer-AO generation");
|
||||||
for (auto scene : frame.RenderScenes){
|
for (auto scene : frame.RenderScenes){
|
||||||
|
PerformanceTimer::StartTimer("Renderer-Depth");
|
||||||
PerformanceTimer::StartTimer("Renderer-Drawing PickingPass");
|
|
||||||
SortRenderJobsByDepth(*scene);
|
SortRenderJobsByDepth(*scene);
|
||||||
GLERROR("SortByDepth");
|
GLERROR("SortByDepth");
|
||||||
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums");
|
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums");
|
||||||
@@ -206,8 +205,11 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
PerformanceTimer::StartTimer("Renderer-ImGuiRenderPass");
|
PerformanceTimer::StartTimer("Renderer-ImGuiRenderPass");
|
||||||
m_ImGuiRenderPass->Draw();
|
m_ImGuiRenderPass->Draw();
|
||||||
GLERROR("Imgui draw");
|
GLERROR("Imgui draw");
|
||||||
|
PerformanceTimer::StopTimer("Renderer-ImGuiRenderPass");
|
||||||
|
|
||||||
|
PerformanceTimer::StartTimer("Renderer-SwapBuffer");
|
||||||
glfwSwapBuffers(m_Window);
|
glfwSwapBuffers(m_Window);
|
||||||
PerformanceTimer::StopTimer("Renderer-ImGuiRenderPass");
|
PerformanceTimer::StopTimer("Renderer-SwapBuffer");
|
||||||
}
|
}
|
||||||
|
|
||||||
PickData Renderer::Pick(glm::vec2 screenCoord)
|
PickData Renderer::Pick(glm::vec2 screenCoord)
|
||||||
@@ -248,7 +250,7 @@ void Renderer::InitializeRenderPasses()
|
|||||||
m_LightCullingPass = new LightCullingPass(this);
|
m_LightCullingPass = new LightCullingPass(this);
|
||||||
m_CubeMapPass = new CubeMapPass(this);
|
m_CubeMapPass = new CubeMapPass(this);
|
||||||
m_SSAOPass = new SSAOPass(this, m_Config);
|
m_SSAOPass = new SSAOPass(this, m_Config);
|
||||||
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass);
|
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass, m_PickingPass->DepthBuffer());
|
||||||
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
|
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
|
||||||
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
|
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
|
||||||
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
|
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ void SSAOPass::InitializeTexture() {
|
|||||||
CommonFunctions::GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
||||||
CommonFunctions::GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R32F, GL_RED, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R32F, GL_RED, GL_FLOAT);
|
||||||
|
|
||||||
CommonFunctions::GenerateTexture(&m_Gaussian_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RGB, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_Gaussian_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
||||||
CommonFunctions::GenerateTexture(&m_Gaussian_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RGB, GL_FLOAT);
|
CommonFunctions::GenerateTexture(&m_Gaussian_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width >> m_TextureQuality, m_Renderer->GetViewportSize().Height >> m_TextureQuality), GL_R8, GL_RED, GL_FLOAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSAOPass::InitializeBuffer()
|
void SSAOPass::InitializeBuffer()
|
||||||
@@ -127,22 +127,22 @@ void SSAOPass::ClearBuffer()
|
|||||||
}
|
}
|
||||||
m_SSAOFramBuffer.Bind();
|
m_SSAOFramBuffer.Bind();
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_SSAOFramBuffer.Unbind();
|
m_SSAOFramBuffer.Unbind();
|
||||||
|
|
||||||
m_SSAOViewSpaceZFramBuffer.Bind();
|
m_SSAOViewSpaceZFramBuffer.Bind();
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_SSAOViewSpaceZFramBuffer.Unbind();
|
m_SSAOViewSpaceZFramBuffer.Unbind();
|
||||||
|
|
||||||
m_GaussianFrameBuffer_horiz.Bind();
|
m_GaussianFrameBuffer_horiz.Bind();
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_GaussianFrameBuffer_horiz.Unbind();
|
m_GaussianFrameBuffer_horiz.Unbind();
|
||||||
|
|
||||||
m_GaussianFrameBuffer_vert.Bind();
|
m_GaussianFrameBuffer_vert.Bind();
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_GaussianFrameBuffer_vert.Unbind();
|
m_GaussianFrameBuffer_vert.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,4 +284,5 @@ void SSAOPass::OnWindowResize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InitializeTexture();
|
InitializeTexture();
|
||||||
|
InitializeBuffer();
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,16 @@ void CommonFunctions::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum f
|
|||||||
GLERROR("Texture initialization failed");
|
GLERROR("Texture initialization failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples, glm::vec2 dimensions, GLint internalFormat)
|
||||||
|
{
|
||||||
|
glDeleteTextures(1, texture);
|
||||||
|
glGenTextures(1, texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, *texture);
|
||||||
|
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, false);
|
||||||
|
GLERROR("Texture initialization failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps)
|
void CommonFunctions::GenerateMipMapTexture(GLuint* texture, GLenum wrapping, glm::vec2 dimensions, GLint format, GLenum type, GLint numMipMaps)
|
||||||
{
|
{
|
||||||
glGenTextures(1, texture);
|
glGenTextures(1, texture);
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
Game game(argc, argv);
|
Game game(argc, argv);
|
||||||
while (game.Running()) {
|
while (game.Running()) {
|
||||||
|
PerformanceTimer::StartTimer("Game-Tick");
|
||||||
game.Tick();
|
game.Tick();
|
||||||
|
PerformanceTimer::StopTimer("Game-Tick");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user