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), | ||||
<<<<<<< .mine | |||||
m_BlurTex8a(0), m_BlurTex8b(0), m_WhichBuffer(true), m_UsingMultisampleBuffer(false), | |||||
m_MultisampleFBO(0), m_MultisampleColorTex(0), m_MultisampleDepthTex(0), | |||||
m_MultisampleCount(0) | |||||
||||||| .r23484 | |||||
m_BlurTex8a(0), m_BlurTex8b(0), m_WhichBuffer(true) | |||||
======= | |||||
m_BlurTex8a(0), m_BlurTex8b(0), m_WhichBuffer(true), m_Sharpness(0.3f) | m_BlurTex8a(0), m_BlurTex8b(0), m_WhichBuffer(true), m_Sharpness(0.3f) | ||||
>>>>>>> .r23989 | |||||
{ | { | ||||
} | } | ||||
CPostprocManager::~CPostprocManager() | CPostprocManager::~CPostprocManager() | ||||
{ | { | ||||
Cleanup(); | Cleanup(); | ||||
} | } | ||||
Show All 21 Lines | void CPostprocManager::Cleanup() | ||||
m_BlurTex2a = m_BlurTex2b = m_BlurTex4a = m_BlurTex4b = m_BlurTex8a = m_BlurTex8b = 0; | m_BlurTex2a = m_BlurTex2b = m_BlurTex4a = m_BlurTex4b = m_BlurTex8a = m_BlurTex8b = 0; | ||||
} | } | ||||
void CPostprocManager::Initialize() | void CPostprocManager::Initialize() | ||||
{ | { | ||||
if (m_IsInitialized) | if (m_IsInitialized) | ||||
return; | return; | ||||
GLint maxSamples = 0; | |||||
glGetIntegerv(GL_MAX_SAMPLES, &maxSamples); | |||||
const GLsizei possibleSampleCounts[] = {2, 4, 8, 16}; | |||||
std::copy_if( | |||||
std::begin(possibleSampleCounts), std::end(possibleSampleCounts), | |||||
std::back_inserter(m_AllowedSampleCounts), | |||||
[maxSamples](const GLsizei sampleCount) { return sampleCount <= maxSamples; } ); | |||||
// The screen size starts out correct and then must be updated with Resize() | // The screen size starts out correct and then must be updated with Resize() | ||||
m_Width = g_Renderer.GetWidth(); | m_Width = g_Renderer.GetWidth(); | ||||
m_Height = g_Renderer.GetHeight(); | m_Height = g_Renderer.GetHeight(); | ||||
UpdateAntiAliasingTechnique(); | UpdateAntiAliasingTechnique(); | ||||
UpdateSharpeningTechnique(); | UpdateSharpeningTechnique(); | ||||
UpdateSharpnessFactor(); | UpdateSharpnessFactor(); | ||||
RecreateBuffers(); | RecreateBuffers(); | ||||
▲ Show 20 Lines • Show All 101 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 96 Lines • ▼ Show 20 Lines | void CPostprocManager::ApplyPostproc() | ||||
const bool hasEffects = m_PostProcEffect != L"default"; | const bool hasEffects = m_PostProcEffect != L"default"; | ||||
const bool hasAA = m_AATech && g_RenderingOptions.GetPreferGLSL(); | const bool hasAA = m_AATech && g_RenderingOptions.GetPreferGLSL(); | ||||
const bool hasSharp = m_SharpTech && g_RenderingOptions.GetPreferGLSL(); | const bool hasSharp = m_SharpTech && g_RenderingOptions.GetPreferGLSL(); | ||||
if (!hasEffects && !hasAA && !hasSharp) | if (!hasEffects && !hasAA && !hasSharp) | ||||
return; | return; | ||||
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); | ||||
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. | |||||
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); | ||||
pglDrawBuffers(1, buffers); | pglDrawBuffers(1, buffers); | ||||
pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PongFbo); | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_PongFbo); | ||||
▲ Show 20 Lines • Show All 76 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") && | |||||
!m_AllowedSampleCounts.empty() && | |||||
g_RenderingOptions.GetPreferGLSL(); | |||||
if (!is_msaa_supported) | |||||
{ | |||||
LOGWARNING("MSAA is unsupported."); | |||||
return; | |||||
} | |||||
std::stringstream ss(m_AAName.substr(msaaPrefix.size())); | |||||
ss >> m_MultisampleCount; | |||||
if (std::find(std::begin(m_AllowedSampleCounts), std::end(m_AllowedSampleCounts), m_MultisampleCount) == | |||||
std::end(m_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::UpdateSharpeningTechnique() | void CPostprocManager::UpdateSharpeningTechnique() | ||||
{ | { | ||||
if (!g_RenderingOptions.GetPreferGLSL()) | if (!g_RenderingOptions.GetPreferGLSL()) | ||||
return; | return; | ||||
CStr newSharpName; | CStr newSharpName; | ||||
Show All 15 Lines | |||||
} | } | ||||
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); | |||||
} | |||||
bool CPostprocManager::IsMultisampleEnabled() const | |||||
{ | |||||
return m_UsingMultisampleBuffer; | |||||
} | |||||
void CPostprocManager::ResolveMultisampleFramebuffer() | |||||
{ | |||||
if (!m_UsingMultisampleBuffer) | |||||
return; | |||||
pglBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_PingFbo); | |||||
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_FRAMEBUFFER_EXT, m_PingFbo); | |||||
} | |||||
#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 61 Lines • ▼ Show 20 Lines | |||||
void CPostprocManager::ApplyPostproc() | void CPostprocManager::ApplyPostproc() | ||||
{ | { | ||||
} | } | ||||
void CPostprocManager::ReleaseRenderOutput() | void CPostprocManager::ReleaseRenderOutput() | ||||
{ | { | ||||
} | } | ||||
void CPostprocManager::CreateMultisampleBuffer() | |||||
{ | |||||
} | |||||
void CPostprocManager::DestroyMultisampleBuffer() | |||||
{ | |||||
} | |||||
bool CPostprocManager::IsMultisampleEnabled() const | |||||
{ | |||||
return false; | |||||
} | |||||
void CPostprocManager::ResolveMultisampleFramebuffer() | |||||
{ | |||||
} | |||||
#endif | #endif |
Wildfire Games · Phabricator
why pingfbo and not mutlisamplefbo?