Removed KRPipeline::setImageBinding, updated all call sites to use image binding reflection system.
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, macos-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Has been cancelled
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Has been cancelled

This commit is contained in:
2026-06-01 00:35:22 -07:00
parent 568a870843
commit 1592087065
9 changed files with 125 additions and 89 deletions

View File

@@ -843,20 +843,3 @@ VkPipeline& KRPipeline::getPipeline()
return m_graphicsPipeline; return m_graphicsPipeline;
} }
void KRPipeline::setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler)
{
for (int stage = 0; stage < static_cast<size_t>(ShaderStage::ShaderStageCount); stage++) {
StageInfo& stageInfo = m_stages[stage];
for (DescriptorSetInfo& descriptorSetInfo : stageInfo.descriptorSets) {
for (DescriptorBinding& binding : descriptorSetInfo.bindings) {
ImageDescriptorInfo* image = std::get_if<ImageDescriptorInfo>(&binding);
if (image) {
if (image->name == name) {
image->texture = texture;
image->sampler = sampler;
}
}
}
}
}
}

View File

@@ -232,8 +232,6 @@ public:
void setPushConstant(ShaderValue location, const hydra::Matrix4& value); void setPushConstant(ShaderValue location, const hydra::Matrix4& value);
void setPushConstant(ShaderValue location, const hydra::Matrix4* value, const size_t count); void setPushConstant(ShaderValue location, const hydra::Matrix4* value, const size_t count);
void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler);
VkPipeline& getPipeline(); VkPipeline& getPipeline();
void bindDescriptorSets(VkCommandBuffer& commandBuffer); void bindDescriptorSets(VkCommandBuffer& commandBuffer);

View File

@@ -859,7 +859,6 @@ bool KRCamera::getImageBinding(const std::string& name, const KRTextureBinding**
*binding = &m_skyBox.val; *binding = &m_skyBox.val;
*sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER; *sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER;
return true; return true;
} else { } else {
return KRNode::getImageBinding(name, binding, sample); return KRNode::getImageBinding(name, binding, sample);
} }

View File

@@ -174,6 +174,7 @@ void KRLight::getResourceBindings(std::list<KRResourceBinding*>& bindings)
void KRLight::render(RenderInfo& ri) void KRLight::render(RenderInfo& ri)
{ {
KRNode::render(ri); KRNode::render(ri);
ri.reflectedObjects.push_back(this);
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_SHADOWMAP && (ri.camera->settings.volumetric_environment_enable || ri.camera->settings.dust_particle_enable || (ri.camera->settings.m_cShadowBuffers > 0 && m_casts_shadow))) { if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_SHADOWMAP && (ri.camera->settings.volumetric_environment_enable || ri.camera->settings.dust_particle_enable || (ri.camera->settings.m_cShadowBuffers > 0 && m_casts_shadow))) {
allocateShadowBuffers(configureShadowBufferViewports(*ri.viewport)); allocateShadowBuffers(configureShadowBufferViewports(*ri.viewport));
@@ -336,6 +337,8 @@ void KRLight::render(RenderInfo& ri)
} }
} }
ri.reflectedObjects.pop_back();
} }
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) { if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) {
@@ -365,9 +368,7 @@ void KRLight::render(RenderInfo& ri)
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
if (pShader) { if (pShader && pShader->bind(ri, getModelMatrix())) {
pShader->setImageBinding("diffuseTexture", m_flareTexture.val.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
if (pShader->bind(ri, getModelMatrix())) {
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0);
} }
@@ -375,8 +376,6 @@ void KRLight::render(RenderInfo& ri)
} }
} }
} }
}
} }
void KRLight::allocateShadowBuffers(int cBuffers) void KRLight::allocateShadowBuffers(int cBuffers)
@@ -552,3 +551,15 @@ bool KRLight::getShaderValue(ShaderValue value, hydra::Vector3* output) const
return KRNode::getShaderValue(value, output); return KRNode::getShaderValue(value, output);
} }
} }
bool KRLight::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const
{
if (name == "flareTexture") {
*binding = &m_flareTexture.val;
*sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER;
return true;
} else {
return KRNode::getImageBinding(name, binding, sample);
}
}

View File

@@ -78,6 +78,7 @@ protected:
bool getShaderValue(ShaderValue value, float* output) const override; bool getShaderValue(ShaderValue value, float* output) const override;
bool getShaderValue(ShaderValue value, hydra::Vector3* output) const override; bool getShaderValue(ShaderValue value, hydra::Vector3* output) const override;
bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const final;
// Properties // Properties
KRNODE_PROPERTY(float, m_decayStart, 0.f, "decay_start"); KRNODE_PROPERTY(float, m_decayStart, 0.f, "decay_start");

View File

@@ -113,10 +113,10 @@ void KRSprite::getResourceBindings(std::list<KRResourceBinding*>& bindings)
void KRSprite::render(RenderInfo& ri) void KRSprite::render(RenderInfo& ri)
{ {
KRNode::render(ri); KRNode::render(ri);
ri.reflectedObjects.push_back(this);
if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) { if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) {
if (m_spriteAlpha > 0.0f) { if (m_spriteAlpha > 0.0f) {
if (m_spriteTexture.val.isBound()) {
// TODO - Sprites are currently additive only. Need to expose this and allow for multiple blending modes // 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; KRMeshManager::KRVBOData& vertices = m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES;
@@ -136,16 +136,13 @@ void KRSprite::render(RenderInfo& ri)
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
if (pShader) { if (pShader && pShader->bind(ri, getModelMatrix())) {
pShader->setImageBinding("diffuseTexture", m_spriteTexture.val.get(), m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
if (pShader->bind(ri, getModelMatrix())) {
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0);
} }
} }
} }
} ri.reflectedObjects.pop_back();
}
} }
bool KRSprite::getShaderValue(ShaderValue value, float* output) const bool KRSprite::getShaderValue(ShaderValue value, float* output) const
@@ -155,3 +152,14 @@ bool KRSprite::getShaderValue(ShaderValue value, float* output) const
return KRNode::getShaderValue(value, output); return KRNode::getShaderValue(value, output);
} }
} }
bool KRSprite::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const
{
if (name == "spriteTexture") {
*binding = &m_spriteTexture.val;
*sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER;
return true;
} else {
return KRNode::getImageBinding(name, binding, sample);
}
}

View File

@@ -60,6 +60,7 @@ public:
protected: protected:
bool getShaderValue(ShaderValue value, float* output) const override; bool getShaderValue(ShaderValue value, float* output) const override;
bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const final;
KRNODE_PROPERTY(KRTextureBinding, m_spriteTexture, KRTexture::TEXTURE_USAGE_SPRITE, "sprite_texture"); KRNODE_PROPERTY(KRTextureBinding, m_spriteTexture, KRTexture::TEXTURE_USAGE_SPRITE, "sprite_texture");
KRNODE_PROPERTY(float, m_spriteAlpha, 1.f, "sprite_alpha"); KRNODE_PROPERTY(float, m_spriteAlpha, 1.f, "sprite_alpha");

View File

@@ -825,28 +825,6 @@ bool KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_
} }
} }
if (bDiffuseMap) {
pShader->setImageBinding("diffuseTexture", m_baseColorMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
}
if (bSpecMap) {
pShader->setImageBinding("specularTexture", m_specularColorMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
}
if (bNormalMap) {
pShader->setImageBinding("normalTexture", m_normalMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
}
if (bReflectionCubeMap) {
// Deprecated by reflection cubes..
// pShader->setImageBinding("reflectionCubeTexture", m_reflectionCube.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
}
if (bReflectionMap) {
// Deprecated by PBR model..
// pShader->setImageBinding("reflectionTexture", m_reflection.texture.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
}
bool success = true; bool success = true;
ri.reflectedObjects.push_back(this); ri.reflectedObjects.push_back(this);
if (!pShader->bind(ri, matModel)) { if (!pShader->bind(ri, matModel)) {
@@ -1178,3 +1156,59 @@ bool KRMaterial::getShaderValue(ShaderValue value, bool* output) const
return false; return false;
} }
} }
bool KRMaterial::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const
{
// TODO - Need to implement sampler selection / generation system
if (name == "baseColorTexture") {
*binding = &m_baseColorMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "normalTexture") {
*binding = &m_normalMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "emissiveTexture") {
*binding = &m_emissiveMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "occlusionTexture") {
*binding = &m_occlusionMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "metalicRoughnessTexture") {
*binding = &m_metalicRoughnessMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "anisotropyTexture") {
*binding = &m_anisotropyMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "clearcoatTexture") {
*binding = &m_clearcoatMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "clearcoatNormalTexture") {
*binding = &m_clearcoatNormalMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "specularTexture") {
*binding = &m_specularMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "specularColorTexture") {
*binding = &m_specularColorMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "thicknessTexture") {
*binding = &m_thicknessMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else if (name == "transmissionTexture") {
*binding = &m_transmissionMap.texture;
*sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER;
return true;
} else {
return KRReflectedObject::getImageBinding(name, binding, sample);
}
}

View File

@@ -190,4 +190,5 @@ private:
bool getShaderValue(ShaderValue value, KRResourceBinding* output) const final; bool getShaderValue(ShaderValue value, KRResourceBinding* output) const final;
bool getShaderValue(ShaderValue value, int64_t* output) const final; bool getShaderValue(ShaderValue value, int64_t* output) const final;
bool getShaderValue(ShaderValue value, bool* output) const final; bool getShaderValue(ShaderValue value, bool* output) const final;
bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const final;
}; };