Add offscreen render targets and rename AssetRegistry to ResourceRegistry #8
@@ -4,6 +4,9 @@
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class Entity;
|
||||
class SceneRenderer; // !TEMP remove this
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
Scene();
|
||||
@@ -14,6 +17,9 @@ class Scene {
|
||||
void setActiveCamera(entt::entity camera) { activeCamera = camera; }
|
||||
|
||||
private:
|
||||
friend class Entity;
|
||||
friend class SceneRenderer; // !TEMP remove this
|
||||
|
||||
entt::registry registry;
|
||||
entt::entity activeCamera = entt::null;
|
||||
};
|
||||
|
||||
@@ -17,9 +17,9 @@ class DebugUI {
|
||||
void show();
|
||||
void hide();
|
||||
|
||||
void showPanelRegistry(bool show = true);
|
||||
void showFrameStats(bool show = true);
|
||||
void showConsole(bool show = true);
|
||||
void showPanelRegistry(bool show = false);
|
||||
void showFrameStats(bool show = false);
|
||||
void showConsole(bool show = false);
|
||||
|
||||
private:
|
||||
PanelRegistry& registry;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "entity.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
Entity::Entity(entt::entity handle, Scene* scene) : handle(handle), scene(scene) {}
|
||||
|
||||
} // namespace sophia
|
||||
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
#include <sophia/scene.hpp>
|
||||
#include <entt/entt.hpp>
|
||||
#include <sophia/util/assert.hpp>
|
||||
#include <sophia/types.hpp>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity(const Entity&) = default;
|
||||
Entity& operator=(const Entity&) = default;
|
||||
|
||||
Entity() = default;
|
||||
Entity(entt::entity handle, Scene* scene);
|
||||
|
||||
template<typename T, typename... Args>
|
||||
T& addComponent(Args&&... args) {
|
||||
SOPHIA_ASSERT(!hasComponent<T>(), "Entity already has component!");
|
||||
T& component = scene->registry.emplace<T>(handle, std::forward<Args>(args)...);
|
||||
// scene->OnComponentAdded<T>(*this, component);
|
||||
return component;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T& getComponent()
|
||||
{
|
||||
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
|
||||
return scene->registry.get<T>(handle);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool hasComponent()
|
||||
{
|
||||
return scene->registry.all_of<T>(handle);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void removeComponent()
|
||||
{
|
||||
SOPHIA_ASSERT(hasComponent<T>(), "Entity does not have component!");
|
||||
scene->registry.remove<T>(handle);
|
||||
}
|
||||
|
||||
operator bool() const { return handle != entt::null; }
|
||||
operator entt::entity() const { return handle; }
|
||||
operator u32() const { return (u32)handle; }
|
||||
|
||||
// UUID GetUUID() { return GetComponent<IDComponent>().ID; }
|
||||
// const std::string& GetName() { return GetComponent<TagComponent>().Tag; }
|
||||
|
||||
bool operator==(const Entity& other) const {
|
||||
return handle == other.handle && scene == other.scene;
|
||||
}
|
||||
|
||||
bool operator!=(const Entity& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
entt::entity handle { entt::null};
|
||||
Scene* scene = nullptr;
|
||||
};
|
||||
|
||||
} // namespace sophia
|
||||
@@ -1,12 +1,61 @@
|
||||
#include "rendering/scene_renderer.hpp"
|
||||
|
||||
#include <sophia/util/assert.hpp>
|
||||
#include <sophia/components.hpp>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
namespace {
|
||||
struct PushConstantData {
|
||||
glm::mat4 transform{1.f};
|
||||
glm::vec4 color{1.f};
|
||||
};
|
||||
}
|
||||
|
||||
SceneRenderer::SceneRenderer(ResourceRegistry& resources)
|
||||
: resources{resources} {}
|
||||
|
||||
SceneRenderer::~SceneRenderer() {}
|
||||
|
||||
void SceneRenderer::render(const Scene& scene, RenderTargetHandle target) {}
|
||||
void SceneRenderer::render(const Scene& scene, Entity camera, RenderTargetHandle target) {
|
||||
SOPHIA_ASSERT(camera.hasComponent<CameraComponent>(), "camera does not have camera component!");
|
||||
|
||||
auto& R = scene.registry;
|
||||
|
||||
// Get all mesh
|
||||
// For each mesh, get all entities(ES) that have a transform and that mesh
|
||||
// For e in ES: add e's transform component to a list
|
||||
|
||||
// We now have
|
||||
/*
|
||||
M = mesh
|
||||
T = transform
|
||||
|
||||
Work Batch
|
||||
|- M0
|
||||
| |- T0
|
||||
| \- T2
|
||||
|
|
||||
|- M1
|
||||
| |- T1
|
||||
| \- T5
|
||||
|
|
||||
\- M2
|
||||
|- T3
|
||||
\- T4
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
for batch in Work Batch:
|
||||
batch.mesh.bind()
|
||||
|
||||
for transform in batch.transforms:
|
||||
commandBuffer.pushConstants(transform)
|
||||
batch.mesh.draw(commandBuffer)
|
||||
|
||||
NOTE: Use instanced rendering?
|
||||
*/
|
||||
}
|
||||
|
||||
} // namespace sophia
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
#include <sophia/handles.hpp>
|
||||
#include <sophia/scene.hpp>
|
||||
|
||||
#include "entity.hpp"
|
||||
#include "resources/resource_registry.hpp"
|
||||
|
||||
namespace sophia {
|
||||
|
||||
/**
|
||||
* !TEMP to be decoupled once scene batching and rendering impl
|
||||
*/
|
||||
class SceneRenderer {
|
||||
public:
|
||||
SceneRenderer(const SceneRenderer&) = delete;
|
||||
@@ -15,8 +19,7 @@ class SceneRenderer {
|
||||
SceneRenderer(ResourceRegistry& resources);
|
||||
~SceneRenderer();
|
||||
|
||||
// add camera as a arg (entity)
|
||||
void render(const Scene& scene, RenderTargetHandle target);
|
||||
void render(const Scene& scene, Entity camera, RenderTargetHandle target);
|
||||
|
||||
private:
|
||||
ResourceRegistry& resources;
|
||||
|
||||
@@ -12,6 +12,7 @@ DebugUI::DebugUI(PanelRegistry& registry, ConsoleCommandRegistry& commands)
|
||||
this->panelRegistryHandle = registry.emplace<PanelRegistryPanel>(registry);
|
||||
this->frameStatsHandle = registry.emplace<FrameStatsPanel>();
|
||||
this->consoleHandle = registry.emplace<ConsolePanel>(commands);
|
||||
hide();
|
||||
// #endif // !NDEBUG
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user