Refactor KRResourceBinding load and isLoaded methods to reflect binding rather than loading

This commit is contained in:
2025-11-13 22:25:34 -08:00
parent dbf31ceebe
commit 13efe5caec
15 changed files with 58 additions and 58 deletions

View File

@@ -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();
}

View File

@@ -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");

View File

@@ -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");

View File

@@ -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;

View File

@@ -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<KRBone*> 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; lod<kMeshLODCount; lod++) {
if (!m_meshes[lod].isLoaded()) {
if (!m_meshes[lod].isBound()) {
continue;
}
KRMesh* mesh = m_meshes[lod].get();

View File

@@ -117,9 +117,9 @@ void KRSprite::preStream(const KRViewport& viewport)
KRNode::preStream(viewport);
// Pre-stream sprites, even if the alpha is zero
m_spriteTexture.load(&getContext());
m_spriteTexture.bind(&getContext());
if (m_spriteTexture.isLoaded()) {
if (m_spriteTexture.isBound()) {
m_spriteTexture.get()->resetPoolExpiry(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;