From 13efe5caec22cb3dcb070daf43ef4242bc9fde3f Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Thu, 13 Nov 2025 22:25:34 -0800 Subject: [PATCH] Refactor KRResourceBinding load and isLoaded methods to reflect binding rather than loading --- kraken/nodes/KRAudioSource.cpp | 6 +-- kraken/nodes/KRCamera.cpp | 4 +- kraken/nodes/KRCollider.cpp | 12 ++--- kraken/nodes/KRLight.cpp | 4 +- kraken/nodes/KRModel.cpp | 20 ++++---- kraken/nodes/KRSprite.cpp | 6 +-- kraken/resources/KRResourceBinding.cpp | 2 +- kraken/resources/KRResourceBinding.h | 4 +- .../resources/audio/KRAudioSampleBinding.cpp | 2 +- kraken/resources/audio/KRAudioSampleBinding.h | 2 +- kraken/resources/material/KRMaterial.cpp | 46 +++++++++---------- kraken/resources/mesh/KRMeshBinding.cpp | 2 +- kraken/resources/mesh/KRMeshBinding.h | 2 +- kraken/resources/texture/KRTextureBinding.cpp | 2 +- kraken/resources/texture/KRTextureBinding.h | 2 +- 15 files changed, 58 insertions(+), 58 deletions(-) diff --git a/kraken/nodes/KRAudioSource.cpp b/kraken/nodes/KRAudioSource.cpp index 2f61566..c0b18de 100755 --- a/kraken/nodes/KRAudioSource.cpp +++ b/kraken/nodes/KRAudioSource.cpp @@ -170,8 +170,8 @@ void KRAudioSource::loadXML(tinyxml2::XMLElement* e) void KRAudioSource::prime() { if (!m_isPrimed) { - m_sample.load(&getContext()); - if (m_sample.isLoaded()) { + m_sample.bind(&getContext()); + if (m_sample.isBound()) { // Prime the buffer queue m_nextBufferIndex = 0; for (int i = 0; i < KRENGINE_AUDIO_BUFFERS_PER_SOURCE; i++) { @@ -374,7 +374,7 @@ std::string KRAudioSource::getSample() KRAudioSample* KRAudioSource::getAudioSample() { - m_sample.load(&getContext()); + m_sample.bind(&getContext()); return m_sample.get(); } diff --git a/kraken/nodes/KRCamera.cpp b/kraken/nodes/KRCamera.cpp index 7b3b45d..0dfb83b 100755 --- a/kraken/nodes/KRCamera.cpp +++ b/kraken/nodes/KRCamera.cpp @@ -154,9 +154,9 @@ void KRCamera::render(KRNode::RenderInfo& ri) GL_PUSH_GROUP_MARKER("Sky Box"); - m_skyBox.load(&getContext()); + m_skyBox.bind(&getContext()); - if (m_skyBox.isLoaded()) { + if (m_skyBox.isBound()) { m_skyBox.get()->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); std::string shader_name("sky_box"); diff --git a/kraken/nodes/KRCollider.cpp b/kraken/nodes/KRCollider.cpp index 1543e46..cb8ce55 100755 --- a/kraken/nodes/KRCollider.cpp +++ b/kraken/nodes/KRCollider.cpp @@ -100,7 +100,7 @@ void KRCollider::loadXML(tinyxml2::XMLElement* e) void KRCollider::loadModel() { KRMesh* prevModel = m_model.get(); - m_model.load(&getContext()); + m_model.bind(&getContext()); if (m_model.get() != prevModel) { getScene().notify_sceneGraphModify(this); } @@ -109,7 +109,7 @@ void KRCollider::loadModel() AABB KRCollider::getBounds() { loadModel(); - if (m_model.isLoaded()) { + if (m_model.isBound()) { return AABB::Create(m_model.get()->getMinPoint(), m_model.get()->getMaxPoint(), getModelMatrix()); } else { return AABB::Infinite(); @@ -120,7 +120,7 @@ bool KRCollider::lineCast(const Vector3& v0, const Vector3& v1, HitInfo& hitinfo { if (layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set loadModel(); - if (m_model.isLoaded()) { + if (m_model.isBound()) { if (getBounds().intersectsLine(v0, v1)) { Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0); Vector3 v1_model_space = Matrix4::Dot(getInverseModelMatrix(), v1); @@ -145,7 +145,7 @@ bool KRCollider::rayCast(const Vector3& v0, const Vector3& dir, HitInfo& hitinfo { if (layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set loadModel(); - if (m_model.isLoaded()) { + if (m_model.isBound()) { if (getBounds().intersectsRay(v0, dir)) { Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0); Vector3 dir_model_space = Vector3::Normalize(Matrix4::DotNoTranslate(getInverseModelMatrix(), dir)); @@ -170,7 +170,7 @@ bool KRCollider::sphereCast(const Vector3& v0, const Vector3& v1, float radius, { if (layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set loadModel(); - if (m_model.isLoaded()) { + if (m_model.isBound()) { AABB sphereCastBounds = AABB::Create( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions Vector3::Create(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3::Create(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius) @@ -214,7 +214,7 @@ void KRCollider::render(RenderInfo& ri) if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT && ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_COLLIDERS) { loadModel(); - if (m_model.isLoaded()) { + if (m_model.isBound()) { GL_PUSH_GROUP_MARKER("Debug Overlays"); diff --git a/kraken/nodes/KRLight.cpp b/kraken/nodes/KRLight.cpp index a224975..325d550 100755 --- a/kraken/nodes/KRLight.cpp +++ b/kraken/nodes/KRLight.cpp @@ -393,9 +393,9 @@ void KRLight::render(RenderInfo& ri) GLDEBUG(glDeleteQueriesEXT(1, &m_occlusionQuery)); if (params) { - m_flareTexture.load(&getContext()); + m_flareTexture.bind(&getContext()); - if (m_flareTexture.isLoaded()) { + if (m_flareTexture.isBound()) { m_flareTexture.get()->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE); KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; diff --git a/kraken/nodes/KRModel.cpp b/kraken/nodes/KRModel.cpp index d4b23f5..58249d4 100755 --- a/kraken/nodes/KRModel.cpp +++ b/kraken/nodes/KRModel.cpp @@ -210,11 +210,11 @@ void KRModel::loadModel() for (int lod = 0; lod < kMeshLODCount; lod++) { KRMesh* prevMesh = nullptr; prevMesh = m_meshes[lod].get(); - m_meshes[lod].load(&getContext()); + m_meshes[lod].bind(&getContext()); if (m_meshes[lod].get() != prevMesh) { meshChanged = true; } - if (m_meshes[lod].isLoaded()) { + if (m_meshes[lod].isBound()) { KRMesh* model = m_meshes[lod].get(); std::vector model_bones; int bone_count = model->getBoneCount(); @@ -279,7 +279,7 @@ void KRModel::render(KRNode::RenderInfo& ri) int bestLOD = -1; KRMesh* pModel = nullptr; for (int lod = 0; lod < kMeshLODCount; lod++) { - if (m_meshes[lod].isLoaded()) { + if (m_meshes[lod].isBound()) { KRMesh* pLODModel = m_meshes[lod].get(); if ((float)pLODModel->getLODCoverage() / 100.0f > lod_coverage) { @@ -292,9 +292,9 @@ void KRModel::render(KRNode::RenderInfo& ri) } } - m_lightMap.load(&getContext()); + m_lightMap.bind(&getContext()); - if (m_lightMap.isLoaded() && ri.camera->settings.bEnableLightMap && ri.renderPass->getType() != RENDER_PASS_SHADOWMAP && ri.renderPass->getType() != RENDER_PASS_SHADOWMAP) { + if (m_lightMap.isBound() && ri.camera->settings.bEnableLightMap && ri.renderPass->getType() != RENDER_PASS_SHADOWMAP && ri.renderPass->getType() != RENDER_PASS_SHADOWMAP) { m_lightMap.get()->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP); // TODO - Vulkan refactoring. We need to bind the shadow map in KRMesh::Render // m_pContext->getTextureManager()->selectTexture(5, m_pLightMap, lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP); @@ -321,14 +321,14 @@ void KRModel::preStream(const KRViewport& viewport) float lod_coverage = viewport.coverage(getBounds()); for (int i = 0; i < kMeshLODCount; i++) { - if (m_meshes[i].isLoaded()) { + if (m_meshes[i].isBound()) { m_meshes[i].get()->preStream(lod_coverage); } } - m_lightMap.load(&getContext()); + m_lightMap.bind(&getContext()); - if (m_lightMap.isLoaded()) { + if (m_lightMap.isBound()) { m_lightMap.get()->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP); } } @@ -341,7 +341,7 @@ kraken_stream_level KRModel::getStreamLevel(const KRViewport& viewport) loadModel(); for (int lod = 0; lod < kMeshLODCount; lod++) { - if (m_meshes[lod].isLoaded()) { + if (m_meshes[lod].isBound()) { stream_level = KRMIN(stream_level, m_meshes[lod].get()->getStreamLevel()); } } @@ -355,7 +355,7 @@ AABB KRModel::getBounds() // Get the bounds of the lowest lod mesh for(int lod=0; lodresetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_SPRITE); } } @@ -130,7 +130,7 @@ void KRSprite::render(RenderInfo& ri) if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) { if (m_spriteAlpha > 0.0f) { - if (m_spriteTexture.isLoaded()) { + if (m_spriteTexture.isBound()) { // TODO - Sprites are currently additive only. Need to expose this and allow for multiple blending modes KRMeshManager::KRVBOData& vertices = m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; diff --git a/kraken/resources/KRResourceBinding.cpp b/kraken/resources/KRResourceBinding.cpp index 4b5c270..9aee856 100644 --- a/kraken/resources/KRResourceBinding.cpp +++ b/kraken/resources/KRResourceBinding.cpp @@ -92,7 +92,7 @@ void KRResourceBinding::clear() set(nullptr); } -bool KRResourceBinding::isLoaded() const +bool KRResourceBinding::isBound() const { return m_resource != nullptr; } \ No newline at end of file diff --git a/kraken/resources/KRResourceBinding.h b/kraken/resources/KRResourceBinding.h index 6ebcf7c..031c5af 100644 --- a/kraken/resources/KRResourceBinding.h +++ b/kraken/resources/KRResourceBinding.h @@ -52,8 +52,8 @@ public: const std::string& getName() const; void setName(const std::string& name); - virtual bool load(KRContext* context) = 0; - bool isLoaded() const; + virtual bool bind(KRContext* context) = 0; + bool isBound() const; protected: KRResource* m_resource; diff --git a/kraken/resources/audio/KRAudioSampleBinding.cpp b/kraken/resources/audio/KRAudioSampleBinding.cpp index ad1db38..8b89124 100644 --- a/kraken/resources/audio/KRAudioSampleBinding.cpp +++ b/kraken/resources/audio/KRAudioSampleBinding.cpp @@ -42,7 +42,7 @@ KRAudioSample* KRAudioSampleBinding::get() return static_cast(m_resource); } -bool KRAudioSampleBinding::load(KRContext* context) +bool KRAudioSampleBinding::bind(KRContext* context) { if (m_name.size() == 0) { return true; diff --git a/kraken/resources/audio/KRAudioSampleBinding.h b/kraken/resources/audio/KRAudioSampleBinding.h index 640ea9d..2477c4c 100644 --- a/kraken/resources/audio/KRAudioSampleBinding.h +++ b/kraken/resources/audio/KRAudioSampleBinding.h @@ -41,6 +41,6 @@ class KRAudioSampleBinding : public KRResourceBinding public: KRAudioSample* get(); - bool load(KRContext* context) override final; + bool bind(KRContext* context) override final; private: }; \ No newline at end of file diff --git a/kraken/resources/material/KRMaterial.cpp b/kraken/resources/material/KRMaterial.cpp index 815536b..b29d8bd 100755 --- a/kraken/resources/material/KRMaterial.cpp +++ b/kraken/resources/material/KRMaterial.cpp @@ -232,27 +232,27 @@ void KRMaterial::preStream(float lodCoverage) { getTextures(); - if (m_ambientMap.isLoaded()) { + if (m_ambientMap.isBound()) { m_ambientMap.get()->resetPoolExpiry(lodCoverage, KRTexture::TEXTURE_USAGE_AMBIENT_MAP); } - if (m_diffuseMap.isLoaded()) { + if (m_diffuseMap.isBound()) { m_diffuseMap.get()->resetPoolExpiry(lodCoverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP); } - if (m_normalMap.isLoaded()) { + if (m_normalMap.isBound()) { m_normalMap.get()->resetPoolExpiry(lodCoverage, KRTexture::TEXTURE_USAGE_NORMAL_MAP); } - if (m_specularMap.isLoaded()) { + if (m_specularMap.isBound()) { m_specularMap.get()->resetPoolExpiry(lodCoverage, KRTexture::TEXTURE_USAGE_SPECULAR_MAP); } - if (m_reflectionMap.isLoaded()) { + if (m_reflectionMap.isBound()) { m_reflectionMap.get()->resetPoolExpiry(lodCoverage, KRTexture::TEXTURE_USAGE_REFLECTION_MAP); } - if (m_reflectionCube.isLoaded()) { + if (m_reflectionCube.isBound()) { m_reflectionCube.get()->resetPoolExpiry(lodCoverage, KRTexture::TEXTURE_USAGE_REFECTION_CUBE); } } @@ -264,27 +264,27 @@ kraken_stream_level KRMaterial::getStreamLevel() getTextures(); - if (m_ambientMap.isLoaded()) { + if (m_ambientMap.isBound()) { stream_level = KRMIN(stream_level, m_ambientMap.get()->getStreamLevel(KRTexture::TEXTURE_USAGE_AMBIENT_MAP)); } - if (m_diffuseMap.isLoaded()) { + if (m_diffuseMap.isBound()) { stream_level = KRMIN(stream_level, m_diffuseMap.get()->getStreamLevel(KRTexture::TEXTURE_USAGE_DIFFUSE_MAP)); } - if (m_normalMap.isLoaded()) { + if (m_normalMap.isBound()) { stream_level = KRMIN(stream_level, m_normalMap.get()->getStreamLevel(KRTexture::TEXTURE_USAGE_NORMAL_MAP)); } - if (m_specularMap.isLoaded()) { + if (m_specularMap.isBound()) { stream_level = KRMIN(stream_level, m_specularMap.get()->getStreamLevel(KRTexture::TEXTURE_USAGE_SPECULAR_MAP)); } - if (m_reflectionMap.isLoaded()) { + if (m_reflectionMap.isBound()) { stream_level = KRMIN(stream_level, m_reflectionMap.get()->getStreamLevel(KRTexture::TEXTURE_USAGE_REFLECTION_MAP)); } - if (m_reflectionCube.isLoaded()) { + if (m_reflectionCube.isBound()) { stream_level = KRMIN(stream_level, m_reflectionCube.get()->getStreamLevel(KRTexture::TEXTURE_USAGE_REFECTION_CUBE)); } @@ -293,12 +293,12 @@ kraken_stream_level KRMaterial::getStreamLevel() void KRMaterial::getTextures() { - m_ambientMap.load(&getContext()); - m_diffuseMap.load(&getContext()); - m_normalMap.load(&getContext()); - m_specularMap.load(&getContext()); - m_reflectionMap.load(&getContext()); - m_reflectionCube.load(&getContext()); + m_ambientMap.bind(&getContext()); + m_diffuseMap.bind(&getContext()); + m_normalMap.bind(&getContext()); + m_specularMap.bind(&getContext()); + m_reflectionMap.bind(&getContext()); + m_reflectionCube.bind(&getContext()); } void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector& bones, const std::vector& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, float lod_coverage) @@ -311,11 +311,11 @@ void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_ Vector2 default_offset = Vector2::Zero(); bool bHasReflection = m_reflectionColor != Vector3::Zero(); - bool bDiffuseMap = m_diffuseMap.isLoaded() && ri.camera->settings.bEnableDiffuseMap; - bool bNormalMap = m_normalMap.isLoaded() && ri.camera->settings.bEnableNormalMap; - bool bSpecMap = m_specularMap.isLoaded() && ri.camera->settings.bEnableSpecMap; - bool bReflectionMap = m_reflectionMap.isLoaded() && ri.camera->settings.bEnableReflectionMap && ri.camera->settings.bEnableReflection && bHasReflection; - bool bReflectionCubeMap = m_reflectionCube.isLoaded() && ri.camera->settings.bEnableReflection && bHasReflection; + bool bDiffuseMap = m_diffuseMap.isBound() && ri.camera->settings.bEnableDiffuseMap; + bool bNormalMap = m_normalMap.isBound() && ri.camera->settings.bEnableNormalMap; + bool bSpecMap = m_specularMap.isBound() && ri.camera->settings.bEnableSpecMap; + bool bReflectionMap = m_reflectionMap.isBound() && ri.camera->settings.bEnableReflectionMap && ri.camera->settings.bEnableReflection && bHasReflection; + bool bReflectionCubeMap = m_reflectionCube.isBound() && ri.camera->settings.bEnableReflection && bHasReflection; bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap; bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE); diff --git a/kraken/resources/mesh/KRMeshBinding.cpp b/kraken/resources/mesh/KRMeshBinding.cpp index f630e24..a958c45 100644 --- a/kraken/resources/mesh/KRMeshBinding.cpp +++ b/kraken/resources/mesh/KRMeshBinding.cpp @@ -39,7 +39,7 @@ KRMesh* KRMeshBinding::get() return static_cast(m_resource); } -bool KRMeshBinding::load(KRContext* context) +bool KRMeshBinding::bind(KRContext* context) { if (m_name.size() == 0) { return true; diff --git a/kraken/resources/mesh/KRMeshBinding.h b/kraken/resources/mesh/KRMeshBinding.h index 85bcc99..7b5b011 100644 --- a/kraken/resources/mesh/KRMeshBinding.h +++ b/kraken/resources/mesh/KRMeshBinding.h @@ -41,6 +41,6 @@ class KRMeshBinding : public KRResourceBinding public: KRMesh* get(); - bool load(KRContext* context) override final; + bool bind(KRContext* context) override final; private: }; \ No newline at end of file diff --git a/kraken/resources/texture/KRTextureBinding.cpp b/kraken/resources/texture/KRTextureBinding.cpp index 28efd17..2a3a8b9 100644 --- a/kraken/resources/texture/KRTextureBinding.cpp +++ b/kraken/resources/texture/KRTextureBinding.cpp @@ -39,7 +39,7 @@ KRTexture* KRTextureBinding::get() return static_cast(m_resource); } -bool KRTextureBinding::load(KRContext* context) +bool KRTextureBinding::bind(KRContext* context) { if (m_name.size() == 0) { return true; diff --git a/kraken/resources/texture/KRTextureBinding.h b/kraken/resources/texture/KRTextureBinding.h index 5288fc6..af835f9 100644 --- a/kraken/resources/texture/KRTextureBinding.h +++ b/kraken/resources/texture/KRTextureBinding.h @@ -41,6 +41,6 @@ class KRTextureBinding : public KRResourceBinding public: KRTexture* get(); - bool load(KRContext* context) override final; + bool bind(KRContext* context) override final; private: }; \ No newline at end of file