Skip to content

Commit

Permalink
Feat: Destroy world grid mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Jan 5, 2024
1 parent e6813b5 commit 7c5a8de
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 15 deletions.
22 changes: 22 additions & 0 deletions src/atta/event/events/meshDestroy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//--------------------------------------------------
// Atta Event Module
// meshDestroy.h
// Date: 2024-01-05
// By Breno Cunha Queiroz
//--------------------------------------------------
#ifndef ATTA_EVENT_EVENTS_MESH_DESTROY_H
#define ATTA_EVENT_EVENTS_MESH_DESTROY_H
#include <atta/event/event.h>

namespace atta::event {

class MeshDestroy : public EventTyped<SID("MeshDestroy")> {
public:
MeshDestroy(StringId sid_) : sid(sid_) {}

const StringId sid;
};

} // namespace atta::event

#endif // ATTA_EVENT_EVENTS_MESH_DESTROY_H
11 changes: 11 additions & 0 deletions src/atta/graphics/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <atta/event/events/imageLoad.h>
#include <atta/event/events/imageUpdate.h>
#include <atta/event/events/meshDestroy.h>
#include <atta/event/events/meshLoad.h>
#include <atta/event/events/meshUpdate.h>
#include <atta/event/interface.h>
Expand Down Expand Up @@ -79,6 +80,7 @@ void Manager::startUpImpl() {
//----- Resource sync -----//
event::subscribe<event::MeshLoad>(BIND_EVENT_FUNC(Manager::onMeshLoadEvent));
event::subscribe<event::MeshUpdate>(BIND_EVENT_FUNC(Manager::onMeshUpdateEvent));
event::subscribe<event::MeshDestroy>(BIND_EVENT_FUNC(Manager::onMeshDestroyEvent));
event::subscribe<event::ImageLoad>(BIND_EVENT_FUNC(Manager::onImageLoadEvent));
event::subscribe<event::ImageUpdate>(BIND_EVENT_FUNC(Manager::onImageUpdateEvent));
syncResources();
Expand All @@ -93,6 +95,7 @@ void Manager::startUpImpl() {
void Manager::shutDownImpl() {
event::unsubscribe<event::MeshLoad>(BIND_EVENT_FUNC(Manager::onMeshLoadEvent));
event::unsubscribe<event::MeshUpdate>(BIND_EVENT_FUNC(Manager::onMeshUpdateEvent));
event::unsubscribe<event::MeshDestroy>(BIND_EVENT_FUNC(Manager::onMeshDestroyEvent));
event::unsubscribe<event::ImageLoad>(BIND_EVENT_FUNC(Manager::onImageLoadEvent));
event::unsubscribe<event::ImageUpdate>(BIND_EVENT_FUNC(Manager::onImageUpdateEvent));

Expand Down Expand Up @@ -372,6 +375,14 @@ void Manager::onMeshUpdateEvent(event::Event& event) {
LOG_WARN("gfx::Manager", "Can not update mesh [w]$0[] that was not created", e.sid);
}

void Manager::onMeshDestroyEvent(event::Event& event) {
event::MeshDestroy& e = reinterpret_cast<event::MeshDestroy&>(event);
if (_meshes.find(e.sid) != _meshes.end())
_meshes[e.sid].reset();
else
LOG_WARN("gfx::Manager", "Can not destroy mesh [w]$0[] that was not created", e.sid);
}

void Manager::onImageLoadEvent(event::Event& event) {
event::ImageLoad& e = reinterpret_cast<event::ImageLoad&>(event);

Expand Down
1 change: 1 addition & 0 deletions src/atta/graphics/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Manager final {
void syncResources();
void onMeshLoadEvent(event::Event& event);
void onMeshUpdateEvent(event::Event& event);
void onMeshDestroyEvent(event::Event& event);
void onImageLoadEvent(event::Event& event);
void onImageUpdateEvent(event::Event& event);
void createMesh(StringId sid);
Expand Down
5 changes: 1 addition & 4 deletions src/atta/graphics/renderers/common/gridPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ GridPipeline::GridPipeline(std::shared_ptr<RenderPass> renderPass) : _numLines(0

// Create line mesh
_gridMeshName = "atta::gfx::GridPipeline[" + std::to_string(_gridId++) + "]";
LOG_DEBUG("GridPipeline", "Mesh id $0", _gridMeshName);
res::Mesh::CreateInfo meshInfo{};
uint8_t* data = (uint8_t*)_lines.data();
size_t size = _lines.size() * sizeof(Line);
Expand All @@ -33,9 +32,7 @@ GridPipeline::GridPipeline(std::shared_ptr<RenderPass> renderPass) : _numLines(0
res::create<res::Mesh>(_gridMeshName, meshInfo);
}

GridPipeline::~GridPipeline() {
// TODO Delete grid
}
GridPipeline::~GridPipeline() { res::destroy<res::Mesh>(_gridMeshName); }

void GridPipeline::update(std::shared_ptr<Camera> camera) {
// Update grid
Expand Down
9 changes: 5 additions & 4 deletions src/atta/graphics/renderers/fastRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ void FastRenderer::render(std::shared_ptr<Camera> camera) {
return imageGroup;
});

// Update grid data
_gridPipeline->update(camera);

// Update drawer data
if (_renderDrawer)
_drawerPipeline->update();

// Update grid data
_gridPipeline->update(camera);

// Render
_renderQueue->begin();
{
Expand Down Expand Up @@ -115,9 +115,10 @@ void FastRenderer::render(std::shared_ptr<Camera> camera) {
}
_geometryPipeline->end();

_gridPipeline->render(camera);

if (_renderDrawer)
_drawerPipeline->render(camera);
_gridPipeline->render(camera);
}
_renderPass->end();
}
Expand Down
8 changes: 7 additions & 1 deletion src/atta/graphics/renderers/pbrRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PbrRenderer::PbrRenderer() : Renderer("PbrRenderer"), _firstRender(true), _wasRe
{
// Framebuffer
Framebuffer::CreateInfo framebufferInfo{};
framebufferInfo.attachments.push_back({Image::Format::RGB});
framebufferInfo.attachments.push_back({Image::Format::RGBA});
framebufferInfo.attachments.push_back({Image::Format::DEPTH24_STENCIL8});
_width = framebufferInfo.width = 500;
_height = framebufferInfo.height = 500;
Expand All @@ -56,6 +56,7 @@ PbrRenderer::PbrRenderer() : Renderer("PbrRenderer"), _firstRender(true), _wasRe

//---------- Common pipelines ----------//
//_selectedPipeline = std::make_unique<SelectedPipeline>(_geometryRenderPass);
_gridPipeline = std::make_unique<GridPipeline>(_geometryRenderPass);
_drawerPipeline = std::make_unique<DrawerPipeline>(_geometryRenderPass);

////---------- Create background shader ----------//
Expand Down Expand Up @@ -299,6 +300,9 @@ void PbrRenderer::geometryPass(std::shared_ptr<Camera> camera) {
return imageGroup;
});

// Update grid data
_gridPipeline->update(camera);

// Update drawer data
if (_renderDrawer)
_drawerPipeline->update();
Expand Down Expand Up @@ -405,6 +409,8 @@ void PbrRenderer::geometryPass(std::shared_ptr<Camera> camera) {
}
_geometryPipeline->end();

_gridPipeline->render(camera);

if (_renderDrawer)
_drawerPipeline->render(camera);
}
Expand Down
4 changes: 3 additions & 1 deletion src/atta/graphics/renderers/pbrRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <atta/graphics/image.h>
#include <atta/graphics/pipeline.h>
#include <atta/graphics/renderers/common/drawerPipeline.h>
#include <atta/graphics/renderers/common/gridPipeline.h>
#include <atta/graphics/renderers/common/selectedPipeline.h>
#include <atta/graphics/renderers/renderer.h>

Expand Down Expand Up @@ -37,8 +38,9 @@ class PbrRenderer final : public Renderer {
std::shared_ptr<RenderQueue> _renderQueue;
std::shared_ptr<RenderPass> _geometryRenderPass;
std::shared_ptr<Pipeline> _geometryPipeline;
std::unique_ptr<SelectedPipeline> _selectedPipeline;
std::unique_ptr<DrawerPipeline> _drawerPipeline;
std::unique_ptr<GridPipeline> _gridPipeline;
std::unique_ptr<SelectedPipeline> _selectedPipeline;

std::shared_ptr<Shader> _backgroundShader;
bool _firstRender;
Expand Down
8 changes: 7 additions & 1 deletion src/atta/graphics/renderers/phongRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ PhongRenderer::PhongRenderer() : Renderer("PhongRenderer"), _wasResized(false) {
_geometryPipeline = graphics::create<Pipeline>(pipelineInfo);

//---------- Common pipelines ----------//
_selectedPipeline = std::make_unique<SelectedPipeline>(_renderPass);
_drawerPipeline = std::make_unique<DrawerPipeline>(_renderPass);
_gridPipeline = std::make_unique<GridPipeline>(_renderPass);
_selectedPipeline = std::make_unique<SelectedPipeline>(_renderPass);
}

PhongRenderer::~PhongRenderer() {}
Expand All @@ -75,6 +76,9 @@ void PhongRenderer::render(std::shared_ptr<Camera> camera) {
return imageGroup;
});

// Update grid data
_gridPipeline->update(camera);

// Update drawer data
if (_renderDrawer)
_drawerPipeline->update();
Expand Down Expand Up @@ -158,6 +162,8 @@ void PhongRenderer::render(std::shared_ptr<Camera> camera) {
}
_geometryPipeline->end();

_gridPipeline->render(camera);

if (_renderDrawer)
_drawerPipeline->render(camera);
}
Expand Down
4 changes: 3 additions & 1 deletion src/atta/graphics/renderers/phongRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <atta/graphics/pipeline.h>
#include <atta/graphics/renderPass.h>
#include <atta/graphics/renderers/common/drawerPipeline.h>
#include <atta/graphics/renderers/common/gridPipeline.h>
#include <atta/graphics/renderers/common/selectedPipeline.h>
#include <atta/graphics/renderers/renderer.h>

Expand All @@ -30,8 +31,9 @@ class PhongRenderer final : public Renderer {
std::shared_ptr<RenderQueue> _renderQueue;
std::shared_ptr<RenderPass> _renderPass;
std::shared_ptr<Pipeline> _geometryPipeline;
std::unique_ptr<SelectedPipeline> _selectedPipeline;
std::unique_ptr<DrawerPipeline> _drawerPipeline;
std::unique_ptr<GridPipeline> _gridPipeline;
std::unique_ptr<SelectedPipeline> _selectedPipeline;

bool _wasResized;
};
Expand Down
2 changes: 0 additions & 2 deletions src/atta/graphics/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const BufferLayout& Shader::getPerFrameImageLayout() const { return _perFrameIma
const BufferLayout& Shader::getPerDrawImageLayout() const { return _perDrawImageLayout; }

void Shader::processASL() {
LOG_DEBUG("gfx::Shader", "Preprocess ASL: [w]$0", _file.string());

// Remove comments
_aslCode = removeComments(_aslCode);

Expand Down
6 changes: 5 additions & 1 deletion src/atta/resource/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <atta/event/events/materialCreate.h>
#include <atta/event/events/materialDestroy.h>
#include <atta/event/events/materialUpdate.h>
#include <atta/event/events/meshDestroy.h>
#include <atta/event/events/meshLoad.h>
#include <atta/event/events/projectOpen.h>
#include <atta/file/manager.h>
Expand Down Expand Up @@ -96,7 +97,10 @@ void Manager::createLoadEvent<Material>(Material* resource, StringId sid) {
}

template <>
void Manager::createDestroyEvent<Mesh>(StringId sid) {}
void Manager::createDestroyEvent<Mesh>(StringId sid) {
event::MeshDestroy e(sid);
event::publish(e);
}
template <>
void Manager::createDestroyEvent<Image>(StringId sid) {}
template <>
Expand Down

0 comments on commit 7c5a8de

Please sign in to comment.