From 741b7848c5bcbeb9216dacd6643c457dd7a4e4db Mon Sep 17 00:00:00 2001 From: kearwood Date: Mon, 26 Sep 2022 22:06:09 -0700 Subject: [PATCH] Implemented camera surface setting for KrUpdateNode and KrCreateNode APIs. Cameras now render only on their assigned surface. --- kraken/KRCamera.cpp | 16 ++++++++++++++-- kraken/KRCamera.h | 1 + kraken/KRSurface.cpp | 5 +++-- kraken/KRSurface.h | 5 +++-- kraken/KRSurfaceManager.cpp | 2 +- kraken/public/kraken.h | 2 +- tests/smoke/hello_cube/hello_cube.cpp | 2 +- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index 36e406c..6563f68 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -39,7 +39,7 @@ void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo) { KRNode::InitNodeInfo(nodeInfo); - nodeInfo->camera.surface = KR_NULL_HANDLE; + nodeInfo->camera.surfaceHandle = 1; nodeInfo->camera.skybox_texture = KR_NULL_HANDLE; } @@ -49,6 +49,7 @@ KrResult KRCamera::update(const KrNodeInfo* nodeInfo) if (res != KR_SUCCESS) { return res; } + m_surfaceHandle = nodeInfo->camera.surfaceHandle; KRTexture* skybox_texture = nullptr; if (nodeInfo->camera.skybox_texture != KR_NULL_HANDLE) { @@ -64,12 +65,12 @@ KrResult KRCamera::update(const KrNodeInfo* nodeInfo) m_skyBox = ""; } - // TODO - Implement surface changes return KR_SUCCESS; } KRCamera::KRCamera(KRScene& scene, std::string name) : KRNode(scene, name) { + m_surfaceHandle = KR_NULL_HANDLE; m_last_frame_start = 0; m_particlesAbsoluteTime = 0.0f; @@ -121,6 +122,12 @@ void KRCamera::loadXML(tinyxml2::XMLElement* e) KRNode::loadXML(e); const char* szSkyBoxName = e->Attribute("skybox"); m_skyBox = szSkyBoxName ? szSkyBoxName : ""; + + unsigned int surfaceHandle = 1; + if (e->QueryUnsignedAttribute("surface", &surfaceHandle) != tinyxml2::XML_SUCCESS) { + surfaceHandle = 1; + } + m_surfaceHandle = surfaceHandle; } void KRCamera::setSkyBox(const std::string& skyBox) @@ -136,6 +143,11 @@ const std::string KRCamera::getSkyBox() const void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeSurface) { + if (compositeSurface.m_handle != m_surfaceHandle) { + // Only render to the assigned surface + return; + } + // ----====---- Record timing information for measuring FPS ----====---- uint64_t current_time = m_pContext->getAbsoluteTimeMilliseconds(); if (m_last_frame_start != 0) { diff --git a/kraken/KRCamera.h b/kraken/KRCamera.h index 202924d..cb28a2a 100755 --- a/kraken/KRCamera.h +++ b/kraken/KRCamera.h @@ -95,6 +95,7 @@ private: void destroyBuffers(); + KrSurfaceHandle m_surfaceHandle; KRTexture* m_pSkyBoxTexture; std::string m_skyBox; KRViewport m_viewport; diff --git a/kraken/KRSurface.cpp b/kraken/KRSurface.cpp index 35091ef..a2bf763 100644 --- a/kraken/KRSurface.cpp +++ b/kraken/KRSurface.cpp @@ -34,11 +34,12 @@ #include "KRRenderPass.h" #ifdef WIN32 -KRSurface::KRSurface(KRContext& context, HWND hWnd) +KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd) #else -KRSurface::KRSurface(KRContext& context) +KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle) #endif : KRContextObject(context) + , m_handle(handle) #ifdef WIN32 , m_hWnd(hWnd) #endif diff --git a/kraken/KRSurface.h b/kraken/KRSurface.h index 011005a..d8c294c 100644 --- a/kraken/KRSurface.h +++ b/kraken/KRSurface.h @@ -42,9 +42,9 @@ class KRSurface : public KRContextObject { public: #ifdef WIN32 - KRSurface(KRContext& context, HWND hWnd); + KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd); #else - KRSurface(KRContext& context); + KRSurface(KRContext& context, KrSurfaceHandle handle); #endif ~KRSurface(); void destroy(); @@ -64,6 +64,7 @@ public: KRRenderPass& getDeferredOpaquePass(); void endFrame(); + KrSurfaceHandle m_handle; #ifdef WIN32 HWND m_hWnd; diff --git a/kraken/KRSurfaceManager.cpp b/kraken/KRSurfaceManager.cpp index 8ace487..d116606 100644 --- a/kraken/KRSurfaceManager.cpp +++ b/kraken/KRSurfaceManager.cpp @@ -53,7 +53,7 @@ KrResult KRSurfaceManager::create(HWND hWnd, KrSurfaceHandle& surfaceHandle) { surfaceHandle = 0; - std::unique_ptr surface = std::make_unique(*m_pContext, hWnd); + std::unique_ptr surface = std::make_unique(*m_pContext, m_topSurfaceHandle, hWnd); KrResult initialize_result = surface->initialize(); if (initialize_result != KR_SUCCESS) { diff --git a/kraken/public/kraken.h b/kraken/public/kraken.h index 59576cf..eaebc61 100644 --- a/kraken/public/kraken.h +++ b/kraken/public/kraken.h @@ -241,7 +241,7 @@ typedef struct struct { // KR_STRUCTURE_TYPE_NODE_CAMERA - KrSurfaceMapIndex surface; + KrSurfaceMapIndex surfaceHandle; KrResourceMapIndex skybox_texture; } camera; struct diff --git a/tests/smoke/hello_cube/hello_cube.cpp b/tests/smoke/hello_cube/hello_cube.cpp index 3a9fafd..a07a740 100644 --- a/tests/smoke/hello_cube/hello_cube.cpp +++ b/tests/smoke/hello_cube/hello_cube.cpp @@ -69,7 +69,7 @@ void smoke_load() create_camera_info.newNodeHandle = kCameraNodeHandle; create_camera_info.sceneHandle = kSceneResourceHandle; create_camera_info.node.pName = "my_camera"; - create_camera_info.node.camera.surface = 1; + create_camera_info.node.camera.surfaceHandle = 1; // create_camera_info.node.camera.skybox_texture = kSkyboxTextureResourceHandle; res = KrCreateNode(&create_camera_info); assert(res == KR_SUCCESS);