Basic renderhierarchy async updates
This commit is contained in:
@@ -33,7 +33,7 @@ DECLARE_REF(CameraActor)
|
|||||||
DECLARE_REF(CameraComponent)
|
DECLARE_REF(CameraComponent)
|
||||||
struct BasePassData
|
struct BasePassData
|
||||||
{
|
{
|
||||||
const Array<StaticMeshBatch> staticDrawList;
|
Array<StaticMeshBatch> staticDrawList;
|
||||||
};
|
};
|
||||||
class BasePass : public RenderPass<BasePassData>
|
class BasePass : public RenderPass<BasePassData>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ DECLARE_REF(CameraActor)
|
|||||||
DECLARE_REF(CameraComponent)
|
DECLARE_REF(CameraComponent)
|
||||||
struct DepthPrepassData
|
struct DepthPrepassData
|
||||||
{
|
{
|
||||||
const Array<StaticMeshBatch> staticDrawList;
|
Array<StaticMeshBatch> staticDrawList;
|
||||||
};
|
};
|
||||||
class DepthPrepass : public RenderPass<DepthPrepassData>
|
class DepthPrepass : public RenderPass<DepthPrepassData>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ DECLARE_REF(Scene)
|
|||||||
DECLARE_REF(Viewport)
|
DECLARE_REF(Viewport)
|
||||||
struct LightCullingPassData
|
struct LightCullingPassData
|
||||||
{
|
{
|
||||||
const LightEnv lightEnv;
|
LightEnv lightEnv;
|
||||||
};
|
};
|
||||||
class LightCullingPass : public RenderPass<LightCullingPassData>
|
class LightCullingPass : public RenderPass<LightCullingPassData>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ public:
|
|||||||
void addPrimitiveComponent(PPrimitiveComponent comp);
|
void addPrimitiveComponent(PPrimitiveComponent comp);
|
||||||
|
|
||||||
const Array<PPrimitiveComponent>& getPrimitives() const { return primitives; }
|
const Array<PPrimitiveComponent>& getPrimitives() const { return primitives; }
|
||||||
const Array<MeshBatch>& getStaticMeshes() const { return staticMeshes; }
|
const Array<StaticMeshBatch>& getStaticMeshes() const { return staticMeshes; }
|
||||||
const LightEnv& getLightBuffer() const { return lightEnv; }
|
const LightEnv& getLightBuffer() const { return lightEnv; }
|
||||||
UPSceneUpdater& getSceneUpdater() { return updater; }
|
UPSceneUpdater& getSceneUpdater() { return updater; }
|
||||||
private:
|
private:
|
||||||
Array<MeshBatch> staticMeshes;
|
Array<StaticMeshBatch> staticMeshes;
|
||||||
Array<PActor> rootActors;
|
Array<PActor> rootActors;
|
||||||
Array<PPrimitiveComponent> primitives;
|
Array<PPrimitiveComponent> primitives;
|
||||||
LightEnv lightEnv;
|
LightEnv lightEnv;
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ target_sources(SeeleEngine
|
|||||||
Layout.cpp
|
Layout.cpp
|
||||||
RenderHierarchy.h
|
RenderHierarchy.h
|
||||||
RenderHierarchy.cpp
|
RenderHierarchy.cpp
|
||||||
|
System.h
|
||||||
|
System.cpp
|
||||||
VerticalLayout.h
|
VerticalLayout.h
|
||||||
VerticalLayout.cpp)
|
VerticalLayout.cpp)
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace UI
|
|||||||
{
|
{
|
||||||
//Element defines any part of the UI
|
//Element defines any part of the UI
|
||||||
DECLARE_REF(Element)
|
DECLARE_REF(Element)
|
||||||
|
DECLARE_REF(System)
|
||||||
class Element
|
class Element
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -32,6 +33,7 @@ protected:
|
|||||||
bool dirty;
|
bool dirty;
|
||||||
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
PSystem system;
|
||||||
PElement parent;
|
PElement parent;
|
||||||
Array<PElement> children;
|
Array<PElement> children;
|
||||||
friend class Layout;
|
friend class Layout;
|
||||||
|
|||||||
@@ -3,12 +3,18 @@
|
|||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::UI;
|
using namespace Seele::UI;
|
||||||
|
|
||||||
RenderElement::RenderElement()
|
void AddElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements)
|
||||||
|
{
|
||||||
|
for(auto element : elements)
|
||||||
|
{
|
||||||
|
if(element.parent == parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RenderElement::~RenderElement()
|
void RemoveElementRenderHierarchyUpdate::apply(Array<RenderElement>& elements)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,10 +29,45 @@ RenderHierarchy::~RenderHierarchy()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderHierarchy::updateHierarchyIndices()
|
void RenderHierarchy::addElement(PElement addedElement)
|
||||||
{
|
{
|
||||||
for (uint32 i = 0; i < drawElements.size(); i++)
|
std::lock_guard lock(updateLock);
|
||||||
|
updates.add(new AddElementRenderHierarchyUpdate{
|
||||||
|
addedElement.getHandle(),
|
||||||
|
addedElement->getParent().getHandle()
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderHierarchy::removeElement(PElement elementToRemove)
|
||||||
{
|
{
|
||||||
drawElements[i].hierarchyIndex = i;
|
std::lock_guard lock(updateLock);
|
||||||
|
updates.add(new RemoveElementRenderHierarchyUpdate{
|
||||||
|
elementToRemove.getHandle(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderHierarchy::moveElement(PElement elementToMove, PElement newParent)
|
||||||
|
{
|
||||||
|
std::lock_guard lock(updateLock);
|
||||||
|
updates.add(new AddElementRenderHierarchyUpdate{
|
||||||
|
elementToMove.getHandle(),
|
||||||
|
newParent.getHandle()
|
||||||
|
});
|
||||||
|
updates.add(new RemoveElementRenderHierarchyUpdate{
|
||||||
|
elementToMove.getHandle()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderHierarchy::updateHierarchy()
|
||||||
|
{
|
||||||
|
Array<RenderHierarchyUpdate*> localUpdates;
|
||||||
|
{ // make a local copy of the updates so we dont hold the lock for too long
|
||||||
|
std::lock_guard lock(updateLock);
|
||||||
|
localUpdates = updates;
|
||||||
|
updates.clear();
|
||||||
|
}
|
||||||
|
for(auto update : localUpdates)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Elements/Element.h"
|
#include "Elements/Element.h"
|
||||||
|
#include "Containers/List.h"
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
@@ -9,32 +10,50 @@ DECLARE_NAME_REF(Gfx, RenderCommand);
|
|||||||
class RenderElement
|
class RenderElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderElement();
|
RenderElement() = default;
|
||||||
virtual ~RenderElement();
|
~RenderElement() = default;
|
||||||
private:
|
|
||||||
uint32 hierarchyIndex;
|
uint32 hierarchyIndex;
|
||||||
RenderElement* parent;
|
Element* parent;
|
||||||
PElement referencedElement;
|
Element* referencedElement;
|
||||||
Gfx::PRenderCommand renderCommand;
|
|
||||||
friend class RenderHierarchy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RenderHierarchyUpdate
|
struct RenderHierarchyUpdate
|
||||||
{};
|
{
|
||||||
DEFINE_REF(RenderHierarchyUpdate)
|
virtual void apply(Array<RenderElement>& elements) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AddElementRenderHierarchyUpdate : public RenderHierarchyUpdate
|
||||||
|
{
|
||||||
|
Element* addedElement;
|
||||||
|
Element* parent;
|
||||||
|
virtual void apply(Array<RenderElement>& elements) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RemoveElementRenderHierarchyUpdate : public RenderHierarchyUpdate
|
||||||
|
{
|
||||||
|
Element* element;
|
||||||
|
virtual void apply(Array<RenderElement>& elements) override;
|
||||||
|
};
|
||||||
|
|
||||||
class RenderHierarchy
|
class RenderHierarchy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderHierarchy();
|
RenderHierarchy();
|
||||||
~RenderHierarchy();
|
~RenderHierarchy();
|
||||||
|
// logic thread interface, queue hierarchy changes
|
||||||
|
void addElement(PElement addedElement);
|
||||||
|
void removeElement(PElement elementToRemove);
|
||||||
|
void moveElement(PElement elementToMove, PElement newParent);
|
||||||
|
|
||||||
|
// render thread interface, apply changes
|
||||||
|
void updateHierarchy();
|
||||||
private:
|
private:
|
||||||
void updateHierarchyIndices();
|
static_assert(std::is_trivially_copyable_v<RenderElement>);
|
||||||
|
|
||||||
// List of all drawable elements in draw order
|
// List of all drawable elements in draw order
|
||||||
Array<RenderElement> drawElements;
|
Array<RenderElement> drawElements;
|
||||||
|
|
||||||
|
List<RenderHierarchyUpdate*> updates;
|
||||||
|
std::mutex updateLock;
|
||||||
};
|
};
|
||||||
} // namespace UI
|
} // namespace UI
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#include "System.h"
|
||||||
|
|
||||||
|
using namespace Seele;
|
||||||
|
using namespace Seele::UI;
|
||||||
|
|
||||||
|
System::System()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
System::~System()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "MinimalEngine.h"
|
||||||
|
#include "RenderHierarchy.h"
|
||||||
|
|
||||||
|
namespace Seele
|
||||||
|
{
|
||||||
|
namespace UI
|
||||||
|
{
|
||||||
|
DECLARE_REF(Panel)
|
||||||
|
class System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
System();
|
||||||
|
virtual ~System();
|
||||||
|
private:
|
||||||
|
PPanel rootPanel;
|
||||||
|
Array<RenderHierarchyUpdate*> updates;
|
||||||
|
};
|
||||||
|
DEFINE_REF(System)
|
||||||
|
} // namespace UI
|
||||||
|
} // namespace Seele
|
||||||
@@ -30,7 +30,7 @@ private:
|
|||||||
BasePass basePass;
|
BasePass basePass;
|
||||||
|
|
||||||
DepthPrepassData depthPrepassData;
|
DepthPrepassData depthPrepassData;
|
||||||
LightCullingPassData lightCullingData;
|
LightCullingPassData lightCullingPassData;
|
||||||
BasePassData basePassData;
|
BasePassData basePassData;
|
||||||
|
|
||||||
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user