diff --git a/kraken/CMakeLists.txt b/kraken/CMakeLists.txt index e5d0957..7043d4e 100644 --- a/kraken/CMakeLists.txt +++ b/kraken/CMakeLists.txt @@ -24,6 +24,7 @@ add_sources(KRCollider.cpp) add_sources(KRContext.cpp) add_sources(KRDevice.cpp) add_sources(KRDeviceManager.cpp) +add_sources(KRRenderPass.cpp) add_sources(KRSurface.cpp) add_sources(KRSurfaceManager.cpp) add_sources(KRStreamerThread.cpp) diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index 9b1591a..7b2a073 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -253,6 +253,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi } else { // ----====---- Opaque Geometry, Forward Rendering ----====---- + // TODO - Vulkan refactoring... + /* + GL_PUSH_GROUP_MARKER("Forward Rendering - Opaque"); // Set render target @@ -286,17 +289,21 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi GLDEBUG(glDepthFunc(GL_LEQUAL)); GLDEBUG(glDepthRangef(0.0, 1.0)); - + */ // Render the geometry scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false); + // TODO - Vulkan refactoring... +/* GL_POP_GROUP_MARKER; +*/ } // ----====---- Sky Box ----====---- - + // TODO - Vulkan refactoring... + /* GL_PUSH_GROUP_MARKER("Sky Box"); // Set render target @@ -313,6 +320,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi GLDEBUG(glEnable(GL_DEPTH_TEST)); GLDEBUG(glDepthFunc(GL_LEQUAL)); GLDEBUG(glDepthRangef(0.0, 1.0)); + */ if(!m_pSkyBoxTexture && m_skyBox.length()) { 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)); } + // TODO - Vulkan refactoring... + /* GL_POP_GROUP_MARKER; + */ // ----====---- Transparent Geometry, Forward Rendering ----====---- + // TODO - Vulkan refactoring... + /* GL_PUSH_GROUP_MARKER("Forward Rendering - Transparent"); // Note: These parameters have already been set up by the skybox render above @@ -359,14 +372,21 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi // Enable alpha blending GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + + */ // Render all transparent geometry scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, false); + // TODO - Vulkan refactoring... + /* GL_POP_GROUP_MARKER; + */ // ----====---- Particle Occlusion Tests ----====---- + // TODO - Vulkan refactoring... + /* GL_PUSH_GROUP_MARKER("Particle Occlusion Tests"); // Set render target @@ -387,14 +407,21 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE)); + + */ // ----====---- Perform Occlusion Tests ----====---- scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, RENDER_PASS_PARTICLE_OCCLUSION, false); + // TODO - Vulkan refactoring... + /* GL_POP_GROUP_MARKER; + */ // ----====---- Flares ----====---- + // TODO - Vulkan refactoring... + /* GL_PUSH_GROUP_MARKER("Additive Particles"); // Set render target @@ -414,11 +441,16 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE)); + + */ // Render all flares scene.render(commandBuffer, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_ADDITIVE_PARTICLES, false); + // TODO - Vulkan refactoring... + /* GL_POP_GROUP_MARKER; + */ // ----====---- Volumetric Lighting ----====---- @@ -463,7 +495,10 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi // ----====---- Debug Overlay ----====---- + // TODO - Vulkan refactoring... + /* GL_PUSH_GROUP_MARKER("Debug Overlays"); + */ if(settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) { // Enable z-buffer test @@ -493,32 +528,40 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, GLint defaultFBO, GLi } } + // TODO - Vulkan refactoring... +/* // Re-enable z-buffer write GLDEBUG(glDepthMask(GL_TRUE)); 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()); + // TODO - Vulkan refactoring... + /* GL_PUSH_GROUP_MARKER("Post Processing"); GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO)); + renderPost(commandBuffer); m_pContext->getMeshManager()->unbindVBO(); GL_POP_GROUP_MARKER; - + #if GL_EXT_discard_framebuffer GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0}; GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments)); #endif + */ } void KRCamera::createBuffers(GLint renderBufferWidth, GLint renderBufferHeight) { - + // TODO - Vulkan Refactoring.. +/* if(renderBufferWidth != m_backingWidth || renderBufferHeight != m_backingHeight) { m_backingWidth = renderBufferWidth; 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)); } } + */ } void KRCamera::destroyBuffers() { + // TODO - Vulkan Refactoring.. + /* if (compositeDepthTexture) { GLDEBUG(glDeleteTextures(1, &compositeDepthTexture)); compositeDepthTexture = 0; @@ -667,6 +713,7 @@ void KRCamera::destroyBuffers() GLDEBUG(glDeleteFramebuffers(1, &volumetricLightAccumulationBuffer)); volumetricLightAccumulationBuffer = 0; } + */ } void KRCamera::renderPost(VkCommandBuffer& commandBuffer) diff --git a/kraken/KRPresentationThread.cpp b/kraken/KRPresentationThread.cpp index d962fd9..3b3b75e 100644 --- a/kraken/KRPresentationThread.cpp +++ b/kraken/KRPresentationThread.cpp @@ -103,6 +103,9 @@ void KRPresentationThread::renderFrame() unordered_map>& surfaces = m_pContext->getSurfaceManager()->getSurfaces(); + KRSceneManager* sceneManager = m_pContext->getSceneManager(); + KRScene *scene = sceneManager->getFirstScene(); + for (auto surfaceItr = surfaces.begin(); surfaceItr != surfaces.end(); surfaceItr++) { KRSurface& surface = *(*surfaceItr).second; 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... float deltaTime = 0.005; // TODO - Replace dummy value - m_pContext->startFrame(deltaTime); - m_pContext->endFrame(deltaTime); + if (scene) { + scene->renderFrame(commandBuffer, 0, deltaTime, surface.m_swapChainExtent.width, surface.m_swapChainExtent.height); + } VkSubmitInfo submitInfo{}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; diff --git a/kraken/KRRenderPass.cpp b/kraken/KRRenderPass.cpp new file mode 100644 index 0000000..ac75310 --- /dev/null +++ b/kraken/KRRenderPass.cpp @@ -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 attachments = { colorAttachment, depthAttachment }; + + VkRenderPassCreateInfo renderPassInfo{}; + renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + renderPassInfo.attachmentCount = static_cast(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; + } +} \ No newline at end of file diff --git a/kraken/KRRenderPass.h b/kraken/KRRenderPass.h new file mode 100644 index 0000000..e406942 --- /dev/null +++ b/kraken/KRRenderPass.h @@ -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 \ No newline at end of file diff --git a/kraken/KRSceneManager.cpp b/kraken/KRSceneManager.cpp index 0db004d..67a3f0e 100755 --- a/kraken/KRSceneManager.cpp +++ b/kraken/KRSceneManager.cpp @@ -59,6 +59,7 @@ KRResource* KRSceneManager::getResource(const std::string& name, const std::stri } KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) { + std::lock_guard lock(m_mutex); std::string lowerName = name; std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); @@ -79,6 +80,7 @@ KRScene* KRSceneManager::createScene(const std::string& name) void KRSceneManager::add(KRScene *scene) { + std::lock_guard lock(m_mutex); std::string lowerName = scene->getName(); std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); @@ -86,6 +88,7 @@ void KRSceneManager::add(KRScene *scene) } KRScene *KRSceneManager::getScene(const std::string &name) { + std::lock_guard lock(m_mutex); std::string lowerName = name; std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower); @@ -99,7 +102,8 @@ KRScene *KRSceneManager::getScene(const std::string &name) { } KRScene *KRSceneManager::getFirstScene() { - static unordered_map::iterator scene_itr = m_scenes.begin(); + std::lock_guard lock(m_mutex); + unordered_map::iterator scene_itr = m_scenes.begin(); if(scene_itr != m_scenes.end()) { return (*scene_itr).second; } else { diff --git a/kraken/KRSceneManager.h b/kraken/KRSceneManager.h index 60280ff..053bd42 100755 --- a/kraken/KRSceneManager.h +++ b/kraken/KRSceneManager.h @@ -63,6 +63,7 @@ public: private: unordered_map m_scenes; + std::mutex m_mutex; }; diff --git a/kraken/KRSurface.cpp b/kraken/KRSurface.cpp index cc489db..16f3041 100644 --- a/kraken/KRSurface.cpp +++ b/kraken/KRSurface.cpp @@ -30,6 +30,7 @@ // #include "KRSurface.h" +#include "KRRenderPass.h" #ifdef WIN32 KRSurface::KRSurface(KRContext& context, HWND hWnd) @@ -51,9 +52,8 @@ KRSurface::KRSurface(KRContext& context) , m_depthImageView(VK_NULL_HANDLE) , m_imageAvailableSemaphore(VK_NULL_HANDLE) , m_renderFinishedSemaphore(VK_NULL_HANDLE) - , m_renderPass(VK_NULL_HANDLE) { - + m_forwardOpaquePass = std::make_unique(context); } KRSurface::~KRSurface() @@ -95,10 +95,9 @@ void KRSurface::destroy() destroySwapChain(); std::unique_ptr& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle); - - if (m_renderPass) { - vkDestroyRenderPass(device->m_logicalDevice, m_renderPass, nullptr); - m_renderPass = VK_NULL_HANDLE; + + if (m_forwardOpaquePass) { + m_forwardOpaquePass->destroy(*device); } if (device && m_renderFinishedSemaphore != VK_NULL_HANDLE) { @@ -388,74 +387,13 @@ KrResult KRSurface::recreateSwapChain() 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 attachments = { colorAttachment, depthAttachment }; - - VkRenderPassCreateInfo renderPassInfo{}; - renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - renderPassInfo.attachmentCount = static_cast(attachments.size()); - renderPassInfo.pAttachments = attachments.data(); - renderPassInfo.subpassCount = 1; - renderPassInfo.pSubpasses = &subpass; - renderPassInfo.dependencyCount = 1; - renderPassInfo.pDependencies = &dependency; - std::unique_ptr& device = m_pContext->getDeviceManager()->getDevice(m_deviceHandle); - - if (vkCreateRenderPass(device->m_logicalDevice, &renderPassInfo, nullptr, &m_renderPass) != VK_SUCCESS) { - // failed! TODO - Error handling - } + m_forwardOpaquePass->create(*device, m_swapChainImageFormat, m_depthImageFormat); } VkRenderPass& KRSurface::getRenderPass() { - return m_renderPass; + return m_forwardOpaquePass->m_renderPass; } std::unique_ptr& KRSurface::getDevice() diff --git a/kraken/KRSurface.h b/kraken/KRSurface.h index a6ed1bb..e31b14e 100644 --- a/kraken/KRSurface.h +++ b/kraken/KRSurface.h @@ -36,6 +36,7 @@ #define KRSURFACE_H class KRDevice; +class KRRenderPass; class KRSurface : public KRContextObject { @@ -78,8 +79,7 @@ public: VkSemaphore m_imageAvailableSemaphore; VkSemaphore m_renderFinishedSemaphore; - // TODO - Move this to a higher context - VkRenderPass m_renderPass; + std::unique_ptr m_forwardOpaquePass; private: void destroySwapChain(); diff --git a/kraken/KRTextureManager.cpp b/kraken/KRTextureManager.cpp index db8996b..b7e657b 100755 --- a/kraken/KRTextureManager.cpp +++ b/kraken/KRTextureManager.cpp @@ -71,7 +71,7 @@ void KRTextureManager::_clearGLState() for(int i=0; i < KRENGINE_MAX_TEXTURE_UNITS; i++) { m_wrapModeS[i] = 0; m_wrapModeT[i] = 0; - m_maxAnisotropy[i] = -1.0f; + m_maxAnisotropy = -1.0f; 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) { - for(int i=0; i < KRENGINE_MAX_TEXTURE_UNITS; i++) { - _setMaxAnisotropy(i, max_anisotropy); - } + m_maxAnisotropy = max_anisotropy; } void KRTextureManager::_setWrapModeT(GLuint i, GLuint wrap_mode) diff --git a/kraken/KRTextureManager.h b/kraken/KRTextureManager.h index 02e888c..3954422 100755 --- a/kraken/KRTextureManager.h +++ b/kraken/KRTextureManager.h @@ -79,7 +79,6 @@ public: void _setActiveTexture(int i); void _setWrapModeS(GLuint i, GLuint wrap_mode); void _setWrapModeT(GLuint i, GLuint wrap_mode); - void _setMaxAnisotropy(int i, float max_anisotropy); void _clearGLState(); void setMaxAnisotropy(float max_anisotropy); @@ -98,7 +97,7 @@ private: int m_boundTextureHandles[KRENGINE_MAX_TEXTURE_UNITS]; GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS]; GLuint m_wrapModeT[KRENGINE_MAX_TEXTURE_UNITS]; - float m_maxAnisotropy[KRENGINE_MAX_TEXTURE_UNITS]; + float m_maxAnisotropy; std::set m_activeTextures;