yes
This commit is contained in:
82
Runtime/Includes/Graphics/Actor.h
git.filemode.normal_file
82
Runtime/Includes/Graphics/Actor.h
git.filemode.normal_file
@@ -0,0 +1,82 @@
|
||||
#ifndef __SCOP_GRAPHICS_ACTOR__
|
||||
#define __SCOP_GRAPHICS_ACTOR__
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <Core/UUID.h>
|
||||
#include <Maths/Vec3.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Core/Script.h>
|
||||
#include <Maths/Quaternions.h>
|
||||
#include <Graphics/Model.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Actor
|
||||
{
|
||||
friend Scene;
|
||||
|
||||
public:
|
||||
struct CustomPipeline
|
||||
{
|
||||
std::shared_ptr<GraphicPipeline> pipeline;
|
||||
std::shared_ptr<DescriptorSet> set;
|
||||
std::shared_ptr<UniformBuffer> data_uniform_buffer;
|
||||
CPUBuffer data;
|
||||
};
|
||||
|
||||
public:
|
||||
Actor();
|
||||
Actor(Model model);
|
||||
Actor(std::uint64_t uuid, Model model);
|
||||
|
||||
inline void AttachScript(std::shared_ptr<ActorScript> script) { p_script = script; }
|
||||
|
||||
inline void SetPosition(Vec3f position) noexcept { m_position = position; }
|
||||
inline void SetScale(Vec3f scale) noexcept { m_scale = scale; }
|
||||
inline void SetOrientation(Quatf orientation) noexcept { m_orientation = orientation; }
|
||||
inline void SetVisibility(bool show) noexcept { m_is_visible = show; }
|
||||
inline void SetIsOpaque(bool opaque) noexcept { m_is_opaque = opaque; }
|
||||
inline void SetCustomPipeline(CustomPipeline pipeline) { m_custom_pipeline = std::move(pipeline); }
|
||||
|
||||
[[nodiscard]] inline const Vec3f& GetPosition() const noexcept { return m_position; }
|
||||
[[nodiscard]] inline const Vec3f& GetScale() const noexcept { return m_scale; }
|
||||
[[nodiscard]] inline const Quatf& GetOrientation() const noexcept { return m_orientation; }
|
||||
[[nodiscard]] inline const Model& GetModel() const noexcept { return m_model; }
|
||||
[[nodiscard]] inline Model& GetModelRef() noexcept { return m_model; }
|
||||
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||
[[nodiscard]] inline bool IsVisible() const noexcept { return m_is_visible; }
|
||||
[[nodiscard]] inline bool IsOpaque() const noexcept { return m_is_opaque; }
|
||||
[[nodiscard]] inline std::optional<CustomPipeline>& GetCustomPipeline() { return m_custom_pipeline; }
|
||||
|
||||
~Actor();
|
||||
|
||||
public:
|
||||
void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep);
|
||||
|
||||
private:
|
||||
Model m_model;
|
||||
Quatf m_orientation = Quatf::Identity();
|
||||
Vec3f m_position = Vec3f{ 0.0f, 0.0f, 0.0f };
|
||||
Vec3f m_scale = Vec3f{ 1.0f, 1.0f, 1.0f };
|
||||
std::shared_ptr<ActorScript> p_script;
|
||||
std::uint64_t m_uuid;
|
||||
std::optional<CustomPipeline> m_custom_pipeline;
|
||||
bool m_is_visible = true;
|
||||
bool m_is_opaque = true;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<Scop::Actor>
|
||||
{
|
||||
std::size_t operator()(const Scop::Actor& a) const noexcept
|
||||
{
|
||||
return static_cast<std::size_t>(a.GetUUID());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
30
Runtime/Includes/Graphics/Cameras/Base.h
git.filemode.normal_file
30
Runtime/Includes/Graphics/Cameras/Base.h
git.filemode.normal_file
@@ -0,0 +1,30 @@
|
||||
#ifndef __SCOP_CAMERAS_BASE__
|
||||
#define __SCOP_CAMERAS_BASE__
|
||||
|
||||
#include <Maths/Mat4.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class BaseCamera
|
||||
{
|
||||
public:
|
||||
BaseCamera() = default;
|
||||
|
||||
virtual void Update(class Inputs& input, float aspect, float timestep) {};
|
||||
|
||||
[[nodiscard]] inline const Mat4f& GetView() const noexcept { return m_view; }
|
||||
[[nodiscard]] inline const Mat4f& GetProj() const noexcept { return m_proj; }
|
||||
|
||||
[[nodiscard]] virtual const Vec3f& GetPosition() const noexcept = 0;
|
||||
|
||||
virtual constexpr std::string GetCameraType() = 0;
|
||||
|
||||
virtual ~BaseCamera() = default;
|
||||
|
||||
protected:
|
||||
Mat4f m_view;
|
||||
Mat4f m_proj;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
53
Runtime/Includes/Graphics/Cameras/FirstPerson3D.h
git.filemode.normal_file
53
Runtime/Includes/Graphics/Cameras/FirstPerson3D.h
git.filemode.normal_file
@@ -0,0 +1,53 @@
|
||||
#ifndef __SCOP_CAMERAS_FIRST_PERSON_3D__
|
||||
#define __SCOP_CAMERAS_FIRST_PERSON_3D__
|
||||
|
||||
#include <Graphics/Cameras/Base.h>
|
||||
#include <Maths/Vec3.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class FirstPerson3D : public BaseCamera
|
||||
{
|
||||
public:
|
||||
FirstPerson3D();
|
||||
FirstPerson3D(Vec3f position, float fov = 90.0f, float speed = 50.0f);
|
||||
|
||||
void Update(class Inputs& input, float aspect, float timestep) override;
|
||||
|
||||
inline constexpr void EnableCamera() noexcept { m_inputs_blocked = false; }
|
||||
inline constexpr void DisableCamera() noexcept { m_inputs_blocked = true; }
|
||||
|
||||
[[nodiscard]] inline constexpr std::string GetCameraType() override { return "FirstPerson3D"; }
|
||||
[[nodiscard]] const Vec3f& GetPosition() const noexcept override { return m_position; }
|
||||
[[nodiscard]] const Vec3f& GetUp() const noexcept { return c_up; }
|
||||
[[nodiscard]] const Vec3f& GetLeft() const noexcept { return m_left; }
|
||||
[[nodiscard]] const Vec3f& GetTarget() const noexcept { return m_target; }
|
||||
[[nodiscard]] const Vec3f& GetDirection() const noexcept { return m_direction; }
|
||||
|
||||
~FirstPerson3D() = default;
|
||||
|
||||
private:
|
||||
void UpdateView();
|
||||
|
||||
private:
|
||||
const Vec3f c_up;
|
||||
Vec3f m_position;
|
||||
Vec3f m_left;
|
||||
Vec3f m_forward;
|
||||
Vec3f m_target;
|
||||
Vec3f m_direction;
|
||||
Vec3f m_mov;
|
||||
|
||||
float m_theta = 0.0;
|
||||
float m_phi = 0.0;
|
||||
|
||||
const float c_speed = 50.0f;
|
||||
const float c_sensivity = 0.7f;
|
||||
float m_speed_factor = 1.0f;
|
||||
float m_fov = 90.0f;
|
||||
|
||||
bool m_inputs_blocked = false;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
2833
Runtime/Includes/Graphics/DogicaTTF.h
git.filemode.normal_file
2833
Runtime/Includes/Graphics/DogicaTTF.h
git.filemode.normal_file
File diff suppressed because it is too large
Load Diff
20
Runtime/Includes/Graphics/Enums.h
git.filemode.normal_file
20
Runtime/Includes/Graphics/Enums.h
git.filemode.normal_file
@@ -0,0 +1,20 @@
|
||||
#ifndef __SCOP_GRAPHICS_ENUMS__
|
||||
#define __SCOP_GRAPHICS_ENUMS__
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
enum class CullMode
|
||||
{
|
||||
None = 0,
|
||||
Back,
|
||||
Front,
|
||||
FrontAndBack,
|
||||
|
||||
EndEnum
|
||||
};
|
||||
constexpr std::size_t CullModeCount = static_cast<std::size_t>(CullMode::EndEnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
61
Runtime/Includes/Graphics/Font.h
git.filemode.normal_file
61
Runtime/Includes/Graphics/Font.h
git.filemode.normal_file
@@ -0,0 +1,61 @@
|
||||
#ifndef __SCOP_FONT__
|
||||
#define __SCOP_FONT__
|
||||
|
||||
#include <variant>
|
||||
#include <filesystem>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <stb_truetype.h>
|
||||
|
||||
#include <Renderer/Image.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
constexpr const int RANGE = 1024;
|
||||
|
||||
class Font
|
||||
{
|
||||
public:
|
||||
Font(const std::filesystem::path& path, float scale) : m_build_data(path), m_name(path.string()), m_scale(scale) {}
|
||||
Font(const std::string& name, const std::vector<std::uint8_t>& ttf_data, float scale) : m_build_data(ttf_data), m_name(name), m_scale(scale) {}
|
||||
|
||||
void BuildFont();
|
||||
void Destroy();
|
||||
|
||||
inline const std::string& GetName() const { return m_name; }
|
||||
inline float GetScale() const noexcept { return m_scale; }
|
||||
inline const std::array<stbtt_packedchar, 96>& GetCharData() const { return m_cdata; }
|
||||
inline const Texture& GetTexture() const noexcept { return m_atlas; }
|
||||
inline bool operator==(const Font& rhs) const { return rhs.m_name == m_name && rhs.m_scale == m_scale; }
|
||||
inline bool operator!=(const Font& rhs) const { return rhs.m_name != m_name || rhs.m_scale != m_scale; }
|
||||
|
||||
inline ~Font() { Destroy(); }
|
||||
|
||||
private:
|
||||
std::array<stbtt_packedchar, 96> m_cdata;
|
||||
Texture m_atlas;
|
||||
std::variant<std::filesystem::path, std::vector<std::uint8_t>> m_build_data;
|
||||
std::string m_name;
|
||||
float m_scale;
|
||||
};
|
||||
|
||||
class FontRegistry
|
||||
{
|
||||
public:
|
||||
FontRegistry() = default;
|
||||
|
||||
inline void RegisterFont(std::shared_ptr<Font> font);
|
||||
inline void UnregisterFont(std::shared_ptr<Font> font);
|
||||
inline std::shared_ptr<Font> GetFont(const std::filesystem::path& name, float scale);
|
||||
inline void Reset();
|
||||
|
||||
~FontRegistry() = default;
|
||||
|
||||
private:
|
||||
std::unordered_set<std::shared_ptr<Font>> m_fonts_registry;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Graphics/Font.inl>
|
||||
|
||||
#endif
|
||||
31
Runtime/Includes/Graphics/Font.inl
git.filemode.normal_file
31
Runtime/Includes/Graphics/Font.inl
git.filemode.normal_file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <Graphics/Font.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
void FontRegistry::RegisterFont(std::shared_ptr<Font> font)
|
||||
{
|
||||
m_fonts_registry.insert(font);
|
||||
}
|
||||
|
||||
void FontRegistry::UnregisterFont(std::shared_ptr<Font> font)
|
||||
{
|
||||
m_fonts_registry.erase(font);
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> FontRegistry::GetFont(const std::filesystem::path& name, float scale)
|
||||
{
|
||||
auto it = std::find_if(m_fonts_registry.begin(), m_fonts_registry.end(), [&name, scale](std::shared_ptr<Font> rhs)
|
||||
{
|
||||
return (name == rhs->GetName() && scale == rhs->GetScale());
|
||||
});
|
||||
return (it != m_fonts_registry.end() ? *it : nullptr);
|
||||
}
|
||||
|
||||
void FontRegistry::Reset()
|
||||
{
|
||||
for(auto& font: m_fonts_registry)
|
||||
font->Destroy();
|
||||
m_fonts_registry.clear();
|
||||
}
|
||||
}
|
||||
14
Runtime/Includes/Graphics/Loaders/BMP.h
git.filemode.normal_file
14
Runtime/Includes/Graphics/Loaders/BMP.h
git.filemode.normal_file
@@ -0,0 +1,14 @@
|
||||
#ifndef __SCOP_BMP_LOADER__
|
||||
#define __SCOP_BMP_LOADER__
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#include <Maths/Vec2.h>
|
||||
#include <Utils/Buffer.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
CPUBuffer LoadBMPFile(const std::filesystem::path& path, Vec2ui32& dimensions);
|
||||
}
|
||||
|
||||
#endif
|
||||
72
Runtime/Includes/Graphics/Loaders/OBJ.h
git.filemode.normal_file
72
Runtime/Includes/Graphics/Loaders/OBJ.h
git.filemode.normal_file
@@ -0,0 +1,72 @@
|
||||
#ifndef __SCOP_OBJ_LOADER__
|
||||
#define __SCOP_OBJ_LOADER__
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <filesystem>
|
||||
|
||||
#include <Maths/Vec2.h>
|
||||
#include <Maths/Vec3.h>
|
||||
#include <Maths/Vec4.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
struct ObjData
|
||||
{
|
||||
struct FaceVertex
|
||||
{
|
||||
FaceVertex() : v(-1), t(-1), n(-1) {}
|
||||
std::int32_t v;
|
||||
std::int32_t t;
|
||||
std::int32_t n;
|
||||
|
||||
inline bool operator<(const FaceVertex& rhs) const
|
||||
{
|
||||
return (v < rhs.v) || (v == rhs.v && t < rhs.t ) || (v == rhs.v && t == rhs.t && n < rhs.n);
|
||||
}
|
||||
inline bool operator==(const FaceVertex& rhs) const
|
||||
{
|
||||
return (v == rhs.v && t == rhs.t && n == rhs.n);
|
||||
}
|
||||
};
|
||||
|
||||
using FaceList = std::pair<std::vector<FaceVertex>, std::vector<std::uint32_t>>;
|
||||
|
||||
std::vector<Vec4f> color;
|
||||
std::vector<Vec3f> vertex;
|
||||
std::vector<Vec3f> normal;
|
||||
std::vector<Vec2f> tex_coord;
|
||||
|
||||
std::map<std::string, FaceList> faces;
|
||||
};
|
||||
|
||||
struct ObjModel
|
||||
{
|
||||
std::vector<Vec4f> color;
|
||||
std::vector<Vec3f> vertex;
|
||||
std::vector<Vec3f> normal;
|
||||
std::vector<Vec2f> tex_coord;
|
||||
|
||||
std::map<std::string, std::vector<std::uint32_t>> faces;
|
||||
};
|
||||
|
||||
std::optional<ObjData> LoadObjFromFile(const std::filesystem::path& path);
|
||||
void TesselateObjData(ObjData& data);
|
||||
ObjModel ConvertObjDataToObjModel(const ObjData& data);
|
||||
|
||||
template<typename T>
|
||||
inline std::istream& operator>>(std::istream& in, std::vector<T>& vec);
|
||||
|
||||
template<typename T>
|
||||
inline std::istream& operator>>(std::istream& in, std::set<T>& vec);
|
||||
|
||||
inline std::istream& operator>>(std::istream& in, ObjData::FaceVertex& f);
|
||||
}
|
||||
|
||||
#include <Graphics/Loaders/OBJ.inl>
|
||||
|
||||
#endif
|
||||
48
Runtime/Includes/Graphics/Loaders/OBJ.inl
git.filemode.normal_file
48
Runtime/Includes/Graphics/Loaders/OBJ.inl
git.filemode.normal_file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <Graphics/Loaders/OBJ.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
template<typename T>
|
||||
inline std::istream& operator>>(std::istream& in, std::vector<T>& vec)
|
||||
{
|
||||
T temp;
|
||||
if(in >> temp)
|
||||
vec.push_back(temp);
|
||||
return in;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline std::istream& operator>>(std::istream& in, std::set<T>& vec)
|
||||
{
|
||||
T temp;
|
||||
if(in >> temp)
|
||||
vec.insert(temp);
|
||||
return in;
|
||||
}
|
||||
|
||||
inline std::istream& operator>>(std::istream& in, ObjData::FaceVertex& f)
|
||||
{
|
||||
std::int32_t val;
|
||||
if(in >> f.v)
|
||||
{
|
||||
if(in.peek() == '/')
|
||||
{
|
||||
in.get();
|
||||
in >> f.t;
|
||||
in.clear();
|
||||
if(in.peek() == '/')
|
||||
{
|
||||
in.get();
|
||||
in >> f.n;
|
||||
in.clear();
|
||||
}
|
||||
}
|
||||
in.clear();
|
||||
f.v--;
|
||||
f.t--;
|
||||
f.n--;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
}
|
||||
81
Runtime/Includes/Graphics/Material.h
git.filemode.normal_file
81
Runtime/Includes/Graphics/Material.h
git.filemode.normal_file
@@ -0,0 +1,81 @@
|
||||
#ifndef __SCOP_RENDERER_MATERIAL__
|
||||
#define __SCOP_RENDERER_MATERIAL__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Core/EventBus.h>
|
||||
#include <Renderer/Image.h>
|
||||
#include <Renderer/Buffer.h>
|
||||
#include <Renderer/Descriptor.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
struct MaterialTextures
|
||||
{
|
||||
std::shared_ptr<Texture> albedo;
|
||||
};
|
||||
|
||||
struct MaterialData
|
||||
{
|
||||
float dissolve_texture_factor = 1.0f;
|
||||
float dissolve_black_white_colors_factor = 1.0f;
|
||||
float dissolve_normals_colors_factor = 0.0f;
|
||||
std::uint8_t __padding[4];
|
||||
};
|
||||
|
||||
class Material
|
||||
{
|
||||
friend class Model;
|
||||
|
||||
public:
|
||||
Material() { m_data_buffer.Init(sizeof(m_data)); SetupEventListener(); }
|
||||
Material(const MaterialTextures& textures) : m_textures(textures) { m_data_buffer.Init(sizeof(m_data)); SetupEventListener(); }
|
||||
|
||||
inline void SetMaterialData(const MaterialData& data) noexcept { m_data = data; }
|
||||
|
||||
~Material() { m_data_buffer.Destroy(); }
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set->GetSet(frame_index); }
|
||||
|
||||
inline void SetupEventListener()
|
||||
{
|
||||
std::function<void(const EventBase&)> functor = [this](const EventBase& event)
|
||||
{
|
||||
if(event.What() == Event::FrameBeginEventCode)
|
||||
m_have_been_updated_this_frame = false;
|
||||
};
|
||||
EventBus::RegisterListener({ functor, "__ScopMaterial" + std::to_string(reinterpret_cast<std::uintptr_t>(this)) });
|
||||
}
|
||||
|
||||
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
|
||||
}
|
||||
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
if(m_have_been_updated_this_frame)
|
||||
return;
|
||||
p_set->SetImage(frame_index, 0, *m_textures.albedo);
|
||||
p_set->SetUniformBuffer(frame_index, 1, m_data_buffer.Get(frame_index));
|
||||
p_set->Update(frame_index, cmd);
|
||||
|
||||
static CPUBuffer buffer(sizeof(MaterialData));
|
||||
std::memcpy(buffer.GetData(), &m_data, buffer.GetSize());
|
||||
m_data_buffer.SetData(buffer, frame_index);
|
||||
|
||||
m_have_been_updated_this_frame = true;
|
||||
}
|
||||
|
||||
private:
|
||||
UniformBuffer m_data_buffer;
|
||||
MaterialTextures m_textures;
|
||||
MaterialData m_data;
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
bool m_have_been_updated_this_frame = false;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
72
Runtime/Includes/Graphics/Mesh.h
git.filemode.normal_file
72
Runtime/Includes/Graphics/Mesh.h
git.filemode.normal_file
@@ -0,0 +1,72 @@
|
||||
#ifndef __SCOPE_RENDERER_MESH__
|
||||
#define __SCOPE_RENDERER_MESH__
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include <Renderer/Vertex.h>
|
||||
#include <Renderer/Buffer.h>
|
||||
#include <Utils/Buffer.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
struct SubMesh
|
||||
{
|
||||
MeshBuffer buffer;
|
||||
std::size_t index_size;
|
||||
std::size_t triangle_count = 0;
|
||||
|
||||
inline SubMesh(const std::vector<Vertex>& vertices, const std::vector<std::uint32_t>& indices, std::size_t index_size = 0)
|
||||
{
|
||||
CPUBuffer data(vertices.size() * sizeof(Vertex) + indices.size() * sizeof(std::uint32_t));
|
||||
std::memcpy(data.GetData(), vertices.data(), vertices.size() * sizeof(Vertex));
|
||||
std::memcpy(data.GetData() + vertices.size() * sizeof(Vertex), indices.data(), indices.size() * sizeof(std::uint32_t));
|
||||
buffer.Init(vertices.size() * sizeof(Vertex), indices.size() * sizeof(std::uint32_t), 0, std::move(data));
|
||||
this->index_size = index_size == 0 ? indices.size() : index_size;
|
||||
triangle_count = this->index_size / 3;
|
||||
}
|
||||
|
||||
inline void SetData(const std::vector<Vertex>& vertices, const std::vector<std::uint32_t>& indices, std::size_t index_size = 0)
|
||||
{
|
||||
CPUBuffer vertex_data(vertices.size() * sizeof(Scop::Vertex));
|
||||
std::memcpy(vertex_data.GetData(), vertices.data(), vertex_data.GetSize());
|
||||
CPUBuffer index_data(indices.size() * sizeof(std::uint32_t));
|
||||
std::memcpy(index_data.GetData(), indices.data(), index_data.GetSize());
|
||||
|
||||
buffer.SetVertexData(std::move(vertex_data));
|
||||
buffer.SetVertexData(std::move(index_data));
|
||||
|
||||
this->index_size = index_size == 0 ? indices.size() : index_size;
|
||||
triangle_count = this->index_size / 3;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
Mesh() = default;
|
||||
|
||||
void Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn) const noexcept;
|
||||
void Draw(VkCommandBuffer cmd, std::size_t& drawcalls, std::size_t& polygondrawn, std::size_t submesh_index) const noexcept;
|
||||
|
||||
inline std::size_t GetSubMeshCount() const { return m_sub_meshes.size(); }
|
||||
|
||||
inline void AddSubMesh(SubMesh mesh) { m_sub_meshes.emplace_back(std::move(mesh)); }
|
||||
[[nodiscard]] inline SubMesh& GetSubMesh(std::size_t index) { return m_sub_meshes.at(index); }
|
||||
inline void Reset()
|
||||
{
|
||||
for(auto& mesh : m_sub_meshes)
|
||||
mesh.buffer.Destroy();
|
||||
m_sub_meshes.clear();
|
||||
}
|
||||
|
||||
~Mesh();
|
||||
|
||||
private:
|
||||
std::vector<SubMesh> m_sub_meshes;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
21
Runtime/Includes/Graphics/MeshFactory.h
git.filemode.normal_file
21
Runtime/Includes/Graphics/MeshFactory.h
git.filemode.normal_file
@@ -0,0 +1,21 @@
|
||||
#ifndef __SCOP_MESH_FACTORY__
|
||||
#define __SCOP_MESH_FACTORY__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Maths/Vec2.h>
|
||||
#include <Maths/Vec3.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
std::shared_ptr<class Mesh> CreateQuad();
|
||||
std::shared_ptr<class Mesh> CreateQuad(float x, float y, float width, float height);
|
||||
std::shared_ptr<class Mesh> CreateQuad(const Vec2f& position, const Vec2f& size);
|
||||
std::shared_ptr<class Mesh> CreateCube();
|
||||
std::shared_ptr<class Mesh> CreatePyramid();
|
||||
std::shared_ptr<class Mesh> CreateSphere(std::uint32_t x_segments = 32, std::uint32_t y_segments = 32);
|
||||
std::shared_ptr<class Mesh> CreateCapsule(float radius = 0.5f, float mid_height = 2.0f, int radial_degments = 64, int rings = 8);
|
||||
std::shared_ptr<class Mesh> CreatePlane(float width, float height, const Vec3f& normal);
|
||||
}
|
||||
|
||||
#endif
|
||||
48
Runtime/Includes/Graphics/Model.h
git.filemode.normal_file
48
Runtime/Includes/Graphics/Model.h
git.filemode.normal_file
@@ -0,0 +1,48 @@
|
||||
#ifndef __SCOPE_RENDERER_MODEL__
|
||||
#define __SCOPE_RENDERER_MODEL__
|
||||
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
|
||||
#include <kvf.h>
|
||||
|
||||
#include <Maths/Vec3.h>
|
||||
#include <Graphics/Mesh.h>
|
||||
#include <Graphics/Material.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
// Only static meshes for now
|
||||
class Model
|
||||
{
|
||||
friend class ScopEngine;
|
||||
friend Model LoadModelFromObjFile(std::filesystem::path path) noexcept;
|
||||
|
||||
public:
|
||||
Model() = default;
|
||||
Model(std::shared_ptr<Mesh> mesh);
|
||||
|
||||
inline void SetMaterial(std::shared_ptr<Material> material, std::size_t mesh_index) { m_materials[mesh_index] = material; }
|
||||
inline std::size_t GetSubMeshCount() const { return p_mesh->GetSubMeshCount(); }
|
||||
|
||||
[[nodiscard]] inline std::shared_ptr<Material> GetMaterial(std::size_t mesh_index) { return m_materials[mesh_index]; }
|
||||
[[nodiscard]] inline std::vector<std::shared_ptr<Material>>& GetAllMaterials() { return m_materials; }
|
||||
[[nodiscard]] inline Vec3f GetCenter() const noexcept { return m_center; }
|
||||
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||
|
||||
void Draw(VkCommandBuffer cmd, std::shared_ptr<DescriptorSet> matrices_set, const class GraphicPipeline& pipeline, std::shared_ptr<DescriptorSet> set, std::size_t& drawcalls, std::size_t& polygondrawn, std::size_t frame_index) const;
|
||||
|
||||
~Model() = default;
|
||||
|
||||
private:
|
||||
inline static std::shared_ptr<Material> s_default_material = nullptr;
|
||||
|
||||
Vec3f m_center = { 0.0f, 0.0f, 0.0f };
|
||||
std::vector<std::shared_ptr<Material>> m_materials;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
};
|
||||
|
||||
Model LoadModelFromObjFile(std::filesystem::path path) noexcept;
|
||||
}
|
||||
|
||||
#endif
|
||||
53
Runtime/Includes/Graphics/Narrator.h
git.filemode.normal_file
53
Runtime/Includes/Graphics/Narrator.h
git.filemode.normal_file
@@ -0,0 +1,53 @@
|
||||
#ifndef __SCOP_GRAPHICS_NARRATOR__
|
||||
#define __SCOP_GRAPHICS_NARRATOR__
|
||||
|
||||
#include <Maths/Vec3.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Maths/Quaternions.h>
|
||||
#include <Core/Script.h>
|
||||
#include <Graphics/Model.h>
|
||||
#include <Core/UUID.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Narrator
|
||||
{
|
||||
friend Scene;
|
||||
|
||||
public:
|
||||
Narrator() : m_uuid(UUID()) {}
|
||||
Narrator(std::uint64_t uuid) : m_uuid(uuid) {}
|
||||
inline void AttachScript(std::shared_ptr<NarratorScript> script) { p_script = script; }
|
||||
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||
inline ~Narrator()
|
||||
{
|
||||
if(p_script)
|
||||
p_script->OnQuit();
|
||||
}
|
||||
|
||||
private:
|
||||
inline void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep)
|
||||
{
|
||||
if(p_script)
|
||||
p_script->OnUpdate(scene, input, timestep);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<NarratorScript> p_script;
|
||||
std::uint64_t m_uuid;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<Scop::Narrator>
|
||||
{
|
||||
std::size_t operator()(const Scop::Narrator& n) const noexcept
|
||||
{
|
||||
return static_cast<std::size_t>(n.GetUUID());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
126
Runtime/Includes/Graphics/Scene.h
git.filemode.normal_file
126
Runtime/Includes/Graphics/Scene.h
git.filemode.normal_file
@@ -0,0 +1,126 @@
|
||||
#ifndef __SCOP_SCENE__
|
||||
#define __SCOP_SCENE__
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
|
||||
#include <Graphics/Enums.h>
|
||||
#include <Graphics/Actor.h>
|
||||
#include <Graphics/Narrator.h>
|
||||
#include <Graphics/Sprite.h>
|
||||
#include <Renderer/Buffer.h>
|
||||
#include <Renderer/Descriptor.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
#include <Graphics/Cameras/Base.h>
|
||||
#include <Renderer/Pipelines/Shader.h>
|
||||
#include <Renderer/Pipelines/Graphics.h>
|
||||
#include <Graphics/Font.h>
|
||||
#include <Graphics/Text.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
struct SceneDescriptor
|
||||
{
|
||||
std::shared_ptr<Shader> fragment_shader;
|
||||
std::shared_ptr<Shader> post_process_shader = nullptr;
|
||||
std::shared_ptr<BaseCamera> camera;
|
||||
CullMode culling;
|
||||
std::size_t post_process_data_size = 0;
|
||||
bool render_3D_enabled = true;
|
||||
bool render_2D_enabled = true;
|
||||
bool render_skybox_enabled = true;
|
||||
bool render_post_process_enabled = false;
|
||||
};
|
||||
|
||||
class Scene
|
||||
{
|
||||
friend class ScopEngine;
|
||||
|
||||
public:
|
||||
struct ForwardData
|
||||
{
|
||||
std::shared_ptr<DescriptorSet> matrices_set;
|
||||
std::shared_ptr<DescriptorSet> albedo_set;
|
||||
std::shared_ptr<UniformBuffer> matrices_buffer;
|
||||
bool wireframe = false;
|
||||
};
|
||||
|
||||
struct PostProcessData
|
||||
{
|
||||
std::shared_ptr<DescriptorSet> set;
|
||||
std::shared_ptr<UniformBuffer> data_buffer;
|
||||
CPUBuffer data;
|
||||
};
|
||||
|
||||
public:
|
||||
Scene(std::string_view name, SceneDescriptor desc);
|
||||
Scene(std::string_view name, SceneDescriptor desc, NonOwningPtr<Scene> parent);
|
||||
|
||||
Actor& CreateActor(Model model) noexcept;
|
||||
Actor& CreateActor(std::string_view name, Model model);
|
||||
|
||||
Narrator& CreateNarrator() noexcept;
|
||||
Narrator& CreateNarrator(std::string_view name);
|
||||
|
||||
Sprite& CreateSprite(std::shared_ptr<Texture> texture) noexcept;
|
||||
Sprite& CreateSprite(std::string_view name, std::shared_ptr<Texture> texture);
|
||||
|
||||
Text& CreateText(std::string text) noexcept;
|
||||
Text& CreateText(std::string_view name, std::string text);
|
||||
|
||||
void LoadFont(std::filesystem::path path, float scale);
|
||||
|
||||
void RemoveActor(Actor& actor) noexcept;
|
||||
void RemoveNarrator(Narrator& narrator) noexcept;
|
||||
void RemoveSprite(Sprite& sprite) noexcept;
|
||||
void RemoveText(Text& text) noexcept;
|
||||
|
||||
[[nodiscard]] inline Scene& AddChildScene(std::string_view name, SceneDescriptor desc) { return m_scene_children.emplace_back(name, std::move(desc), this); }
|
||||
inline void AddSkybox(std::shared_ptr<CubeTexture> cubemap) { p_skybox = cubemap; }
|
||||
void SwitchToChild(std::string_view name) const noexcept;
|
||||
void SwitchToParent() const noexcept;
|
||||
|
||||
[[nodiscard]] inline ForwardData& GetForwardData() noexcept { return m_forward; }
|
||||
[[nodiscard]] inline PostProcessData& GetPostProcessData() noexcept { return m_post_process; }
|
||||
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Actor>& GetActors() const noexcept { return m_actors; }
|
||||
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Sprite>& GetSprites() const noexcept { return m_sprites; }
|
||||
[[nodiscard]] inline const std::unordered_map<std::uint64_t, Text>& GetTexts() const noexcept { return m_texts; }
|
||||
[[nodiscard]] inline const std::string& GetName() const noexcept { return m_name; }
|
||||
[[nodiscard]] inline GraphicPipeline& GetPipeline() noexcept { return m_pipeline; }
|
||||
[[nodiscard]] inline std::shared_ptr<BaseCamera> GetCamera() const { return m_descriptor.camera; }
|
||||
[[nodiscard]] inline DepthImage& GetDepth() noexcept { return m_depth; }
|
||||
[[nodiscard]] inline std::shared_ptr<Shader> GetFragmentShader() const { return m_descriptor.fragment_shader; }
|
||||
[[nodiscard]] inline std::shared_ptr<CubeTexture> GetSkybox() const { return p_skybox; }
|
||||
[[nodiscard]] inline const SceneDescriptor& GetDescription() const noexcept { return m_descriptor; }
|
||||
|
||||
~Scene() = default;
|
||||
|
||||
private:
|
||||
Scene() = default;
|
||||
void Init(NonOwningPtr<class Renderer> renderer);
|
||||
void Update(class Inputs& input, float delta, float aspect);
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
GraphicPipeline m_pipeline;
|
||||
ForwardData m_forward;
|
||||
PostProcessData m_post_process;
|
||||
DepthImage m_depth;
|
||||
SceneDescriptor m_descriptor;
|
||||
FontRegistry m_fonts_registry;
|
||||
std::shared_ptr<CubeTexture> p_skybox;
|
||||
std::unordered_map<std::uint64_t, Actor> m_actors;
|
||||
std::unordered_map<std::uint64_t, Text> m_texts;
|
||||
std::unordered_map<std::uint64_t, Sprite> m_sprites;
|
||||
std::unordered_map<std::uint64_t, Narrator> m_narrators;
|
||||
std::vector<Scene> m_scene_children;
|
||||
std::string m_name;
|
||||
NonOwningPtr<Scene> p_parent;
|
||||
std::shared_ptr<Font> p_bound_font;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
78
Runtime/Includes/Graphics/Sprite.h
git.filemode.normal_file
78
Runtime/Includes/Graphics/Sprite.h
git.filemode.normal_file
@@ -0,0 +1,78 @@
|
||||
#ifndef __SCOP_RENDERER_SPRITE__
|
||||
#define __SCOP_RENDERER_SPRITE__
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Maths/Vec2.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Core/Script.h>
|
||||
#include <Graphics/Mesh.h>
|
||||
#include <Renderer/Descriptor.h>
|
||||
#include <Renderer/Image.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Sprite
|
||||
{
|
||||
friend class Render2DPass;
|
||||
|
||||
public:
|
||||
Sprite(std::shared_ptr<Texture> texture);
|
||||
Sprite(std::uint64_t uuid, std::shared_ptr<Texture> texture);
|
||||
|
||||
inline void AttachScript(std::shared_ptr<SpriteScript> script) { p_script = script; }
|
||||
void Update(NonOwningPtr<class Scene> scene, class Inputs& input, float timestep);
|
||||
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = color; }
|
||||
inline void SetPosition(Vec2ui position) noexcept { m_position = position; }
|
||||
inline void SetScale(Vec2f scale) noexcept { m_scale = scale; }
|
||||
|
||||
[[nodiscard]] inline const Vec4f& GetColor() const noexcept { return m_color; }
|
||||
[[nodiscard]] inline const Vec2ui& GetPosition() const noexcept { return m_position; }
|
||||
[[nodiscard]] inline const Vec2f& GetScale() const noexcept { return m_scale; }
|
||||
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||
[[nodiscard]] inline std::shared_ptr<Texture> GetTexture() const { return p_texture; }
|
||||
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||
|
||||
~Sprite();
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set->GetSet(frame_index); }
|
||||
|
||||
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
|
||||
}
|
||||
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
p_set->SetImage(frame_index, 0, *p_texture);
|
||||
p_set->Update(frame_index, cmd);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
std::shared_ptr<Texture> p_texture;
|
||||
std::shared_ptr<class SpriteScript> p_script;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
Vec2ui m_position = Vec2ui{ 0, 0 };
|
||||
Vec2f m_scale = Vec2f{ 1.0f, 1.0f };
|
||||
std::uint64_t m_uuid;
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<Scop::Sprite>
|
||||
{
|
||||
std::size_t operator()(const Scop::Sprite& s) const noexcept
|
||||
{
|
||||
return static_cast<std::size_t>(s.GetUUID());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
56
Runtime/Includes/Graphics/Text.h
git.filemode.normal_file
56
Runtime/Includes/Graphics/Text.h
git.filemode.normal_file
@@ -0,0 +1,56 @@
|
||||
#ifndef __SCOP_TEXT__
|
||||
#define __SCOP_TEXT__
|
||||
|
||||
#include <Graphics/Font.h>
|
||||
#include <Graphics/Mesh.h>
|
||||
#include <Renderer/Descriptor.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Text
|
||||
{
|
||||
friend class Render2DPass;
|
||||
|
||||
public:
|
||||
Text(std::uint64_t uuid, const std::string& text, std::shared_ptr<Font> font);
|
||||
|
||||
inline void SetColor(Vec4f color) noexcept { m_color = color; }
|
||||
inline void SetPosition(Vec2ui position) noexcept { m_position = position; }
|
||||
inline void SetScale(Vec2f scale) noexcept { m_scale = scale; }
|
||||
|
||||
[[nodiscard]] inline const std::string& GetText() const { return m_text; }
|
||||
[[nodiscard]] inline std::shared_ptr<Font> GetFont() const { return p_font; }
|
||||
[[nodiscard]] inline const Vec4f& GetColor() const noexcept { return m_color; }
|
||||
[[nodiscard]] inline const Vec2ui& GetPosition() const noexcept { return m_position; }
|
||||
[[nodiscard]] inline const Vec2f& GetScale() const noexcept { return m_scale; }
|
||||
[[nodiscard]] inline std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
|
||||
[[nodiscard]] inline std::uint64_t GetUUID() const noexcept { return m_uuid; }
|
||||
|
||||
virtual ~Text() = default;
|
||||
|
||||
private:
|
||||
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
|
||||
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set->GetSet(frame_index); }
|
||||
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
|
||||
}
|
||||
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd)
|
||||
{
|
||||
p_set->SetImage(frame_index, 0, const_cast<Texture&>(p_font->GetTexture()));
|
||||
p_set->Update(frame_index, cmd);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<DescriptorSet> p_set;
|
||||
std::shared_ptr<Mesh> p_mesh;
|
||||
std::shared_ptr<Font> p_font;
|
||||
std::string m_text;
|
||||
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
Vec2ui m_position = Vec2ui{ 0, 0 };
|
||||
Vec2f m_scale = Vec2f{ 1.0f, 1.0f };
|
||||
std::uint64_t m_uuid;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user