Commit 87608150 authored by Administrator's avatar Administrator
Browse files

use com pointer

parent f4450a4d
......@@ -30,15 +30,7 @@ DxgiInfoManager::DxgiInfoManager()
}
HRESULT hr;
GFX_THROW_NOINFO( DxgiGetDebugInterface( __uuidof(IDXGIInfoQueue),reinterpret_cast<void**>(&pDxgiInfoQueue) ) );
}
DxgiInfoManager::~DxgiInfoManager()
{
if( pDxgiInfoQueue != nullptr )
{
pDxgiInfoQueue->Release();
}
GFX_THROW_NOINFO(DxgiGetDebugInterface(__uuidof(IDXGIInfoQueue), &pDxgiInfoQueue));
}
void DxgiInfoManager::Set() noexcept
......
#pragma once
#include "ChiliWin.h"
#include <wrl.h>
#include <vector>
#include <dxgidebug.h>
#include <string>
class DxgiInfoManager
{
public:
DxgiInfoManager();
~DxgiInfoManager();
~DxgiInfoManager() = default;
DxgiInfoManager( const DxgiInfoManager& ) = delete;
DxgiInfoManager& operator=( const DxgiInfoManager& ) = delete;
void Set() noexcept;
std::vector<std::string> GetMessages() const;
private:
unsigned long long next = 0u;
struct IDXGIInfoQueue* pDxgiInfoQueue = nullptr;
Microsoft::WRL::ComPtr<IDXGIInfoQueue> pDxgiInfoQueue;
};
\ No newline at end of file
......@@ -2,6 +2,8 @@
#include "dxerr.h"
#include <sstream>
namespace wrl = Microsoft::WRL;
#pragma comment(lib,"d3d11.lib")
// graphics exception checking/throwing macros (some with dxgi infos)
......@@ -65,37 +67,9 @@ Graphics::Graphics( HWND hWnd )
// gain access to texture subresource in swap chain (back buffer)
// 定义指向backBuffer的指针
ID3D11Resource* pBackBuffer = nullptr;
// 通过SwapChian,取得backBuffer
GFX_THROW_INFO(pSwap->GetBuffer(0, __uuidof(ID3D11Resource), reinterpret_cast<void**>(&pBackBuffer)));
// 取得指向属于backBuffer的View的指针
GFX_THROW_INFO(pDevice->CreateRenderTargetView(pBackBuffer, nullptr, &pTarget));
pBackBuffer->Release();
}
Graphics::~Graphics()
{
// 释放View, Context, SwapChain和Device
if (pTarget != nullptr)
{
pTarget->Release();
}
if( pContext != nullptr )
{
pContext->Release();
}
if( pSwap != nullptr )
{
pSwap->Release();
}
if( pDevice != nullptr )
{
pDevice->Release();
}
wrl::ComPtr<ID3D11Resource> pBackBuffer;
GFX_THROW_INFO(pSwap->GetBuffer(0, __uuidof(ID3D11Resource), &pBackBuffer));
GFX_THROW_INFO(pDevice->CreateRenderTargetView(pBackBuffer.Get(), nullptr, &pTarget));
}
void Graphics::EndFrame()
......@@ -121,7 +95,7 @@ void Graphics::EndFrame()
void Graphics::ClearBuffer(float red, float green, float blue) noexcept
{
const float color[] = { red,green,blue,1.0f };
pContext->ClearRenderTargetView(pTarget, color);
pContext->ClearRenderTargetView(pTarget.Get(), color);
}
// Graphics exception stuff
......
......@@ -2,6 +2,7 @@
#include "ChiliWin.h"
#include "ChiliException.h"
#include <d3d11.h>
#include <wrl.h>
#include <vector>
#include "DxgiInfoManager.h"
......@@ -38,7 +39,7 @@ public:
Graphics( HWND hWnd );
Graphics( const Graphics& ) = delete;
Graphics& operator=( const Graphics& ) = delete;
~Graphics();
~Graphics() = default;
void EndFrame();
// 刷新RGB
void ClearBuffer(float red, float green, float blue) noexcept;
......@@ -47,11 +48,11 @@ private:
DxgiInfoManager infoManager;
#endif
// 指向Device的指针
ID3D11Device* pDevice = nullptr;
Microsoft::WRL::ComPtr<ID3D11Device> pDevice;
// 指向交换链的指针
IDXGISwapChain* pSwap = nullptr;
Microsoft::WRL::ComPtr<IDXGISwapChain> pSwap;
// 指向Context的指针
ID3D11DeviceContext* pContext = nullptr;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> pContext;
// 指向View的指针
ID3D11RenderTargetView* pTarget = nullptr;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> pTarget;
};
\ No newline at end of file
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