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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user