Minor - Vsync toggle
New Method : + Set Vsync + Set Screen Width + Set Screen Height + Get Hwnd + Set Hwnd + IsWindowed + SetWindowed New UI For Engine Settings : + Add Vsync Toggle to UI
This commit is contained in:
parent
79f266b479
commit
bce659e55d
@ -257,6 +257,8 @@ LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam
|
|||||||
// If Direct3D is initialized, update the swap chain. Otherwise, store the window dimensions
|
// If Direct3D is initialized, update the swap chain. Otherwise, store the window dimensions
|
||||||
if (m_isDirect3DInitialized && m_Application && m_Application->GetDirect3D())
|
if (m_isDirect3DInitialized && m_Application && m_Application->GetDirect3D())
|
||||||
{
|
{
|
||||||
|
m_Application->SetScreenWidth(newWidth);
|
||||||
|
m_Application->SetScreenHeight(newHeight);
|
||||||
m_Application->GetDirect3D()->ResizeSwapChain(newWidth, newHeight);
|
m_Application->GetDirect3D()->ResizeSwapChain(newWidth, newHeight);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -56,6 +56,11 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
m_screenWidth = screenWidth;
|
m_screenWidth = screenWidth;
|
||||||
m_screenHeight = screenHeight;
|
m_screenHeight = screenHeight;
|
||||||
|
|
||||||
|
SetHwnd(hwnd);
|
||||||
|
SetWindowed(FULL_SCREEN);
|
||||||
|
SetScreenHeight(screenHeight);
|
||||||
|
SetScreenWidth(screenWidth);
|
||||||
|
|
||||||
// Create the Direct3D object.
|
// Create the Direct3D object.
|
||||||
m_Direct3D = new D3DClass;
|
m_Direct3D = new D3DClass;
|
||||||
if (!m_Direct3D)
|
if (!m_Direct3D)
|
||||||
@ -1975,3 +1980,50 @@ void ApplicationClass::SetLightPosition(int index, XMVECTOR position)
|
|||||||
//set the position
|
//set the position
|
||||||
m_Lights[index]->SetPosition(lightPosition.x, lightPosition.y, lightPosition.z);
|
m_Lights[index]->SetPosition(lightPosition.x, lightPosition.y, lightPosition.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::SetVsync(bool vsync)
|
||||||
|
{
|
||||||
|
VSYNC_ENABLED = vsync;
|
||||||
|
|
||||||
|
if (m_Direct3D)
|
||||||
|
{
|
||||||
|
Logger::Get().Log("Setting Vsync to " + std::to_string(vsync) + " with a screen width : " + std::to_string(GetScreenWidth()) + "and a screen height : " + std::to_string(GetScreenHeight()), __FILE__, __LINE__);
|
||||||
|
m_Direct3D->SetVsync(vsync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HWND ApplicationClass::GetHwnd() const
|
||||||
|
{
|
||||||
|
return m_hwnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::SetHwnd(HWND hwnd)
|
||||||
|
{
|
||||||
|
m_hwnd = hwnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ApplicationClass::IsWindowed() const
|
||||||
|
{
|
||||||
|
return m_windowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::SetWindowed(bool windowed)
|
||||||
|
{
|
||||||
|
// log the new windowed mode
|
||||||
|
Logger::Get().Log("Setting windowed mode to " + std::to_string(windowed), __FILE__, __LINE__);
|
||||||
|
m_windowed = windowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::SetScreenHeight(int height)
|
||||||
|
{
|
||||||
|
// log the new screen height
|
||||||
|
Logger::Get().Log("Setting screen height to " + std::to_string(height), __FILE__, __LINE__);
|
||||||
|
m_screenHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationClass::SetScreenWidth(int width)
|
||||||
|
{
|
||||||
|
// log the new screen width
|
||||||
|
Logger::Get().Log("Setting screen width to " + std::to_string(width), __FILE__, __LINE__);
|
||||||
|
m_screenWidth = width;
|
||||||
|
}
|
@ -38,7 +38,6 @@
|
|||||||
// GLOBALS //
|
// GLOBALS //
|
||||||
/////////////
|
/////////////
|
||||||
const bool FULL_SCREEN = false;
|
const bool FULL_SCREEN = false;
|
||||||
const bool VSYNC_ENABLED = false;
|
|
||||||
const float SCREEN_DEPTH = 1000.0f;
|
const float SCREEN_DEPTH = 1000.0f;
|
||||||
const float SCREEN_NEAR = 0.3f;
|
const float SCREEN_NEAR = 0.3f;
|
||||||
|
|
||||||
@ -59,7 +58,9 @@ public:
|
|||||||
bool Frame(InputClass*);
|
bool Frame(InputClass*);
|
||||||
|
|
||||||
int GetScreenWidth() const;
|
int GetScreenWidth() const;
|
||||||
|
void SetScreenWidth(int screenWidth);
|
||||||
int GetScreenHeight() const;
|
int GetScreenHeight() const;
|
||||||
|
void SetScreenHeight(int screenHeight);
|
||||||
|
|
||||||
float GetSpeed() const { return m_speed; };
|
float GetSpeed() const { return m_speed; };
|
||||||
void SetSpeed(float speed) { this->m_speed = speed; };
|
void SetSpeed(float speed) { this->m_speed = speed; };
|
||||||
@ -92,6 +93,15 @@ public:
|
|||||||
|
|
||||||
std::vector<ID3D11ShaderResourceView*> textures;
|
std::vector<ID3D11ShaderResourceView*> textures;
|
||||||
|
|
||||||
|
void SetVsync(bool vsync);
|
||||||
|
bool GetVsync() const { return VSYNC_ENABLED; };
|
||||||
|
|
||||||
|
HWND GetHwnd() const;
|
||||||
|
void SetHwnd(HWND hwnd);
|
||||||
|
|
||||||
|
bool IsWindowed() const;
|
||||||
|
void SetWindowed(bool windowed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Render(float, float, float, float, float);
|
bool Render(float, float, float, float, float);
|
||||||
bool UpdateMouseStrings(int, int, bool);
|
bool UpdateMouseStrings(int, int, bool);
|
||||||
@ -111,6 +121,10 @@ private :
|
|||||||
IDXGISwapChain* m_swapChain;
|
IDXGISwapChain* m_swapChain;
|
||||||
ModelClass* m_Model,* m_GroundModel, * m_WallModel, * m_BathModel, * m_WaterModel;
|
ModelClass* m_Model,* m_GroundModel, * m_WallModel, * m_BathModel, * m_WaterModel;
|
||||||
ModelListClass* m_ModelList;
|
ModelListClass* m_ModelList;
|
||||||
|
bool VSYNC_ENABLED = true;
|
||||||
|
|
||||||
|
HWND m_hwnd;
|
||||||
|
bool m_windowed;
|
||||||
|
|
||||||
// ------------------------------------- //
|
// ------------------------------------- //
|
||||||
// ------------- RENDERING ------------- //
|
// ------------- RENDERING ------------- //
|
||||||
|
@ -695,7 +695,8 @@ IDXGISwapChain* D3DClass::GetSwapChain()
|
|||||||
void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
void D3DClass::ResizeSwapChain(int newWidth, int newHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
Logger::Get().Log("Resizing swap chain", __FILE__, __LINE__);
|
// log the new width and height
|
||||||
|
Logger::Get().Log("Resizing swap chain to " + std::to_string(newWidth) + "x" + std::to_string(newHeight), __FILE__, __LINE__);
|
||||||
|
|
||||||
HRESULT result;
|
HRESULT result;
|
||||||
|
|
||||||
@ -766,3 +767,8 @@ void D3DClass::DisableAlphaBlending()
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void D3DClass::SetVsync(bool vsync)
|
||||||
|
{
|
||||||
|
m_vsync_enabled = vsync;
|
||||||
|
}
|
@ -46,6 +46,8 @@ public:
|
|||||||
IDXGISwapChain* m_swapChain;
|
IDXGISwapChain* m_swapChain;
|
||||||
IDXGISwapChain* GetSwapChain();
|
IDXGISwapChain* GetSwapChain();
|
||||||
void ResizeSwapChain(int, int);
|
void ResizeSwapChain(int, int);
|
||||||
|
void SetVsync(bool vsync);
|
||||||
|
|
||||||
|
|
||||||
XMMATRIX GetProjectionMatrix() const { return m_projectionMatrix; };
|
XMMATRIX GetProjectionMatrix() const { return m_projectionMatrix; };
|
||||||
XMMATRIX GetWorldMatrix() const { return m_worldMatrix;};
|
XMMATRIX GetWorldMatrix() const { return m_worldMatrix;};
|
||||||
|
@ -3,7 +3,7 @@ Pos=60,60
|
|||||||
Size=400,400
|
Size=400,400
|
||||||
|
|
||||||
[Window][Khaotic Engine]
|
[Window][Khaotic Engine]
|
||||||
Pos=1113,54
|
Pos=1143,44
|
||||||
Size=392,273
|
Size=392,273
|
||||||
|
|
||||||
[Window][Objects]
|
[Window][Objects]
|
||||||
@ -20,6 +20,10 @@ Pos=1548,17
|
|||||||
Size=358,535
|
Size=358,535
|
||||||
|
|
||||||
[Window][Shader Manager]
|
[Window][Shader Manager]
|
||||||
Pos=28,261
|
Pos=471,90
|
||||||
Size=172,284
|
Size=180,79
|
||||||
|
|
||||||
|
[Window][Engine Settings]
|
||||||
|
Pos=561,352
|
||||||
|
Size=168,77
|
||||||
|
|
||||||
|
@ -318,6 +318,11 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
|
|||||||
showShaderWindow = true;
|
showShaderWindow = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button("Open Engine Settings Window"))
|
||||||
|
{
|
||||||
|
showEngineSettingsWindow = true;
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
// Show windows if their corresponding variables are true
|
// Show windows if their corresponding variables are true
|
||||||
@ -341,6 +346,11 @@ bool imguiManager::ImGuiWidgetRenderer(ApplicationClass* app)
|
|||||||
WidgetShaderWindow(app);
|
WidgetShaderWindow(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showEngineSettingsWindow)
|
||||||
|
{
|
||||||
|
WidgetEngineSettingsWindow(app);
|
||||||
|
}
|
||||||
|
|
||||||
//render imgui
|
//render imgui
|
||||||
Render();
|
Render();
|
||||||
|
|
||||||
@ -381,3 +391,17 @@ void imguiManager::WidgetLightWindow(ApplicationClass* app)
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void imguiManager::WidgetEngineSettingsWindow(ApplicationClass* app)
|
||||||
|
{
|
||||||
|
ImGui::Begin("Engine Settings", &showEngineSettingsWindow);
|
||||||
|
|
||||||
|
// Checkbox for toggling vsync globally in the application class by calling the SetVsync function in the application class when the checkbox state changes
|
||||||
|
bool vsync = app->GetVsync();
|
||||||
|
if (ImGui::Checkbox("Vsync", &vsync))
|
||||||
|
{
|
||||||
|
app->SetVsync(vsync);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
@ -32,6 +32,7 @@ public:
|
|||||||
void WidgetTerrainWindow(ApplicationClass* app);
|
void WidgetTerrainWindow(ApplicationClass* app);
|
||||||
void WidgetLightWindow(ApplicationClass* app);
|
void WidgetLightWindow(ApplicationClass* app);
|
||||||
void WidgetShaderWindow(ApplicationClass* app);
|
void WidgetShaderWindow(ApplicationClass* app);
|
||||||
|
void WidgetEngineSettingsWindow(ApplicationClass* app);
|
||||||
|
|
||||||
bool ImGuiWidgetRenderer(ApplicationClass* app);
|
bool ImGuiWidgetRenderer(ApplicationClass* app);
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ private :
|
|||||||
bool showTerrainWindow = false;
|
bool showTerrainWindow = false;
|
||||||
bool showLightWindow = false;
|
bool showLightWindow = false;
|
||||||
bool showShaderWindow = false;
|
bool showShaderWindow = false;
|
||||||
|
bool showEngineSettingsWindow = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImGuiIO* io;
|
ImGuiIO* io;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user