Vulkan Refactoring - Added KRRenderPass, WIP refactorign KRScene::RenderFrame
This commit is contained in:
@@ -24,6 +24,7 @@ add_sources(KRCollider.cpp)
|
|||||||
add_sources(KRContext.cpp)
|
add_sources(KRContext.cpp)
|
||||||
add_sources(KRDevice.cpp)
|
add_sources(KRDevice.cpp)
|
||||||
add_sources(KRDeviceManager.cpp)
|
add_sources(KRDeviceManager.cpp)
|
||||||
|
add_sources(KRRenderPass.cpp)
|
||||||
add_sources(KRSurface.cpp)
|
add_sources(KRSurface.cpp)
|
||||||
add_sources(KRSurfaceManager.cpp)
|
add_sources(KRSurfaceManager.cpp)
|
||||||
add_sources(KRStreamerThread.cpp)
|
add_sources(KRStreamerThread.cpp)
|
||||||
|
|||||||
@@ -253,6 +253,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
} else {
|
} else {
|
||||||
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
|
|
||||||
GL_PUSH_GROUP_MARKER("Forward Rendering - Opaque");
|
GL_PUSH_GROUP_MARKER("Forward Rendering - Opaque");
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
@@ -286,17 +289,21 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// Render the geometry
|
// Render the geometry
|
||||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false);
|
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false);
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----====---- Sky Box ----====----
|
// ----====---- Sky Box ----====----
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_PUSH_GROUP_MARKER("Sky Box");
|
GL_PUSH_GROUP_MARKER("Sky Box");
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
@@ -313,6 +320,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
GLDEBUG(glEnable(GL_DEPTH_TEST));
|
||||||
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
GLDEBUG(glDepthFunc(GL_LEQUAL));
|
||||||
GLDEBUG(glDepthRangef(0.0, 1.0));
|
GLDEBUG(glDepthRangef(0.0, 1.0));
|
||||||
|
*/
|
||||||
|
|
||||||
if(!m_pSkyBoxTexture && m_skyBox.length()) {
|
if(!m_pSkyBoxTexture && m_skyBox.length()) {
|
||||||
m_pSkyBoxTexture = getContext().getTextureManager()->getTextureCube(m_skyBox.c_str());
|
m_pSkyBoxTexture = getContext().getTextureManager()->getTextureCube(m_skyBox.c_str());
|
||||||
@@ -328,11 +336,16 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_PUSH_GROUP_MARKER("Forward Rendering - Transparent");
|
GL_PUSH_GROUP_MARKER("Forward Rendering - Transparent");
|
||||||
|
|
||||||
// Note: These parameters have already been set up by the skybox render above
|
// Note: These parameters have already been set up by the skybox render above
|
||||||
@@ -360,13 +373,20 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLDEBUG(glEnable(GL_BLEND));
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// Render all transparent geometry
|
// Render all transparent geometry
|
||||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, false);
|
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, false);
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
|
*/
|
||||||
|
|
||||||
// ----====---- Particle Occlusion Tests ----====----
|
// ----====---- Particle Occlusion Tests ----====----
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_PUSH_GROUP_MARKER("Particle Occlusion Tests");
|
GL_PUSH_GROUP_MARKER("Particle Occlusion Tests");
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
@@ -388,13 +408,20 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLDEBUG(glEnable(GL_BLEND));
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// ----====---- Perform Occlusion Tests ----====----
|
// ----====---- Perform Occlusion Tests ----====----
|
||||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, RENDER_PASS_PARTICLE_OCCLUSION, false);
|
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, RENDER_PASS_PARTICLE_OCCLUSION, false);
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
|
*/
|
||||||
|
|
||||||
// ----====---- Flares ----====----
|
// ----====---- Flares ----====----
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_PUSH_GROUP_MARKER("Additive Particles");
|
GL_PUSH_GROUP_MARKER("Additive Particles");
|
||||||
|
|
||||||
// Set render target
|
// Set render target
|
||||||
@@ -415,10 +442,15 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLDEBUG(glEnable(GL_BLEND));
|
GLDEBUG(glEnable(GL_BLEND));
|
||||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// Render all flares
|
// Render all flares
|
||||||
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_ADDITIVE_PARTICLES, false);
|
scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_ADDITIVE_PARTICLES, false);
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
|
*/
|
||||||
|
|
||||||
// ----====---- Volumetric Lighting ----====----
|
// ----====---- Volumetric Lighting ----====----
|
||||||
|
|
||||||
@@ -463,7 +495,10 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
|
|
||||||
// ----====---- Debug Overlay ----====----
|
// ----====---- Debug Overlay ----====----
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_PUSH_GROUP_MARKER("Debug Overlays");
|
GL_PUSH_GROUP_MARKER("Debug Overlays");
|
||||||
|
*/
|
||||||
|
|
||||||
if(settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) {
|
if(settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) {
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
@@ -493,16 +528,22 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
// Re-enable z-buffer write
|
// Re-enable z-buffer write
|
||||||
GLDEBUG(glDepthMask(GL_TRUE));
|
GLDEBUG(glDepthMask(GL_TRUE));
|
||||||
|
|
||||||
GL_POP_GROUP_MARKER;
|
GL_POP_GROUP_MARKER;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i/%i Kbyte (active/total) Shader Handles: %i Visible Bounds: %i Max Texture LOD: %i\n", (int)m_pContext->getMeshManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getActiveMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024, (int)m_pContext->getPipelineManager()->getShaderHandlesUsed(), (int)m_visibleBounds.size(), m_pContext->getTextureManager()->getLODDimCap());
|
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i/%i Kbyte (active/total) Shader Handles: %i Visible Bounds: %i Max Texture LOD: %i\n", (int)m_pContext->getMeshManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getActiveMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024, (int)m_pContext->getPipelineManager()->getShaderHandlesUsed(), (int)m_visibleBounds.size(), m_pContext->getTextureManager()->getLODDimCap());
|
||||||
|
// TODO - Vulkan refactoring...
|
||||||
|
/*
|
||||||
GL_PUSH_GROUP_MARKER("Post Processing");
|
GL_PUSH_GROUP_MARKER("Post Processing");
|
||||||
|
|
||||||
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO));
|
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO));
|
||||||
|
|
||||||
renderPost(commandBuffer);
|
renderPost(commandBuffer);
|
||||||
m_pContext->getMeshManager()->unbindVBO();
|
m_pContext->getMeshManager()->unbindVBO();
|
||||||
|
|
||||||
@@ -514,11 +555,13 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi
|
|||||||
GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0};
|
GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0};
|
||||||
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments));
|
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments));
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void KRCamera::createBuffers(GLint renderBufferWidth, GLint renderBufferHeight) {
|
void KRCamera::createBuffers(GLint renderBufferWidth, GLint renderBufferHeight) {
|
||||||
|
// TODO - Vulkan Refactoring..
|
||||||
|
/*
|
||||||
if(renderBufferWidth != m_backingWidth || renderBufferHeight != m_backingHeight) {
|
if(renderBufferWidth != m_backingWidth || renderBufferHeight != m_backingHeight) {
|
||||||
m_backingWidth = renderBufferWidth;
|
m_backingWidth = renderBufferWidth;
|
||||||
m_backingHeight = renderBufferHeight;
|
m_backingHeight = renderBufferHeight;
|
||||||
@@ -629,10 +672,13 @@ void KRCamera::createBuffers(GLint renderBufferWidth, GLint renderBufferHeight)
|
|||||||
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, volumetricLightAccumulationTexture, 0));
|
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, volumetricLightAccumulationTexture, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRCamera::destroyBuffers()
|
void KRCamera::destroyBuffers()
|
||||||
{
|
{
|
||||||
|
// TODO - Vulkan Refactoring..
|
||||||
|
/*
|
||||||
if (compositeDepthTexture) {
|
if (compositeDepthTexture) {
|
||||||
GLDEBUG(glDeleteTextures(1, &compositeDepthTexture));
|
GLDEBUG(glDeleteTextures(1, &compositeDepthTexture));
|
||||||
compositeDepthTexture = 0;
|
compositeDepthTexture = 0;
|
||||||
@@ -667,6 +713,7 @@ void KRCamera::destroyBuffers()
|
|||||||
GLDEBUG(glDeleteFramebuffers(1, &volumetricLightAccumulationBuffer));
|
GLDEBUG(glDeleteFramebuffers(1, &volumetricLightAccumulationBuffer));
|
||||||
volumetricLightAccumulationBuffer = 0;
|
volumetricLightAccumulationBuffer = 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ void KRPresentationThread::renderFrame()
|
|||||||
|
|
||||||
unordered_map<KrSurfaceHandle, std::unique_ptr<KRSurface>>& surfaces = m_pContext->getSurfaceManager()->getSurfaces();
|
unordered_map<KrSurfaceHandle, std::unique_ptr<KRSurface>>& surfaces = m_pContext->getSurfaceManager()->getSurfaces();
|
||||||
|
|
||||||
|
KRSceneManager* sceneManager = m_pContext->getSceneManager();
|
||||||
|
KRScene *scene = sceneManager->getFirstScene();
|
||||||
|
|
||||||
for (auto surfaceItr = surfaces.begin(); surfaceItr != surfaces.end(); surfaceItr++) {
|
for (auto surfaceItr = surfaces.begin(); surfaceItr != surfaces.end(); surfaceItr++) {
|
||||||
KRSurface& surface = *(*surfaceItr).second;
|
KRSurface& surface = *(*surfaceItr).second;
|
||||||
KRDevice& device = *m_pContext->getDeviceManager()->getDevice(surface.m_deviceHandle);
|
KRDevice& device = *m_pContext->getDeviceManager()->getDevice(surface.m_deviceHandle);
|
||||||
@@ -183,8 +186,9 @@ void KRPresentationThread::renderFrame()
|
|||||||
|
|
||||||
// TODO - This needs to be moved to the Render thread...
|
// TODO - This needs to be moved to the Render thread...
|
||||||
float deltaTime = 0.005; // TODO - Replace dummy value
|
float deltaTime = 0.005; // TODO - Replace dummy value
|
||||||
m_pContext->startFrame(deltaTime);
|
if (scene) {
|
||||||
m_pContext->endFrame(deltaTime);
|
scene->renderFrame(commandBuffer, 0, deltaTime, surface.m_swapChainExtent.width, surface.m_swapChainExtent.height);
|
||||||
|
}
|
||||||
|
|
||||||
VkSubmitInfo submitInfo{};
|
VkSubmitInfo submitInfo{};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
|
|||||||
117
kraken/KRRenderPass.cpp
Normal file
117
kraken/KRRenderPass.cpp
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
//
|
||||||
|
// KRSurface.cpp
|
||||||
|
// Kraken Engine
|
||||||
|
//
|
||||||
|
// Copyright 2022 Kearwood Gilbert. All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
// provided with the distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||||
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// The views and conclusions contained in the software and documentation are those of the
|
||||||
|
// authors and should not be interpreted as representing official policies, either expressed
|
||||||
|
// or implied, of Kearwood Gilbert.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "KRRenderPass.h"
|
||||||
|
|
||||||
|
KRRenderPass::KRRenderPass(KRContext& context)
|
||||||
|
: KRContextObject(context)
|
||||||
|
, m_renderPass(VK_NULL_HANDLE)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
KRRenderPass::~KRRenderPass()
|
||||||
|
{
|
||||||
|
assert(m_renderPass == VK_NULL_HANDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRRenderPass::create(KRDevice &device, VkFormat swapChainImageFormat, VkFormat depthImageFormat)
|
||||||
|
{
|
||||||
|
if (m_renderPass) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkAttachmentDescription colorAttachment{};
|
||||||
|
colorAttachment.format = swapChainImageFormat;
|
||||||
|
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
|
||||||
|
|
||||||
|
VkAttachmentDescription depthAttachment{};
|
||||||
|
depthAttachment.format = depthImageFormat;
|
||||||
|
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||||
|
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
|
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
|
depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
|
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
|
VkAttachmentReference depthAttachmentRef{};
|
||||||
|
depthAttachmentRef.attachment = 1;
|
||||||
|
depthAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
|
VkAttachmentReference colorAttachmentRef{};
|
||||||
|
colorAttachmentRef.attachment = 0;
|
||||||
|
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
|
VkSubpassDescription subpass{};
|
||||||
|
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
|
subpass.colorAttachmentCount = 1;
|
||||||
|
subpass.pColorAttachments = &colorAttachmentRef;
|
||||||
|
subpass.pDepthStencilAttachment = &depthAttachmentRef;
|
||||||
|
|
||||||
|
VkSubpassDependency dependency{};
|
||||||
|
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||||
|
dependency.dstSubpass = 0;
|
||||||
|
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
||||||
|
dependency.srcAccessMask = 0;
|
||||||
|
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
||||||
|
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||||
|
|
||||||
|
std::array<VkAttachmentDescription, 2> attachments = { colorAttachment, depthAttachment };
|
||||||
|
|
||||||
|
VkRenderPassCreateInfo renderPassInfo{};
|
||||||
|
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||||
|
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
|
||||||
|
renderPassInfo.pAttachments = attachments.data();
|
||||||
|
renderPassInfo.subpassCount = 1;
|
||||||
|
renderPassInfo.pSubpasses = &subpass;
|
||||||
|
renderPassInfo.dependencyCount = 1;
|
||||||
|
renderPassInfo.pDependencies = &dependency;
|
||||||
|
|
||||||
|
if (vkCreateRenderPass(device.m_logicalDevice, &renderPassInfo, nullptr, &m_renderPass) != VK_SUCCESS) {
|
||||||
|
// failed! TODO - Error handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KRRenderPass::destroy(KRDevice &device)
|
||||||
|
{
|
||||||
|
if (m_renderPass) {
|
||||||
|
vkDestroyRenderPass(device.m_logicalDevice, m_renderPass, nullptr);
|
||||||
|
m_renderPass = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
51
kraken/KRRenderPass.h
Normal file
51
kraken/KRRenderPass.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
//
|
||||||
|
// KRScene.h
|
||||||
|
// Kraken Engine
|
||||||
|
//
|
||||||
|
// Copyright 2022 Kearwood Gilbert. All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
// provided with the distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||||
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// The views and conclusions contained in the software and documentation are those of the
|
||||||
|
// authors and should not be interpreted as representing official policies, either expressed
|
||||||
|
// or implied, of Kearwood Gilbert.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef KRRENDERPASS_H
|
||||||
|
#define KRRENDERPASS_H
|
||||||
|
|
||||||
|
#include "KREngine-common.h"
|
||||||
|
#include "KRContext.h"
|
||||||
|
|
||||||
|
class KRRenderPass : public KRContextObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
KRRenderPass(KRContext& context);
|
||||||
|
~KRRenderPass();
|
||||||
|
void create(KRDevice& device, VkFormat swapChainImageFormat, VkFormat depthImageFormat);
|
||||||
|
void destroy(KRDevice& device);
|
||||||
|
|
||||||
|
// private:
|
||||||
|
VkRenderPass m_renderPass;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // KRRENDERPASS_H
|
||||||
@@ -59,6 +59,7 @@ KRResource* KRSceneManager::getResource(const std::string& name, const std::stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) {
|
KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
std::string lowerName = name;
|
std::string lowerName = name;
|
||||||
std::transform(lowerName.begin(), lowerName.end(),
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
lowerName.begin(), ::tolower);
|
lowerName.begin(), ::tolower);
|
||||||
@@ -79,6 +80,7 @@ KRScene* KRSceneManager::createScene(const std::string& name)
|
|||||||
|
|
||||||
void KRSceneManager::add(KRScene *scene)
|
void KRSceneManager::add(KRScene *scene)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
std::string lowerName = scene->getName();
|
std::string lowerName = scene->getName();
|
||||||
std::transform(lowerName.begin(), lowerName.end(),
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
lowerName.begin(), ::tolower);
|
lowerName.begin(), ::tolower);
|
||||||
@@ -86,6 +88,7 @@ void KRSceneManager::add(KRScene *scene)
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::getScene(const std::string &name) {
|
KRScene *KRSceneManager::getScene(const std::string &name) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
std::string lowerName = name;
|
std::string lowerName = name;
|
||||||
std::transform(lowerName.begin(), lowerName.end(),
|
std::transform(lowerName.begin(), lowerName.end(),
|
||||||
lowerName.begin(), ::tolower);
|
lowerName.begin(), ::tolower);
|
||||||
@@ -99,7 +102,8 @@ KRScene *KRSceneManager::getScene(const std::string &name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
KRScene *KRSceneManager::getFirstScene() {
|
KRScene *KRSceneManager::getFirstScene() {
|
||||||
static unordered_map<std::string, KRScene *>::iterator scene_itr = m_scenes.begin();
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
unordered_map<std::string, KRScene *>::iterator scene_itr = m_scenes.begin();
|
||||||
if(scene_itr != m_scenes.end()) {
|
if(scene_itr != m_scenes.end()) {
|
||||||
return (*scene_itr).second;
|
return (*scene_itr).second;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
unordered_map<std::string, KRScene *> m_scenes;
|
unordered_map<std::string, KRScene *> m_scenes;
|
||||||
|
std::mutex m_mutex;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "KRSurface.h"
|
#include "KRSurface.h"
|
||||||
|
#include "KRRenderPass.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
KRSurface::KRSurface(KRContext& context, HWND hWnd)
|
KRSurface::KRSurface(KRContext& context, HWND hWnd)
|
||||||
@@ -51,9 +52,8 @@ KRSurface::KRSurface(KRContext& context)
|
|||||||
, m_depthImageView(VK_NULL_HANDLE)
|
, m_depthImageView(VK_NULL_HANDLE)
|
||||||
, m_imageAvailableSemaphore(VK_NULL_HANDLE)
|
, m_imageAvailableSemaphore(VK_NULL_HANDLE)
|
||||||
, m_renderFinishedSemaphore(VK_NULL_HANDLE)
|
, m_renderFinishedSemaphore(VK_NULL_HANDLE)
|
||||||
, m_renderPass(VK_NULL_HANDLE)
|
|
||||||
{
|
{
|
||||||
|
m_forwardOpaquePass = std::make_unique<KRRenderPass>(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRSurface::~KRSurface()
|
KRSurface::~KRSurface()
|
||||||
@@ -96,9 +96,8 @@ void KRSurface::destroy()
|
|||||||
|
|
||||||
std::unique_ptr<KRDevice>& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle);
|
std::unique_ptr<KRDevice>& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle);
|
||||||
|
|
||||||
if (m_renderPass) {
|
if (m_forwardOpaquePass) {
|
||||||
vkDestroyRenderPass(device->m_logicalDevice, m_renderPass, nullptr);
|
m_forwardOpaquePass->destroy(*device);
|
||||||
m_renderPass = VK_NULL_HANDLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device && m_renderFinishedSemaphore != VK_NULL_HANDLE) {
|
if (device && m_renderFinishedSemaphore != VK_NULL_HANDLE) {
|
||||||
@@ -388,74 +387,13 @@ KrResult KRSurface::recreateSwapChain()
|
|||||||
|
|
||||||
void KRSurface::createRenderPasses()
|
void KRSurface::createRenderPasses()
|
||||||
{
|
{
|
||||||
if (m_renderPass) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
VkAttachmentDescription colorAttachment{};
|
|
||||||
colorAttachment.format = m_swapChainImageFormat;
|
|
||||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
||||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
|
||||||
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
||||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
||||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
||||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
|
||||||
|
|
||||||
|
|
||||||
VkAttachmentDescription depthAttachment{};
|
|
||||||
depthAttachment.format = m_depthImageFormat;
|
|
||||||
depthAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
|
||||||
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
||||||
depthAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
|
||||||
depthAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
|
||||||
depthAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
||||||
depthAttachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
||||||
|
|
||||||
VkAttachmentReference depthAttachmentRef{};
|
|
||||||
depthAttachmentRef.attachment = 1;
|
|
||||||
depthAttachmentRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
||||||
|
|
||||||
VkAttachmentReference colorAttachmentRef{};
|
|
||||||
colorAttachmentRef.attachment = 0;
|
|
||||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
||||||
|
|
||||||
VkSubpassDescription subpass{};
|
|
||||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
|
||||||
subpass.colorAttachmentCount = 1;
|
|
||||||
subpass.pColorAttachments = &colorAttachmentRef;
|
|
||||||
subpass.pDepthStencilAttachment = &depthAttachmentRef;
|
|
||||||
|
|
||||||
VkSubpassDependency dependency{};
|
|
||||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
|
||||||
dependency.dstSubpass = 0;
|
|
||||||
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
|
||||||
dependency.srcAccessMask = 0;
|
|
||||||
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
|
||||||
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
|
||||||
|
|
||||||
std::array<VkAttachmentDescription, 2> attachments = { colorAttachment, depthAttachment };
|
|
||||||
|
|
||||||
VkRenderPassCreateInfo renderPassInfo{};
|
|
||||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
|
||||||
renderPassInfo.attachmentCount = static_cast<uint32_t>(attachments.size());
|
|
||||||
renderPassInfo.pAttachments = attachments.data();
|
|
||||||
renderPassInfo.subpassCount = 1;
|
|
||||||
renderPassInfo.pSubpasses = &subpass;
|
|
||||||
renderPassInfo.dependencyCount = 1;
|
|
||||||
renderPassInfo.pDependencies = &dependency;
|
|
||||||
|
|
||||||
std::unique_ptr<KRDevice>& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle);
|
std::unique_ptr<KRDevice>& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle);
|
||||||
|
m_forwardOpaquePass->create(*device, m_swapChainImageFormat, m_depthImageFormat);
|
||||||
if (vkCreateRenderPass(device->m_logicalDevice, &renderPassInfo, nullptr, &m_renderPass) != VK_SUCCESS) {
|
|
||||||
// failed! TODO - Error handling
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkRenderPass& KRSurface::getRenderPass()
|
VkRenderPass& KRSurface::getRenderPass()
|
||||||
{
|
{
|
||||||
return m_renderPass;
|
return m_forwardOpaquePass->m_renderPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<KRDevice>& KRSurface::getDevice()
|
std::unique_ptr<KRDevice>& KRSurface::getDevice()
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#define KRSURFACE_H
|
#define KRSURFACE_H
|
||||||
|
|
||||||
class KRDevice;
|
class KRDevice;
|
||||||
|
class KRRenderPass;
|
||||||
|
|
||||||
class KRSurface : public KRContextObject
|
class KRSurface : public KRContextObject
|
||||||
{
|
{
|
||||||
@@ -78,8 +79,7 @@ public:
|
|||||||
VkSemaphore m_imageAvailableSemaphore;
|
VkSemaphore m_imageAvailableSemaphore;
|
||||||
VkSemaphore m_renderFinishedSemaphore;
|
VkSemaphore m_renderFinishedSemaphore;
|
||||||
|
|
||||||
// TODO - Move this to a higher context
|
std::unique_ptr<KRRenderPass> m_forwardOpaquePass;
|
||||||
VkRenderPass m_renderPass;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void destroySwapChain();
|
void destroySwapChain();
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ void KRTextureManager::_clearGLState()
|
|||||||
for(int i=0; i < KRENGINE_MAX_TEXTURE_UNITS; i++) {
|
for(int i=0; i < KRENGINE_MAX_TEXTURE_UNITS; i++) {
|
||||||
m_wrapModeS[i] = 0;
|
m_wrapModeS[i] = 0;
|
||||||
m_wrapModeT[i] = 0;
|
m_wrapModeT[i] = 0;
|
||||||
m_maxAnisotropy[i] = -1.0f;
|
m_maxAnisotropy = -1.0f;
|
||||||
selectTexture(i, NULL, 0.0f, KRTexture::TEXTURE_USAGE_NONE);
|
selectTexture(i, NULL, 0.0f, KRTexture::TEXTURE_USAGE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,22 +95,9 @@ void KRTextureManager::_setWrapModeS(GLuint i, GLuint wrap_mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRTextureManager::_setMaxAnisotropy(int i, float max_anisotropy)
|
|
||||||
{
|
|
||||||
#if !defined(ANDROID)
|
|
||||||
if(m_maxAnisotropy[i] != max_anisotropy) {
|
|
||||||
_setActiveTexture(i);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
|
|
||||||
m_maxAnisotropy[i] = max_anisotropy;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void KRTextureManager::setMaxAnisotropy(float max_anisotropy)
|
void KRTextureManager::setMaxAnisotropy(float max_anisotropy)
|
||||||
{
|
{
|
||||||
for(int i=0; i < KRENGINE_MAX_TEXTURE_UNITS; i++) {
|
m_maxAnisotropy = max_anisotropy;
|
||||||
_setMaxAnisotropy(i, max_anisotropy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRTextureManager::_setWrapModeT(GLuint i, GLuint wrap_mode)
|
void KRTextureManager::_setWrapModeT(GLuint i, GLuint wrap_mode)
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ public:
|
|||||||
void _setActiveTexture(int i);
|
void _setActiveTexture(int i);
|
||||||
void _setWrapModeS(GLuint i, GLuint wrap_mode);
|
void _setWrapModeS(GLuint i, GLuint wrap_mode);
|
||||||
void _setWrapModeT(GLuint i, GLuint wrap_mode);
|
void _setWrapModeT(GLuint i, GLuint wrap_mode);
|
||||||
void _setMaxAnisotropy(int i, float max_anisotropy);
|
|
||||||
|
|
||||||
void _clearGLState();
|
void _clearGLState();
|
||||||
void setMaxAnisotropy(float max_anisotropy);
|
void setMaxAnisotropy(float max_anisotropy);
|
||||||
@@ -98,7 +97,7 @@ private:
|
|||||||
int m_boundTextureHandles[KRENGINE_MAX_TEXTURE_UNITS];
|
int m_boundTextureHandles[KRENGINE_MAX_TEXTURE_UNITS];
|
||||||
GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS];
|
GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS];
|
||||||
GLuint m_wrapModeT[KRENGINE_MAX_TEXTURE_UNITS];
|
GLuint m_wrapModeT[KRENGINE_MAX_TEXTURE_UNITS];
|
||||||
float m_maxAnisotropy[KRENGINE_MAX_TEXTURE_UNITS];
|
float m_maxAnisotropy;
|
||||||
|
|
||||||
|
|
||||||
std::set<KRTexture *> m_activeTextures;
|
std::set<KRTexture *> m_activeTextures;
|
||||||
|
|||||||
Reference in New Issue
Block a user