tidy up graphics code

This commit is contained in:
Bailey Harrison 2023-05-29 14:52:14 +01:00
parent 7e2da23398
commit 6d49f022ec
5 changed files with 1683 additions and 1588 deletions

View File

@ -22,14 +22,22 @@ class GFXDevice {
gfx::DrawBuffer* BeginRender(); gfx::DrawBuffer* BeginRender();
/* - draw_buffer MUST be a valid pointer returned by BeginRender().
- draw_buffer is invalid after this function has been called. */
void FinishRender(gfx::DrawBuffer* draw_buffer); void FinishRender(gfx::DrawBuffer* draw_buffer);
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- pipeline MUST be a valid pointer returned by CreatePipeline() */
void CmdBindPipeline(gfx::DrawBuffer* draw_buffer, void CmdBindPipeline(gfx::DrawBuffer* draw_buffer,
const gfx::Pipeline* pipeline); const gfx::Pipeline* pipeline);
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding, void CmdBindVertexBuffer(gfx::DrawBuffer* draw_buffer, uint32_t binding,
const gfx::Buffer* buffer); const gfx::Buffer* buffer);
/* - draw_buffer MUST be a valid pointer returned by BeginRender()
- buffer MUST be a valid pointer returned by CreateBuffer */
void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer, void CmdBindIndexBuffer(gfx::DrawBuffer* draw_buffer,
const gfx::Buffer* buffer); const gfx::Buffer* buffer);
@ -57,6 +65,8 @@ class GFXDevice {
gfx::DescriptorSet* AllocateDescriptorSet( gfx::DescriptorSet* AllocateDescriptorSet(
const gfx::DescriptorSetLayout* layout); const gfx::DescriptorSetLayout* layout);
void FreeDescriptorSet(const gfx::DescriptorSet* set);
// This updates all copies of the descriptor. // This updates all copies of the descriptor.
// This cannot be used after any frames have been renderered // This cannot be used after any frames have been renderered
void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set, void UpdateDescriptorUniformBuffer(const gfx::DescriptorSet* set,

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,7 @@ std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(
CharacterRenderInfo renderInfo{}; CharacterRenderInfo renderInfo{};
renderInfo.advance = advanceWidth * sf; renderInfo.advance = static_cast<int>(static_cast<float>(advanceWidth) * sf);
if (stbtt_IsGlyphEmpty(font_info_.get(), glyph_index) == 0) { if (stbtt_IsGlyphEmpty(font_info_.get(), glyph_index) == 0) {
renderInfo.isEmpty = false; renderInfo.isEmpty = false;

View File

@ -100,6 +100,7 @@ Texture::Texture(RenderData* render_data, const uint8_t* bitmap, int width,
Texture::~Texture() { Texture::~Texture() {
LOG_INFO("Destroying texture..."); LOG_INFO("Destroying texture...");
gfx_->FreeDescriptorSet(descriptor_set_);
gfx_->DestroyImage(image_); gfx_->DestroyImage(image_);
} }

View File

@ -175,16 +175,18 @@ void PlayGame(GameSettings settings) {
time_elapsed += ts; time_elapsed += ts;
if (time_elapsed >= 1.0f) { if (time_elapsed >= 1.0f) {
time_elapsed = 0; time_elapsed = 0;
LOG_INFO("Time step: {}", ts);
int fpsWidth, fpsHeight; int fpsWidth, fpsHeight;
auto fpsBitmap = LOG_INFO("Creating new bitmap...");
/*auto fpsBitmap =
app.GetResource<engine::resources::Font>("builtin.mono") app.GetResource<engine::resources::Font>("builtin.mono")
->GetTextBitmap("fps", 768.0f, fpsWidth, fpsHeight); ->GetTextBitmap(std::to_string(ts), 768.0f, fpsWidth, fpsHeight);*/
textbox_renderable->material->texture_ = LOG_INFO("Bitmap created! Loading into new texture...");
/*textbox_renderable->material->texture_ =
std::make_unique<engine::resources::Texture>( std::make_unique<engine::resources::Texture>(
&app.render_data_, fpsBitmap->data(), fpsWidth, fpsHeight, &app.render_data_, fpsBitmap->data(), fpsWidth, fpsHeight,
engine::resources::Texture::Filtering::kBilinear); engine::resources::Texture::Filtering::kBilinear);*/
LOG_INFO("Texture created!");
} }
}; };
} }