Implemented camera surface setting for KrUpdateNode and KrCreateNode APIs.
Cameras now render only on their assigned surface.
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
|
void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
|
||||||
{
|
{
|
||||||
KRNode::InitNodeInfo(nodeInfo);
|
KRNode::InitNodeInfo(nodeInfo);
|
||||||
nodeInfo->camera.surface = KR_NULL_HANDLE;
|
nodeInfo->camera.surfaceHandle = 1;
|
||||||
nodeInfo->camera.skybox_texture = KR_NULL_HANDLE;
|
nodeInfo->camera.skybox_texture = KR_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +49,7 @@ KrResult KRCamera::update(const KrNodeInfo* nodeInfo)
|
|||||||
if (res != KR_SUCCESS) {
|
if (res != KR_SUCCESS) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
m_surfaceHandle = nodeInfo->camera.surfaceHandle;
|
||||||
|
|
||||||
KRTexture* skybox_texture = nullptr;
|
KRTexture* skybox_texture = nullptr;
|
||||||
if (nodeInfo->camera.skybox_texture != KR_NULL_HANDLE) {
|
if (nodeInfo->camera.skybox_texture != KR_NULL_HANDLE) {
|
||||||
@@ -64,12 +65,12 @@ KrResult KRCamera::update(const KrNodeInfo* nodeInfo)
|
|||||||
m_skyBox = "";
|
m_skyBox = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Implement surface changes
|
|
||||||
return KR_SUCCESS;
|
return KR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRCamera::KRCamera(KRScene& scene, std::string name) : KRNode(scene, name)
|
KRCamera::KRCamera(KRScene& scene, std::string name) : KRNode(scene, name)
|
||||||
{
|
{
|
||||||
|
m_surfaceHandle = KR_NULL_HANDLE;
|
||||||
m_last_frame_start = 0;
|
m_last_frame_start = 0;
|
||||||
|
|
||||||
m_particlesAbsoluteTime = 0.0f;
|
m_particlesAbsoluteTime = 0.0f;
|
||||||
@@ -121,6 +122,12 @@ void KRCamera::loadXML(tinyxml2::XMLElement* e)
|
|||||||
KRNode::loadXML(e);
|
KRNode::loadXML(e);
|
||||||
const char* szSkyBoxName = e->Attribute("skybox");
|
const char* szSkyBoxName = e->Attribute("skybox");
|
||||||
m_skyBox = szSkyBoxName ? szSkyBoxName : "";
|
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)
|
void KRCamera::setSkyBox(const std::string& skyBox)
|
||||||
@@ -136,6 +143,11 @@ const std::string KRCamera::getSkyBox() const
|
|||||||
|
|
||||||
void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeSurface)
|
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 ----====----
|
// ----====---- Record timing information for measuring FPS ----====----
|
||||||
uint64_t current_time = m_pContext->getAbsoluteTimeMilliseconds();
|
uint64_t current_time = m_pContext->getAbsoluteTimeMilliseconds();
|
||||||
if (m_last_frame_start != 0) {
|
if (m_last_frame_start != 0) {
|
||||||
|
|||||||
@@ -95,6 +95,7 @@ private:
|
|||||||
|
|
||||||
void destroyBuffers();
|
void destroyBuffers();
|
||||||
|
|
||||||
|
KrSurfaceHandle m_surfaceHandle;
|
||||||
KRTexture* m_pSkyBoxTexture;
|
KRTexture* m_pSkyBoxTexture;
|
||||||
std::string m_skyBox;
|
std::string m_skyBox;
|
||||||
KRViewport m_viewport;
|
KRViewport m_viewport;
|
||||||
|
|||||||
@@ -34,11 +34,12 @@
|
|||||||
#include "KRRenderPass.h"
|
#include "KRRenderPass.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
KRSurface::KRSurface(KRContext& context, HWND hWnd)
|
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd)
|
||||||
#else
|
#else
|
||||||
KRSurface::KRSurface(KRContext& context)
|
KRSurface::KRSurface(KRContext& context, KrSurfaceHandle handle)
|
||||||
#endif
|
#endif
|
||||||
: KRContextObject(context)
|
: KRContextObject(context)
|
||||||
|
, m_handle(handle)
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
, m_hWnd(hWnd)
|
, m_hWnd(hWnd)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ class KRSurface : public KRContextObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
KRSurface(KRContext& context, HWND hWnd);
|
KRSurface(KRContext& context, KrSurfaceHandle handle, HWND hWnd);
|
||||||
#else
|
#else
|
||||||
KRSurface(KRContext& context);
|
KRSurface(KRContext& context, KrSurfaceHandle handle);
|
||||||
#endif
|
#endif
|
||||||
~KRSurface();
|
~KRSurface();
|
||||||
void destroy();
|
void destroy();
|
||||||
@@ -64,6 +64,7 @@ public:
|
|||||||
KRRenderPass& getDeferredOpaquePass();
|
KRRenderPass& getDeferredOpaquePass();
|
||||||
|
|
||||||
void endFrame();
|
void endFrame();
|
||||||
|
KrSurfaceHandle m_handle;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HWND m_hWnd;
|
HWND m_hWnd;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ KrResult KRSurfaceManager::create(HWND hWnd, KrSurfaceHandle& surfaceHandle)
|
|||||||
{
|
{
|
||||||
surfaceHandle = 0;
|
surfaceHandle = 0;
|
||||||
|
|
||||||
std::unique_ptr<KRSurface> surface = std::make_unique<KRSurface>(*m_pContext, hWnd);
|
std::unique_ptr<KRSurface> surface = std::make_unique<KRSurface>(*m_pContext, m_topSurfaceHandle, hWnd);
|
||||||
|
|
||||||
KrResult initialize_result = surface->initialize();
|
KrResult initialize_result = surface->initialize();
|
||||||
if (initialize_result != KR_SUCCESS) {
|
if (initialize_result != KR_SUCCESS) {
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ typedef struct
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
// KR_STRUCTURE_TYPE_NODE_CAMERA
|
// KR_STRUCTURE_TYPE_NODE_CAMERA
|
||||||
KrSurfaceMapIndex surface;
|
KrSurfaceMapIndex surfaceHandle;
|
||||||
KrResourceMapIndex skybox_texture;
|
KrResourceMapIndex skybox_texture;
|
||||||
} camera;
|
} camera;
|
||||||
struct
|
struct
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ void smoke_load()
|
|||||||
create_camera_info.newNodeHandle = kCameraNodeHandle;
|
create_camera_info.newNodeHandle = kCameraNodeHandle;
|
||||||
create_camera_info.sceneHandle = kSceneResourceHandle;
|
create_camera_info.sceneHandle = kSceneResourceHandle;
|
||||||
create_camera_info.node.pName = "my_camera";
|
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;
|
// create_camera_info.node.camera.skybox_texture = kSkyboxTextureResourceHandle;
|
||||||
res = KrCreateNode(&create_camera_info);
|
res = KrCreateNode(&create_camera_info);
|
||||||
assert(res == KR_SUCCESS);
|
assert(res == KR_SUCCESS);
|
||||||
|
|||||||
Reference in New Issue
Block a user