support shader draw calls without vertex data

This commit is contained in:
Bailey Harrison 2023-08-04 21:33:14 +01:00
parent a26fa5153b
commit a8ac1dbe1a
6 changed files with 35 additions and 31 deletions

View File

@ -12,6 +12,8 @@ struct RenderableComponent {
std::shared_ptr<resources::Mesh> mesh; std::shared_ptr<resources::Mesh> mesh;
std::shared_ptr<resources::Material> material; std::shared_ptr<resources::Material> material;
bool shown = true; bool shown = true;
uint32_t index_count_override =
0; // for shaders that don't use vertex/index buffers, 0 means ignored
}; };
} // namespace engine } // namespace engine

View File

@ -45,6 +45,10 @@ class GFXDevice {
uint32_t instance_count, uint32_t first_index, uint32_t instance_count, uint32_t first_index,
int32_t vertex_offset, uint32_t first_instance); int32_t vertex_offset, uint32_t first_instance);
void CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count,
uint32_t instance_count, uint32_t first_vertex,
uint32_t first_instance);
void CmdPushConstants(gfx::DrawBuffer* draw_buffer, void CmdPushConstants(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline, uint32_t offset, const gfx::Pipeline* pipeline, uint32_t offset,
uint32_t size, const void* data); uint32_t size, const void* data);

View File

@ -225,12 +225,6 @@ void Application::GameLoop() {
/* logic */ /* logic */
scene_manager_->UpdateActiveScene(window_->dt()); scene_manager_->UpdateActiveScene(window_->dt());
if (window_->GetKeyPress(inputs::Key::K_F)) [[unlikely]] {
window_->InfoBox("fps", std::to_string(window_->GetFPS()) + " fps " +
std::to_string(window_->dt() * 1000.0f) +
" ms");
}
uint64_t now = window_->GetNanos(); uint64_t now = window_->GetNanos();
if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] { if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] {
lastTick = now; lastTick = now;

View File

@ -844,6 +844,13 @@ void GFXDevice::CmdDrawIndexed(gfx::DrawBuffer* drawBuffer, uint32_t indexCount,
firstIndex, vertexOffset, firstInstance); firstIndex, vertexOffset, firstInstance);
} }
void GFXDevice::CmdDraw(gfx::DrawBuffer* drawBuffer, uint32_t vertex_count,
uint32_t instance_count, uint32_t first_vertex,
uint32_t first_instance) {
assert(drawBuffer != nullptr);
vkCmdDraw(drawBuffer->frameData.drawBuf, vertex_count, instance_count, first_vertex, first_instance);
}
void GFXDevice::CmdPushConstants(gfx::DrawBuffer* drawBuffer, void GFXDevice::CmdPushConstants(gfx::DrawBuffer* drawBuffer,
const gfx::Pipeline* pipeline, uint32_t offset, const gfx::Pipeline* pipeline, uint32_t offset,
uint32_t size, const void* data) { uint32_t size, const void* data) {

View File

@ -79,7 +79,6 @@ void RenderSystem::OnUpdate(float ts) {
assert(r != nullptr); assert(r != nullptr);
assert(r->material != nullptr); assert(r->material != nullptr);
assert(r->material->texture_ != nullptr); assert(r->material->texture_ != nullptr);
assert(r->mesh != nullptr);
if (r->shown == false) continue; if (r->shown == false) continue;
auto t = scene_->GetComponent<TransformComponent>(entity); auto t = scene_->GetComponent<TransformComponent>(entity);
@ -90,10 +89,17 @@ void RenderSystem::OnUpdate(float ts) {
const gfx::Pipeline* pipeline = r->material->GetShader()->GetPipeline(); const gfx::Pipeline* pipeline = r->material->GetShader()->GetPipeline();
DrawCallData data{}; DrawCallData data{};
data.vb = r->mesh->GetVB(); if (r->mesh) {
data.ib = r->mesh->GetIB(); data.vb = r->mesh->GetVB();
data.ib = r->mesh->GetIB();
}
data.material_set = r->material->texture_->GetDescriptorSet(); data.material_set = r->material->texture_->GetDescriptorSet();
data.index_count = r->mesh->GetCount(); if (r->index_count_override == 0) {
assert(r->mesh != nullptr);
data.index_count = r->mesh->GetCount();
} else {
data.index_count = r->index_count_override;
}
data.push_constants.model = t->world_matrix; data.push_constants.model = t->world_matrix;
unsorted_draw_calls.emplace_back( unsorted_draw_calls.emplace_back(
@ -134,10 +140,14 @@ void RenderSystem::OnUpdate(float ts) {
draw_call.material_set, 2); draw_call.material_set, 2);
gfx_->CmdPushConstants(render_data.draw_buffer, pipeline, 0, gfx_->CmdPushConstants(render_data.draw_buffer, pipeline, 0,
sizeof(PushConstants), &draw_call.push_constants); sizeof(PushConstants), &draw_call.push_constants);
gfx_->CmdBindVertexBuffer(render_data.draw_buffer, 0, draw_call.vb); if (draw_call.ib) {
gfx_->CmdBindIndexBuffer(render_data.draw_buffer, draw_call.ib); gfx_->CmdBindVertexBuffer(render_data.draw_buffer, 0, draw_call.vb);
gfx_->CmdDrawIndexed(render_data.draw_buffer, draw_call.index_count, 1, 0, gfx_->CmdBindIndexBuffer(render_data.draw_buffer, draw_call.ib);
0, 0); gfx_->CmdDrawIndexed(render_data.draw_buffer, draw_call.index_count, 1, 0,
0, 0);
} else {
gfx_->CmdDraw(render_data.draw_buffer, draw_call.index_count, 1, 0, 0);
}
} }
/* draw */ /* draw */

View File

@ -154,7 +154,8 @@ void PlayGame(GameSettings settings) {
std::make_unique<engine::resources::Texture>( std::make_unique<engine::resources::Texture>(
&app.render_data_, bitmap->data(), width, height, &app.render_data_, bitmap->data(), width, height,
engine::resources::Texture::Filtering::kAnisotropic); engine::resources::Texture::Filtering::kAnisotropic);
textbox_renderable->mesh = GenSphereMesh(app.gfxdev(), 1.0f, 5); textbox_renderable->mesh = nullptr;
textbox_renderable->index_count_override = 6;
auto textTransform = auto textTransform =
my_scene->GetComponent<engine::TransformComponent>(textbox); my_scene->GetComponent<engine::TransformComponent>(textbox);
textTransform->scale.y = textTransform->scale.y =
@ -169,26 +170,12 @@ void PlayGame(GameSettings settings) {
LOG_INFO("Textbox custom component initialised!"); LOG_INFO("Textbox custom component initialised!");
}; };
textboxComponent->onUpdate = [&](float ts) { textboxComponent->onUpdate = [](float ts) {
(void)ts;
static float time_elapsed; static float time_elapsed;
time_elapsed += ts; time_elapsed += ts;
if (time_elapsed >= 1.0f) { if (time_elapsed >= 1.0f) {
time_elapsed = 0.0f; time_elapsed = 0.0f;
LOG_INFO("COMPONENT UPDATE");
LOG_INFO("COMPONENT UPDATE");
// LOG_INFO("Creating new bitmap...");
// auto fpsBitmap =
// app.GetResource<engine::resources::Font>("builtin.mono")
// ->GetTextBitmap(std::to_string(ts), 768.0f, fpsWidth,
// fpsHeight);
// LOG_INFO("Bitmap created! Loading into new texture...");
// textbox_renderable->material->texture_ =
// std::make_unique<engine::resources::Texture>(
// &app.render_data_, fpsBitmap->data(), fpsWidth, fpsHeight,
// engine::resources::Texture::Filtering::kBilinear);
// LOG_INFO("Texture created!");
} }
}; };
} }