MSAA mostly working. Only merging the MS render buffer to a single texture so that others could use the AA texture easly
This commit is contained in:
@@ -27,15 +27,80 @@ public:
|
||||
void OnWindowResize();
|
||||
|
||||
//Return the texture that is used in later stages to apply the bloom effect
|
||||
GLuint BloomTexture() const { return m_BloomTexture; }
|
||||
GLuint BloomTexture() const {
|
||||
if (m_MSAA){
|
||||
m_AntiAliasedFrameBuffer->Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_AntiAliasedFrameBuffer->Unbind();
|
||||
m_FinalPassFrameBuffer->Read();
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT1);
|
||||
m_AntiAliasedFrameBuffer->Draw();
|
||||
glBlitFramebuffer(
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
glReadBuffer(GL_BACK);
|
||||
return m_AntiAliasedTexture;
|
||||
}
|
||||
return m_BloomTexture; }
|
||||
//Return the texture with diffuse and lighting of the scene.
|
||||
GLuint SceneTexture() const { return m_SceneTexture; }
|
||||
GLuint SceneTexture() const {
|
||||
if (m_MSAA) {
|
||||
m_AntiAliasedFrameBuffer->Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_AntiAliasedFrameBuffer->Unbind();
|
||||
GLERROR("SceneTexture() 11");
|
||||
m_FinalPassFrameBuffer->Read();
|
||||
GLERROR("SceneTexture() 12");
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||
GLERROR("SceneTexture() 13");
|
||||
m_AntiAliasedFrameBuffer->Draw();
|
||||
GLERROR("SceneTexture() 14");
|
||||
glBlitFramebuffer(
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
GLERROR("SceneTexture() 15");
|
||||
glReadBuffer(GL_BACK);
|
||||
return m_AntiAliasedTexture;
|
||||
}
|
||||
return m_SceneTexture; }
|
||||
//Return the SceneTexture with the blurred HUD bits.
|
||||
GLuint CombinedSceneTexture() const { return m_CombinedTexture; }
|
||||
GLuint CombinedSceneTexture() const {
|
||||
if (m_MSAA) {
|
||||
m_AntiAliasedFrameBuffer->Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_AntiAliasedFrameBuffer->Unbind();
|
||||
m_FinalPassFrameBuffer->Read();
|
||||
m_AntiAliasedFrameBuffer->Draw();
|
||||
glBlitFramebuffer(
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
return m_AntiAliasedTexture;
|
||||
}
|
||||
return m_CombinedTexture; }
|
||||
//Return the blurred scene texture.
|
||||
GLuint FullBlurredTexture() const { return m_FullBlurredTexture; }
|
||||
GLuint FullBlurredTexture() const {
|
||||
if (m_MSAA) {
|
||||
m_AntiAliasedFrameBuffer->Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
m_AntiAliasedFrameBuffer->Unbind();
|
||||
m_FinalPassFrameBuffer->Read();
|
||||
m_AntiAliasedFrameBuffer->Draw();
|
||||
glBlitFramebuffer(
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
return m_AntiAliasedTexture;
|
||||
}
|
||||
return m_FullBlurredTexture; }
|
||||
//Return the framebuffer used in the scene rendering stage.
|
||||
FrameBuffer* FinalPassFrameBuffer() { return &m_FinalPassFrameBuffer; }
|
||||
FrameBuffer* FinalPassFrameBuffer() { return m_FinalPassFrameBuffer; }
|
||||
|
||||
private:
|
||||
void DrawSprites(std::list<std::shared_ptr<RenderJob>>&jobs, RenderScene& scene);
|
||||
@@ -56,18 +121,21 @@ private:
|
||||
Texture* m_GreyTexture;
|
||||
Texture* m_ErrorTexture;
|
||||
|
||||
FrameBuffer m_FinalPassFrameBuffer;
|
||||
FrameBuffer m_ShieldDepthFrameBuffer;
|
||||
FrameBuffer* m_FinalPassFrameBuffer = nullptr;
|
||||
FrameBuffer* m_ShieldDepthFrameBuffer = nullptr;
|
||||
FrameBuffer* m_AntiAliasedFrameBuffer = nullptr;
|
||||
GLuint m_BloomTexture = 0;
|
||||
GLuint m_SceneTexture = 0;
|
||||
GLuint m_DepthBuffer = 0;
|
||||
GLuint m_ShieldBuffer = 0;
|
||||
GLuint m_CubeMapTexture = 0;
|
||||
GLuint m_FullBlurredTexture;
|
||||
GLuint m_CombinedTexture; //This can be removed for less memory usage, just set m_sceneTexture to the return from m_BlurHUDPass.CombineTextures
|
||||
GLuint m_FullBlurredTexture = 0;
|
||||
GLuint m_CombinedTexture = 0; //This can be removed for less memory usage, just set m_sceneTexture to the return from m_BlurHUDPass.CombineTextures
|
||||
GLuint m_AntiAliasedTexture = 0; //Is only used when MSAA is active;
|
||||
|
||||
//maqke this component based i guess?
|
||||
GLuint m_ShieldPixelRate = 16;
|
||||
unsigned int m_MSAA = 4;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
class BufferResource
|
||||
{
|
||||
public:
|
||||
BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod);
|
||||
BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod, bool multiSampling);
|
||||
|
||||
GLuint* m_ResourceHandle;
|
||||
GLenum m_ResourceType;
|
||||
GLenum m_Attachment;
|
||||
GLuint m_MipMapLod = 0;
|
||||
bool m_MultiSampling = false;
|
||||
private:
|
||||
|
||||
};
|
||||
@@ -21,24 +22,33 @@ template <GLenum RESOURCETYPE>
|
||||
class ResourceType : public BufferResource
|
||||
{
|
||||
public:
|
||||
ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod)
|
||||
: BufferResource(resourceHandle, RESOURCETYPE, attachment, mipMapLod) { }
|
||||
ResourceType(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod, bool multiSampling)
|
||||
: BufferResource(resourceHandle, RESOURCETYPE, attachment, mipMapLod, multiSampling) { }
|
||||
};
|
||||
|
||||
class Texture2D : public ResourceType<GL_TEXTURE_2D>
|
||||
{
|
||||
public:
|
||||
Texture2D(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod = 0)
|
||||
: ResourceType(resourceHandle, attachment, mipMapLod) { };
|
||||
: ResourceType(resourceHandle, attachment, mipMapLod, false) { };
|
||||
|
||||
~Texture2D();
|
||||
};
|
||||
|
||||
class Texture2DMultiSample : public ResourceType<GL_TEXTURE_2D_MULTISAMPLE>
|
||||
{
|
||||
public:
|
||||
Texture2DMultiSample(GLuint* resourceHandle, GLenum attachment, GLuint mipMapLod = 0)
|
||||
: ResourceType(resourceHandle, attachment, mipMapLod, true) { };
|
||||
|
||||
~Texture2DMultiSample();
|
||||
};
|
||||
|
||||
class RenderBuffer : public ResourceType<GL_RENDERBUFFER>
|
||||
{
|
||||
public:
|
||||
RenderBuffer(GLuint* resourceHandle, GLenum attachment)
|
||||
: ResourceType(resourceHandle, attachment, 0)
|
||||
RenderBuffer(GLuint* resourceHandle, GLenum attachment, bool multiSampling = false)
|
||||
: ResourceType(resourceHandle, attachment, 0, multiSampling)
|
||||
{ };
|
||||
|
||||
~RenderBuffer();
|
||||
@@ -48,12 +58,13 @@ class Texture2DArray : public ResourceType<GL_TEXTURE_2D_ARRAY>
|
||||
{
|
||||
public:
|
||||
Texture2DArray(GLuint* resourceHandle, GLenum attachment)
|
||||
: ResourceType(resourceHandle, attachment, 0)
|
||||
: ResourceType(resourceHandle, attachment, 0, false)
|
||||
{ };
|
||||
|
||||
~Texture2DArray();
|
||||
};
|
||||
|
||||
|
||||
class FrameBuffer
|
||||
{
|
||||
public:
|
||||
@@ -65,9 +76,13 @@ public:
|
||||
void Generate();
|
||||
void Bind();
|
||||
void Unbind();
|
||||
void Read();
|
||||
void Draw();
|
||||
GLuint GetHandle();
|
||||
bool MultiSampling() { return m_MultiSampling; };
|
||||
|
||||
private:
|
||||
bool m_MultiSampling = true;
|
||||
GLuint m_BufferHandle;
|
||||
std::vector<std::shared_ptr<BufferResource>> m_Resources;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,9 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
|
||||
{
|
||||
//TODO: Make sure that uniforms are not sent into shader if not needed.
|
||||
m_ShieldPixelRate = 8;
|
||||
m_FinalPassFrameBuffer = new FrameBuffer();
|
||||
m_ShieldDepthFrameBuffer = new FrameBuffer();
|
||||
|
||||
InitializeTextures();
|
||||
InitializeShaderPrograms();
|
||||
InitializeFrameBuffers();
|
||||
@@ -19,6 +22,9 @@ DrawFinalPass::~DrawFinalPass(){
|
||||
CommonFunctions::DeleteTexture(&m_DepthBuffer);
|
||||
CommonFunctions::DeleteTexture(&m_ShieldBuffer);
|
||||
CommonFunctions::DeleteTexture(&m_CubeMapTexture);
|
||||
|
||||
delete m_FinalPassFrameBuffer;
|
||||
delete m_ShieldDepthFrameBuffer;
|
||||
}
|
||||
|
||||
void DrawFinalPass::InitializeTextures()
|
||||
@@ -32,26 +38,78 @@ void DrawFinalPass::InitializeTextures()
|
||||
|
||||
void DrawFinalPass::InitializeFrameBuffers()
|
||||
{
|
||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, 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);
|
||||
//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);
|
||||
if (m_MSAA) {
|
||||
CommonFunctions::GenerateTexture(&m_AntiAliasedTexture, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
|
||||
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);
|
||||
if (m_AntiAliasedFrameBuffer == nullptr) {
|
||||
m_AntiAliasedFrameBuffer = new FrameBuffer();
|
||||
m_AntiAliasedFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_AntiAliasedTexture, GL_COLOR_ATTACHMENT0)));
|
||||
}
|
||||
m_AntiAliasedFrameBuffer->Generate();
|
||||
|
||||
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_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
m_FinalPassFrameBuffer.Generate();
|
||||
glGenRenderbuffers(1, &m_SceneTexture);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_SceneTexture);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
|
||||
glGenRenderbuffers(1, &m_BloomTexture);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_BloomTexture);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_RGB16F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
|
||||
glGenRenderbuffers(1, &m_DepthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_DEPTH24_STENCIL8, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
|
||||
glGenRenderbuffers(1, &m_ShieldBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, m_ShieldBuffer);
|
||||
glRenderbufferStorageMultisample(GL_RENDERBUFFER, m_MSAA, GL_DEPTH_COMPONENT32F, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_SceneTexture, m_MSAA, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F);
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_BloomTexture, m_MSAA, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F);
|
||||
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_DepthBuffer, m_MSAA,
|
||||
//glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8);
|
||||
|
||||
//CommonFunctions::GenerateMultiSampleTexture(&m_ShieldBuffer, m_MSAA,
|
||||
//glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F);
|
||||
} else {
|
||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, 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);
|
||||
//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);
|
||||
|
||||
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);
|
||||
|
||||
CommonFunctions::GenerateTexture(&m_ShieldBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
|
||||
}
|
||||
|
||||
if (m_FinalPassFrameBuffer->GetHandle() == 0) {
|
||||
if (m_MSAA) {
|
||||
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_StencilTexture, GL_STENCIL_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
} else {
|
||||
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_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
}
|
||||
}
|
||||
m_FinalPassFrameBuffer->Generate();
|
||||
GLERROR("FBO generation");
|
||||
|
||||
CommonFunctions::GenerateTexture(&m_ShieldBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT);
|
||||
m_ShieldDepthFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_ShieldDepthFrameBuffer.Generate();
|
||||
if (m_ShieldDepthFrameBuffer->GetHandle() == 0) {
|
||||
if (m_MSAA) {
|
||||
m_ShieldDepthFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
} else {
|
||||
m_ShieldDepthFrameBuffer->AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_ShieldBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
}
|
||||
}
|
||||
m_ShieldDepthFrameBuffer->Generate();
|
||||
}
|
||||
|
||||
void DrawFinalPass::InitializeShaderPrograms()
|
||||
@@ -245,14 +303,14 @@ void DrawFinalPass::InitializeShaderPrograms()
|
||||
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
||||
{
|
||||
GLERROR("Pre");
|
||||
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
|
||||
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer->GetHandle());
|
||||
//Draw shields to stencil
|
||||
DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene);
|
||||
GLERROR("StencilPass");
|
||||
delete stateDethp;
|
||||
|
||||
|
||||
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
|
||||
if (scene.ClearDepth) {
|
||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
||||
state->Disable(GL_DEPTH_TEST);
|
||||
@@ -293,16 +351,21 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
||||
delete state;
|
||||
if (scene.ShouldBlur) {
|
||||
//This needs to be drawn only when the full scene is being renderd, and then let be, otherwise sprite and other shit will show on it.
|
||||
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
|
||||
GLuint sceneTexture = SceneTexture();
|
||||
GLERROR("SceneTexture() 1");
|
||||
m_FullBlurredTexture = blurHUDPass->Draw(sceneTexture, scene);
|
||||
}
|
||||
|
||||
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
|
||||
if(scene.ShouldBlur) {
|
||||
//Combine nonblur and blur texture
|
||||
stateSprite->Disable(GL_DEPTH_TEST);
|
||||
stateSprite->Disable(GL_STENCIL_TEST);
|
||||
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
|
||||
|
||||
GLuint sceneTexture = SceneTexture();
|
||||
GLERROR("SceneTexture() 2");
|
||||
delete stateSprite;
|
||||
stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
|
||||
m_CombinedTexture = blurHUDPass->CombineTextures(sceneTexture, m_FullBlurredTexture);
|
||||
}
|
||||
//Draw Transparen objects
|
||||
//state->BlendFunc(GL_ONE, GL_ONE);
|
||||
@@ -325,30 +388,37 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
|
||||
void DrawFinalPass::ClearBuffer()
|
||||
{
|
||||
GLERROR("PRE");
|
||||
m_ShieldDepthFrameBuffer.Bind();
|
||||
m_ShieldDepthFrameBuffer->Bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
m_ShieldDepthFrameBuffer.Unbind();
|
||||
m_FinalPassFrameBuffer.Bind();
|
||||
m_ShieldDepthFrameBuffer->Unbind();
|
||||
m_FinalPassFrameBuffer->Bind();
|
||||
GLERROR("Bind HighRes");
|
||||
glViewport(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");
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
m_FinalPassFrameBuffer->Unbind();
|
||||
GLERROR("END");
|
||||
}
|
||||
|
||||
|
||||
void DrawFinalPass::OnWindowResize()
|
||||
{
|
||||
//InitializeFrameBuffers();
|
||||
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);
|
||||
CommonFunctions::GenerateTexture(&m_SceneTexture, GL_CLAMP_TO_BORDER, 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_BORDER, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
m_FinalPassFrameBuffer.Generate();
|
||||
if (m_FinalPassFrameBuffer->MultiSampling() != (bool)m_MSAA) {
|
||||
delete m_FinalPassFrameBuffer;
|
||||
delete m_ShieldDepthFrameBuffer;
|
||||
m_FinalPassFrameBuffer = new FrameBuffer();
|
||||
m_ShieldDepthFrameBuffer = new FrameBuffer();
|
||||
}
|
||||
|
||||
if (!m_MSAA) {
|
||||
if (m_AntiAliasedFrameBuffer != nullptr) {
|
||||
delete m_AntiAliasedFrameBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
InitializeFrameBuffers();
|
||||
GLERROR("Error changing texture resolutions");
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
#include "Rendering/FrameBuffer.h"
|
||||
|
||||
|
||||
BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod)
|
||||
BufferResource::BufferResource(GLuint* resourceHandle, GLenum resourceType, GLenum attachment, GLuint mipMapLod, bool multiSampling)
|
||||
{
|
||||
m_ResourceHandle = resourceHandle;
|
||||
m_ResourceType = resourceType;
|
||||
m_Attachment = attachment;
|
||||
m_MipMapLod = mipMapLod;
|
||||
m_MultiSampling = multiSampling;
|
||||
}
|
||||
|
||||
Texture2D::~Texture2D()
|
||||
@@ -17,6 +18,12 @@ Texture2D::~Texture2D()
|
||||
}
|
||||
}
|
||||
|
||||
Texture2DMultiSample::~Texture2DMultiSample()
|
||||
{
|
||||
if (m_ResourceHandle != 0) {
|
||||
glDeleteTextures(1, m_ResourceHandle);
|
||||
}
|
||||
}
|
||||
|
||||
RenderBuffer::~RenderBuffer()
|
||||
{
|
||||
@@ -42,6 +49,14 @@ FrameBuffer::~FrameBuffer()
|
||||
|
||||
void FrameBuffer::AddResource(std::shared_ptr<BufferResource> resource)
|
||||
{
|
||||
//m_MultiSampling is true when initialized
|
||||
if (m_MultiSampling != resource->m_MultiSampling) {
|
||||
if (m_MultiSampling == false) {
|
||||
GLERROR("All renderbuffers is/is not using multisampling");
|
||||
} else {
|
||||
m_MultiSampling = false;
|
||||
}
|
||||
}
|
||||
m_Resources.push_back(resource);
|
||||
}
|
||||
|
||||
@@ -55,20 +70,23 @@ void FrameBuffer::Generate()
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_BufferHandle);
|
||||
GLERROR("1");
|
||||
|
||||
for (auto it = m_Resources.begin(); it != m_Resources.end(); it++) {
|
||||
switch ((*it)->m_ResourceType) {
|
||||
case GL_TEXTURE_2D_MULTISAMPLE:
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, (*it)->m_Attachment, GL_TEXTURE_2D_MULTISAMPLE, 0, 0);
|
||||
GLERROR("FrameBuffer generate: GL_TEXTURE_2D_MULTISAMPLE");
|
||||
break;
|
||||
case GL_TEXTURE_2D:
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, (*it)->m_MipMapLod);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2D");
|
||||
GLERROR("FrameBuffer generate: GL_TEXTURE_2D");
|
||||
break;
|
||||
case GL_RENDERBUFFER:
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, (*it)->m_Attachment, (*it)->m_ResourceType, *(*it)->m_ResourceHandle);
|
||||
GLERROR("FrameBuffer generate: glFramebufferRenderbuffer");
|
||||
GLERROR("FrameBuffer generate: GL_RENDERBUFFER");
|
||||
break;
|
||||
case GL_TEXTURE_2D_ARRAY:
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, (*it)->m_Attachment, *(*it)->m_ResourceHandle, 0);
|
||||
GLERROR("FrameBuffer generate: glFramebufferTexture2DArray");
|
||||
GLERROR("FrameBuffer generate: GL_TEXTURE_2D_ARRAY");
|
||||
break;
|
||||
}
|
||||
GLERROR("2");
|
||||
@@ -77,8 +95,8 @@ void FrameBuffer::Generate()
|
||||
attachments.push_back((*it)->m_Attachment);
|
||||
}
|
||||
GLERROR("Attachment");
|
||||
|
||||
}
|
||||
|
||||
GLERROR("3");
|
||||
|
||||
GLenum* bufferTextures = attachments.data();
|
||||
@@ -89,7 +107,7 @@ void FrameBuffer::Generate()
|
||||
|
||||
if (GLenum frameBufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
GLERROR("Framebuffer incomplete");
|
||||
//LOG_ERROR("FrameBuffer incomplete: 0x%x\n", frameBufferStatus);
|
||||
LOG_ERROR("FrameBuffer incomplete: 0x%x\n", glCheckFramebufferStatus(GL_FRAMEBUFFER));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
GLERROR("END");
|
||||
@@ -110,3 +128,11 @@ GLuint FrameBuffer::GetHandle()
|
||||
{
|
||||
return m_BufferHandle;
|
||||
}
|
||||
|
||||
void FrameBuffer::Read() {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_BufferHandle);
|
||||
}
|
||||
|
||||
void FrameBuffer::Draw() {
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_BufferHandle);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ void CommonFunctions::GenerateMultiSampleTexture(GLuint* texture, int numSamples
|
||||
{
|
||||
glDeleteTextures(1, texture);
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, *texture);
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, false);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
GLERROR("Texture initialization failed 1");
|
||||
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, numSamples, internalFormat, dimensions.x, dimensions.y, GL_FALSE);
|
||||
GLERROR("Texture initialization failed");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user