Replacing glDraw commands with vkCmdDraw and populating PipelineInfo with vertex formats.

This commit is contained in:
2022-07-05 21:40:26 -07:00
parent bbc0de400c
commit 54e484bd71
3 changed files with 19 additions and 6 deletions

View File

@@ -137,6 +137,8 @@ void KRDirectionalLight::render(RenderInfo& ri) {
Vector3 light_direction_view_space = getWorldLightDirection();
light_direction_view_space = Matrix4::Dot(matModelViewInverseTranspose, light_direction_view_space);
light_direction_view_space.normalize();
KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES;
PipelineInfo info{};
std::string shader_name("light_directional");
@@ -146,6 +148,9 @@ void KRDirectionalLight::render(RenderInfo& ri) {
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), nullptr, &this_light, nullptr, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
@@ -154,8 +159,8 @@ void KRDirectionalLight::render(RenderInfo& ri) {
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_INTENSITY, m_intensity * 0.01f);
// Render a full screen quad
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0);
}
}
}

View File

@@ -100,6 +100,9 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) {
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA);
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
// Vector3 rim_color; Vector4 fade_color;
@@ -113,7 +116,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) {
, "Newtonian Particles"
#endif
);
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3));
vkCmdDraw(ri.commandBuffer, particle_count * 3, 1, 0, 0);
}
}
}

View File

@@ -140,7 +140,9 @@ void KRSprite::render(RenderInfo& ri) {
if(m_pSpriteTexture) {
// 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;
// Render light sprite on transparency pass
PipelineInfo info{};
std::string shader_name("sprite");
@@ -152,12 +154,15 @@ void KRSprite::render(RenderInfo& ri) {
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = KRMesh::model_format_t::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0);
}
}
}