mirror of
https://github.com/bailwillharr/engine.git
synced 2024-09-21 04:51:18 +00:00
Begin refactor (broken builds)
This commit is contained in:
parent
52f4203e9e
commit
774e80aa8e
@ -1,7 +1,7 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Google
|
||||
AccessModifierOffset: -1
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
|
@ -43,70 +43,69 @@ set(SRC_FILES
|
||||
"src/libs/weldmesh.c"
|
||||
"src/libs/weldmesh.h"
|
||||
"src/renderer.cpp"
|
||||
"src/resources/font.cpp"
|
||||
"src/resources/material.cpp"
|
||||
"src/resources/mesh.cpp"
|
||||
"src/resources/shader.cpp"
|
||||
"src/resources/texture.cpp"
|
||||
"src/resource_font.cpp"
|
||||
"src/resource_material.cpp"
|
||||
"src/resource_mesh.cpp"
|
||||
"src/resource_shader.cpp"
|
||||
"src/resource_texture.cpp"
|
||||
"src/scene.cpp"
|
||||
"src/scene_manager.cpp"
|
||||
"src/systems/collisions.cpp"
|
||||
"src/systems/custom_behaviour.cpp"
|
||||
"src/systems/mesh_render_system.cpp"
|
||||
"src/systems/ui_render_system.cpp"
|
||||
"src/systems/transform.cpp"
|
||||
"src/util/files.cpp"
|
||||
"src/util/gen_tangents.cpp"
|
||||
"src/util/gltf_loader.cpp"
|
||||
"src/vulkan/device.cpp"
|
||||
"src/vulkan/device.h"
|
||||
"src/vulkan/gpu_allocator.cpp"
|
||||
"src/vulkan/gpu_allocator.h"
|
||||
"src/vulkan/instance.cpp"
|
||||
"src/vulkan/instance.h"
|
||||
"src/vulkan/swapchain.cpp"
|
||||
"src/vulkan/swapchain.h"
|
||||
"src/system_collisions.cpp"
|
||||
"src/system_custom_behaviour.cpp"
|
||||
"src/system_mesh_render.cpp"
|
||||
"src/system_transform.cpp"
|
||||
"src/files.cpp"
|
||||
"src/gen_tangents.cpp"
|
||||
"src/gltf_loader.cpp"
|
||||
"src/vulkan_device.cpp"
|
||||
"src/vulkan_allocator.cpp"
|
||||
"src/vulkan_instance.cpp"
|
||||
"src/vulkan_swapchain.cpp"
|
||||
"src/window.cpp"
|
||||
"src/util/file_dialog.cpp")
|
||||
"src/file_dialog.cpp"
|
||||
)
|
||||
|
||||
set(INCLUDE_FILES
|
||||
"include/application.h"
|
||||
"include/application_component.h"
|
||||
"include/components/collider.h"
|
||||
"include/components/custom.h"
|
||||
"include/components/mesh_renderable.h"
|
||||
"include/components/ui_renderable.h"
|
||||
"include/components/transform.h"
|
||||
"include/component_collider.h"
|
||||
"include/component_custom.h"
|
||||
"include/component_mesh.h"
|
||||
"include/component_transform.h"
|
||||
"include/ecs.h"
|
||||
"include/engine_api.h"
|
||||
"include/vulkan_allocator.h"
|
||||
"include/vulkan_device.h"
|
||||
"include/vulkan_instance.h"
|
||||
"include/vulkan_swapchain.h"
|
||||
"include/event_system.h"
|
||||
"include/gfx.h"
|
||||
"include/gfx_device.h"
|
||||
"include/input_manager.h"
|
||||
"include/inputs/keyboard.h"
|
||||
"include/inputs/mouse.h"
|
||||
"include/input_keys.h"
|
||||
"include/input_mouse.h"
|
||||
"include/log.h"
|
||||
"include/logger.h"
|
||||
"include/renderer.h"
|
||||
"include/resource_manager.h"
|
||||
"include/resources/font.h"
|
||||
"include/resources/material.h"
|
||||
"include/resources/mesh.h"
|
||||
"include/resources/shader.h"
|
||||
"include/resources/texture.h"
|
||||
"include/resource_font.h"
|
||||
"include/resource_material.h"
|
||||
"include/resource_mesh.h"
|
||||
"include/resource_shader.h"
|
||||
"include/resource_texture.h"
|
||||
"include/scene.h"
|
||||
"include/scene_manager.h"
|
||||
"include/systems/collisions.h"
|
||||
"include/systems/custom_behaviour.h"
|
||||
"include/systems/mesh_render_system.h"
|
||||
"include/systems/ui_render_system.h"
|
||||
"include/systems/transform.h"
|
||||
"include/system_collisions.h"
|
||||
"include/system_custom_behaviour.h"
|
||||
"include/system_mesh_render.h"
|
||||
"include/system_transform.h"
|
||||
"include/util.h"
|
||||
"include/util/files.h"
|
||||
"include/util/gen_tangents.h"
|
||||
"include/util/gltf_loader.h"
|
||||
"include/files.h"
|
||||
"include/gen_tangents.h"
|
||||
"include/gltf_loader.h"
|
||||
"include/window.h"
|
||||
"include/util/file_dialog.h")
|
||||
"include/file_dialog.h"
|
||||
)
|
||||
|
||||
|
||||
file(GLOB_RECURSE RES_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res/engine/*")
|
||||
|
||||
|
@ -119,6 +119,19 @@ private:
|
||||
};
|
||||
`
|
||||
|
||||
Structs are laid out as follows:
|
||||
`
|
||||
struct Y {
|
||||
/* static data members */
|
||||
/* non-static data members */
|
||||
|
||||
/* static methods */
|
||||
/* non-static methods */
|
||||
};
|
||||
`
|
||||
Avoid having access specifiers in structs.
|
||||
Structs should almost always be POD. If not, consider using a class instead.
|
||||
|
||||
Inlined methods are to be avoided as much as possible. Even for trivial getters/setters.
|
||||
Inline methods are only used when doing so provides a tangible performance gain.
|
||||
|
||||
@ -127,3 +140,22 @@ and copy/move assignment operators explicitly deleted.
|
||||
|
||||
Ensure that constructors with a single argument are marked `explicit` unless implicit construction
|
||||
is intended.
|
||||
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
|
||||
######################
|
||||
# INCLUDE DIRECTIVES #
|
||||
######################
|
||||
|
||||
Header files should be included in the following order:
|
||||
- Header corresponding to source file
|
||||
- C standard library includes (as, e.g., cstdint)
|
||||
- C++ STL includes
|
||||
- External libraries from, e.g., 'dependencies/' directory or Vulkan SDK. Use angle brackets.
|
||||
- Libraries in the source tree. Use double quotes. (TODO: Move these into 'dependencies/')
|
||||
- Header files from the current project. Use double quotes.
|
||||
Each section should be sorted alphabetically (In VS: highlight the includes, right-click -> #include directives -> sort).
|
12
include/component_custom.h
Normal file
12
include/component_custom.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct CustomComponent {
|
||||
std::function<void(void)> on_init; // void on_init(void);
|
||||
std::function<void(float)> on_update; // void on_update(float ts);
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct CustomComponent {
|
||||
std::function<void(void)> onInit; // void onInit(void);
|
||||
std::function<void(float)> onUpdate; // void onUpdate(float ts);
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace engine {
|
||||
|
||||
struct UIRenderableComponent {
|
||||
int x;
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
/*
|
||||
#ifndef ENGINE_API
|
||||
# ifdef _MSC_VER
|
||||
# ifdef ENGINE_EXPORTS
|
||||
# define ENGINE_API __declspec(dllexport)
|
||||
# else
|
||||
# define ENGINE_API __declspec(dllimport)
|
||||
# endif
|
||||
# else
|
||||
# define ENGINE_API
|
||||
# endif
|
||||
#endif
|
||||
*/
|
||||
|
||||
#define ENGINE_API
|
@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace engine {
|
||||
namespace util {
|
||||
|
||||
std::unique_ptr<std::vector<char>> ReadTextFile(const std::string& path);
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path);
|
||||
@ -14,5 +15,4 @@ std::unique_ptr<std::vector<uint8_t>> ReadBinaryFile(const std::string& path);
|
||||
// minimum. Output format is R8G8B8A8_UINT
|
||||
std::unique_ptr<std::vector<uint8_t>> ReadImageFile(const std::string& path, int& width, int& height);
|
||||
|
||||
} // namespace util
|
||||
} // namespace engine
|
@ -2,8 +2,7 @@
|
||||
|
||||
// Keyboard scancodes, taken from SDL_scancode.h
|
||||
|
||||
namespace engine {
|
||||
namespace inputs {
|
||||
namespace engine::inputs {
|
||||
|
||||
enum class Key : int {
|
||||
K_UNKNOWN = 0,
|
||||
@ -372,5 +371,4 @@ enum class Key : int {
|
||||
for array bounds */
|
||||
};
|
||||
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
||||
} // namespace engine::inputs
|
@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace engine {
|
||||
namespace inputs {
|
||||
namespace engine::inputs {
|
||||
|
||||
enum class MouseButton : int { M_LEFT, M_MIDDLE, M_RIGHT, M_X1, M_X2, M_INVALID = 7, M_SIZE = 7 };
|
||||
|
||||
enum class MouseAxis : int { X, Y, X_SCR, Y_SCR };
|
||||
|
||||
} // namespace inputs
|
||||
} // namespace engine
|
||||
} // namespace engine::inputs
|
@ -10,20 +10,22 @@
|
||||
namespace engine {
|
||||
|
||||
class Font {
|
||||
std::unique_ptr<stbtt_fontinfo> m_font_info{};
|
||||
std::unique_ptr<std::vector<uint8_t>> m_font_buffer{};
|
||||
std::map<int, int> m_unicode_to_glyph{};
|
||||
|
||||
public:
|
||||
Font(const std::string& path);
|
||||
~Font();
|
||||
explicit Font(const std::string& path);
|
||||
Font(const Font&) = delete;
|
||||
|
||||
~Font();
|
||||
|
||||
Font& operator=(const Font&) = delete;
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> GetTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out);
|
||||
std::unique_ptr<std::vector<uint8_t>> getTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out);
|
||||
|
||||
private:
|
||||
std::unique_ptr<stbtt_fontinfo> font_info_{};
|
||||
std::unique_ptr<std::vector<uint8_t>> font_buffer_{};
|
||||
std::map<int, int> unicode_to_glyph_{};
|
||||
|
||||
int GetGlyphIndex(int unicode_codepoint);
|
||||
int getGlyphIndex(int unicode_codepoint);
|
||||
};
|
||||
|
||||
} // namespace engine
|
36
include/resource_material.h
Normal file
36
include/resource_material.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "resources/shader.h"
|
||||
#include "resources/texture.h"
|
||||
|
||||
// a material is just a shader with assigned textures/parameters
|
||||
|
||||
namespace engine {
|
||||
|
||||
// copyable
|
||||
class Material {
|
||||
const std::shared_ptr<Shader> m_shader;
|
||||
std::shared_ptr<Texture> m_texture_albedo;
|
||||
std::shared_ptr<Texture> m_texture_normal;
|
||||
std::shared_ptr<Texture> m_texture_occlusion_roughness_metallic;
|
||||
const gfx::DescriptorSet* m_material_set = nullptr;
|
||||
Renderer* const m_renderer;
|
||||
|
||||
public:
|
||||
Material(Renderer* renderer, std::shared_ptr<engine::Shader> shader);
|
||||
Material(const Material&) = delete;
|
||||
|
||||
~Material();
|
||||
|
||||
Material& operator=(const Material&) = delete;
|
||||
|
||||
void setAlbedoTexture(std::shared_ptr<Texture> texture);
|
||||
void setNormalTexture(std::shared_ptr<Texture> texture);
|
||||
void setOcclusionRoughnessMetallicTexture(std::shared_ptr<Texture> texture);
|
||||
const gfx::DescriptorSet* getDescriptorSet() { return m_material_set; }
|
||||
Shader* getShader() { return m_shader.get(); }
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "gfx.h"
|
||||
#include "gfx_device.h"
|
||||
@ -15,33 +16,31 @@ struct Vertex {
|
||||
glm::vec3 norm;
|
||||
glm::vec4 tangent; // w component flips binormal if -1. w should be 1 or -1
|
||||
glm::vec2 uv;
|
||||
static constexpr int FloatsPerVertex() { return static_cast<int>(sizeof(Vertex) / sizeof(float)); }
|
||||
|
||||
static constexpr int floatsPerVertex() { return static_cast<int>(sizeof(Vertex) / sizeof(float)); }
|
||||
};
|
||||
|
||||
} // namespace engine
|
||||
|
||||
namespace engine {
|
||||
|
||||
class Mesh {
|
||||
GFXDevice* const m_gfx;
|
||||
const gfx::Buffer* m_vb;
|
||||
const gfx::Buffer* m_ib;
|
||||
uint32_t m_count;
|
||||
|
||||
public:
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices);
|
||||
Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
||||
~Mesh();
|
||||
Mesh(const Mesh&) = delete;
|
||||
|
||||
~Mesh();
|
||||
|
||||
Mesh& operator=(const Mesh&) = delete;
|
||||
|
||||
const gfx::Buffer* GetVB();
|
||||
const gfx::Buffer* GetIB();
|
||||
uint32_t GetCount();
|
||||
const gfx::Buffer* getVB();
|
||||
const gfx::Buffer* getIB();
|
||||
uint32_t getCount();
|
||||
|
||||
private:
|
||||
GFXDevice* const gfx_;
|
||||
|
||||
const gfx::Buffer* vb_;
|
||||
const gfx::Buffer* ib_;
|
||||
uint32_t count_;
|
||||
|
||||
void InitMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
||||
void initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices);
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "resources/shader.h"
|
||||
#include "resources/texture.h"
|
||||
|
||||
// a material is just a shader with assigned textures/parameters
|
||||
|
||||
namespace engine {
|
||||
|
||||
// copyable
|
||||
class Material {
|
||||
public:
|
||||
Material(Renderer* renderer, std::shared_ptr<engine::Shader> shader);
|
||||
~Material();
|
||||
Material& operator=(const Material&) = delete;
|
||||
|
||||
void SetAlbedoTexture(std::shared_ptr<Texture> texture);
|
||||
void SetNormalTexture(std::shared_ptr<Texture> texture);
|
||||
void SetOcclusionRoughnessMetallicTexture(std::shared_ptr<Texture> texture);
|
||||
|
||||
const gfx::DescriptorSet* GetDescriptorSet() { return material_set_; }
|
||||
Shader* GetShader() { return shader_.get(); }
|
||||
|
||||
private:
|
||||
const std::shared_ptr<Shader> shader_;
|
||||
std::shared_ptr<Texture> texture_albedo_;
|
||||
std::shared_ptr<Texture> texture_normal_;
|
||||
std::shared_ptr<Texture> texture_occlusion_roughness_metallic_;
|
||||
|
||||
const gfx::DescriptorSet* material_set_ = nullptr;
|
||||
|
||||
Renderer* const renderer_;
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
#include "ecs.h"
|
||||
#include "scene.h"
|
||||
#include "gfx.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
class UIRenderSystem : public System {
|
||||
public:
|
||||
UIRenderSystem(Scene* scene);
|
||||
~UIRenderSystem();
|
||||
|
||||
void OnComponentInsert(Entity entity) override;
|
||||
void OnUpdate(float ts) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace engine
|
@ -1,12 +1,11 @@
|
||||
#include "application.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <numeric>
|
||||
|
||||
#include <glm/mat4x4.hpp>
|
||||
|
||||
@ -14,6 +13,8 @@
|
||||
#include "imgui/imgui_impl_sdl2.h"
|
||||
#include "imgui/imgui_impl_vulkan.h"
|
||||
|
||||
#include "components/collider.h"
|
||||
#include "components/transform.h"
|
||||
#include "gfx.h"
|
||||
#include "gfx_device.h"
|
||||
#include "input_manager.h"
|
||||
@ -23,15 +24,13 @@
|
||||
#include "resources/mesh.h"
|
||||
#include "resources/shader.h"
|
||||
#include "resources/texture.h"
|
||||
#include "systems/mesh_render_system.h"
|
||||
#include "components/transform.h"
|
||||
#include "components/collider.h"
|
||||
#include "scene.h"
|
||||
#include "scene_manager.h"
|
||||
#include "window.h"
|
||||
#include "util/gltf_loader.h"
|
||||
#include "systems/collisions.h"
|
||||
#include "systems/mesh_render_system.h"
|
||||
#include "util/file_dialog.h"
|
||||
#include <systems/collisions.h>
|
||||
#include "util/gltf_loader.h"
|
||||
#include "window.h"
|
||||
|
||||
static struct ImGuiThings {
|
||||
ImGuiContext* context;
|
||||
@ -145,9 +144,9 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph
|
||||
/* default materials */
|
||||
{
|
||||
auto defaultMaterial = std::make_unique<Material>(renderer(), GetResource<Shader>("builtin.fancy"));
|
||||
defaultMaterial->SetAlbedoTexture(GetResource<Texture>("builtin.white"));
|
||||
defaultMaterial->SetNormalTexture(GetResource<Texture>("builtin.normal"));
|
||||
defaultMaterial->SetOcclusionRoughnessMetallicTexture(GetResource<Texture>("builtin.mr"));
|
||||
defaultMaterial->setAlbedoTexture(GetResource<Texture>("builtin.white"));
|
||||
defaultMaterial->setNormalTexture(GetResource<Texture>("builtin.normal"));
|
||||
defaultMaterial->setOcclusionRoughnessMetallicTexture(GetResource<Texture>("builtin.mr"));
|
||||
GetResourceManager<Material>()->AddPersistent("builtin.default", std::move(defaultMaterial));
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ std::vector<uint32_t> engine::util::GenTangents(std::vector<engine::Vertex>& ver
|
||||
std::vector<Vertex> vertex_data_out(vertices.size()); // initialised to zeros
|
||||
|
||||
const int new_vertex_count = WeldMesh(reinterpret_cast<int*>(remap_table.data()), reinterpret_cast<float*>(vertex_data_out.data()), reinterpret_cast<float*>(vertices.data()),
|
||||
static_cast<int>(vertices.size()), Vertex::FloatsPerVertex());
|
||||
static_cast<int>(vertices.size()), Vertex::floatsPerVertex());
|
||||
assert(new_vertex_count >= 0);
|
||||
|
||||
// get new vertices into the vector.
|
@ -248,10 +248,10 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
|
||||
materials.emplace_back(std::make_shared<Material>(scene.app()->renderer(), scene.app()->GetResource<Shader>("builtin.fancy")));
|
||||
|
||||
// base color
|
||||
materials.back()->SetAlbedoTexture(scene.app()->GetResource<Texture>("builtin.white"));
|
||||
materials.back()->setAlbedoTexture(scene.app()->GetResource<Texture>("builtin.white"));
|
||||
if (material.pbrMetallicRoughness.baseColorTexture.index != -1) {
|
||||
if (material.pbrMetallicRoughness.baseColorTexture.texCoord == 0) {
|
||||
materials.back()->SetAlbedoTexture(textures.at(material.pbrMetallicRoughness.baseColorTexture.index));
|
||||
materials.back()->setAlbedoTexture(textures.at(material.pbrMetallicRoughness.baseColorTexture.index));
|
||||
}
|
||||
else {
|
||||
LOG_WARN("Material {} base color texture specifies a UV channel other than zero which is unsupported.", material.name);
|
||||
@ -269,16 +269,16 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
|
||||
samplerInfo.anisotropic_filtering = false;
|
||||
colour_textures.emplace(std::make_pair(c, std::make_shared<Texture>(scene.app()->renderer(), pixel, 1, 1, samplerInfo, true)));
|
||||
}
|
||||
materials.back()->SetAlbedoTexture(colour_textures.at(c));
|
||||
materials.back()->setAlbedoTexture(colour_textures.at(c));
|
||||
}
|
||||
|
||||
// occlusion roughness metallic
|
||||
materials.back()->SetOcclusionRoughnessMetallicTexture(
|
||||
materials.back()->setOcclusionRoughnessMetallicTexture(
|
||||
scene.app()->GetResource<Texture>("builtin.white")); // default ao = 1.0, rough = 1.0, metal = 1.0
|
||||
if (material.pbrMetallicRoughness.metallicRoughnessTexture.index != -1) {
|
||||
if (material.pbrMetallicRoughness.metallicRoughnessTexture.texCoord == 0) {
|
||||
LOG_DEBUG("Setting occlusion roughness metallic texture!");
|
||||
materials.back()->SetOcclusionRoughnessMetallicTexture(textures.at(material.pbrMetallicRoughness.metallicRoughnessTexture.index));
|
||||
materials.back()->setOcclusionRoughnessMetallicTexture(textures.at(material.pbrMetallicRoughness.metallicRoughnessTexture.index));
|
||||
}
|
||||
else {
|
||||
LOG_WARN("Material {} metallic roughness texture specifies a UV channel other than zero which is unsupported.", material.name);
|
||||
@ -298,7 +298,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
|
||||
samplerInfo.anisotropic_filtering = false;
|
||||
metal_rough_textures.emplace(std::make_pair(mr, std::make_shared<Texture>(scene.app()->renderer(), pixel, 1, 1, samplerInfo, false)));
|
||||
}
|
||||
materials.back()->SetOcclusionRoughnessMetallicTexture(metal_rough_textures.at(mr));
|
||||
materials.back()->setOcclusionRoughnessMetallicTexture(metal_rough_textures.at(mr));
|
||||
}
|
||||
|
||||
// occlusion texture
|
||||
@ -316,10 +316,10 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
|
||||
}
|
||||
|
||||
// normal map
|
||||
materials.back()->SetNormalTexture(scene.app()->GetResource<Texture>("builtin.normal"));
|
||||
materials.back()->setNormalTexture(scene.app()->GetResource<Texture>("builtin.normal"));
|
||||
if (material.normalTexture.index != -1) {
|
||||
if (material.normalTexture.texCoord == 0) {
|
||||
materials.back()->SetNormalTexture(textures.at(material.normalTexture.index));
|
||||
materials.back()->setNormalTexture(textures.at(material.normalTexture.index));
|
||||
}
|
||||
else {
|
||||
LOG_WARN("Material {} normal texture specifies a UV channel other than zero which is unsupported.", material.name);
|
||||
@ -521,7 +521,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic)
|
||||
std::vector<Vertex> vertex_data_out(num_indices); // initialised to zeros
|
||||
|
||||
const int num_unq_vertices = WeldMesh(remap_table.data(), reinterpret_cast<float*>(vertex_data_out.data()),
|
||||
reinterpret_cast<float*>(vertices.data()), static_cast<int>(num_indices), Vertex::FloatsPerVertex());
|
||||
reinterpret_cast<float*>(vertices.data()), static_cast<int>(num_indices), Vertex::floatsPerVertex());
|
||||
assert(num_unq_vertices >= 0);
|
||||
|
||||
// get new vertices into the vector
|
@ -585,7 +585,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
|
||||
return true;
|
||||
}
|
||||
|
||||
// For reference, the average total _allocation count_ for a table is:
|
||||
// For reference, the average total _allocation m_count for a table is:
|
||||
// + 0 (for ImGuiTable instance, we are pooling allocations in g.Tables[])
|
||||
// + 1 (for table->RawData allocated below)
|
||||
// + 1 (for table->ColumnsNames, if names are used)
|
||||
|
@ -12,10 +12,10 @@ namespace engine {
|
||||
|
||||
Font::Font(const std::string& path)
|
||||
{
|
||||
font_buffer_ = util::ReadBinaryFile(path);
|
||||
font_info_ = std::make_unique<stbtt_fontinfo>();
|
||||
m_font_buffer = util::ReadBinaryFile(path);
|
||||
m_font_info = std::make_unique<stbtt_fontinfo>();
|
||||
|
||||
if (stbtt_InitFont(font_info_.get(), font_buffer_->data(), 0) == 0) {
|
||||
if (stbtt_InitFont(m_font_info.get(), m_font_buffer->data(), 0) == 0) {
|
||||
throw std::runtime_error("Failed to initialise font!");
|
||||
}
|
||||
|
||||
@ -24,12 +24,12 @@ Font::Font(const std::string& path)
|
||||
|
||||
Font::~Font() { LOG_DEBUG("Destroyed font"); }
|
||||
|
||||
std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out)
|
||||
std::unique_ptr<std::vector<uint8_t>> Font::getTextBitmap(const std::string& text, float height_px, int& width_out, int& height_out)
|
||||
{
|
||||
const float sf = stbtt_ScaleForPixelHeight(font_info_.get(), height_px);
|
||||
const float sf = stbtt_ScaleForPixelHeight(m_font_info.get(), height_px);
|
||||
|
||||
int ascent, descent, line_gap;
|
||||
stbtt_GetFontVMetrics(font_info_.get(), &ascent, &descent, &line_gap);
|
||||
stbtt_GetFontVMetrics(m_font_info.get(), &ascent, &descent, &line_gap);
|
||||
|
||||
struct CharacterRenderInfo {
|
||||
int advance; // bitmap advance
|
||||
@ -42,10 +42,10 @@ std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(const std::string& tex
|
||||
|
||||
int width = 0;
|
||||
for (size_t i = 0; i < text.size(); i++) {
|
||||
const int glyph_index = GetGlyphIndex(static_cast<int>(text.at(i)));
|
||||
const int glyph_index = getGlyphIndex(static_cast<int>(text.at(i)));
|
||||
|
||||
int advanceWidth, leftSideBearing;
|
||||
stbtt_GetGlyphHMetrics(font_info_.get(), glyph_index, &advanceWidth, &leftSideBearing);
|
||||
stbtt_GetGlyphHMetrics(m_font_info.get(), glyph_index, &advanceWidth, &leftSideBearing);
|
||||
|
||||
if (i == 0 && leftSideBearing < 0) {
|
||||
// if the character extends before the current point
|
||||
@ -57,7 +57,7 @@ std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(const std::string& tex
|
||||
|
||||
renderInfo.advance = static_cast<int>(static_cast<float>(advanceWidth) * sf);
|
||||
|
||||
if (stbtt_IsGlyphEmpty(font_info_.get(), glyph_index) == 0) {
|
||||
if (stbtt_IsGlyphEmpty(m_font_info.get(), glyph_index) == 0) {
|
||||
renderInfo.isEmpty = false;
|
||||
}
|
||||
else {
|
||||
@ -66,7 +66,7 @@ std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(const std::string& tex
|
||||
|
||||
if (!renderInfo.isEmpty) {
|
||||
renderInfo.bitmap =
|
||||
stbtt_GetGlyphBitmap(font_info_.get(), sf, sf, glyph_index, &renderInfo.width, &renderInfo.height, &renderInfo.xoff, &renderInfo.yoff);
|
||||
stbtt_GetGlyphBitmap(m_font_info.get(), sf, sf, glyph_index, &renderInfo.width, &renderInfo.height, &renderInfo.xoff, &renderInfo.yoff);
|
||||
}
|
||||
|
||||
characterRenderInfos.push_back(renderInfo);
|
||||
@ -114,17 +114,17 @@ std::unique_ptr<std::vector<uint8_t>> Font::GetTextBitmap(const std::string& tex
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
int Font::GetGlyphIndex(int unicode_codepoint)
|
||||
int Font::getGlyphIndex(int unicode_codepoint)
|
||||
{
|
||||
if (unicode_to_glyph_.contains(unicode_codepoint)) {
|
||||
return unicode_to_glyph_.at(unicode_codepoint);
|
||||
if (m_unicode_to_glyph.contains(unicode_codepoint)) {
|
||||
return m_unicode_to_glyph.at(unicode_codepoint);
|
||||
}
|
||||
else {
|
||||
const int glyph_index = stbtt_FindGlyphIndex(font_info_.get(), unicode_codepoint);
|
||||
const int glyph_index = stbtt_FindGlyphIndex(m_font_info.get(), unicode_codepoint);
|
||||
if (glyph_index == 0) {
|
||||
throw std::runtime_error("Glyph not found in font!");
|
||||
}
|
||||
unicode_to_glyph_.emplace(std::make_pair(unicode_codepoint, glyph_index));
|
||||
m_unicode_to_glyph.emplace(std::make_pair(unicode_codepoint, glyph_index));
|
||||
return glyph_index;
|
||||
}
|
||||
}
|
33
src/resource_material.cpp
Normal file
33
src/resource_material.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "resources/material.h"
|
||||
|
||||
#include "resources/shader.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
Material::Material(Renderer* renderer, std::shared_ptr<Shader> shader) : m_shader(shader), m_renderer(renderer)
|
||||
{
|
||||
m_material_set = renderer->GetDevice()->AllocateDescriptorSet(renderer->GetMaterialSetLayout());
|
||||
LOG_DEBUG("Created material");
|
||||
}
|
||||
|
||||
Material::~Material() { m_renderer->GetDevice()->FreeDescriptorSet(m_material_set); LOG_DEBUG("Destroyed material"); }
|
||||
|
||||
void Material::setAlbedoTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
m_renderer->GetDevice()->UpdateDescriptorCombinedImageSampler(m_material_set, 0, texture->GetImage(), texture->GetSampler());
|
||||
m_texture_albedo = texture;
|
||||
}
|
||||
|
||||
void Material::setNormalTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
m_renderer->GetDevice()->UpdateDescriptorCombinedImageSampler(m_material_set, 1, texture->GetImage(), texture->GetSampler());
|
||||
m_texture_normal = texture;
|
||||
}
|
||||
|
||||
void Material::setOcclusionRoughnessMetallicTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
m_renderer->GetDevice()->UpdateDescriptorCombinedImageSampler(m_material_set, 2, texture->GetImage(), texture->GetSampler());
|
||||
m_texture_occlusion_roughness_metallic = texture;
|
||||
}
|
||||
|
||||
} // namespace engine
|
40
src/resource_mesh.cpp
Normal file
40
src/resource_mesh.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "resources/mesh.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "gfx_device.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices) : m_gfx(gfx)
|
||||
{
|
||||
std::vector<uint32_t> indices(vertices.size());
|
||||
for (uint32_t i = 0; i < indices.size(); i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
initMesh(vertices, indices);
|
||||
}
|
||||
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices) : m_gfx(gfx) { initMesh(vertices, indices); }
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
m_gfx->DestroyBuffer(m_ib);
|
||||
m_gfx->DestroyBuffer(m_vb);
|
||||
LOG_DEBUG("Destroyed mesh");
|
||||
}
|
||||
|
||||
const gfx::Buffer* Mesh::getVB() { return m_vb; }
|
||||
|
||||
const gfx::Buffer* Mesh::getIB() { return m_ib; }
|
||||
|
||||
uint32_t Mesh::getCount() { return m_count; }
|
||||
|
||||
void Mesh::initMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
{
|
||||
m_vb = m_gfx->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
||||
m_ib = m_gfx->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
||||
m_count = (uint32_t)indices.size();
|
||||
LOG_DEBUG("Created mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
||||
}
|
||||
|
||||
} // namespace engine
|
@ -1,33 +0,0 @@
|
||||
#include "resources/material.h"
|
||||
|
||||
#include "resources/shader.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
Material::Material(Renderer* renderer, std::shared_ptr<Shader> shader) : shader_(shader), renderer_(renderer)
|
||||
{
|
||||
material_set_ = renderer->GetDevice()->AllocateDescriptorSet(renderer->GetMaterialSetLayout());
|
||||
LOG_DEBUG("Created material");
|
||||
}
|
||||
|
||||
Material::~Material() { renderer_->GetDevice()->FreeDescriptorSet(material_set_); LOG_DEBUG("Destroyed material"); }
|
||||
|
||||
void Material::SetAlbedoTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
renderer_->GetDevice()->UpdateDescriptorCombinedImageSampler(material_set_, 0, texture->GetImage(), texture->GetSampler());
|
||||
texture_albedo_ = texture;
|
||||
}
|
||||
|
||||
void Material::SetNormalTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
renderer_->GetDevice()->UpdateDescriptorCombinedImageSampler(material_set_, 1, texture->GetImage(), texture->GetSampler());
|
||||
texture_normal_ = texture;
|
||||
}
|
||||
|
||||
void Material::SetOcclusionRoughnessMetallicTexture(std::shared_ptr<Texture> texture)
|
||||
{
|
||||
renderer_->GetDevice()->UpdateDescriptorCombinedImageSampler(material_set_, 2, texture->GetImage(), texture->GetSampler());
|
||||
texture_occlusion_roughness_metallic_ = texture;
|
||||
}
|
||||
|
||||
} // namespace engine
|
@ -1,40 +0,0 @@
|
||||
#include "resources/mesh.h"
|
||||
|
||||
#include "log.h"
|
||||
#include "gfx_device.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices) : gfx_(gfx)
|
||||
{
|
||||
std::vector<uint32_t> indices(vertices.size());
|
||||
for (uint32_t i = 0; i < indices.size(); i++) {
|
||||
indices[i] = i;
|
||||
}
|
||||
InitMesh(vertices, indices);
|
||||
}
|
||||
|
||||
Mesh::Mesh(GFXDevice* gfx, const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices) : gfx_(gfx) { InitMesh(vertices, indices); }
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
gfx_->DestroyBuffer(ib_);
|
||||
gfx_->DestroyBuffer(vb_);
|
||||
LOG_DEBUG("Destroyed mesh");
|
||||
}
|
||||
|
||||
const gfx::Buffer* Mesh::GetVB() { return vb_; }
|
||||
|
||||
const gfx::Buffer* Mesh::GetIB() { return ib_; }
|
||||
|
||||
uint32_t Mesh::GetCount() { return count_; }
|
||||
|
||||
void Mesh::InitMesh(const std::vector<Vertex>& vertices, const std::vector<uint32_t>& indices)
|
||||
{
|
||||
vb_ = gfx_->CreateBuffer(gfx::BufferType::kVertex, vertices.size() * sizeof(Vertex), vertices.data());
|
||||
ib_ = gfx_->CreateBuffer(gfx::BufferType::kIndex, indices.size() * sizeof(uint32_t), indices.data());
|
||||
count_ = (uint32_t)indices.size();
|
||||
LOG_DEBUG("Created mesh, vertices: {}, indices: {}", vertices.size(), indices.size());
|
||||
}
|
||||
|
||||
} // namespace engine
|
@ -22,12 +22,12 @@ void CustomBehaviourSystem::OnUpdate(float ts) {
|
||||
assert(c != nullptr);
|
||||
bool& entity_initialised = entity_is_initialised_.at(entity);
|
||||
if (entity_initialised == false) {
|
||||
if (c->onInit == nullptr) throw std::runtime_error("CustomComponent::onInit not set! Entity: " + std::to_string(entity));
|
||||
if (c->onUpdate == nullptr) throw std::runtime_error("CustomComponent::onUpdate not set! Entity: " + std::to_string(entity));
|
||||
c->onInit();
|
||||
if (c->on_init == nullptr) throw std::runtime_error("CustomComponent::on_init not set! Entity: " + std::to_string(entity));
|
||||
if (c->on_update == nullptr) throw std::runtime_error("CustomComponent::on_update not set! Entity: " + std::to_string(entity));
|
||||
c->on_init();
|
||||
entity_initialised = true;
|
||||
}
|
||||
c->onUpdate(ts);
|
||||
c->on_update(ts);
|
||||
}
|
||||
}
|
||||
|
@ -52,17 +52,17 @@ void MeshRenderSystem::BuildRenderList(RenderList& render_list, bool with_static
|
||||
|
||||
if (renderable->visible == false) continue;
|
||||
|
||||
const gfx::Pipeline* pipeline = renderable->material->GetShader()->GetPipeline();
|
||||
const gfx::Pipeline* pipeline = renderable->material->getShader()->GetPipeline();
|
||||
|
||||
render_list.emplace_back(RenderListEntry{.pipeline = pipeline,
|
||||
.vertex_buffer = renderable->mesh->GetVB(),
|
||||
.index_buffer = renderable->mesh->GetIB(),
|
||||
.material_set = renderable->material->GetDescriptorSet(),
|
||||
.vertex_buffer = renderable->mesh->getVB(),
|
||||
.index_buffer = renderable->mesh->getIB(),
|
||||
.material_set = renderable->material->getDescriptorSet(),
|
||||
.model_matrix = transform->world_matrix,
|
||||
.index_count = renderable->mesh->GetCount()});
|
||||
.index_count = renderable->mesh->getCount()});
|
||||
|
||||
if (render_orders.contains(pipeline) == false) {
|
||||
render_orders.emplace(pipeline, renderable->material->GetShader()->GetRenderOrder());
|
||||
render_orders.emplace(pipeline, renderable->material->getShader()->GetRenderOrder());
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
#include "systems/ui_render_system.h"
|
||||
|
||||
#include "components/transform.h"
|
||||
#include "components/ui_renderable.h"
|
||||
|
||||
namespace engine {
|
||||
|
||||
UIRenderSystem::UIRenderSystem(Scene* scene)
|
||||
: System(scene, { typeid(TransformComponent).hash_code(),
|
||||
typeid(UIRenderableComponent).hash_code() }) {}
|
||||
|
||||
UIRenderSystem::~UIRenderSystem() {}
|
||||
|
||||
void UIRenderSystem::OnComponentInsert(Entity entity) {
|
||||
(void)entity;
|
||||
}
|
||||
|
||||
void UIRenderSystem::OnUpdate(float ts) {
|
||||
(void)ts;
|
||||
}
|
||||
|
||||
} // namespace engine
|
@ -139,8 +139,8 @@ void PlayGame(GameSettings settings)
|
||||
cube_ren->mesh = GenCuboidMesh(app.renderer()->GetDevice(), 1.0f, 1.0f, 1.0f);
|
||||
cube_ren->visible = true;
|
||||
auto cubeCustom = main_scene->AddComponent<engine::CustomComponent>(cube);
|
||||
cubeCustom->onInit = [] {};
|
||||
cubeCustom->onUpdate = [&main_scene, cube](float dt) {
|
||||
cubeCustom->on_init = [] {};
|
||||
cubeCustom->on_update = [&main_scene, cube](float dt) {
|
||||
static float yaw = 0.0f;
|
||||
yaw += dt;
|
||||
main_scene->GetRotation(cube) = glm::angleAxis(yaw, glm::vec3{0.0f, 0.0f, 1.0f});
|
||||
|
Loading…
Reference in New Issue
Block a user