Reduced boilerplate needed to select and bind a KRPipeline

This commit is contained in:
2022-04-05 22:25:19 -07:00
parent 858064fa4b
commit 52c8ec2776
16 changed files with 85 additions and 115 deletions

View File

@@ -340,19 +340,13 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
if(m_pSkyBoxTexture) {
std::string shader_name("sky_box");
std::vector<KRPointLight*> no_point_lights;
std::vector<KRDirectionalLight*> no_directional_lights;
std::vector<KRSpotLight*> no_spot_lights;
KRPipelineManager::PipelineInfo info{};
info.shader_name = &shader_name;
info.pCamera = this;
info.point_lights = &no_point_lights;
info.directional_lights = &no_directional_lights;
info.spot_lights = &no_spot_lights;
info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(info);
getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), no_point_lights, no_directional_lights, no_spot_lights, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE);
@@ -539,16 +533,10 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glEnable(GL_BLEND));
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
std::vector<KRPointLight*> no_point_lights;
std::vector<KRDirectionalLight*> no_directional_lights;
std::vector<KRSpotLight*> no_spot_lights;
KRPipelineManager::PipelineInfo info{};
std::string shader_name("visualize_overlay");
info.shader_name = &shader_name;
info.pCamera = this;
info.point_lights = &no_point_lights;
info.directional_lights = &no_directional_lights;
info.spot_lights = &no_spot_lights;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline(info);
@@ -557,7 +545,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
Matrix4 matModel = Matrix4();
matModel.scale((*itr).first.size() * 0.5f);
matModel.translate((*itr).first.center());
if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) {
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
}
}
@@ -782,22 +770,16 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
GLDEBUG(glViewport(0, 0, (GLsizei)m_viewport.getSize().x, (GLsizei)m_viewport.getSize().y));
GLDEBUG(glDisable(GL_DEPTH_TEST));
std::vector<KRPointLight*> no_point_lights;
std::vector<KRDirectionalLight*> no_directional_lights;
std::vector<KRSpotLight*> no_spot_lights;
KRPipelineManager::PipelineInfo info{};
std::string shader_name("PostShader");
info.shader_name = &shader_name;
info.pCamera = this;
info.point_lights = &no_point_lights;
info.directional_lights = &no_directional_lights;
info.spot_lights = &no_spot_lights;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(info);
Vector3 rim_color;
getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture);
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 1, compositeColorTexture);
@@ -979,19 +961,13 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer)
// Enable alpha blending
GLDEBUG(glEnable(GL_BLEND));
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
std::vector<KRPointLight*> no_point_lights;
std::vector<KRDirectionalLight*> no_directional_lights;
std::vector<KRSpotLight*> no_spot_lights;
KRPipelineManager::PipelineInfo info{};
std::string shader_name("debug_font");
info.shader_name = &shader_name;
info.pCamera = this;
info.point_lights = &no_point_lights;
info.directional_lights = &no_directional_lights;
info.spot_lights = &no_spot_lights;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(info);
getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());
m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI);