Skip to content

Commit 628a846

Browse files
committed
Added State::inherit(..) method.
1 parent 1f62d24 commit 628a846

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

include/vsg/vk/State.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ namespace vsg
3939
Stack stack;
4040
size_t pos = 0;
4141

42+
StateStack& operator = (const StateStack& rhs)
43+
{
44+
stack = rhs.stack;
45+
pos = rhs.pos;
46+
dirty();
47+
48+
return *this;
49+
}
50+
4251
inline void reset()
4352
{
4453
pos = 0;
@@ -93,6 +102,15 @@ namespace vsg
93102
uint32_t offset = 0;
94103
bool dirty = false;
95104

105+
MatrixStack& operator = (const MatrixStack& rhs)
106+
{
107+
matrixStack = rhs.matrixStack;
108+
offset = rhs.offset;
109+
dirty = true;
110+
111+
return *this;
112+
}
113+
96114
inline void set(const mat4& matrix)
97115
{
98116
matrixStack = {};
@@ -150,6 +168,7 @@ namespace vsg
150168
return;
151169
}
152170

171+
153172
// make sure matrix is a float matrix.
154173
mat4 newmatrix(matrixStack.top());
155174
vkCmdPushConstants(commandBuffer, pipeline, stageFlags, offset, sizeof(newmatrix), newmatrix.data());
@@ -267,8 +286,11 @@ namespace vsg
267286

268287
void reset();
269288

289+
void inherit(State& state);
290+
270291
inline void dirtyStateStacks()
271292
{
293+
dirty = true;
272294
for (auto& stateStack : stateStacks)
273295
{
274296
stateStack.dirty();
@@ -307,6 +329,7 @@ namespace vsg
307329
{
308330
if (dirty)
309331
{
332+
310333
for (uint32_t slot = 0; slot <= activeMaxStateSlot; ++slot)
311334
{
312335
stateStacks[slot].record(*_commandBuffer);

src/vsg/app/RecordTraversal.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,15 @@ void RecordTraversal::apply(const CommandGraph& commandGraph)
670670
auto cg = const_cast<CommandGraph*>(&commandGraph);
671671
if (cg->device)
672672
{
673+
#if 1
674+
cg->getOrCreateRecordTraversal()->_state->inherit(*_state);
675+
#else
673676
if (_viewDependentState && _viewDependentState->view && _viewDependentState->view->camera)
674677
{
675678
auto camera = _viewDependentState->view->camera;
676679
cg->getOrCreateRecordTraversal()->_state->setInhertiedViewProjectionAndViewMatrix(camera->projectionMatrix->transform(), camera->viewMatrix->transform());
677680
}
681+
#endif
678682

679683
cg->record(recordedCommandBuffers, _frameStamp, _databasePager);
680684
}

src/vsg/vk/State.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ void State::reserve(const Slots& in_maxSlots)
3535

3636
void State::reset()
3737
{
38-
//info("State::reset()");
3938
for (auto& stateStack : stateStacks)
4039
{
4140
stateStack.reset();
@@ -48,7 +47,11 @@ void State::connect(ref_ptr<CommandBuffer> commandBuffer)
4847
{
4948
_commandBuffer = commandBuffer;
5049
commandBuffer->state = this;
50+
#if 0
5151
reset();
52+
#else
53+
dirtyStateStacks();
54+
#endif
5255
}
5356

5457
void State::pushView(ref_ptr<StateCommand> command)
@@ -74,3 +77,28 @@ void State::popView(const View& view)
7477
//info("State::popView(View&, ", &view, ")");
7578
if ((viewportStateHint & DYNAMIC_VIEWPORTSTATE) && view.camera && view.camera->viewportState) popView(view.camera->viewportState);
7679
}
80+
81+
void State::inherit(State& state)
82+
{
83+
dirty = true;
84+
85+
_frustumUnit = state._frustumUnit;
86+
_frustumProjected = state._frustumProjected;
87+
88+
_frustumStack = state._frustumStack;
89+
90+
inheritViewForLODScaling = state.inheritViewForLODScaling;
91+
inheritedProjectionMatrix = state.inheritedProjectionMatrix;
92+
inheritedViewMatrix = state.inheritedViewMatrix;
93+
inheritedViewTransform = state.inheritedViewTransform;
94+
95+
maxSlots = state.maxSlots;
96+
activeMaxStateSlot = state.activeMaxStateSlot;
97+
98+
stateStacks = state.stateStacks;
99+
100+
viewportStateHint = state.viewportStateHint;
101+
102+
projectionMatrixStack = state.projectionMatrixStack;
103+
modelviewMatrixStack = state.modelviewMatrixStack;
104+
}

0 commit comments

Comments
 (0)