Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/PostprocManager.cpp
Show All 26 Lines | |||||
#include "maths/MathUtil.h" | #include "maths/MathUtil.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/World.h" | #include "ps/World.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/RenderingOptions.h" | #include "renderer/RenderingOptions.h" | ||||
#include "tools/atlas/GameInterface/GameLoop.h" | |||||
#if !CONFIG2_GLES | #if !CONFIG2_GLES | ||||
CPostprocManager::CPostprocManager() | CPostprocManager::CPostprocManager() | ||||
: m_IsInitialized(false), m_PingFbo(0), m_PongFbo(0), m_PostProcEffect(L"default"), m_ColorTex1(0), m_ColorTex2(0), | : m_IsInitialized(false), m_PingFbo(0), m_PongFbo(0), m_PostProcEffect(L"default"), m_ColorTex1(0), m_ColorTex2(0), | ||||
m_DepthTex(0), m_BloomFbo(0), m_BlurTex2a(0), m_BlurTex2b(0), m_BlurTex4a(0), m_BlurTex4b(0), | m_DepthTex(0), m_BloomFbo(0), m_BlurTex2a(0), m_BlurTex2b(0), m_BlurTex4a(0), m_BlurTex4b(0), | ||||
m_BlurTex8a(0), m_BlurTex8b(0), m_WhichBuffer(true) | m_BlurTex8a(0), m_BlurTex8b(0), m_WhichBuffer(true) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | void CPostprocManager::RecreateBuffers() | ||||
status = pglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); | status = pglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); | ||||
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) | if (status != GL_FRAMEBUFFER_COMPLETE_EXT) | ||||
{ | { | ||||
LOGWARNING("Framebuffer object incomplete (B): 0x%04X", status); | LOGWARNING("Framebuffer object incomplete (B): 0x%04X", status); | ||||
} | } | ||||
*/ | */ | ||||
if (m_UsingMultisampleBuffer) | |||||
{ | |||||
DestroyMultisampleBuffer(); | |||||
CreateMultisampleBuffer(); | |||||
} | |||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | ||||
} | } | ||||
void CPostprocManager::ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight) | void CPostprocManager::ApplyBlurDownscale2x(GLuint inTex, GLuint outTex, int inWidth, int inHeight) | ||||
{ | { | ||||
// Bind inTex to framebuffer for rendering. | // Bind inTex to framebuffer for rendering. | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_BloomFbo); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_BloomFbo); | ||||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | void CPostprocManager::CaptureRenderOutput() | ||||
GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; | GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT }; | ||||
pglDrawBuffers(1, buffers); | pglDrawBuffers(1, buffers); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PingFbo); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PingFbo); | ||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | ||||
pglDrawBuffers(1, buffers); | pglDrawBuffers(1, buffers); | ||||
m_WhichBuffer = true; | m_WhichBuffer = true; | ||||
if (m_UsingMultisampleBuffer) | |||||
{ | |||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_MultisampleFBO); | |||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |||||
pglDrawBuffers(1, buffers); | |||||
} | |||||
} | } | ||||
void CPostprocManager::ReleaseRenderOutput() | void CPostprocManager::ReleaseRenderOutput() | ||||
{ | { | ||||
ENSURE(m_IsInitialized); | ENSURE(m_IsInitialized); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
void CPostprocManager::ApplyPostproc() | void CPostprocManager::ApplyPostproc() | ||||
{ | { | ||||
ENSURE(m_IsInitialized); | ENSURE(m_IsInitialized); | ||||
// Don't do anything if we are using the default effect. | // Don't do anything if we are using the default effect. | ||||
if (m_PostProcEffect == L"default") | if (m_PostProcEffect == L"default") | ||||
return; | return; | ||||
if (m_UsingMultisampleBuffer) | |||||
{ | |||||
pglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_PingFbo); | |||||
Silier: why pingfbo and not mutlisamplefbo? | |||||
Done Inline ActionsBecause it's the target: GL_DRAW_FRAMEBUFFER_EXT, not the source. vladislavbelov: Because it's the target: `GL_DRAW_FRAMEBUFFER_EXT`, not the source. | |||||
pglBlitFramebufferEXT(0, 0, m_Width, m_Height, 0, 0, m_Width, m_Height, | |||||
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST); | |||||
pglBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); | |||||
} | |||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PongFbo); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PongFbo); | ||||
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); | pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); | ||||
GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT }; | GLenum buffers[] = { GL_COLOR_ATTACHMENT0_EXT }; | ||||
pglDrawBuffers(1, buffers); | pglDrawBuffers(1, buffers); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PingFbo); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PingFbo); | ||||
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); | pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, 0, 0); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | void CPostprocManager::UpdateAntiAliasingTechnique() | ||||
CStr newAAName; | CStr newAAName; | ||||
CFG_GET_VAL("antialiasing", newAAName); | CFG_GET_VAL("antialiasing", newAAName); | ||||
if (m_AAName == newAAName) | if (m_AAName == newAAName) | ||||
return; | return; | ||||
m_AAName = newAAName; | m_AAName = newAAName; | ||||
m_AATech.reset(); | m_AATech.reset(); | ||||
if (m_UsingMultisampleBuffer) | |||||
{ | |||||
m_UsingMultisampleBuffer = false; | |||||
DestroyMultisampleBuffer(); | |||||
} | |||||
// We have to hardcode names in the engine, because anti-aliasing | // We have to hardcode names in the engine, because anti-aliasing | ||||
// techinques strongly depend on the graphics pipeline. | // techinques strongly depend on the graphics pipeline. | ||||
// We might use enums in future though. | // We might use enums in future though. | ||||
const CStr msaaPrefix = "msaa"; | |||||
if (m_AAName == "fxaa") | if (m_AAName == "fxaa") | ||||
{ | { | ||||
m_AATech = g_Renderer.GetShaderManager().LoadEffect(CStrIntern("fxaa")); | m_AATech = g_Renderer.GetShaderManager().LoadEffect(CStrIntern("fxaa")); | ||||
} | } | ||||
else if (m_AAName.size() > msaaPrefix.size() && m_AAName.substr(0, msaaPrefix.size()) == msaaPrefix) | |||||
{ | |||||
#if !CONFIG2_GLES | |||||
// We don't want to enable MSAA in Atlas, because it uses wxWidgets and its canvas. | |||||
Not Done Inline ActionsWill it still be accurrate after the threading removal ? Stan: Will it still be accurrate after the threading removal ? | |||||
if (g_AtlasGameLoop && g_AtlasGameLoop->running) | |||||
Not Done Inline ActionsIf I remove this, it works in Atlas but I get once ERROR: GL error GL_INVALID_VALUE (0x0501) occurred though Stan: If I remove this, it works in Atlas but I get once
```
ERROR: GL error GL_INVALID_VALUE… | |||||
return; | |||||
const bool is_msaa_supported = | |||||
ogl_HaveVersion("3.3") && | |||||
ogl_HaveExtension("GL_ARB_multisample") && | |||||
Not Done Inline ActionsShould be added to the userreporter I think. Stan: Should be added to the userreporter I think. | |||||
ogl_HaveExtension("GL_ARB_texture_multisample") && | |||||
g_RenderingOptions.GetPreferGLSL(); | |||||
if (!is_msaa_supported) | |||||
{ | |||||
LOGWARNING("MSAA is unsupported."); | |||||
return; | |||||
} | |||||
std::stringstream ss(m_AAName.substr(msaaPrefix.size())); | |||||
ss >> m_MultisampleCount; | |||||
const GLsizei allowedSampleCounts[] = {2, 4, 8, 16}; | |||||
if (std::find(std::begin(allowedSampleCounts), std::end(allowedSampleCounts), m_MultisampleCount) == | |||||
std::end(allowedSampleCounts)) | |||||
{ | |||||
m_MultisampleCount = 4; | |||||
LOGWARNING("Wrong MSAA sample count: %s.", m_AAName.EscapeToPrintableASCII().c_str()); | |||||
Not Done Inline ActionsI assume we can't translate that. Unsupported would be better no? It's not necesserarily wrong is it? Stan: I assume we can't translate that. Unsupported would be better no? It's not necesserarily wrong… | |||||
} | |||||
m_UsingMultisampleBuffer = true; | |||||
CreateMultisampleBuffer(); | |||||
#else | |||||
#warning TODO: implement and test MSAA for GLES | |||||
LOGWARNING("MSAA is unsupported."); | |||||
#endif | |||||
} | |||||
} | } | ||||
void CPostprocManager::SetDepthBufferClipPlanes(float nearPlane, float farPlane) | void CPostprocManager::SetDepthBufferClipPlanes(float nearPlane, float farPlane) | ||||
{ | { | ||||
m_NearPlane = nearPlane; | m_NearPlane = nearPlane; | ||||
m_FarPlane = farPlane; | m_FarPlane = farPlane; | ||||
} | } | ||||
void CPostprocManager::CreateMultisampleBuffer() | |||||
{ | |||||
glEnable(GL_MULTISAMPLE); | |||||
glGenTextures(1, &m_MultisampleColorTex); | |||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_MultisampleColorTex); | |||||
pglTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_MultisampleCount, GL_RGBA, m_Width, m_Height, GL_TRUE); | |||||
// Allocate the Depth/Stencil texture. | |||||
glGenTextures(1, &m_MultisampleDepthTex); | |||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_MultisampleDepthTex); | |||||
pglTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, m_MultisampleCount, GL_DEPTH24_STENCIL8_EXT, m_Width, m_Height, GL_TRUE); | |||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE); | |||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); | |||||
ogl_WarnIfError(); | |||||
// Set up the framebuffers with some initial textures. | |||||
pglGenFramebuffersEXT(1, &m_MultisampleFBO); | |||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_MultisampleFBO); | |||||
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, | |||||
GL_TEXTURE_2D_MULTISAMPLE, m_MultisampleColorTex, 0); | |||||
pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_STENCIL_ATTACHMENT, | |||||
GL_TEXTURE_2D_MULTISAMPLE, m_MultisampleDepthTex, 0); | |||||
GLenum status = pglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); | |||||
if (status != GL_FRAMEBUFFER_COMPLETE_EXT) | |||||
{ | |||||
LOGWARNING("Multisample framebuffer object incomplete (A): 0x%04X", status); | |||||
m_UsingMultisampleBuffer = false; | |||||
DestroyMultisampleBuffer(); | |||||
} | |||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); | |||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); | |||||
glBindTexture(GL_TEXTURE_2D, 0); | |||||
} | |||||
void CPostprocManager::DestroyMultisampleBuffer() | |||||
{ | |||||
if (m_UsingMultisampleBuffer) | |||||
return; | |||||
if (m_MultisampleFBO) | |||||
pglDeleteFramebuffersEXT(1, &m_MultisampleFBO); | |||||
if (m_MultisampleColorTex) | |||||
glDeleteTextures(1, &m_MultisampleColorTex); | |||||
if (m_MultisampleDepthTex) | |||||
glDeleteTextures(1, &m_MultisampleDepthTex); | |||||
glDisable(GL_MULTISAMPLE); | |||||
} | |||||
#else | #else | ||||
#warning TODO: implement PostprocManager for GLES | #warning TODO: implement PostprocManager for GLES | ||||
void ApplyBlurDownscale2x(GLuint UNUSED(inTex), GLuint UNUSED(outTex), int UNUSED(inWidth), int UNUSED(inHeight)) | void ApplyBlurDownscale2x(GLuint UNUSED(inTex), GLuint UNUSED(outTex), int UNUSED(inWidth), int UNUSED(inHeight)) | ||||
{ | { | ||||
} | } | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
void CPostprocManager::ApplyPostproc() | void CPostprocManager::ApplyPostproc() | ||||
{ | { | ||||
} | } | ||||
void CPostprocManager::ReleaseRenderOutput() | void CPostprocManager::ReleaseRenderOutput() | ||||
{ | { | ||||
} | } | ||||
void CPostprocManager::CreateMultisampleBuffer() | |||||
{ | |||||
} | |||||
void CPostprocManager::DestroyMultisampleBuffer() | |||||
{ | |||||
} | |||||
#endif | #endif |
Wildfire Games · Phabricator
why pingfbo and not mutlisamplefbo?