Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Clark Lin
hw3d
Commits
0c2a85c3
Commit
0c2a85c3
authored
Mar 03, 2019
by
chili
Browse files
imgui flow improvement
parent
2e168856
Changes
4
Hide whitespace changes
Inline
Side-by-side
hw3d/App.cpp
View file @
0c2a85c3
...
@@ -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.07
f
,
0.0
f
,
0.12
f
);
if
(
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
)
{
wnd
.
Gfx
().
DisableImgui
();
}
else
{
wnd
.
Gfx
().
EnableImgui
();
}
wnd
.
Gfx
().
BeginFrame
(
0.07
f
,
0.0
f
,
0.12
f
);
for
(
auto
&
d
:
drawables
)
for
(
auto
&
d
:
drawables
)
{
{
d
->
Update
(
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
?
0.0
f
:
dt
);
d
->
Update
(
wnd
.
kbd
.
KeyIsPressed
(
VK_SPACE
)
?
0.0
f
:
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
();
...
...
hw3d/App.h
View file @
0c2a85c3
...
@@ -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
hw3d/Graphics.cpp
View file @
0c2a85c3
...
@@ -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.0
f
};
const
float
color
[]
=
{
red
,
green
,
blue
,
1.0
f
};
pContext
->
ClearRenderTargetView
(
pTarget
.
Get
(),
color
);
pContext
->
ClearRenderTargetView
(
pTarget
.
Get
(),
color
);
pContext
->
ClearDepthStencilView
(
pDSV
.
Get
(),
D3D11_CLEAR_DEPTH
,
1.0
f
,
0u
);
pContext
->
ClearDepthStencilView
(
pDSV
.
Get
(),
D3D11_CLEAR_DEPTH
,
1.0
f
,
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
...
...
hw3d/Graphics.h
View file @
0c2a85c3
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment