Add a way to set the vsync_interval CVar from code (#5813)

* Add a way to set the render vsync from code

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>

* Update change with PR feedback. Missing whitespace plus a comment on why the assignment is outside the value changed check

Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com>
This commit is contained in:
rgba16f
2021-11-30 10:11:26 -06:00
committed by GitHub
parent 6908a3e945
commit 768a196b63
7 changed files with 30 additions and 0 deletions
@@ -32,7 +32,16 @@ namespace AZ
template <typename BASE_TYPE, ThreadSafety THREAD_SAFETY>
inline void ConsoleDataWrapper<BASE_TYPE, THREAD_SAFETY>::operator =(const BASE_TYPE& rhs)
{
const BASE_TYPE currentValue = this->m_value;
// Do the value assignment outside new value check.
// Client code can supply a type for m_value that overrides the operator= function and trigger side effects
// in the operator= function body. Doing the assignment outside the value change check avoids those side
// effects not being triggered because AzCore believes the value wouldn't change.
this->m_value = rhs;
if (currentValue != rhs)
{
InvokeCallback();
}
}
template <typename BASE_TYPE, ThreadSafety THREAD_SAFETY>
@@ -143,6 +143,13 @@ namespace AzFramework
return vsync_interval;
}
bool NativeWindow::SetSyncInterval(uint32_t newSyncInterval)
{
vsync_interval = newSyncInterval;
return true;
}
/*static*/ bool NativeWindow::GetFullScreenStateOfDefaultWindow()
{
NativeWindowHandle defaultWindowHandle = nullptr;
@@ -132,6 +132,7 @@ namespace AzFramework
void ToggleFullScreenState() override;
float GetDpiScaleFactor() const override;
uint32_t GetSyncInterval() const override;
bool SetSyncInterval(uint32_t newSyncInterval) override;
uint32_t GetDisplayRefreshRate() const override;
//! Get the full screen state of the default window.
@@ -78,6 +78,10 @@ namespace AzFramework
//! Returns the sync interval which tells the drivers the number of v-blanks to synchronize with
virtual uint32_t GetSyncInterval() const = 0;
//! Sets the sync interval which tells the drivers the number of v-blanks to synchronize with
//! Returns if the sync interval was succesfully set
virtual bool SetSyncInterval(uint32_t newSyncInterval) = 0;
//! Returns the refresh rate of the main display
virtual uint32_t GetDisplayRefreshRate() const = 0;
};
@@ -36,6 +36,7 @@ namespace UnitTest
MOCK_METHOD0(ToggleFullScreenState, void());
MOCK_CONST_METHOD0(GetDpiScaleFactor, float());
MOCK_CONST_METHOD0(GetSyncInterval, uint32_t());
MOCK_METHOD1(SetSyncInterval, bool(uint32_t));
MOCK_CONST_METHOD0(GetDisplayRefreshRate, uint32_t());
};
} // namespace UnitTest
@@ -116,6 +116,7 @@ namespace AtomToolsFramework
void ToggleFullScreenState() override;
float GetDpiScaleFactor() const override;
uint32_t GetSyncInterval() const override;
bool SetSyncInterval(uint32_t newSyncInterval) override;
uint32_t GetDisplayRefreshRate() const override;
protected:
@@ -395,4 +395,11 @@ namespace AtomToolsFramework
{
return 1;
}
// Editor ignores requests to change the sync interval
bool RenderViewportWidget::SetSyncInterval(uint32_t /*ignored*/)
{
return false;
}
} //namespace AtomToolsFramework