Last active
February 3, 2017 03:46
-
-
Save sdcb/7bd010bdf7165eedcc1597edaee5e39e to your computer and use it in GitHub Desktop.
dxtk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DeviceResources.h - A wrapper for the Direct3D 11 device and swapchain | |
// | |
#pragma once | |
namespace DX | |
{ | |
// Provides an interface for an application that owns DeviceResources to be notified of the device being lost or created. | |
interface IDeviceNotify | |
{ | |
virtual void OnDeviceLost() = 0; | |
virtual void OnDeviceRestored() = 0; | |
}; | |
// Controls all the DirectX device resources. | |
class DeviceResources | |
{ | |
public: | |
DeviceResources(DXGI_FORMAT backBufferFormat = DXGI_FORMAT_B8G8R8A8_UNORM, | |
DXGI_FORMAT depthBufferFormat = DXGI_FORMAT_D24_UNORM_S8_UINT, | |
UINT backBufferCount = 2, | |
D3D_FEATURE_LEVEL minFeatureLevel = D3D_FEATURE_LEVEL_9_1); | |
void CreateDeviceResources(); | |
void CreateWindowSizeDependentResources(); | |
void SetWindow(HWND window, int width, int height); | |
bool WindowSizeChanged(int width, int height); | |
void HandleDeviceLost(); | |
void RegisterDeviceNotify(IDeviceNotify* deviceNotify) { m_deviceNotify = deviceNotify; } | |
void Present(); | |
// Device Accessors. | |
RECT GetOutputSize() const { return m_outputSize; } | |
// Direct3D Accessors. | |
ID3D11Device* GetD3DDevice() const { return m_d3dDevice.Get(); } | |
ID3D11Device1* GetD3DDevice1() const { return m_d3dDevice1.Get(); } | |
ID3D11DeviceContext* GetD3DDeviceContext() const { return m_d3dContext.Get(); } | |
ID3D11DeviceContext1* GetD3DDeviceContext1() const { return m_d3dContext1.Get(); } | |
IDXGISwapChain* GetSwapChain() const { return m_swapChain.Get(); } | |
IDXGISwapChain1* GetSwapChain1() const { return m_swapChain1.Get(); } | |
D3D_FEATURE_LEVEL GetDeviceFeatureLevel() const { return m_d3dFeatureLevel; } | |
ID3D11Texture2D* GetRenderTarget() const { return m_renderTarget.Get(); } | |
ID3D11Texture2D* GetDepthStencil() const { return m_depthStencil.Get(); } | |
ID3D11RenderTargetView* GetRenderTargetView() const { return m_d3dRenderTargetView.Get(); } | |
ID3D11DepthStencilView* GetDepthStencilView() const { return m_d3dDepthStencilView.Get(); } | |
DXGI_FORMAT GetBackBufferFormat() const { return m_backBufferFormat; } | |
DXGI_FORMAT GetDepthBufferFormat() const { return m_depthBufferFormat; } | |
D3D11_VIEWPORT GetScreenViewport() const { return m_screenViewport; } | |
UINT GetBackBufferCount() const { return m_backBufferCount; } | |
KennyKerr::Direct2D::DeviceContext GetD2DDeviceContext() const { return m_deviceContext; } | |
KennyKerr::Direct2D::Factory2 GetD2DFactory() const { return m_d2dFactory; } | |
KennyKerr::DirectWrite::Factory1 GetDWriteFactory() const { return m_dwriteFactory; } | |
KennyKerr::Wic::Factory GetWicFactory() const { return m_wicFactory; } | |
// Performance events | |
void PIXBeginEvent(_In_z_ const wchar_t* name) | |
{ | |
if (m_d3dAnnotation) | |
{ | |
m_d3dAnnotation->BeginEvent(name); | |
} | |
} | |
void PIXEndEvent() | |
{ | |
if (m_d3dAnnotation) | |
{ | |
m_d3dAnnotation->EndEvent(); | |
} | |
} | |
void PIXSetMarker(_In_z_ const wchar_t* name) | |
{ | |
if (m_d3dAnnotation) | |
{ | |
m_d3dAnnotation->SetMarker(name); | |
} | |
} | |
private: | |
void GetHardwareAdapter(IDXGIAdapter1** ppAdapter); | |
// Direct3D objects. | |
Microsoft::WRL::ComPtr<ID3D11Device> m_d3dDevice; | |
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice1; | |
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_d3dContext; | |
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext1; | |
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swapChain; | |
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain1; | |
Microsoft::WRL::ComPtr<ID3DUserDefinedAnnotation> m_d3dAnnotation; | |
KennyKerr::Direct2D::DeviceContext m_deviceContext; | |
KennyKerr::Direct2D::Factory2 m_d2dFactory; | |
KennyKerr::DirectWrite::Factory1 m_dwriteFactory; | |
KennyKerr::Wic::Factory m_wicFactory; | |
// Direct3D rendering objects. Required for 3D. | |
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_renderTarget; | |
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_depthStencil; | |
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_d3dRenderTargetView; | |
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_d3dDepthStencilView; | |
D3D11_VIEWPORT m_screenViewport; | |
// Direct3D properties. | |
DXGI_FORMAT m_backBufferFormat; | |
DXGI_FORMAT m_depthBufferFormat; | |
UINT m_backBufferCount; | |
D3D_FEATURE_LEVEL m_d3dMinFeatureLevel; | |
// Cached device properties. | |
HWND m_window; | |
D3D_FEATURE_LEVEL m_d3dFeatureLevel; | |
RECT m_outputSize; | |
// The IDeviceNotify can be held directly as it owns the DeviceResources. | |
IDeviceNotify* m_deviceNotify; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DirectXTK/Audio.h> | |
#include <DirectXTK/CommonStates.h> | |
#include <DirectXTK/DDSTextureLoader.h> | |
#include <DirectXTK/DirectXHelpers.h> | |
#include <DirectXTK/Effects.h> | |
#include <DirectXTK/GamePad.h> | |
#include <DirectXTK/GeometricPrimitive.h> | |
#include <DirectXTK/GraphicsMemory.h> | |
#include <DirectXTK/Keyboard.h> | |
#include <DirectXTK/Model.h> | |
#include <DirectXTK/Mouse.h> | |
#include <DirectXTK/PrimitiveBatch.h> | |
#include <DirectXTK/ScreenGrab.h> | |
#include <DirectXTK/SimpleMath.h> | |
#include <DirectXTK/SpriteBatch.h> | |
#include <DirectXTK/SpriteFont.h> | |
#include <DirectXTK/VertexTypes.h> | |
#include <DirectXTK/WICTextureLoader.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DirectXTK12/Audio.h" | |
#include "DirectXTK12/CommonStates.h" | |
#include "DirectXTK12/DDSTextureLoader.h" | |
#include "DirectXTK12/DescriptorHeap.h" | |
#include "DirectXTK12/DirectXHelpers.h" | |
#include "DirectXTK12/Effects.h" | |
#include "DirectXTK12/GamePad.h" | |
#include "DirectXTK12/GeometricPrimitive.h" | |
#include "DirectXTK12/GraphicsMemory.h" | |
#include "DirectXTK12/Keyboard.h" | |
#include "DirectXTK12/Model.h" | |
#include "DirectXTK12/Mouse.h" | |
#include "DirectXTK12/PrimitiveBatch.h" | |
#include "DirectXTK12/RenderTargetState.h" | |
#include "DirectXTK12/ResourceUploadBatch.h" | |
#include "DirectXTK12/ScreenGrab.h" | |
#include "DirectXTK12/SimpleMath.h" | |
#include "DirectXTK12/SpriteBatch.h" | |
#include "DirectXTK12/SpriteFont.h" | |
#include "DirectXTK12/VertexTypes.h" | |
#include "DirectXTK12/WICTextureLoader.h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment