Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/PostprocManager.cpp
Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | void CPostprocManager::RecreateBuffers() | ||||
// that these are fairly small it's probably not worth complicating the coordinates passed | // that these are fairly small it's probably not worth complicating the coordinates passed | ||||
// to the blur helper functions. | // to the blur helper functions. | ||||
uint32_t width = m_Width / 2, height = m_Height / 2; | uint32_t width = m_Width / 2, height = m_Height / 2; | ||||
for (BlurScale& scale : m_BlurScales) | for (BlurScale& scale : m_BlurScales) | ||||
{ | { | ||||
for (BlurScale::Step& step : scale.steps) | for (BlurScale::Step& step : scale.steps) | ||||
{ | { | ||||
GEN_BUFFER_RGBA(step.texture, width, height); | GEN_BUFFER_RGBA(step.texture, width, height); | ||||
step.framebuffer = backendDevice->CreateFramebuffer("BlurScaleSteoFramebuffer", | step.framebuffer = backendDevice->CreateFramebuffer( | ||||
step.texture.get(), nullptr); | "BlurScaleSteoFramebuffer", step.texture.get(), | ||||
Renderer::Backend::AttachmentLoadOp::LOAD, | |||||
Renderer::Backend::AttachmentStoreOp::STORE, | |||||
CColor(0.0f, 0.0f, 0.0f, 0.0f), nullptr, | |||||
Renderer::Backend::AttachmentLoadOp::DONT_CARE, | |||||
Renderer::Backend::AttachmentStoreOp::DONT_CARE); | |||||
} | } | ||||
width /= 2; | width /= 2; | ||||
height /= 2; | height /= 2; | ||||
} | } | ||||
#undef GEN_BUFFER_RGBA | #undef GEN_BUFFER_RGBA | ||||
// Allocate the Depth/Stencil texture. | // Allocate the Depth/Stencil texture. | ||||
m_DepthTex = backendDevice->CreateTexture2D("PostProcDepthTexture", | m_DepthTex = backendDevice->CreateTexture2D("PostProcDepthTexture", | ||||
Renderer::Backend::ITexture::Usage::SAMPLED | | Renderer::Backend::ITexture::Usage::SAMPLED | | ||||
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT, | Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT, | ||||
Renderer::Backend::Format::D24_S8, m_Width, m_Height, | Renderer::Backend::Format::D24_S8, m_Width, m_Height, | ||||
Renderer::Backend::Sampler::MakeDefaultSampler( | Renderer::Backend::Sampler::MakeDefaultSampler( | ||||
Renderer::Backend::Sampler::Filter::LINEAR, | Renderer::Backend::Sampler::Filter::LINEAR, | ||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE)); | Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE)); | ||||
// Set up the framebuffers with some initial textures. | // Set up the framebuffers with some initial textures. | ||||
m_CaptureFramebuffer = backendDevice->CreateFramebuffer("PostprocCaptureFramebuffer", | m_CaptureFramebuffer = backendDevice->CreateFramebuffer("PostprocCaptureFramebuffer", | ||||
m_ColorTex1.get(), m_DepthTex.get(), CColor(0.0f, 0.0f, 0.0f, 0.0f)); | m_ColorTex1.get(), | ||||
Renderer::Backend::AttachmentLoadOp::DONT_CARE, | |||||
Renderer::Backend::AttachmentStoreOp::STORE, | |||||
CColor(0.0f, 0.0f, 0.0f, 0.0f), m_DepthTex.get(), | |||||
Renderer::Backend::AttachmentLoadOp::CLEAR, | |||||
Renderer::Backend::AttachmentStoreOp::STORE); | |||||
m_PingFramebuffer = backendDevice->CreateFramebuffer("PostprocPingFramebuffer", | m_PingFramebuffer = backendDevice->CreateFramebuffer("PostprocPingFramebuffer", | ||||
m_ColorTex1.get(), nullptr); | m_ColorTex1.get(), | ||||
Renderer::Backend::AttachmentLoadOp::LOAD, | |||||
Renderer::Backend::AttachmentStoreOp::STORE, | |||||
CColor(0.0f, 0.0f, 0.0f, 0.0f), nullptr, | |||||
Renderer::Backend::AttachmentLoadOp::DONT_CARE, | |||||
Renderer::Backend::AttachmentStoreOp::DONT_CARE); | |||||
m_PongFramebuffer = backendDevice->CreateFramebuffer("PostprocPongFramebuffer", | m_PongFramebuffer = backendDevice->CreateFramebuffer("PostprocPongFramebuffer", | ||||
m_ColorTex2.get(), nullptr); | m_ColorTex2.get(), | ||||
Renderer::Backend::AttachmentLoadOp::LOAD, | |||||
Renderer::Backend::AttachmentStoreOp::STORE, | |||||
CColor(0.0f, 0.0f, 0.0f, 0.0f), nullptr, | |||||
Renderer::Backend::AttachmentLoadOp::DONT_CARE, | |||||
Renderer::Backend::AttachmentStoreOp::DONT_CARE); | |||||
if (!m_CaptureFramebuffer || !m_PingFramebuffer || !m_PongFramebuffer) | if (!m_CaptureFramebuffer || !m_PingFramebuffer || !m_PongFramebuffer) | ||||
{ | { | ||||
LOGWARNING("Failed to create postproc framebuffers"); | LOGWARNING("Failed to create postproc framebuffers"); | ||||
g_RenderingOptions.SetPostProc(false); | g_RenderingOptions.SetPostProc(false); | ||||
} | } | ||||
if (m_UsingMultisampleBuffer) | if (m_UsingMultisampleBuffer) | ||||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | void CPostprocManager::CaptureRenderOutput( | ||||
deviceCommandContext->BeginFramebufferPass( | deviceCommandContext->BeginFramebufferPass( | ||||
m_UsingMultisampleBuffer ? m_MultisampleFramebuffer.get() : m_CaptureFramebuffer.get()); | m_UsingMultisampleBuffer ? m_MultisampleFramebuffer.get() : m_CaptureFramebuffer.get()); | ||||
m_WhichBuffer = true; | m_WhichBuffer = true; | ||||
} | } | ||||
void CPostprocManager::ReleaseRenderOutput( | void CPostprocManager::ReleaseRenderOutput( | ||||
Renderer::Backend::IDeviceCommandContext* deviceCommandContext) | Renderer::Backend::IDeviceCommandContext* deviceCommandContext, | ||||
Renderer::Backend::IFramebuffer* destination) | |||||
{ | { | ||||
ENSURE(m_IsInitialized); | ENSURE(m_IsInitialized); | ||||
GPU_SCOPED_LABEL(deviceCommandContext, "Copy postproc to backbuffer"); | GPU_SCOPED_LABEL(deviceCommandContext, "Copy postproc to backbuffer"); | ||||
// We blit to the backbuffer from the previous active buffer. | // We blit to the backbuffer from the previous active buffer. | ||||
deviceCommandContext->BlitFramebuffer( | deviceCommandContext->BlitFramebuffer( | ||||
deviceCommandContext->GetDevice()->GetCurrentBackbuffer(), | destination, (m_WhichBuffer ? m_PingFramebuffer : m_PongFramebuffer).get()); | ||||
(m_WhichBuffer ? m_PingFramebuffer : m_PongFramebuffer).get()); | |||||
} | } | ||||
void CPostprocManager::ApplyEffect( | void CPostprocManager::ApplyEffect( | ||||
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, | Renderer::Backend::IDeviceCommandContext* deviceCommandContext, | ||||
const CShaderTechniquePtr& shaderTech, int pass) | const CShaderTechniquePtr& shaderTech, int pass) | ||||
{ | { | ||||
// select the other FBO for rendering | // select the other FBO for rendering | ||||
deviceCommandContext->BeginFramebufferPass( | deviceCommandContext->BeginFramebufferPass( | ||||
▲ Show 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | m_MultisampleDepthTex = backendDevice->CreateTexture("PostProcDepthMS", | ||||
Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE, | Renderer::Backend::ITexture::Type::TEXTURE_2D_MULTISAMPLE, | ||||
Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT, | Renderer::Backend::ITexture::Usage::DEPTH_STENCIL_ATTACHMENT, | ||||
Renderer::Backend::Format::D24_S8, m_Width, m_Height, | Renderer::Backend::Format::D24_S8, m_Width, m_Height, | ||||
Renderer::Backend::Sampler::MakeDefaultSampler( | Renderer::Backend::Sampler::MakeDefaultSampler( | ||||
Renderer::Backend::Sampler::Filter::LINEAR, | Renderer::Backend::Sampler::Filter::LINEAR, | ||||
Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE), 1, m_MultisampleCount); | Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE), 1, m_MultisampleCount); | ||||
// Set up the framebuffers with some initial textures. | // Set up the framebuffers with some initial textures. | ||||
m_MultisampleFramebuffer = backendDevice->CreateFramebuffer("PostprocMultisampleFramebuffer", | m_MultisampleFramebuffer = backendDevice->CreateFramebuffer( | ||||
m_MultisampleColorTex.get(), m_MultisampleDepthTex.get(), CColor(0.0f, 0.0f, 0.0f, 0.0f)); | "PostprocMultisampleFramebuffer", m_MultisampleColorTex.get(), | ||||
Renderer::Backend::AttachmentLoadOp::DONT_CARE, | |||||
Renderer::Backend::AttachmentStoreOp::STORE, | |||||
CColor(0.0f, 0.0f, 0.0f, 0.0f), m_MultisampleDepthTex.get(), | |||||
Renderer::Backend::AttachmentLoadOp::CLEAR, | |||||
Renderer::Backend::AttachmentStoreOp::STORE); | |||||
if (!m_MultisampleFramebuffer) | if (!m_MultisampleFramebuffer) | ||||
{ | { | ||||
LOGERROR("Failed to create postproc multisample framebuffer"); | LOGERROR("Failed to create postproc multisample framebuffer"); | ||||
m_UsingMultisampleBuffer = false; | m_UsingMultisampleBuffer = false; | ||||
DestroyMultisampleBuffer(); | DestroyMultisampleBuffer(); | ||||
} | } | ||||
} | } | ||||
Show All 25 Lines |
Wildfire Games · Phabricator