mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
support shader draw calls without vertex data
This commit is contained in:
parent
a26fa5153b
commit
a8ac1dbe1a
@ -12,6 +12,8 @@ struct RenderableComponent {
|
||||
std::shared_ptr<resources::Mesh> mesh;
|
||||
std::shared_ptr<resources::Material> material;
|
||||
bool shown = true;
|
||||
uint32_t index_count_override =
|
||||
0; // for shaders that don't use vertex/index buffers, 0 means ignored
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
@ -45,6 +45,10 @@ class GFXDevice {
|
||||
uint32_t instance_count, uint32_t first_index,
|
||||
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,
|
||||
const gfx::Pipeline* pipeline, uint32_t offset,
|
||||
uint32_t size, const void* data);
|
||||
|
@ -225,12 +225,6 @@ void Application::GameLoop() {
|
||||
/* logic */
|
||||
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();
|
||||
if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] {
|
||||
lastTick = now;
|
||||
|
@ -844,6 +844,13 @@ void GFXDevice::CmdDrawIndexed(gfx::DrawBuffer* drawBuffer, uint32_t indexCount,
|
||||
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,
|
||||
const gfx::Pipeline* pipeline, uint32_t offset,
|
||||
uint32_t size, const void* data) {
|
||||
|
@ -79,7 +79,6 @@ void RenderSystem::OnUpdate(float ts) {
|
||||
assert(r != nullptr);
|
||||
assert(r->material != nullptr);
|
||||
assert(r->material->texture_ != nullptr);
|
||||
assert(r->mesh != nullptr);
|
||||
if (r->shown == false) continue;
|
||||
|
||||
auto t = scene_->GetComponent<TransformComponent>(entity);
|
||||
@ -90,10 +89,17 @@ void RenderSystem::OnUpdate(float ts) {
|
||||
const gfx::Pipeline* pipeline = r->material->GetShader()->GetPipeline();
|
||||
|
||||
DrawCallData data{};
|
||||
data.vb = r->mesh->GetVB();
|
||||
data.ib = r->mesh->GetIB();
|
||||
if (r->mesh) {
|
||||
data.vb = r->mesh->GetVB();
|
||||
data.ib = r->mesh->GetIB();
|
||||
}
|
||||
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;
|
||||
|
||||
unsorted_draw_calls.emplace_back(
|
||||
@ -134,10 +140,14 @@ void RenderSystem::OnUpdate(float ts) {
|
||||
draw_call.material_set, 2);
|
||||
gfx_->CmdPushConstants(render_data.draw_buffer, pipeline, 0,
|
||||
sizeof(PushConstants), &draw_call.push_constants);
|
||||
gfx_->CmdBindVertexBuffer(render_data.draw_buffer, 0, draw_call.vb);
|
||||
gfx_->CmdBindIndexBuffer(render_data.draw_buffer, draw_call.ib);
|
||||
gfx_->CmdDrawIndexed(render_data.draw_buffer, draw_call.index_count, 1, 0,
|
||||
0, 0);
|
||||
if (draw_call.ib) {
|
||||
gfx_->CmdBindVertexBuffer(render_data.draw_buffer, 0, draw_call.vb);
|
||||
gfx_->CmdBindIndexBuffer(render_data.draw_buffer, draw_call.ib);
|
||||
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 */
|
||||
|
@ -154,7 +154,8 @@ void PlayGame(GameSettings settings) {
|
||||
std::make_unique<engine::resources::Texture>(
|
||||
&app.render_data_, bitmap->data(), width, height,
|
||||
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 =
|
||||
my_scene->GetComponent<engine::TransformComponent>(textbox);
|
||||
textTransform->scale.y =
|
||||
@ -169,26 +170,12 @@ void PlayGame(GameSettings settings) {
|
||||
LOG_INFO("Textbox custom component initialised!");
|
||||
};
|
||||
|
||||
textboxComponent->onUpdate = [&](float ts) {
|
||||
(void)ts;
|
||||
textboxComponent->onUpdate = [](float ts) {
|
||||
static float time_elapsed;
|
||||
time_elapsed += ts;
|
||||
if (time_elapsed >= 1.0f) {
|
||||
time_elapsed = 0.0f;
|
||||
|
||||
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!");
|
||||
LOG_INFO("COMPONENT UPDATE");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user