Vulkan Refactoring - Updated KRTextureManager::selectTexture call sites to use KRShader::setImageBinding
This commit is contained in:
@@ -259,6 +259,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_pSkyBoxTexture) {
|
if (m_pSkyBoxTexture) {
|
||||||
|
m_pSkyBoxTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE);
|
||||||
|
|
||||||
std::string shader_name("sky_box");
|
std::string shader_name("sky_box");
|
||||||
PipelineInfo info{};
|
PipelineInfo info{};
|
||||||
@@ -269,10 +270,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
|
|||||||
info.cullMode = CullMode::kCullNone;
|
info.cullMode = CullMode::kCullNone;
|
||||||
|
|
||||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(compositeSurface, info);
|
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(compositeSurface, info);
|
||||||
|
pPipeline->setImageBinding("diffuseTexture", m_pSkyBoxTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
pPipeline->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_OPAQUE);
|
pPipeline->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, KRNode::RENDER_PASS_FORWARD_OPAQUE);
|
||||||
|
|
||||||
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE);
|
|
||||||
|
|
||||||
// Render a full screen quad
|
// Render a full screen quad
|
||||||
m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
|
||||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||||
|
|||||||
@@ -404,6 +404,7 @@ void KRLight::render(RenderInfo& ri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_pFlareTexture) {
|
if (m_pFlareTexture) {
|
||||||
|
m_pFlareTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);
|
||||||
KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES;
|
KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES;
|
||||||
|
|
||||||
// Render light flare on transparency pass
|
// Render light flare on transparency pass
|
||||||
@@ -424,9 +425,9 @@ void KRLight::render(RenderInfo& ri)
|
|||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, 1.0f);
|
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, 1.0f);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize);
|
pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize);
|
||||||
|
pShader->setImageBinding("diffuseTexture", m_pFlareTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
|
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -439,24 +439,28 @@ void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __u
|
|||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_tr);
|
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_tr);
|
||||||
|
|
||||||
if (bDiffuseMap) {
|
if (bDiffuseMap) {
|
||||||
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap, lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);
|
m_pDiffuseMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_DIFFUSE_MAP);
|
||||||
|
pShader->setImageBinding("diffuseTexture", m_pDiffuseMap, getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bSpecMap) {
|
if (bSpecMap) {
|
||||||
m_pContext->getTextureManager()->selectTexture(1, m_pSpecularMap, lod_coverage, KRTexture::TEXTURE_USAGE_SPECULAR_MAP);
|
m_pSpecularMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_SPECULAR_MAP);
|
||||||
|
pShader->setImageBinding("specularTexture", m_pDiffuseMap, getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bNormalMap) {
|
if (bNormalMap) {
|
||||||
m_pContext->getTextureManager()->selectTexture(2, m_pNormalMap, lod_coverage, KRTexture::TEXTURE_USAGE_NORMAL_MAP);
|
m_pNormalMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_NORMAL_MAP);
|
||||||
|
pShader->setImageBinding("normalTexture", m_pNormalMap, getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bReflectionCubeMap && (ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || ri.renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
|
if (bReflectionCubeMap) {
|
||||||
m_pContext->getTextureManager()->selectTexture(4, m_pReflectionCube, lod_coverage, KRTexture::TEXTURE_USAGE_REFECTION_CUBE);
|
m_pReflectionCube->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_REFECTION_CUBE);
|
||||||
|
pShader->setImageBinding("reflectionCubeTexture", m_pReflectionCube, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bReflectionMap && (ri.renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT || ri.renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
|
if (bReflectionMap) {
|
||||||
// GL_TEXTURE7 is used for reading the depth buffer in gBuffer pass 2 and re-used for the reflection map in gBuffer Pass 3 and in forward rendering
|
m_pReflectionMap->resetPoolExpiry(lod_coverage, KRTexture::TEXTURE_USAGE_REFLECTION_MAP);
|
||||||
m_pContext->getTextureManager()->selectTexture(7, m_pReflectionMap, lod_coverage, KRTexture::TEXTURE_USAGE_REFLECTION_MAP);
|
pShader->setImageBinding("reflectionTexture", m_pReflectionMap, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, matModel, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
|
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, matModel, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
|
||||||
|
|||||||
@@ -217,7 +217,9 @@ void KRModel::render(KRNode::RenderInfo& ri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_pLightMap && ri.camera->settings.bEnableLightMap && ri.renderPass != RENDER_PASS_SHADOWMAP && ri.renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) {
|
if (m_pLightMap && ri.camera->settings.bEnableLightMap && ri.renderPass != RENDER_PASS_SHADOWMAP && ri.renderPass != RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||||
m_pContext->getTextureManager()->selectTexture(5, m_pLightMap, lod_coverage, KRTexture::TEXTURE_USAGE_LIGHT_MAP);
|
m_pLightMap->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);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix4 matModel = getModelMatrix();
|
Matrix4 matModel = getModelMatrix();
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri)
|
|||||||
|
|
||||||
if (ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
if (ri.renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
|
||||||
if (ri.viewport.visible(getBounds())) {
|
if (ri.viewport.visible(getBounds())) {
|
||||||
m_pContext->getTextureManager()->selectTexture(0, pParticleTexture, 0.0f, KRTexture::TEXTURE_USAGE_PARTICLE);
|
|
||||||
|
|
||||||
int particle_count = 10000;
|
int particle_count = 10000;
|
||||||
PipelineInfo info{};
|
PipelineInfo info{};
|
||||||
|
|||||||
@@ -163,9 +163,9 @@ void KRSprite::render(RenderInfo& ri)
|
|||||||
|
|
||||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||||
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha);
|
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha);
|
||||||
|
pShader->setImageBinding("diffuseTexture", m_pSpriteTexture, m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER);
|
||||||
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
|
pShader->bind(ri.commandBuffer, *ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass);
|
||||||
|
|
||||||
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -229,27 +229,6 @@ KRTexture* KRTextureManager::getTexture(const std::string& name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRTextureManager::selectTexture(int iTextureUnit, KRTexture* pTexture, float lod_coverage, KRTexture::texture_usage_t textureUsage)
|
|
||||||
{
|
|
||||||
bool is_animated = false;
|
|
||||||
if (pTexture) {
|
|
||||||
pTexture->resetPoolExpiry(lod_coverage, textureUsage);
|
|
||||||
if (pTexture->isAnimated()) is_animated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_boundTextures[iTextureUnit] != pTexture || is_animated) {
|
|
||||||
|
|
||||||
if (pTexture != NULL) {
|
|
||||||
_setActiveTexture(iTextureUnit);
|
|
||||||
//pTexture->bind(iTextureUnit);
|
|
||||||
} else {
|
|
||||||
selectTexture(GL_TEXTURE_2D, iTextureUnit, 0);
|
|
||||||
}
|
|
||||||
m_boundTextures[iTextureUnit] = pTexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KRTextureManager::selectTexture(GLenum target, int iTextureUnit, int iTextureHandle)
|
bool KRTextureManager::selectTexture(GLenum target, int iTextureUnit, int iTextureHandle)
|
||||||
{
|
{
|
||||||
if (m_boundTextureHandles[iTextureUnit] != iTextureHandle) {
|
if (m_boundTextureHandles[iTextureUnit] != iTextureHandle) {
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public:
|
|||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
void selectTexture(int iTextureUnit, KRTexture* pTexture, float lod_coverage, KRTexture::texture_usage_t textureUsage);
|
|
||||||
bool selectTexture(GLenum target, int iTextureUnit, int iTextureHandle);
|
bool selectTexture(GLenum target, int iTextureUnit, int iTextureHandle);
|
||||||
|
|
||||||
KRTexture* loadTexture(const char* szName, const char* szExtension, KRDataBlock* data);
|
KRTexture* loadTexture(const char* szName, const char* szExtension, KRDataBlock* data);
|
||||||
|
|||||||
Reference in New Issue
Block a user