KRCamera now using KRNodeProperty

This commit is contained in:
2025-11-24 18:16:54 -08:00
parent 8fc846ce6b
commit aeb8f3434e
2 changed files with 14 additions and 24 deletions

View File

@@ -44,7 +44,7 @@ using namespace hydra;
void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo) void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
{ {
KRNode::InitNodeInfo(nodeInfo); KRNode::InitNodeInfo(nodeInfo);
nodeInfo->camera.surfaceHandle = 1; nodeInfo->camera.surfaceHandle = decltype(m_surfaceHandle)::defaultVal;
nodeInfo->camera.skybox_texture = KR_NULL_HANDLE; nodeInfo->camera.skybox_texture = KR_NULL_HANDLE;
} }
@@ -63,7 +63,7 @@ KrResult KRCamera::update(const KrNodeInfo* nodeInfo)
return res; return res;
} }
} }
m_skyBox.set(skybox_texture); m_skyBox.val.set(skybox_texture);
return KR_SUCCESS; return KR_SUCCESS;
} }
@@ -71,7 +71,6 @@ KrResult KRCamera::update(const KrNodeInfo* nodeInfo)
KRCamera::KRCamera(KRScene& scene, std::string name) KRCamera::KRCamera(KRScene& scene, std::string name)
: KRNode(scene, name) : KRNode(scene, name)
, m_fontTexture(KRTextureBinding("font", KRTexture::TEXTURE_USAGE_UI)) , m_fontTexture(KRTextureBinding("font", KRTexture::TEXTURE_USAGE_UI))
, m_skyBox(KRTextureBinding(KRTexture::TEXTURE_USAGE_SKY_CUBE))
{ {
m_surfaceHandle = KR_NULL_HANDLE; m_surfaceHandle = KR_NULL_HANDLE;
m_last_frame_start = 0; m_last_frame_start = 0;
@@ -113,7 +112,8 @@ std::string KRCamera::getElementName()
tinyxml2::XMLElement* KRCamera::saveXML(tinyxml2::XMLNode* parent) tinyxml2::XMLElement* KRCamera::saveXML(tinyxml2::XMLNode* parent)
{ {
tinyxml2::XMLElement* e = KRNode::saveXML(parent); tinyxml2::XMLElement* e = KRNode::saveXML(parent);
e->SetAttribute("skybox", m_skyBox.getName().c_str()); m_skyBox.save(e);
m_surfaceHandle.save(e);
return e; return e;
} }
@@ -122,35 +122,25 @@ tinyxml2::XMLElement* KRCamera::saveXML(tinyxml2::XMLNode* parent)
void KRCamera::loadXML(tinyxml2::XMLElement* e) void KRCamera::loadXML(tinyxml2::XMLElement* e)
{ {
KRNode::loadXML(e); KRNode::loadXML(e);
const char* szSkyBoxName = e->Attribute("skybox"); m_skyBox.load(e);
if (szSkyBoxName) { m_surfaceHandle.load(e);
m_skyBox.set(szSkyBoxName);
} else {
m_skyBox.clear();
}
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)
{ {
m_skyBox.set(skyBox); m_skyBox.val.set(skyBox);
} }
const std::string KRCamera::getSkyBox() const const std::string KRCamera::getSkyBox() const
{ {
return m_skyBox.getName(); return m_skyBox.val.getName();
} }
void KRCamera::getResourceBindings(std::list<KRResourceBinding*>& bindings) void KRCamera::getResourceBindings(std::list<KRResourceBinding*>& bindings)
{ {
KRNode::getResourceBindings(bindings); KRNode::getResourceBindings(bindings);
bindings.push_back(&m_skyBox); bindings.push_back(&m_skyBox.val);
bindings.push_back(&m_fontTexture); bindings.push_back(&m_fontTexture);
} }
@@ -165,7 +155,7 @@ void KRCamera::render(KRNode::RenderInfo& ri)
GL_PUSH_GROUP_MARKER("Sky Box"); GL_PUSH_GROUP_MARKER("Sky Box");
if (m_skyBox.isBound()) { if (m_skyBox.val.isBound()) {
std::string shader_name("sky_box"); std::string shader_name("sky_box");
PipelineInfo info{}; PipelineInfo info{};
@@ -176,7 +166,7 @@ void KRCamera::render(KRNode::RenderInfo& ri)
info.cullMode = CullMode::kCullNone; info.cullMode = CullMode::kCullNone;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pPipeline->setImageBinding("diffuseTexture", m_skyBox.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); pPipeline->setImageBinding("diffuseTexture", m_skyBox.val.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
pPipeline->bind(ri, Matrix4()); pPipeline->bind(ri, Matrix4());
// Render a full screen quad // Render a full screen quad

View File

@@ -102,8 +102,6 @@ private:
void destroyBuffers(); void destroyBuffers();
KrSurfaceHandle m_surfaceHandle;
KRViewport m_viewport; KRViewport m_viewport;
float m_particlesAbsoluteTime; float m_particlesAbsoluteTime;
@@ -123,7 +121,9 @@ private:
KRMeshManager::KRVBOData m_debug_text_vbo_data; KRMeshManager::KRVBOData m_debug_text_vbo_data;
KRTextureBinding m_fontTexture; KRTextureBinding m_fontTexture;
KRTextureBinding m_skyBox; KRNODE_PROPERTY(KRTextureBinding, m_skyBox, KRTexture::TEXTURE_USAGE_SKY_CUBE, "skybox");
KRNODE_PROPERTY(KrSurfaceHandle, m_surfaceHandle, 1, "surface");
uint64_t m_last_frame_start; uint64_t m_last_frame_start;
int m_frame_times[KRAKEN_FPS_AVERAGE_FRAME_COUNT]; int m_frame_times[KRAKEN_FPS_AVERAGE_FRAME_COUNT];