Skip to content

Commit 10d0f49

Browse files
committed
Added State::InhertanceMask.
1 parent 83e9d95 commit 10d0f49

4 files changed

Lines changed: 44 additions & 22 deletions

File tree

include/vsg/app/CommandGraph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace vsg
4141
int presentFamily = -1;
4242
int submitOrder = 0;
4343
Slots maxSlots;
44+
State::InheritanceMask stateInheritanceMask = State::INHERIT_ALL;
4445

4546
ref_ptr<RecordTraversal> getOrCreateRecordTraversal();
4647

include/vsg/vk/State.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,16 @@ namespace vsg
286286

287287
void reset();
288288

289-
void inherit(State& state);
289+
enum InheritanceMask
290+
{
291+
INHERIT_STATE = (1<<0),
292+
INHERIT_VIEWPORT_STATE_HINT = (1<<1),
293+
INHERIT_VIEWPOINT = (1<<2),
294+
INHERIT_MATRICES = (1<<4)
295+
INHERIT_ALL = INHERIT_STATE | INHERIT_VIEWPORT_STATE_HINT | INHERIT_VIEWPOINT | INHERIT_MATRICES;
296+
};
297+
298+
void inherit(State& state, InheritanceMask inheritanceMask = INHERIT_ALL);
290299

291300
inline void dirtyStateStacks()
292301
{

src/vsg/app/RecordTraversal.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,15 +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
676-
if (_viewDependentState && _viewDependentState->view && _viewDependentState->view->camera)
673+
674+
cg->getOrCreateRecordTraversal()->_state->inherit(*_state, cg->stateInheritanceMask);
675+
676+
if (_viewDependentState && _viewDependentState->view && (_viewDependentState->view->features & INHERIT_VIEWPOINT)!=0))
677677
{
678678
auto camera = _viewDependentState->view->camera;
679-
cg->getOrCreateRecordTraversal()->_state->setInhertiedViewProjectionAndViewMatrix(camera->projectionMatrix->transform(), camera->viewMatrix->transform());
679+
if(camera) cg->getOrCreateRecordTraversal()->_state->setInhertiedViewProjectionAndViewMatrix(camera->projectionMatrix->transform(), camera->viewMatrix->transform());
680680
}
681-
#endif
681+
682682

683683
cg->record(recordedCommandBuffers, _frameStamp, _databasePager);
684684
}

src/vsg/vk/State.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,37 @@ void State::popView(const View& view)
8080

8181
void State::inherit(State& state)
8282
{
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;
83+
reset();
9484

85+
dirty = true;
9586
maxSlots = state.maxSlots;
9687
activeMaxStateSlot = state.activeMaxStateSlot;
9788

98-
stateStacks = state.stateStacks;
89+
if ((inheritMask & INHERIT_VIEWPOINT) !=0)
90+
{
91+
inheritViewForLODScaling = state.inheritViewForLODScaling;
92+
inheritedProjectionMatrix = state.inheritedProjectionMatrix;
93+
inheritedViewMatrix = state.inheritedViewMatrix;
94+
inheritedViewTransform = state.inheritedViewTransform;
95+
}
96+
97+
if ((inheritMask & INHERIT_STATE)!=0)
98+
{
99+
stateStacks = state.stateStacks;
100+
}
101+
102+
if ((inheritMask & INHERIT_VIEWPORT_STATE_HINT)!=0)
103+
{
104+
viewportStateHint = state.viewportStateHint;
105+
}
99106

100-
viewportStateHint = state.viewportStateHint;
107+
if ((inheritMask & INHERIT_MATRICES)!=0)
108+
{
109+
projectionMatrixStack = state.projectionMatrixStack;
110+
modelviewMatrixStack = state.modelviewMatrixStack;
101111

102-
projectionMatrixStack = state.projectionMatrixStack;
103-
modelviewMatrixStack = state.modelviewMatrixStack;
112+
_frustumUnit = state._frustumUnit;
113+
_frustumProjected = state._frustumProjected;
114+
_frustumStack = state._frustumStack;
115+
}
104116
}

0 commit comments

Comments
 (0)