Commit d5ba4169 authored by chili's avatar chili
Browse files

wrl comptr ftw

parent d9d02261
...@@ -30,15 +30,7 @@ DxgiInfoManager::DxgiInfoManager() ...@@ -30,15 +30,7 @@ DxgiInfoManager::DxgiInfoManager()
} }
HRESULT hr; HRESULT hr;
GFX_THROW_NOINFO( DxgiGetDebugInterface( __uuidof(IDXGIInfoQueue),reinterpret_cast<void**>(&pDxgiInfoQueue) ) ); GFX_THROW_NOINFO( DxgiGetDebugInterface( __uuidof(IDXGIInfoQueue),&pDxgiInfoQueue ) );
}
DxgiInfoManager::~DxgiInfoManager()
{
if( pDxgiInfoQueue != nullptr )
{
pDxgiInfoQueue->Release();
}
} }
void DxgiInfoManager::Set() noexcept void DxgiInfoManager::Set() noexcept
......
#pragma once #pragma once
#include "ChiliWin.h" #include "ChiliWin.h"
#include <wrl.h>
#include <vector> #include <vector>
#include <dxgidebug.h>
class DxgiInfoManager class DxgiInfoManager
{ {
public: public:
DxgiInfoManager(); DxgiInfoManager();
~DxgiInfoManager(); ~DxgiInfoManager() = default;
DxgiInfoManager( const DxgiInfoManager& ) = delete; DxgiInfoManager( const DxgiInfoManager& ) = delete;
DxgiInfoManager& operator=( const DxgiInfoManager& ) = delete; DxgiInfoManager& operator=( const DxgiInfoManager& ) = delete;
void Set() noexcept; void Set() noexcept;
std::vector<std::string> GetMessages() const; std::vector<std::string> GetMessages() const;
private: private:
unsigned long long next = 0u; unsigned long long next = 0u;
struct IDXGIInfoQueue* pDxgiInfoQueue = nullptr; Microsoft::WRL::ComPtr<IDXGIInfoQueue> pDxgiInfoQueue;
}; };
\ No newline at end of file
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include "dxerr.h" #include "dxerr.h"
#include <sstream> #include <sstream>
namespace wrl = Microsoft::WRL;
#pragma comment(lib,"d3d11.lib") #pragma comment(lib,"d3d11.lib")
// graphics exception checking/throwing macros (some with dxgi infos) // graphics exception checking/throwing macros (some with dxgi infos)
...@@ -62,30 +64,9 @@ Graphics::Graphics( HWND hWnd ) ...@@ -62,30 +64,9 @@ Graphics::Graphics( HWND hWnd )
&pContext &pContext
) ); ) );
// gain access to texture subresource in swap chain (back buffer) // gain access to texture subresource in swap chain (back buffer)
ID3D11Resource* pBackBuffer = nullptr; wrl::ComPtr<ID3D11Resource> pBackBuffer;
GFX_THROW_INFO( pSwap->GetBuffer( 0,__uuidof(ID3D11Resource),reinterpret_cast<void**>(&pBackBuffer) ) ); GFX_THROW_INFO( pSwap->GetBuffer( 0,__uuidof(ID3D11Resource),&pBackBuffer ) );
GFX_THROW_INFO( pDevice->CreateRenderTargetView( pBackBuffer,nullptr,&pTarget ) ); GFX_THROW_INFO( pDevice->CreateRenderTargetView( pBackBuffer.Get(),nullptr,&pTarget ) );
pBackBuffer->Release();
}
Graphics::~Graphics()
{
if( pTarget != nullptr )
{
pTarget->Release();
}
if( pContext != nullptr )
{
pContext->Release();
}
if( pSwap != nullptr )
{
pSwap->Release();
}
if( pDevice != nullptr )
{
pDevice->Release();
}
} }
void Graphics::EndFrame() void Graphics::EndFrame()
...@@ -110,7 +91,7 @@ void Graphics::EndFrame() ...@@ -110,7 +91,7 @@ void Graphics::EndFrame()
void Graphics::ClearBuffer( float red,float green,float blue ) noexcept void Graphics::ClearBuffer( float red,float green,float blue ) noexcept
{ {
const float color[] = { red,green,blue,1.0f }; const float color[] = { red,green,blue,1.0f };
pContext->ClearRenderTargetView( pTarget,color ); pContext->ClearRenderTargetView( pTarget.Get(),color );
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "ChiliWin.h" #include "ChiliWin.h"
#include "ChiliException.h" #include "ChiliException.h"
#include <d3d11.h> #include <d3d11.h>
#include <wrl.h>
#include <vector> #include <vector>
#include "DxgiInfoManager.h" #include "DxgiInfoManager.h"
...@@ -38,15 +39,15 @@ public: ...@@ -38,15 +39,15 @@ public:
Graphics( HWND hWnd ); Graphics( HWND hWnd );
Graphics( const Graphics& ) = delete; Graphics( const Graphics& ) = delete;
Graphics& operator=( const Graphics& ) = delete; Graphics& operator=( const Graphics& ) = delete;
~Graphics(); ~Graphics() = default;
void EndFrame(); void EndFrame();
void ClearBuffer( float red,float green,float blue ) noexcept; void ClearBuffer( float red,float green,float blue ) noexcept;
private: private:
#ifndef NDEBUG #ifndef NDEBUG
DxgiInfoManager infoManager; DxgiInfoManager infoManager;
#endif #endif
ID3D11Device* pDevice = nullptr; Microsoft::WRL::ComPtr<ID3D11Device> pDevice;
IDXGISwapChain* pSwap = nullptr; Microsoft::WRL::ComPtr<IDXGISwapChain> pSwap;
ID3D11DeviceContext* pContext = nullptr; Microsoft::WRL::ComPtr<ID3D11DeviceContext> pContext;
ID3D11RenderTargetView* pTarget = nullptr; Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pTarget;
}; };
\ No newline at end of file
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<VCProjectVersion>15.0</VCProjectVersion> <VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{63E56790-0977-47CC-B52B-B1BF8746AFD4}</ProjectGuid> <ProjectGuid>{63E56790-0977-47CC-B52B-B1BF8746AFD4}</ProjectGuid>
<RootNamespace>hw3d</RootNamespace> <RootNamespace>hw3d</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
......
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