Commit 831380f6 authored by chili's avatar chili
Browse files

graphics twerking, doing a thing

parent 73eda06a
...@@ -21,5 +21,5 @@ int App::Go() ...@@ -21,5 +21,5 @@ int App::Go()
void App::DoFrame() void App::DoFrame()
{ {
wnd.Gfx().EndFrame();
} }
\ No newline at end of file
#include "Graphics.h"
#pragma comment(lib,"d3d11.lib")
Graphics::Graphics( HWND hWnd )
{
DXGI_SWAP_CHAIN_DESC sd = {};
sd.BufferDesc.Width = 0;
sd.BufferDesc.Height = 0;
sd.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 0;
sd.BufferDesc.RefreshRate.Denominator = 0;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
sd.OutputWindow = hWnd;
sd.Windowed = TRUE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = 0;
// create device and front/back buffers, and swap chain and rendering context
D3D11CreateDeviceAndSwapChain(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
&sd,
&pSwap,
&pDevice,
nullptr,
&pContext
);
}
Graphics::~Graphics()
{
if( pContext != nullptr )
{
pContext->Release();
}
if( pSwap != nullptr )
{
pSwap->Release();
}
if( pDevice != nullptr )
{
pDevice->Release();
}
}
void Graphics::EndFrame()
{
pSwap->Present( 1u,0u );
}
#pragma once
#include "ChiliWin.h"
#include <d3d11.h>
class Graphics
{
public:
Graphics( HWND hWnd );
Graphics( const Graphics& ) = delete;
Graphics& operator=( const Graphics& ) = delete;
~Graphics();
void EndFrame();
private:
ID3D11Device* pDevice = nullptr;
IDXGISwapChain* pSwap = nullptr;
ID3D11DeviceContext* pContext = nullptr;
};
\ No newline at end of file
...@@ -95,8 +95,10 @@ Window::Window( int width,int height,const char* name ) ...@@ -95,8 +95,10 @@ Window::Window( int width,int height,const char* name )
{ {
throw CHWND_LAST_EXCEPT(); throw CHWND_LAST_EXCEPT();
} }
// show window // newly created windows start off as hidden
ShowWindow( hWnd,SW_SHOWDEFAULT ); ShowWindow( hWnd,SW_SHOWDEFAULT );
// create graphics object
pGfx = std::make_unique<Graphics>( hWnd );
} }
Window::~Window() Window::~Window()
...@@ -134,6 +136,11 @@ std::optional<int> Window::ProcessMessages() ...@@ -134,6 +136,11 @@ std::optional<int> Window::ProcessMessages()
return {}; return {};
} }
Graphics& Window::Gfx()
{
return *pGfx;
}
LRESULT CALLBACK Window::HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept LRESULT CALLBACK Window::HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept
{ {
// use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side // use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side
......
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
#include "ChiliException.h" #include "ChiliException.h"
#include "Keyboard.h" #include "Keyboard.h"
#include "Mouse.h" #include "Mouse.h"
#include "Graphics.h"
#include <optional> #include <optional>
#include <memory>
class Window class Window
...@@ -63,6 +65,7 @@ public: ...@@ -63,6 +65,7 @@ public:
Window& operator=( const Window& ) = delete; Window& operator=( const Window& ) = delete;
void SetTitle( const std::string& title ); void SetTitle( const std::string& title );
static std::optional<int> ProcessMessages(); static std::optional<int> ProcessMessages();
Graphics& Gfx();
private: private:
static LRESULT CALLBACK HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept; static LRESULT CALLBACK HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept;
static LRESULT CALLBACK HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept; static LRESULT CALLBACK HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept;
...@@ -74,6 +77,7 @@ private: ...@@ -74,6 +77,7 @@ private:
int width; int width;
int height; int height;
HWND hWnd; HWND hWnd;
std::unique_ptr<Graphics> pGfx;
}; };
......
...@@ -148,6 +148,7 @@ ...@@ -148,6 +148,7 @@
<ClCompile Include="App.cpp" /> <ClCompile Include="App.cpp" />
<ClCompile Include="ChiliException.cpp" /> <ClCompile Include="ChiliException.cpp" />
<ClCompile Include="ChiliTimer.cpp" /> <ClCompile Include="ChiliTimer.cpp" />
<ClCompile Include="Graphics.cpp" />
<ClCompile Include="Keyboard.cpp" /> <ClCompile Include="Keyboard.cpp" />
<ClCompile Include="Mouse.cpp" /> <ClCompile Include="Mouse.cpp" />
<ClCompile Include="Window.cpp" /> <ClCompile Include="Window.cpp" />
...@@ -159,6 +160,7 @@ ...@@ -159,6 +160,7 @@
<ClInclude Include="ChiliException.h" /> <ClInclude Include="ChiliException.h" />
<ClInclude Include="ChiliTimer.h" /> <ClInclude Include="ChiliTimer.h" />
<ClInclude Include="ChiliWin.h" /> <ClInclude Include="ChiliWin.h" />
<ClInclude Include="Graphics.h" />
<ClInclude Include="Keyboard.h" /> <ClInclude Include="Keyboard.h" />
<ClInclude Include="Mouse.h" /> <ClInclude Include="Mouse.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
......
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
<ClCompile Include="ChiliTimer.cpp"> <ClCompile Include="ChiliTimer.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Graphics.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="WindowsMessageMap.h"> <ClInclude Include="WindowsMessageMap.h">
...@@ -68,6 +71,9 @@ ...@@ -68,6 +71,9 @@
<ClInclude Include="ChiliTimer.h"> <ClInclude Include="ChiliTimer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Graphics.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="hw3d.rc"> <ResourceCompile Include="hw3d.rc">
......
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