Commit 0c2a85c3 authored by chili's avatar chili
Browse files

imgui flow improvement

parent 2e168856
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
#include "Surface.h" #include "Surface.h"
#include "GDIPlusManager.h" #include "GDIPlusManager.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"
#include "imgui/imgui_impl_win32.h"
#include "imgui/imgui_impl_dx11.h"
GDIPlusManager gdipm; GDIPlusManager gdipm;
...@@ -82,25 +80,27 @@ App::App() ...@@ -82,25 +80,27 @@ App::App()
void App::DoFrame() void App::DoFrame()
{ {
const auto dt = timer.Mark(); const auto dt = timer.Mark();
wnd.Gfx().ClearBuffer( 0.07f,0.0f,0.12f );
if( wnd.kbd.KeyIsPressed( VK_SPACE ) )
{
wnd.Gfx().DisableImgui();
}
else
{
wnd.Gfx().EnableImgui();
}
wnd.Gfx().BeginFrame( 0.07f,0.0f,0.12f );
for( auto& d : drawables ) for( auto& d : drawables )
{ {
d->Update( wnd.kbd.KeyIsPressed( VK_SPACE ) ? 0.0f : dt ); d->Update( wnd.kbd.KeyIsPressed( VK_SPACE ) ? 0.0f : dt );
d->Draw( wnd.Gfx() ); d->Draw( wnd.Gfx() );
} }
// imgui stuff
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
static bool show_demo_window = true;
if( show_demo_window ) if( show_demo_window )
{ {
ImGui::ShowDemoWindow( &show_demo_window ); ImGui::ShowDemoWindow( &show_demo_window );
} }
ImGui::Render();
ImGui_ImplDX11_RenderDrawData( ImGui::GetDrawData() );
// present // present
wnd.Gfx().EndFrame(); wnd.Gfx().EndFrame();
......
...@@ -17,5 +17,6 @@ private: ...@@ -17,5 +17,6 @@ private:
Window wnd; Window wnd;
ChiliTimer timer; ChiliTimer timer;
std::vector<std::unique_ptr<class Drawable>> drawables; std::vector<std::unique_ptr<class Drawable>> drawables;
bool show_demo_window = true;
static constexpr size_t nDrawables = 180; static constexpr size_t nDrawables = 180;
}; };
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <DirectXMath.h> #include <DirectXMath.h>
#include "GraphicsThrowMacros.h" #include "GraphicsThrowMacros.h"
#include "imgui/imgui_impl_dx11.h" #include "imgui/imgui_impl_dx11.h"
#include "imgui/imgui_impl_win32.h"
namespace wrl = Microsoft::WRL; namespace wrl = Microsoft::WRL;
namespace dx = DirectX; namespace dx = DirectX;
...@@ -115,6 +116,13 @@ Graphics::Graphics( HWND hWnd ) ...@@ -115,6 +116,13 @@ Graphics::Graphics( HWND hWnd )
void Graphics::EndFrame() void Graphics::EndFrame()
{ {
// imgui frame end
if( imguiEnabled )
{
ImGui::Render();
ImGui_ImplDX11_RenderDrawData( ImGui::GetDrawData() );
}
HRESULT hr; HRESULT hr;
#ifndef NDEBUG #ifndef NDEBUG
infoManager.Set(); infoManager.Set();
...@@ -132,8 +140,16 @@ void Graphics::EndFrame() ...@@ -132,8 +140,16 @@ void Graphics::EndFrame()
} }
} }
void Graphics::ClearBuffer( float red,float green,float blue ) noexcept void Graphics::BeginFrame( float red,float green,float blue ) noexcept
{ {
// imgui begin frame
if( imguiEnabled )
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
}
const float color[] = { red,green,blue,1.0f }; const float color[] = { red,green,blue,1.0f };
pContext->ClearRenderTargetView( pTarget.Get(),color ); pContext->ClearRenderTargetView( pTarget.Get(),color );
pContext->ClearDepthStencilView( pDSV.Get(),D3D11_CLEAR_DEPTH,1.0f,0u ); pContext->ClearDepthStencilView( pDSV.Get(),D3D11_CLEAR_DEPTH,1.0f,0u );
...@@ -154,6 +170,21 @@ DirectX::XMMATRIX Graphics::GetProjection() const noexcept ...@@ -154,6 +170,21 @@ DirectX::XMMATRIX Graphics::GetProjection() const noexcept
return projection; return projection;
} }
void Graphics::EnableImgui() noexcept
{
imguiEnabled = true;
}
void Graphics::DisableImgui() noexcept
{
imguiEnabled = false;
}
bool Graphics::IsImguiEnabled() const noexcept
{
return imguiEnabled;
}
// Graphics exception stuff // Graphics exception stuff
Graphics::HrException::HrException( int line,const char * file,HRESULT hr,std::vector<std::string> infoMsgs ) noexcept Graphics::HrException::HrException( int line,const char * file,HRESULT hr,std::vector<std::string> infoMsgs ) noexcept
......
...@@ -56,11 +56,15 @@ public: ...@@ -56,11 +56,15 @@ public:
Graphics& operator=( const Graphics& ) = delete; Graphics& operator=( const Graphics& ) = delete;
~Graphics() = default; ~Graphics() = default;
void EndFrame(); void EndFrame();
void ClearBuffer( float red,float green,float blue ) noexcept; void BeginFrame( float red,float green,float blue ) noexcept;
void DrawIndexed( UINT count ) noexcept(!IS_DEBUG); void DrawIndexed( UINT count ) noexcept(!IS_DEBUG);
void SetProjection( DirectX::FXMMATRIX proj ) noexcept; void SetProjection( DirectX::FXMMATRIX proj ) noexcept;
DirectX::XMMATRIX GetProjection() const noexcept; DirectX::XMMATRIX GetProjection() const noexcept;
void EnableImgui() noexcept;
void DisableImgui() noexcept;
bool IsImguiEnabled() const noexcept;
private: private:
bool imguiEnabled = true;
DirectX::XMMATRIX projection; DirectX::XMMATRIX projection;
#ifndef NDEBUG #ifndef NDEBUG
DxgiInfoManager infoManager; DxgiInfoManager infoManager;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment