Skip to content

Commit

Permalink
Updated call sites to no longer pass clear color to KRRenderPass::Beg…
Browse files Browse the repository at this point in the history
…in(), as KRRenderPass now retains the clear color after initialization.

KRRenderPass now has configurable stencil clear, load, and store operations.
  • Loading branch information
kearwood committed Jan 21, 2024
1 parent d92a039 commit a2d125b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
10 changes: 5 additions & 5 deletions kraken/KRCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS

// Start render pass
KRRenderPass& deferredGBufferPass = compositeSurface.getDeferredGBufferPass();
deferredGBufferPass.begin(commandBuffer, compositeSurface, Vector4::Zero());
deferredGBufferPass.begin(commandBuffer, compositeSurface);

// Render the geometry
scene.render(commandBuffer, compositeSurface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false);
Expand Down Expand Up @@ -234,7 +234,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS

// Start render pass
KRRenderPass& deferredOpaquePass = compositeSurface.getDeferredOpaquePass();
deferredOpaquePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
deferredOpaquePass.begin(commandBuffer, compositeSurface);

// Set source to buffers from pass 2
m_pContext->getTextureManager()->selectTexture(0 /*GL_TEXTURE_2D*/, 6, lightAccumulationTexture);
Expand All @@ -253,7 +253,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS

// Start render pass
KRRenderPass& forwardOpaquePass = compositeSurface.getForwardOpaquePass();
forwardOpaquePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
forwardOpaquePass.begin(commandBuffer, compositeSurface);

// Render the geometry
scene.render(commandBuffer, compositeSurface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false);
Expand Down Expand Up @@ -414,7 +414,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
GL_PUSH_GROUP_MARKER("Post Processing");

KRRenderPass& postCompositePass = compositeSurface.getPostCompositePass();
postCompositePass.begin(commandBuffer, compositeSurface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
postCompositePass.begin(commandBuffer, compositeSurface);

renderPost(commandBuffer, compositeSurface);

Expand Down Expand Up @@ -774,7 +774,7 @@ void KRCamera::renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface)
m_debug_text_vbo_data.load(commandBuffer);

KRRenderPass& debugPass = surface.getDebugPass();
debugPass.begin(commandBuffer, surface, Vector4::Create(0.0f, 0.0f, 0.0f, 1.0f));
debugPass.begin(commandBuffer, surface);

KRTexture* fontTexture = m_pContext->getTextureManager()->getTexture("font");
fontTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_UI);
Expand Down
7 changes: 4 additions & 3 deletions kraken/KRRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void KRRenderPass::create(KRDevice& device, VkFormat swapChainImageFormat, VkFor
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
depthAttachment.loadOp = info.clearDepth ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
depthAttachment.storeOp = info.keepDepth ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.stencilLoadOp = info.clearStencil ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
depthAttachment.stencilStoreOp = info.keepStencil ? VK_ATTACHMENT_STORE_OP_STORE : VK_ATTACHMENT_STORE_OP_DONT_CARE;
depthAttachment.initialLayout = info.clearDepth ? VK_IMAGE_LAYOUT_UNDEFINED : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;

Expand Down Expand Up @@ -133,7 +133,8 @@ void KRRenderPass::begin(VkCommandBuffer& commandBuffer, KRSurface& surface)
clearValues[0].color.float32[1] = m_info.clearColorValue[1];
clearValues[0].color.float32[2] = m_info.clearColorValue[2];
clearValues[0].color.float32[3] = m_info.clearColorValue[3];
clearValues[1].depthStencil = { 1.0f, 0 };
clearValues[1].depthStencil.depth = m_info.clearDepthValue;
clearValues[1].depthStencil.stencil = m_info.clearStencilValue;

VkRenderPassBeginInfo renderPassInfo{};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
Expand Down
8 changes: 7 additions & 1 deletion kraken/KRRenderPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ class KRRenderPass : public KRContextObject
bool keepColor;
bool clearDepth;
bool keepDepth;
bool clearStencil;
bool keepStencil;
bool finalPass;
hydra::Vector4 clearColorValue;
float clearDepthValue;
uint32_t clearStencilValue;
};

void create(KRDevice& device, VkFormat swapChainImageFormat, VkFormat depthImageFormat, const RenderPassInfo& info);
void destroy(KRDevice& device);

void begin(VkCommandBuffer& commandBuffer, KRSurface& surface, const hydra::Vector4& clearColor);
void begin(VkCommandBuffer& commandBuffer, KRSurface& surface);
void end(VkCommandBuffer& commandBuffer);

// private:
VkRenderPass m_renderPass;
RenderPassInfo m_info;
};
10 changes: 8 additions & 2 deletions kraken/KRSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,16 @@ KrResult KRSurface::createSwapChain()
KRRenderPass::RenderPassInfo info{};
info.clearColor = true;
info.keepColor = true;
info.clearColorValue = Vector4::Zero();

info.clearDepth = true;
info.keepDepth = false;
info.keepDepth = true;
info.clearDepthValue = 1.0f;

info.clearStencil = true;
info.keepStencil = true;
info.clearStencilValue = 0;
info.finalPass = false;
info.clearColorValue = Vector4::Zero();
m_forwardOpaquePass->create(*device, selectedSurfaceFormat.format, depthImageFormat, info);

info.clearColor = true;
Expand Down

0 comments on commit a2d125b

Please sign in to comment.