Skip to content

Commit f3dee33

Browse files
draft ITransformTreeManager
1 parent 4316c44 commit f3dee33

14 files changed

+498
-403
lines changed

include/ISceneManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ namespace scene
3232
{
3333
class ICameraSceneNode;
3434
class IDummyTransformationSceneNode;
35-
class IMeshLoader;
3635
class IMeshSceneNode;
37-
class IMeshWriter;
3836
class ISceneNode;
3937
class ISceneNodeAnimator;
4038

include/ISceneNodeAnimator.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "nbl/core/core.h"
1010

11-
#include "ESceneNodeAnimatorTypes.h"
1211
#include "IEventReceiver.h"
1312

1413
namespace nbl
@@ -31,12 +30,6 @@ namespace scene
3130
\param timeMs Current time in milli seconds. */
3231
virtual void animateNode(IDummyTransformationSceneNode* node, uint32_t timeMs) =0;
3332

34-
//! Creates a clone of this animator.
35-
/** Please note that you will have to drop
36-
(IReferenceCounted::drop()) the returned pointer after calling this. */
37-
virtual ISceneNodeAnimator* createClone(IDummyTransformationSceneNode* node,
38-
ISceneManager* newManager=0) =0;
39-
4033
//! Returns true if this animator receives events.
4134
/** When attached to an active camera, this animator will be
4235
able to respond to events such as mouse and keyboard events. */
@@ -50,20 +43,6 @@ namespace scene
5043
{
5144
return false;
5245
}
53-
54-
//! Returns type of the scene node animator
55-
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
56-
{
57-
return ESNAT_UNKNOWN;
58-
}
59-
60-
//! Returns if the animator has finished.
61-
/** This is only valid for non-looping animators with a discrete end state.
62-
\return true if the animator has finished, false if it is still running. */
63-
virtual bool hasFinished(void) const
64-
{
65-
return false;
66-
}
6746
};
6847

6948

include/nbl/builtin/glsl/scene/node.glsl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ mat2x3 nbl_glsl_scene_Node_static_data_t_getAABB(in nbl_glsl_scene_Node_static_d
4040
return mat2x3(node.AABBMin,node.AABBMax);
4141
}
4242

43-
44-
struct nbl_glsl_scene_Node_animation_data_t
45-
{
46-
mat4x3 relativeTransformation;
47-
float animationTime;
48-
};
49-
50-
5143
struct nbl_glsl_scene_Node_output_data_t
5244
{
5345
mat4x3 globalTransformation;
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O.
2+
// For conditions of distribution and use, see copyright notice in nabla.h
3+
// See the original file in irrlicht source for authors
4+
5+
#ifndef __NBL_SCENE_I_TREE_TRANSFORM_MANAGER_H_INCLUDED__
6+
#define __NBL_SCENE_I_TREE_TRANSFORM_MANAGER_H_INCLUDED__
7+
8+
#include "nbl/core/core.h"
9+
#include "nbl/video/video.h"
10+
11+
namespace nbl
12+
{
13+
namespace scene
14+
{
15+
16+
17+
class ITransformTreeManager : public virtual core::IReferenceCounted
18+
{
19+
public:
20+
using node_t = uint32_t;
21+
_NBL_STATIC_INLINE_CONSTEXPR node_t invalid_node = video::IPropertyPool::invalid_index;
22+
23+
using timestamp_t = video::IGPUAnimationLibrary::timestamp_t;
24+
25+
_NBL_STATIC_INLINE_CONSTEXPR uint32_t global_transform_prop_ix = 3u;
26+
private:
27+
using parent_t = node_t;
28+
using relative_transform_t = core::matrix3x4SIMD;
29+
using modified_stamp_t = timestamp_t;
30+
using global_transform_t = core::matrix3x4SIMD;
31+
using recomputed_stamp_t = timestamp_t;
32+
33+
public:
34+
using property_pool_t = video::CPropertyPool<core::allocator,
35+
parent_t,
36+
relative_transform_t,modified_stamp_t,
37+
global_transform_t,recomputed_stamp_t
38+
>;
39+
40+
// creation
41+
static inline core::smart_refctd_ptr<ITransformTreeManager> create(video::IVideoDriver* _driver, asset::SBufferRange<video::IGPUBuffer>&& memoryBlock, core::allocator<uint8_t>&& alloc = core::allocator<uint8_t>())
42+
{
43+
const auto reservedSize = video::IPropertyPool::getReservedSize(property_pool_t::calcApproximateCapacity(memoryBlock.size));
44+
auto reserved = std::allocator_traits<core::allocator<uint8_t>>::allocate(alloc,reservedSize);
45+
if (!reserved)
46+
return nullptr;
47+
48+
auto retval = create(_driver,std::move(memoryBlock),reserved,std::move(alloc));
49+
if (!retval)
50+
std::allocator_traits<core::allocator<uint8_t>>::deallocate(alloc,reserved,reservedSize);
51+
52+
return retval;
53+
}
54+
// if this method fails to create the pool, the callee must free the reserved memory themselves, also the reserved pointer must be compatible with the allocator so it can free it
55+
static inline core::smart_refctd_ptr<ITransformTreeManager> create(video::IVideoDriver* _driver, asset::SBufferRange<video::IGPUBuffer>&& memoryBlock, void* reserved, core::allocator<uint8_t>&& alloc=core::allocator<uint8_t>())
56+
{
57+
auto _nodeStorage = property_pool_t::create(std::move(memoryBlock),reserved,std::move(alloc));
58+
if (!_nodeStorage)
59+
return nullptr;
60+
61+
auto* ttm = new ITransformTreeManager(_driver,std::move(_nodeStorage));
62+
return core::smart_refctd_ptr<ITransformTreeManager>(ttm,core::dont_grab);
63+
}
64+
65+
//
66+
inline const auto* getNodePropertyPool() const {return m_nodeStorage.get();}
67+
68+
//
69+
inline asset::SBufferRange<video::IGPUBuffer> getGlobalTransformationBufferRange() const
70+
{
71+
asset::SBufferRange<video::IGPUBuffer> retval = {m_nodeStorage->getPropertyOffset(global_transform_prop_ix),m_nodeStorage->getCapacity()*sizeof(global_transform_t),m_nodeStorage->getMemoryBlock().buffer};
72+
return retval;
73+
}
74+
#if 0
75+
//
76+
struct AllocationRequest
77+
{
78+
core::SRange<node_t> outNodes;
79+
const parent_t* parents;
80+
const relative_transform_t* relativeTransforms;
81+
// what to do about timestamps?
82+
};
83+
template<typename ParentNodeIt>
84+
inline void addNodes(CPropertyPoolHandler* propertyPoolHandler, node_t* nodesBegin, node_t* nodesEnd, ParentNodeIt parentsBegin, const std::chrono::steady_clock::time_point& maxWaitPoint=video::GPUEventWrapper::default_wait())
85+
{
86+
if (std::distance(nodesBegin,nodesEnd)>m_nodeStorage->getFree())
87+
return;
88+
89+
m_nodeStorage->allocateProperties(nodesBegin,nodesEnd);
90+
assert(false); // TODO
91+
}
92+
// TODO: utilities for adding root nodes, adding skeleton node instances, etc.
93+
// should we just do it ourselves with a shader? (set correct timestamps so global gets recomputed)
94+
#endif
95+
//
96+
inline void removeNodes(const node_t* begin, const node_t* end)
97+
{
98+
m_nodeStorage->freeProperties(begin,end);
99+
}
100+
//
101+
inline void clearNodes()
102+
{
103+
m_nodeStorage->freeAllProperties();
104+
}
105+
106+
// TODO: make all these functions take a pipeline barrier type (future new API) with default being a full barrier
107+
void updateLocalTransforms(const asset::SBufferBinding<video::IGPUBuffer>& dispatchIndirectParameters, const asset::SBufferBinding<video::IGPUBuffer>& requestBuffer) //do we take a per-request nodeID buffer too?
108+
{
109+
assert(false); // TODO
110+
}
111+
//
112+
void recomputeGlobalTransforms(/*dispatchIndirectParams,nodeList*/)
113+
{
114+
// TODO: do it properly
115+
auto out = getGlobalTransformationBufferRange();
116+
m_driver->copyBuffer(m_nodeStorage->getMemoryBlock().buffer.get(),out.buffer.get(),m_nodeStorage->getPropertyOffset(1u),out.offset,out.size);
117+
}
118+
//
119+
void updateAndRecomputeGlobalTransforms(/*Same args as `updateLocalTransforms` and `recomputeGlobalTransforms`*/)
120+
{
121+
assert(false); // TODO
122+
}
123+
124+
//
125+
auto transferGlobalTransforms(const node_t* begin, const node_t* end, const asset::SBufferBinding<video::IGPUBuffer>& outputBuffer, const std::chrono::steady_clock::time_point& maxWaitPoint=video::GPUEventWrapper::default_wait())
126+
{
127+
video::CPropertyPoolHandler::TransferRequest request;
128+
request.download = true;
129+
request.pool = m_nodeStorage.get();
130+
request.indices = {begin,end};
131+
request.propertyID = 3u;
132+
//m_nodeStorage->transferProperties();
133+
assert(false); // TODO: Need a transfer to GPU mem
134+
}
135+
//auto downloadGlobalTransforms()
136+
137+
protected:
138+
ITransformTreeManager(video::IVideoDriver* _driver, core::smart_refctd_ptr<property_pool_t>&& _nodeStorage) : m_driver(_driver), m_nodeStorage(std::move(_nodeStorage))
139+
{
140+
// TODO: the ComputePipeline for update,recompute and combined update&recompute
141+
}
142+
~ITransformTreeManager()
143+
{
144+
//
145+
}
146+
147+
#if 0
148+
struct RootNodeParentIterator
149+
{
150+
inline RootNodeParentIterator& operator++()
151+
{
152+
//do nothing
153+
return *this;
154+
}
155+
inline RootNodeParentIterator operator++(int)
156+
{
157+
//do nothing
158+
}
159+
160+
inline node_t operator*() const
161+
{
162+
return invalid_node;
163+
}
164+
165+
//using iterator_category = typename std::iterator_traits::;
166+
//using difference_type = ptrdiff_t;
167+
using value_type = node_t;
168+
};
169+
#endif
170+
video::IVideoDriver* m_driver;
171+
core::smart_refctd_ptr<property_pool_t> m_nodeStorage;
172+
};
173+
174+
175+
} // end namespace scene
176+
} // end namespace nbl
177+
178+
#endif
179+

include/nbl/scene/scene.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@
99
#include "nbl/video/video.h"
1010
#include "nbl/ui/ui.h"
1111

12+
//
13+
//#include "nbl/scene/IAnimationBlendManager.h"
14+
#include "nbl/scene/ITransformTreeManager.h"
15+
//#include "nbl/scene/ILevelOfDetailLibrary.h"
16+
//#include "nbl/scene/ISensor.h" or asset? or a struct?
17+
//#include "nbl/scene/ICamera.h" or do we stick it inside the renderpass?
18+
//#include "nbl/scene/IRenderpassManager.h"
19+
//#include "nbl/scene/ISceneManager.h" do we need this?
20+
//#include "nbl/scene/.h"
21+
1222
#endif

include/nbl/video/CPropertyPool.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ class CPropertyPool final : public IPropertyPool
2323
{
2424
return (sizeof(Properties) + ...);
2525
}
26-
static uint32_t calcApproximateCapacity(size_t bufferSize)
27-
{
28-
return bufferSize/propertyCombinedSize();
29-
}
3026

3127
_NBL_STATIC_INLINE_CONSTEXPR auto PropertyCount = sizeof...(Properties);
3228

3329
public:
30+
static inline uint32_t calcApproximateCapacity(size_t bufferSize)
31+
{
32+
return bufferSize/propertyCombinedSize();
33+
}
34+
3435
static inline core::smart_refctd_ptr<this_t> create(asset::SBufferRange<IGPUBuffer>&& _memoryBlock, allocator<uint8_t>&& alloc = allocator<uint8_t>())
3536
{
3637
const auto reservedSize = getReservedSize(calcApproximateCapacity(_memoryBlock.size));

include/nbl/video/IPropertyPool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ class IPropertyPool : public core::IReferenceCounted
8686
{
8787
indexAllocator.reset();
8888
}
89-
90-
protected:
89+
90+
//
9191
#define PROPERTY_ADDRESS_ALLOCATOR_ARGS 1u,capacity,1u
9292
static inline PropertyAddressAllocator::size_type getReservedSize(uint32_t capacity)
9393
{
9494
return PropertyAddressAllocator::reserved_size(PROPERTY_ADDRESS_ALLOCATOR_ARGS);
9595
}
96-
96+
protected:
9797
IPropertyPool(asset::SBufferRange<IGPUBuffer>&& _memoryBlock, uint32_t capacity, void* reserved)
9898
: memoryBlock(std::move(_memoryBlock)), indexAllocator(reserved,0u,0u,PROPERTY_ADDRESS_ALLOCATOR_ARGS)
9999
{

source/Nabla/CSceneManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ namespace nbl
1818
class ITimer;
1919
namespace io
2020
{
21-
class IXMLWriter;
2221
class IFileSystem;
2322
}
2423
namespace scene
2524
{
26-
class IAnimatedMeshSceneNode;
2725

2826
/*!
2927
The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff.

source/Nabla/CSceneNodeAnimatorCameraFPS.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,6 @@ void CSceneNodeAnimatorCameraFPS::setInvertMouse(bool invert)
332332
}
333333

334334

335-
ISceneNodeAnimator* CSceneNodeAnimatorCameraFPS::createClone(IDummyTransformationSceneNode* node, ISceneManager* newManager)
336-
{
337-
CSceneNodeAnimatorCameraFPS * newAnimator =
338-
new CSceneNodeAnimatorCameraFPS(CursorControl, RotateSpeed, MoveSpeed, JumpSpeed,
339-
0, 0, NoVerticalMovement);
340-
newAnimator->setKeyMap(KeyMap);
341-
return newAnimator;
342-
}
343-
344-
345335
} // namespace scene
346336
} // namespace nbl
347337

source/Nabla/CSceneNodeAnimatorCameraFPS.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,6 @@ namespace scene
8080
return true;
8181
}
8282

83-
//! Returns the type of this animator
84-
virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
85-
{
86-
return ESNAT_CAMERA_FPS;
87-
}
88-
89-
//! Creates a clone of this animator.
90-
/** Please note that you will have to drop
91-
(IReferenceCounted::drop()) the returned pointer once you're
92-
done with it. */
93-
virtual ISceneNodeAnimator* createClone(IDummyTransformationSceneNode* node, ISceneManager* newManager=0);
94-
9583
private:
9684
void allKeysUp();
9785

0 commit comments

Comments
 (0)