Skip to content

Commit

Permalink
gh-81: start implementing mesh manager
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Sep 13, 2024
1 parent 005ed8b commit d033e35
Show file tree
Hide file tree
Showing 46 changed files with 480 additions and 437 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
![language](https://img.shields.io/badge/language-C++17-_)
![license](https://img.shields.io/badge/license-MIT-_)

**"Write my own game engine (wmoge)"** is a modern high-performance 2d and 3d graphics game engine with Vulkan and
**"Write my own game engine (wmoge)"** is a modern high-performance 3d graphics game engine with Vulkan and
OpenGL backends. The idea of the project is to implement a self-sufficient, small, but featured engine and a number of
2d and 3d games using it. Primary focus is the core architecture of the engine, reliability, clean and performant code.
Currently, the work is focused on a minor refactoring, new runtime scene representation, building a high-level rendering
Expand All @@ -22,9 +22,6 @@ project for educational purposes only.
guide:** [github.com/EgorOrachyov/wmoge/blob/main/CONTRIBUTING.md](https://github.com/EgorOrachyov/wmoge/blob/main/CONTRIBUTING.md)
* **Source code:** [github.com/EgorOrachyov/wmoge](https://github.com/EgorOrachyov/wmoge)

![gif](https://github.com/EgorOrachyov/wmoge/raw/main/docs/media/background.gif?raw=true&sanitize=true)
> Work in progress, new features coming soon! This 2d demo is an old build!
## About the engine

### Features
Expand All @@ -38,7 +35,9 @@ project for educational purposes only.
* ⚙ Command line and hook system to build custom tools.
* ⚙ Simple stack-based config system.
* ⚙ Dependency injection and IoC container system for global managers.
* 🎥 Abstract graphics (gfx) device interface for GPU driver communication.
* 🎥 Higl-level render dendency graph (RDG) for scheduling GPU rendering and compute work.
* 🎥 Modern graphics (gfx) device interface for GPU driver communication.
* 🎥 Explicit command list and resource bariers management in gfx api.
* 🎥 Vulkan-based gfx device backend.
* 🎥 (future) OpenGL-based gfx device backend.
* 🎥 (future) DX12-based gfx device backend.
Expand All @@ -57,7 +56,6 @@ project for educational purposes only.
* 🅰️ Custom math library with 2d and 3d-space primitives.
* 🅰️ (future) SIMD utilities for fast vectorized math.
* 🧱 Ecs-based scene model with fast, parallel and memory-friendly update.
* 🧱 Tree-based object model for editor (offline) scene description.
* 🎧 (in progress) OpenAL audio renderer for playing game sounds.
* 📜 (in progress) Modern Lua scripting backend for game logic programming.
* 🐞 Built-in CPU performance and tasking profiling with support to google trace exporting.
Expand Down
11 changes: 9 additions & 2 deletions engine/plugins/assimp/assimp_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "math/math_utils3d.hpp"
#include "mesh/mesh.hpp"
#include "mesh/mesh_builder.hpp"
#include "mesh/mesh_manager.hpp"
#include "platform/file_system.hpp"
#include "profiler/profiler.hpp"
#include "system/ioc_container.hpp"
Expand Down Expand Up @@ -77,11 +78,15 @@ namespace wmoge {
return StatusCode::Error;
}

Ref<Mesh> mesh = make_ref<Mesh>();
MeshManager* mesh_manager = IocContainer::iresolve_v<MeshManager>();

MeshFlags flags;
flags.set(MeshFlag::FromDisk);

Ref<Mesh> mesh = mesh_manager->create_mesh(flags);

asset = mesh;
asset->set_name(name);
asset->set_import_data(meta.import_data);

MeshBuilder& builder = importer.get_builder();
builder.set_mesh(mesh);
Expand All @@ -90,6 +95,8 @@ namespace wmoge {
return StatusCode::Error;
}

mesh_manager->init_mesh(mesh.get());

return WG_OK;
}

Expand Down
5 changes: 1 addition & 4 deletions engine/plugins/assimp/assimp_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace wmoge {
const GfxVertAttribs attribs = m_attribs;

Ref<ArrayMesh> array_mesh = make_ref<ArrayMesh>();
array_mesh->set_name(SID(get_file_name() + "." + name.str()));
array_mesh->set_aabb(aabb);

for (unsigned int vert_id = 0; vert_id < num_vertices; vert_id++) {
Expand Down Expand Up @@ -180,10 +181,6 @@ namespace wmoge {

m_builder.add_chunk(name, array_mesh);

if (parent) {
m_builder.add_child(parent.value(), get_next_mesh_id());
}

return WG_OK;
}

Expand Down
1 change: 0 additions & 1 deletion engine/plugins/freetype/freetype_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ namespace wmoge {

asset = font;
asset->set_name(name);
asset->set_import_data(meta.import_data);

FreetypeFont loader;
return loader.load(font, import_data->source_files[0].file, import_data->height, import_data->glyphs_in_row);
Expand Down
2 changes: 1 addition & 1 deletion engine/plugins/freetype/freetype_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace wmoge {

font_desc.texture = m_texture_manager->create_2d(flags, GfxFormat::R8, bitmap_width, bitmap_height, GfxTexSwizz::RRRRtoRGBA);
font_desc.texture->set_name(SID(font->get_name().str() + "_bitmap"));
font_desc.texture->set_sampler_from_desc(sampler_desc);
font_desc.texture->set_sampler(m_gfx_driver->make_sampler(sampler_desc, SID(sampler_desc.to_string())));
font_desc.texture->set_compression(compression_params);
font_desc.texture->set_source_images({bitmap});

Expand Down
1 change: 0 additions & 1 deletion engine/plugins/runtime/asset/default_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ namespace wmoge {
};

asset->set_name(name);
asset->set_import_data(meta.import_data);

IoContext context;

Expand Down
1 change: 0 additions & 1 deletion engine/plugins/runtime/asset/image_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace wmoge {

asset = image;
asset->set_name(name);
asset->set_import_data(meta.import_data);

return image->load(import_data->source_files[0].file, import_data->channels);
}
Expand Down
1 change: 0 additions & 1 deletion engine/plugins/runtime/asset/shader_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ namespace wmoge {

asset = shader;
asset->set_name(name);
asset->set_import_data(meta.import_data);

return WG_OK;
}
Expand Down
8 changes: 4 additions & 4 deletions engine/plugins/runtime/asset/texture_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace wmoge {
return StatusCode::FailedResize;
}

auto gfx_driver = IocContainer::iresolve_v<GfxDriver>();
auto texture_manager = IocContainer::iresolve_v<TextureManager>();

TextureFlags flags;
Expand All @@ -84,10 +85,9 @@ namespace wmoge {

asset = texture;
asset->set_name(name);
asset->set_import_data(meta.import_data);

texture->set_source_images({source_image});
texture->set_sampler_from_desc(import_data->sampling);
texture->set_sampler(gfx_driver->make_sampler(import_data->sampling, SID(import_data->sampling.to_string())));
texture->set_compression(import_data->compression);

if (import_data->mipmaps) {
Expand Down Expand Up @@ -150,6 +150,7 @@ namespace wmoge {
}
}

auto gfx_driver = IocContainer::iresolve_v<GfxDriver>();
auto texture_manager = IocContainer::iresolve_v<TextureManager>();

TextureFlags flags;
Expand All @@ -170,10 +171,9 @@ namespace wmoge {

asset = texture;
asset->set_name(name);
asset->set_import_data(meta.import_data);

texture->set_source_images(source_images);
texture->set_sampler_from_desc(import_data->sampling);
texture->set_sampler(gfx_driver->make_sampler(import_data->sampling, SID(import_data->sampling.to_string())));
texture->set_compression(import_data->compression);

if (import_data->mipmaps) {
Expand Down
1 change: 0 additions & 1 deletion engine/plugins/runtime/asset/wav_asset_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ namespace wmoge {

asset = audio;
asset->set_name(name);
asset->set_import_data(meta.import_data);

return audio->load(import_data->source_files[0].file);
}
Expand Down
21 changes: 8 additions & 13 deletions engine/runtime/asset/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#pragma once

#include "asset/asset_import_data.hpp"
#include "core/buffered_vector.hpp"
#include "core/class.hpp"
#include "core/flat_set.hpp"
Expand Down Expand Up @@ -95,29 +94,25 @@ namespace wmoge {
public:
WG_RTTI_CLASS(Asset, RttiObject);

void set_name(Strid name) { m_id = AssetId(name); }
void set_id(AssetId id) { m_id = id; }
void set_uuid(UUID uuid) { m_uuid = uuid; }
void set_import_data(Ref<AssetImportData> import_data) { m_import_data = std::move(import_data); }
const Strid& get_name() { return m_id.sid(); }
const AssetId& get_id() { return m_id; }
const UUID& get_uuid() { return m_uuid; }
const Ref<AssetImportData>& get_import_data() const { return m_import_data; }
void set_name(Strid name) { m_id = AssetId(name); }
void set_id(AssetId id) { m_id = id; }
void set_uuid(UUID uuid) { m_uuid = uuid; }
const Strid& get_name() { return m_id.sid(); }
const AssetId& get_id() { return m_id; }
const UUID& get_uuid() { return m_uuid; }

virtual void collect_deps(class AssetDependencies& deps) {}

private:
AssetId m_id;
UUID m_uuid;
Ref<AssetImportData> m_import_data;
AssetId m_id;
UUID m_uuid;
};

WG_RTTI_CLASS_BEGIN(Asset) {
WG_RTTI_META_DATA(RttiUiHint("Base class for any engine asset"));
WG_RTTI_FACTORY();
WG_RTTI_FIELD(m_id, {RttiNoSaveLoad});
WG_RTTI_FIELD(m_uuid, {RttiNoSaveLoad});
WG_RTTI_FIELD(m_import_data, {RttiNoSaveLoad});
}
WG_RTTI_END;

Expand Down
8 changes: 1 addition & 7 deletions engine/runtime/asset/asset_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,12 @@ namespace wmoge {
void load_loaders();

private:
/**
* @class LoadState
* @brief Tracks loading state of a single asset
*/
class LoadState {
public:
struct LoadState {
buffered_vector<Async> deps;
AsyncOp<Ref<Asset>> async_op;
TaskHnd task_hnd;
};

private:
buffered_vector<std::shared_ptr<AssetPak>> m_paks;
flat_map<AssetId, WeakRef<Asset>> m_assets;
flat_map<AssetId, LoadState> m_loading;
Expand Down
2 changes: 1 addition & 1 deletion engine/runtime/asset/asset_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace wmoge {
Status yaml_read(IoContext& context, YamlConstNodeRef node, AssetRef<T>& ref) {
AssetId id;
WG_YAML_READ(context, node, id);
Ref<T> ptr = context.get_asset_manager()->load(id).cast<T>();
Ref<T> ptr = context.get_asset_manager()->find(id).cast<T>();
if (!ptr) {
return StatusCode::NoAsset;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/runtime/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
#include "mesh/mesh_batch.hpp"
#include "mesh/mesh_bucket.hpp"
#include "mesh/mesh_builder.hpp"
#include "mesh/mesh_manager.hpp"
#include "mesh/mesh_pass.hpp"

#include "pfx/pfx_component.hpp"
Expand Down Expand Up @@ -201,7 +202,6 @@
#include "render/graphics_pipeline.hpp"
#include "render/light.hpp"
#include "render/model.hpp"
#include "render/model_instance.hpp"
#include "render/render_engine.hpp"
#include "render/render_queue.hpp"
#include "render/render_scene.hpp"
Expand Down
15 changes: 0 additions & 15 deletions engine/runtime/gfx/gfx_buffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,4 @@ namespace wmoge {
return d;
}

WG_IO_BEGIN(GfxVertStream)
WG_IO_FIELD(attribs)
WG_IO_FIELD(buffer)
WG_IO_FIELD(offset)
WG_IO_FIELD(size)
WG_IO_FIELD(stride)
WG_IO_END(GfxVertStream)

WG_IO_BEGIN(GfxIndexStream)
WG_IO_FIELD(index_type)
WG_IO_FIELD(buffer)
WG_IO_FIELD(offset)
WG_IO_FIELD(size)
WG_IO_END(GfxIndexStream)

}// namespace wmoge
28 changes: 0 additions & 28 deletions engine/runtime/gfx/gfx_buffers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "core/data.hpp"
#include "gfx/gfx_resource.hpp"
#include "io/serialization.hpp"

#include <array>

Expand Down Expand Up @@ -160,31 +159,4 @@ namespace wmoge {
/** @brief Setup to bind storage buffer */
using GfxStorageBufferSetup = GfxBufferSetup<GfxStorageBuffer>;

/**
* @class GfxVertStream
* @brief Provides setup for a stream of vertex attributes packed into vertex buffer
*/
struct GfxVertStream {
GfxVertAttribs attribs;
int buffer = -1;
int offset = 0;
int size = 0;
int stride = 0;

WG_IO_DECLARE(GfxVertStream);
};

/**
* @class GfxIndexStream
* @brief Provides setup with index data packed into index buffer
*/
struct GfxIndexStream {
GfxIndexType index_type = GfxIndexType::None;
int buffer = -1;
int offset = 0;
int size = 0;

WG_IO_DECLARE(GfxIndexStream);
};

}// namespace wmoge
7 changes: 7 additions & 0 deletions engine/runtime/gfx/vulkan/vk_cmd_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "gfx/vulkan/vk_driver.hpp"
#include "gfx/vulkan/vk_queues.hpp"
#include "profiler/profiler.hpp"

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -57,6 +58,8 @@ namespace wmoge {
}

void VKCmdManager::update(std::size_t frame_id) {
WG_AUTO_PROFILE_VULKAN("VKCmdManager::update");

m_frame_id = frame_id;
m_index = m_frame_id % GfxLimits::FRAMES_IN_FLIGHT;

Expand Down Expand Up @@ -116,6 +119,8 @@ namespace wmoge {
}

void VKCmdManager::submit(GfxQueueType queue_type, VkCommandBuffer buffer, array_view<VkSemaphore> wait, array_view<VkSemaphore> signal, VkFence fence) {
WG_AUTO_PROFILE_VULKAN("VKCmdManager::submit");

assert(buffer);

WG_VK_CHECK(vkEndCommandBuffer(buffer));
Expand Down Expand Up @@ -175,6 +180,8 @@ namespace wmoge {
}

void VKCmdManager::flush(array_view<VkSemaphore> wait, array_view<VkSemaphore> signal) {
WG_AUTO_PROFILE_VULKAN("VKCmdManager::flush");

buffered_vector<VkPipelineStageFlags> wait_flags;

for (CmdBufferQueue& queue : m_queues) {
Expand Down
1 change: 0 additions & 1 deletion engine/runtime/glsl/glsl_shader_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "core/timer.hpp"
#include "glsl/glsl_builder.hpp"
#include "glsl/glsl_include_processor.hpp"
#include "grc/shader_compiler_task_manager.hpp"
#include "io/archive.hpp"
#include "io/enum.hpp"
#include "profiler/profiler.hpp"
Expand Down
2 changes: 1 addition & 1 deletion engine/runtime/grc/pso_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include "core/task.hpp"
#include "gfx/gfx_driver.hpp"
#include "grc/shader_compiler_task_manager.hpp"
#include "grc/shader_compiler.hpp"
#include "grc/shader_library.hpp"
#include "profiler/profiler.hpp"
#include "system/ioc_container.hpp"
Expand Down
Loading

0 comments on commit d033e35

Please sign in to comment.