1
0
mirror of https://github.com/borgesdan/xn65 synced 2024-12-29 21:54:47 +01:00

Implementa ponteiros ComPtr

This commit is contained in:
Danilo 2024-06-25 17:06:37 -03:00
parent b983ebcf74
commit 49345ff7df
14 changed files with 143 additions and 382 deletions

View File

@ -12,14 +12,14 @@ namespace xna {
} }
uptr<GraphicsAdapter> GraphicsAdapter::DefaultAdapter() { uptr<GraphicsAdapter> GraphicsAdapter::DefaultAdapter() {
IDXGIFactory1* pFactory = nullptr; comptr<IDXGIFactory1> pFactory = nullptr;
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)pFactory.GetAddressOf()))
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
IDXGIAdapter1* pAdapter = nullptr; comptr<IDXGIAdapter1> pAdapter = nullptr;
if (pFactory->EnumAdapters1(0, &pAdapter) != DXGI_ERROR_NOT_FOUND) { if (pFactory->EnumAdapters1(0, pAdapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND) {
auto adp = unew<GraphicsAdapter>(); auto adp = unew<GraphicsAdapter>();
adp->impl->_index = 0; adp->impl->_index = 0;
@ -28,22 +28,19 @@ namespace xna {
return adp; return adp;
} }
pFactory->Release();
pFactory = nullptr;
return nullptr; return nullptr;
} }
void GraphicsAdapter::Adapters(std::vector<uptr<GraphicsAdapter>>& adapters) { void GraphicsAdapter::Adapters(std::vector<uptr<GraphicsAdapter>>& adapters) {
IDXGIFactory1* pFactory = nullptr; comptr<IDXGIFactory1> pFactory = nullptr;
if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&pFactory)) if FAILED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)pFactory.GetAddressOf()))
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
IDXGIAdapter1* pAdapter = nullptr; comptr<IDXGIAdapter1> pAdapter = nullptr;
UINT count = 0; UINT count = 0;
for (; pFactory->EnumAdapters1(count, &pAdapter) != DXGI_ERROR_NOT_FOUND; ++count) { for (; pFactory->EnumAdapters1(count, pAdapter.GetAddressOf()) != DXGI_ERROR_NOT_FOUND; ++count) {
auto adp = unew<GraphicsAdapter>(); auto adp = unew<GraphicsAdapter>();
adp->impl->_index = count; adp->impl->_index = count;
@ -51,9 +48,6 @@ namespace xna {
adapters.push_back(std::move(adp)); adapters.push_back(std::move(adp));
} }
pFactory->Release();
pFactory = nullptr;
} }
String GraphicsAdapter::Description() const { String GraphicsAdapter::Description() const {
@ -141,7 +135,7 @@ namespace xna {
uptr<DisplayModeCollection> GraphicsAdapter::SupportedDisplayModes() const { uptr<DisplayModeCollection> GraphicsAdapter::SupportedDisplayModes() const {
if (!impl->dxadapter) return nullptr; if (!impl->dxadapter) return nullptr;
const auto totalDisplay = getDisplayModesCount(impl->dxadapter); const auto totalDisplay = getDisplayModesCount(impl->dxadapter.Get());
if (totalDisplay == 0) if (totalDisplay == 0)
return nullptr; return nullptr;

View File

@ -102,13 +102,12 @@ namespace xna {
} }
if (impl->dxBlendState) { if (impl->dxBlendState) {
impl->dxBlendState->Release();
impl->dxBlendState = nullptr; impl->dxBlendState = nullptr;
} }
const auto hr = m_device->impl->_device->CreateBlendState( const auto hr = m_device->impl->_device->CreateBlendState(
&impl->dxDescription, &impl->dxDescription,
&impl->dxBlendState); impl->dxBlendState.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -127,7 +126,7 @@ namespace xna {
} }
m_device->impl->_context->OMSetBlendState( m_device->impl->_context->OMSetBlendState(
impl->dxBlendState, impl->dxBlendState.Get(),
impl->blendFactor, impl->blendFactor,
impl->sampleMask); impl->sampleMask);

View File

@ -22,14 +22,13 @@ namespace xna {
} }
if (impl->_buffer) { if (impl->_buffer) {
impl->_buffer->Release();
impl->_buffer = nullptr; impl->_buffer = nullptr;
} }
const auto hr = m_device->impl->_device->CreateBuffer( const auto hr = m_device->impl->_device->CreateBuffer(
&impl->_description, &impl->_description,
&impl->_subResource, &impl->_subResource,
&impl->_buffer); impl->_buffer.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -56,7 +55,6 @@ namespace xna {
} }
if (impl->_blob) { if (impl->_blob) {
impl->_blob->Release();
impl->_blob = nullptr; impl->_blob = nullptr;
} }
@ -80,7 +78,7 @@ namespace xna {
Exception::Throw(ExMessage::ApplyComponent); Exception::Throw(ExMessage::ApplyComponent);
} }
m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer, DXGI_FORMAT_R16_UINT, 0); m_device->impl->_context->IASetIndexBuffer(impl->dxBuffer.Get(), DXGI_FORMAT_R16_UINT, 0);
return true; return true;
} }
@ -109,7 +107,7 @@ namespace xna {
UINT stride = impl->size; UINT stride = impl->size;
UINT offset = 0; UINT offset = 0;
m_device->impl->_context->IASetVertexBuffers(0, 1, m_device->impl->_context->IASetVertexBuffers(0, 1,
&impl->dxBuffer, &stride, &offset); impl->dxBuffer.GetAddressOf(), &stride, &offset);
return true; return true;
} }
@ -132,7 +130,6 @@ namespace xna {
} }
if (impl->_inputLayout) { if (impl->_inputLayout) {
impl->_inputLayout->Release();
impl->_inputLayout = nullptr; impl->_inputLayout = nullptr;
} }
@ -141,7 +138,7 @@ namespace xna {
static_cast<UINT>(impl->_description.size()), static_cast<UINT>(impl->_description.size()),
blob.impl->_blob->GetBufferPointer(), blob.impl->_blob->GetBufferPointer(),
blob.impl->_blob->GetBufferSize(), blob.impl->_blob->GetBufferSize(),
&impl->_inputLayout); impl->_inputLayout.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);

View File

@ -42,13 +42,12 @@ namespace xna {
} }
if (impl->dxDepthStencil) { if (impl->dxDepthStencil) {
impl->dxDepthStencil->Release();
impl->dxDepthStencil = nullptr; impl->dxDepthStencil = nullptr;
} }
const auto hr = m_device->impl->_device->CreateDepthStencilState( const auto hr = m_device->impl->_device->CreateDepthStencilState(
&impl->dxDescription, &impl->dxDescription,
&impl->dxDepthStencil); impl->dxDepthStencil.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -67,7 +66,7 @@ namespace xna {
Exception::Throw(ExMessage::UnintializedComponent); Exception::Throw(ExMessage::UnintializedComponent);
} }
m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil, 0); m_device->impl->_context->OMSetDepthStencilState(impl->dxDepthStencil.Get(), 0);
return true; return true;
} }

View File

@ -26,16 +26,16 @@ namespace xna {
createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG; createDeviceFlags = D3D11_CREATE_DEVICE_FLAG::D3D11_CREATE_DEVICE_DEBUG;
#endif #endif
auto hr = D3D11CreateDevice( auto hr = D3D11CreateDevice(
impl._adapter->impl->dxadapter, impl._adapter->impl->dxadapter.Get(),
D3D_DRIVER_TYPE_UNKNOWN, D3D_DRIVER_TYPE_UNKNOWN,
NULL, NULL,
createDeviceFlags, createDeviceFlags,
NULL, NULL,
0, 0,
D3D11_SDK_VERSION, D3D11_SDK_VERSION,
&impl._device, impl._device.GetAddressOf(),
&impl._featureLevel, &impl._featureLevel,
&impl._context); impl._context.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
OutputDebugString("---> Usando Adaptador WARP: não há suporte ao D3D11\n"); OutputDebugString("---> Usando Adaptador WARP: não há suporte ao D3D11\n");
@ -48,9 +48,9 @@ namespace xna {
NULL, NULL,
0, 0,
D3D11_SDK_VERSION, D3D11_SDK_VERSION,
&impl._device, impl._device.GetAddressOf(),
&impl._featureLevel, &impl._featureLevel,
&impl._context); impl._context.GetAddressOf());
if FAILED(hr) if FAILED(hr)
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -156,7 +156,10 @@ namespace xna {
if (!impl) return false; if (!impl) return false;
const auto result = impl->_swapChain->Present(impl->_usevsync); const auto result = impl->_swapChain->Present(impl->_usevsync);
impl->_context->OMSetRenderTargets(1, &impl->_renderTarget2D->render_impl->_renderTargetView, nullptr); impl->_context->OMSetRenderTargets(
1,
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(),
nullptr);
return result; return result;
} }
@ -172,7 +175,7 @@ namespace xna {
impl->_backgroundColor[3] = v4.W; impl->_backgroundColor[3] = v4.W;
impl->_context->ClearRenderTargetView( impl->_context->ClearRenderTargetView(
impl->_renderTarget2D->render_impl->_renderTargetView, impl->_renderTarget2D->render_impl->_renderTargetView.Get(),
impl->_backgroundColor); impl->_backgroundColor);
} }

View File

@ -18,9 +18,9 @@ namespace xna {
//UINT FXFlags, //UINT FXFlags,
0, 0,
//ID3D11Device * pDevice, //ID3D11Device * pDevice,
device->impl->_device, device->impl->_device.Get(),
//ID3DX11Effect * *ppEffect //ID3DX11Effect * *ppEffect
&impl->dxEffect impl->dxEffect.ReleaseAndGetAddressOf()
); );
if FAILED(result) if FAILED(result)
@ -331,7 +331,7 @@ namespace xna {
if (!impl->dxPass) if (!impl->dxPass)
throw std::runtime_error("EffectPass::Apply: The class was not initialized correctly"); throw std::runtime_error("EffectPass::Apply: The class was not initialized correctly");
const auto hr = impl->dxPass->Apply(0, impl->dxContext); const auto hr = impl->dxPass->Apply(0, impl->dxContext.Get());
if FAILED(hr) if FAILED(hr)
throw std::runtime_error("EffectPass::Apply: error to call Apply"); throw std::runtime_error("EffectPass::Apply: error to call Apply");
@ -399,14 +399,12 @@ namespace xna {
auto current = impl->dxTechnique->GetPassByIndex(i); auto current = impl->dxTechnique->GetPassByIndex(i);
auto pass = snew<EffectPass>(); auto pass = snew<EffectPass>();
pass->impl->dxPass = current; pass->impl->dxPass.Attach(current);
pass->impl->dxPass->AddRef();
current->Release(); current->Release();
current = nullptr; current = nullptr;
pass->impl->dxContext = impl->dxContext; pass->impl->dxContext = impl->dxContext;
pass->impl->dxContext->AddRef();
list[i] = pass; list[i] = pass;
} }
@ -580,8 +578,7 @@ namespace xna {
break; break;
auto efparam = snew<EffectParameter>(); auto efparam = snew<EffectParameter>();
efparam->impl->dxVariable = el; efparam->impl->dxVariable.Attach(el);
efparam->impl->dxVariable->AddRef();
el->Release(); el->Release();
el = nullptr; el = nullptr;
@ -603,8 +600,7 @@ namespace xna {
break; break;
auto efparam = snew<EffectParameter>(); auto efparam = snew<EffectParameter>();
efparam->impl->dxVariable = member; efparam->impl->dxVariable.Attach(member);
efparam->impl->dxVariable->AddRef();
member->Release(); member->Release();
member = nullptr; member = nullptr;

View File

@ -22,13 +22,12 @@ namespace xna {
} }
if (impl->dxRasterizerState) { if (impl->dxRasterizerState) {
impl->dxRasterizerState->Release();
impl->dxRasterizerState = nullptr; impl->dxRasterizerState = nullptr;
} }
const auto hr = m_device->impl->_device->CreateRasterizerState( const auto hr = m_device->impl->_device->CreateRasterizerState(
&impl->dxDescription, &impl->dxDescription,
&impl->dxRasterizerState); impl->dxRasterizerState.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -47,7 +46,7 @@ namespace xna {
Exception::Throw(ExMessage::UnintializedComponent); Exception::Throw(ExMessage::UnintializedComponent);
} }
m_device->impl->_context->RSSetState(impl->dxRasterizerState); m_device->impl->_context->RSSetState(impl->dxRasterizerState.Get());
return true; return true;
} }

View File

@ -16,19 +16,14 @@ namespace xna {
bool RenderTarget2D::Initialize() { bool RenderTarget2D::Initialize() {
if (!impl || !m_device || !m_device->impl->_device) { if (!impl || !m_device || !m_device->impl->_device) {
Exception::Throw(ExMessage::InitializeComponent); Exception::Throw(ExMessage::InitializeComponent);
} }
if (impl->dxTexture2D) {
impl->dxTexture2D->Release();
impl->dxTexture2D = nullptr;
}
if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D)) if (!m_device->impl->_swapChain->impl->GetBackBuffer(impl->dxTexture2D))
return false; return false;
auto& dxdevice = m_device->impl->_device; auto& dxdevice = m_device->impl->_device;
const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D, NULL, &render_impl->_renderTargetView); const auto hr = dxdevice->CreateRenderTargetView(impl->dxTexture2D.Get(), NULL, render_impl->_renderTargetView.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -46,7 +41,7 @@ namespace xna {
Exception::Throw(ExMessage::UnintializedComponent); Exception::Throw(ExMessage::UnintializedComponent);
auto& context = m_device->impl->_context; auto& context = m_device->impl->_context;
context->OMSetRenderTargets(1, &render_impl->_renderTargetView, nullptr); context->OMSetRenderTargets(1, render_impl->_renderTargetView.GetAddressOf(), nullptr);
return true; return true;
} }
} }

View File

@ -16,13 +16,12 @@ namespace xna {
} }
if (impl->_samplerState) { if (impl->_samplerState) {
impl->_samplerState->Release();
impl->_samplerState = nullptr; impl->_samplerState = nullptr;
} }
const auto hr = m_device->impl->_device->CreateSamplerState( const auto hr = m_device->impl->_device->CreateSamplerState(
&impl->_description, &impl->_description,
&impl->_samplerState); impl->_samplerState.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -41,7 +40,7 @@ namespace xna {
Exception::Throw(ExMessage::UnintializedComponent); Exception::Throw(ExMessage::UnintializedComponent);
} }
m_device->impl->_context->PSSetSamplers(0, 1, &impl->_samplerState); m_device->impl->_context->PSSetSamplers(0, 1, impl->_samplerState.GetAddressOf());
return true; return true;
} }
@ -62,7 +61,7 @@ namespace xna {
if (!current || !current->impl || !current->impl->_samplerState) if (!current || !current->impl || !current->impl->_samplerState)
Exception::Throw(ExMessage::InvalidOperation); Exception::Throw(ExMessage::InvalidOperation);
states[i] = current->impl->_samplerState; states[i] = current->impl->_samplerState.Get();
states[i]->AddRef(); states[i]->AddRef();
} }

View File

@ -68,15 +68,14 @@ namespace xna {
} }
if (impl->_vertexShader) { if (impl->_vertexShader) {
impl->_vertexShader->Release(); impl->_vertexShader.ReleaseAndGetAddressOf();
impl->_vertexShader = nullptr;
} }
const auto hr = m_device->impl->_device->CreateVertexShader( const auto hr = m_device->impl->_device->CreateVertexShader(
buffer.impl->_blob->GetBufferPointer(), buffer.impl->_blob->GetBufferPointer(),
buffer.impl->_blob->GetBufferSize(), buffer.impl->_blob->GetBufferSize(),
NULL, NULL,
&impl->_vertexShader); impl->_vertexShader.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -92,15 +91,14 @@ namespace xna {
} }
if (impl->_pixelShader) { if (impl->_pixelShader) {
impl->_pixelShader->Release(); impl->_pixelShader.ReleaseAndGetAddressOf();
impl->_pixelShader = nullptr;
} }
const auto hr = m_device->impl->_device->CreatePixelShader( const auto hr = m_device->impl->_device->CreatePixelShader(
buffer.impl->_blob->GetBufferPointer(), buffer.impl->_blob->GetBufferPointer(),
buffer.impl->_blob->GetBufferSize(), buffer.impl->_blob->GetBufferSize(),
NULL, NULL,
&impl->_pixelShader); impl->_pixelShader.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);

View File

@ -63,7 +63,7 @@ namespace xna {
impl = unew<PlatformImplementation>(); impl = unew<PlatformImplementation>();
impl->_dxSpriteFont = unew<DxSpriteFont>( impl->_dxSpriteFont = unew<DxSpriteFont>(
//ID3D11ShaderResourceView* texture //ID3D11ShaderResourceView* texture
texture->impl->dxShaderResource, texture->impl->dxShaderResource.Get(),
//Glyph const* glyphs //Glyph const* glyphs
dxGlyps.data(), dxGlyps.data(),
//size_t glyphCount //size_t glyphCount
@ -130,7 +130,7 @@ namespace xna {
implementation = unew<PlatformImplementation>(); implementation = unew<PlatformImplementation>();
implementation->_dxspriteBatch = snew<DxSpriteBatch>( implementation->_dxspriteBatch = snew<DxSpriteBatch>(
//ID3D11DeviceContext* deviceContext //ID3D11DeviceContext* deviceContext
device->impl->_context device->impl->_context.Get()
); );
Viewport(device->Viewport()); Viewport(device->Viewport());
@ -154,10 +154,10 @@ namespace xna {
implementation->_dxspriteBatch->Begin( implementation->_dxspriteBatch->Begin(
sort, sort,
blendState ? blendState->impl->dxBlendState : nullptr, blendState ? blendState->impl->dxBlendState.Get() : nullptr,
samplerState ? samplerState->impl->_samplerState : nullptr, samplerState ? samplerState->impl->_samplerState.Get() : nullptr,
depthStencil ? depthStencil->impl->dxDepthStencil : nullptr, depthStencil ? depthStencil->impl->dxDepthStencil.Get() : nullptr,
rasterizerState ? rasterizerState->impl->dxRasterizerState : nullptr, rasterizerState ? rasterizerState->impl->dxRasterizerState.Get() : nullptr,
nullptr, nullptr,
matrix matrix
); );
@ -182,7 +182,7 @@ namespace xna {
XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W }; XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
implementation->_dxspriteBatch->Draw( implementation->_dxspriteBatch->Draw(
texture.impl->dxShaderResource, texture.impl->dxShaderResource.Get(),
_position, _position,
_color _color
); );
@ -209,7 +209,7 @@ namespace xna {
}; };
implementation->_dxspriteBatch->Draw( implementation->_dxspriteBatch->Draw(
texture.impl->dxShaderResource, texture.impl->dxShaderResource.Get(),
_position, _position,
sourceRectangle ? &_sourceRect : nullptr, sourceRectangle ? &_sourceRect : nullptr,
_color); _color);
@ -239,7 +239,7 @@ namespace xna {
const DxSpriteEffects _effects = static_cast<DxSpriteEffects>(effects); const DxSpriteEffects _effects = static_cast<DxSpriteEffects>(effects);
implementation->_dxspriteBatch->Draw( implementation->_dxspriteBatch->Draw(
texture.impl->dxShaderResource, texture.impl->dxShaderResource.Get(),
_position, _position,
sourceRectangle ? &_sourceRect : nullptr, sourceRectangle ? &_sourceRect : nullptr,
_color, _color,
@ -275,7 +275,7 @@ namespace xna {
const XMFLOAT2 _scale = { scale.X, scale.Y }; const XMFLOAT2 _scale = { scale.X, scale.Y };
implementation->_dxspriteBatch->Draw( implementation->_dxspriteBatch->Draw(
texture.impl->dxShaderResource, texture.impl->dxShaderResource.Get(),
_position, _position,
sourceRectangle ? &_sourceRect : nullptr, sourceRectangle ? &_sourceRect : nullptr,
_color, _color,
@ -302,7 +302,7 @@ namespace xna {
const auto v4 = color.ToVector4(); const auto v4 = color.ToVector4();
const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W }; const XMVECTORF32 _color = { v4.X, v4.Y, v4.Z, v4.W };
implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource, _destinationRect, _color); implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource.Get(), _destinationRect, _color);
} }
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color) { void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color) {
@ -330,7 +330,7 @@ namespace xna {
_sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height; _sourceRect.bottom = sourceRectangle->Y + sourceRectangle->Height;
}; };
implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource, _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color); implementation->_dxspriteBatch->Draw(texture.impl->dxShaderResource.Get(), _destinationRect, sourceRectangle ? &_sourceRect : nullptr, _color);
} }
void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) { void SpriteBatch::Draw(Texture2D& texture, Rectangle const& destinationRectangle, std::optional<Rectangle> const& sourceRectangle, Color const& color, float rotation, Vector2 const& origin, SpriteEffects effects, float layerDepth) {
@ -362,7 +362,7 @@ namespace xna {
const auto _effects = static_cast<DxSpriteEffects>(effects); const auto _effects = static_cast<DxSpriteEffects>(effects);
implementation->_dxspriteBatch->Draw( implementation->_dxspriteBatch->Draw(
texture.impl->dxShaderResource, texture.impl->dxShaderResource.Get(),
_destinationRect, _destinationRect,
sourceRectangle ? &_sourceRect : nullptr, sourceRectangle ? &_sourceRect : nullptr,
_color, _color,

View File

@ -16,13 +16,12 @@ namespace xna {
impl = nullptr; impl = nullptr;
} }
static bool internalInit(GraphicsDevice& device, HWND windowHandle, IDXGISwapChain1*& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) { static bool internalInit(GraphicsDevice& device, HWND windowHandle, comptr<IDXGISwapChain1>& swapChain, DXGI_SWAP_CHAIN_DESC1 const& desc, DXGI_SWAP_CHAIN_FULLSCREEN_DESC const& fdesc) {
if (!device.impl->_device || !windowHandle) if (!device.impl->_device || !windowHandle)
return false; return false;
if (swapChain) { if (swapChain) {
swapChain->Release(); swapChain.ReleaseAndGetAddressOf();
swapChain = nullptr;
} }
auto adapter = device.Adapter(); auto adapter = device.Adapter();
@ -39,12 +38,12 @@ namespace xna {
if (FAILED(hr)) return false; if (FAILED(hr)) return false;
dxFactory2->CreateSwapChainForHwnd( dxFactory2->CreateSwapChainForHwnd(
device.impl->_device, device.impl->_device.Get(),
windowHandle, windowHandle,
&desc, &desc,
&fdesc, &fdesc,
nullptr, nullptr,
&swapChain); swapChain.GetAddressOf());
return true; return true;

View File

@ -9,44 +9,30 @@ namespace xna {
{ {
auto _this = device.shared_from_this(); auto _this = device.shared_from_this();
auto texture2d = snew<Texture2D>(_this); auto texture2d = snew<Texture2D>(_this);
ID3D11Resource* resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
auto wstr = XnaHelper::ToWString(fileName); auto wstr = XnaHelper::ToWString(fileName);
HRESULT result = DirectX::CreateWICTextureFromFile( HRESULT result = DirectX::CreateWICTextureFromFile(
device.impl->_device, device.impl->_device.Get(),
device.impl->_context, device.impl->_context.Get(),
wstr.c_str(), wstr.c_str(),
&resource, resource.GetAddressOf(),
&texture2d->impl->dxShaderResource, texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf(),
0U); 0U);
if (FAILED(result)) if (FAILED(result)) {
{
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr; return nullptr;
} }
result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D); result = resource->QueryInterface(IID_ID3D11Texture2D, (void**)texture2d->impl->dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(result)) { if (FAILED(result)) {
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr; return nullptr;
} }
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
texture2d->impl->dxTexture2D->GetDesc(&desc); texture2d->impl->dxTexture2D->GetDesc(&desc);
texture2d->impl->dxDescription = desc; texture2d->impl->dxDescription = desc;
resource->Release();
resource = nullptr;
return texture2d; return texture2d;
} }
@ -57,25 +43,20 @@ namespace xna {
Exception::Throw(ExMessage::InitializeComponent); Exception::Throw(ExMessage::InitializeComponent);
} }
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D); auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
} }
ID3D11Resource* resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::InvalidOperation); Exception::Throw(ExMessage::InvalidOperation);
} }
hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource); hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, &impl->dxShaderResource);
if (resource) {
resource->Release();
resource = nullptr;
}
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -128,35 +109,25 @@ namespace xna {
HRESULT internalSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data) HRESULT internalSetData(Texture2D::PlatformImplementation& impl, GraphicsDevice& device, UINT const* data)
{ {
if (!impl.dxTexture2D) { if (!impl.dxTexture2D) {
auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, &impl.dxTexture2D); auto hr = device.impl->_device->CreateTexture2D(&impl.dxDescription, nullptr, impl.dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
} }
} }
ID3D11Resource* resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); auto hr = impl.dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::InvalidOperation); Exception::Throw(ExMessage::InvalidOperation);
} }
constexpr int R8G8B8A8U_BYTE_SIZE = 4; constexpr int R8G8B8A8U_BYTE_SIZE = 4;
device.impl->_context->UpdateSubresource(resource, 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); device.impl->_context->UpdateSubresource(resource.Get(), 0, nullptr, data, impl.dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
if (impl.dxShaderResource) {
impl.dxShaderResource->Release();
impl.dxShaderResource = nullptr;
}
impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels; impl.dxShaderDescription.Texture2D.MipLevels = impl.dxDescription.MipLevels;
hr = device.impl->_device->CreateShaderResourceView(resource, &impl.dxShaderDescription, &impl.dxShaderResource); hr = device.impl->_device->CreateShaderResourceView(resource.Get(), &impl.dxShaderDescription, impl.dxShaderResource.ReleaseAndGetAddressOf());
if (resource) {
resource->Release();
resource = nullptr;
}
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -216,15 +187,15 @@ namespace xna {
} }
if (!impl->dxTexture2D) { if (!impl->dxTexture2D) {
auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, &impl->dxTexture2D); auto hr = m_device->impl->_device->CreateTexture2D(&impl->dxDescription, nullptr, impl->dxTexture2D.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
} }
} }
ID3D11Resource* resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
auto hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)&resource); auto hr = impl->dxTexture2D->QueryInterface(IID_ID3D11Resource, (void**)resource.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::InvalidOperation); Exception::Throw(ExMessage::InvalidOperation);
@ -233,30 +204,20 @@ namespace xna {
D3D11_BOX box{}; D3D11_BOX box{};
if (rect) { if (rect) {
box.left = rect->X; box.left = rect->Left();
box.right = rect->X + rect->Width; box.right = rect->Right();
box.top = rect->Y; box.top = rect->Top();
box.bottom = rect->Y + rect->Height; box.bottom = rect->Bottom();
box.back = level; box.back = level;
box.front = 0; box.front = 0;
} }
constexpr int R8G8B8A8U_BYTE_SIZE = 4; constexpr int R8G8B8A8U_BYTE_SIZE = 4;
m_device->impl->_context->UpdateSubresource(resource, 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0); m_device->impl->_context->UpdateSubresource(resource.Get(), 0, rect ? &box : nullptr, finalData.data(), impl->dxDescription.Width * R8G8B8A8U_BYTE_SIZE, 0);
if (impl->dxShaderResource) {
impl->dxShaderResource->Release();
impl->dxShaderResource = nullptr;
}
impl->dxShaderDescription.Format = impl->dxDescription.Format; impl->dxShaderDescription.Format = impl->dxDescription.Format;
impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels; impl->dxShaderDescription.Texture2D.MipLevels = impl->dxDescription.MipLevels;
hr = m_device->impl->_device->CreateShaderResourceView(resource, &impl->dxShaderDescription, &impl->dxShaderResource); hr = m_device->impl->_device->CreateShaderResourceView(resource.Get(), &impl->dxShaderDescription, impl->dxShaderResource.ReleaseAndGetAddressOf());
if (resource) {
resource->Release();
resource = nullptr;
}
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -286,34 +247,24 @@ namespace xna {
{ {
auto _this = device.shared_from_this(); auto _this = device.shared_from_this();
auto texture2d = snew<Texture2D>(_this); auto texture2d = snew<Texture2D>(_this);
ID3D11Resource* resource = nullptr; comptr<ID3D11Resource> resource = nullptr;
auto hr = DirectX::CreateWICTextureFromMemory( auto hr = DirectX::CreateWICTextureFromMemory(
device.impl->_device, device.impl->_device.Get(),
device.impl->_context, device.impl->_context.Get(),
data.data(), data.data(),
data.size(), data.size(),
&resource, resource.GetAddressOf(),
&texture2d->impl->dxShaderResource); texture2d->impl->dxShaderResource.ReleaseAndGetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
{ {
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr; return nullptr;
} }
hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)&texture2d->impl->dxTexture2D); hr = resource->QueryInterface(IID_ID3D11Texture2D, (void**)texture2d->impl->dxTexture2D.ReleaseAndGetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
if (resource) {
resource->Release();
resource = nullptr;
}
return nullptr; return nullptr;
} }
@ -321,9 +272,6 @@ namespace xna {
texture2d->impl->dxTexture2D->GetDesc(&desc); texture2d->impl->dxTexture2D->GetDesc(&desc);
texture2d->impl->dxDescription = desc; texture2d->impl->dxDescription = desc;
resource->Release();
resource = nullptr;
return texture2d; return texture2d;
} }

View File

@ -512,14 +512,8 @@ namespace xna {
}; };
struct GraphicsAdapter::PlatformImplementation { struct GraphicsAdapter::PlatformImplementation {
~PlatformImplementation() { comptr<IDXGIAdapter1> dxadapter = nullptr;
if (dxadapter) {
dxadapter->Release();
dxadapter = nullptr;
}
}
IDXGIAdapter1* dxadapter = nullptr;
private: private:
friend class GraphicsAdapter; friend class GraphicsAdapter;
Uint _index{ 0 }; Uint _index{ 0 };
@ -543,57 +537,29 @@ namespace xna {
}; };
struct BlendState::PlatformImplementation { struct BlendState::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11BlendState> dxBlendState = nullptr;
if (dxBlendState) {
dxBlendState->Release();
dxBlendState = nullptr;
}
}
ID3D11BlendState* dxBlendState = nullptr;
D3D11_BLEND_DESC dxDescription{}; D3D11_BLEND_DESC dxDescription{};
float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F }; float blendFactor[4]{ 1.0F, 1.0F, 1.0F, 1.0F };
UINT sampleMask{ 0xffffffff }; UINT sampleMask{ 0xffffffff };
}; };
struct ConstantBuffer::PlatformImplementation { struct ConstantBuffer::PlatformImplementation {
~PlatformImplementation() {
if (_buffer) {
_buffer->Release();
_buffer = nullptr;
}
}
D3D11_BUFFER_DESC _description{}; D3D11_BUFFER_DESC _description{};
D3D11_SUBRESOURCE_DATA _subResource{}; D3D11_SUBRESOURCE_DATA _subResource{};
ID3D11Buffer* _buffer = nullptr; comptr<ID3D11Buffer> _buffer = nullptr;
DirectX::XMMATRIX _worldViewProjection{}; DirectX::XMMATRIX _worldViewProjection{};
}; };
struct DataBuffer::PlatformImplementation { struct DataBuffer::PlatformImplementation {
~PlatformImplementation() { comptr<ID3DBlob> _blob = nullptr;
if (_blob) {
_blob->Release();
_blob = nullptr;
}
}
ID3DBlob* _blob = nullptr; void Set(comptr<ID3DBlob> const& blob) {
void Set(ID3DBlob*& blob) {
_blob = blob; _blob = blob;
} }
}; };
struct DepthStencilState::PlatformImplementation { struct DepthStencilState::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11DepthStencilState> dxDepthStencil = nullptr;
if (dxDepthStencil) {
dxDepthStencil->Release();
dxDepthStencil = nullptr;
}
}
ID3D11DepthStencilState* dxDepthStencil = nullptr;
D3D11_DEPTH_STENCIL_DESC dxDescription{}; D3D11_DEPTH_STENCIL_DESC dxDescription{};
}; };
@ -646,14 +612,7 @@ namespace xna {
}; };
struct IndexBuffer::PlatformImplementation { struct IndexBuffer::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11Buffer> dxBuffer = nullptr;
if (dxBuffer) {
dxBuffer->Release();
dxBuffer = nullptr;
}
}
ID3D11Buffer* dxBuffer = nullptr;
}; };
struct Keyboard::PlatformImplementation { struct Keyboard::PlatformImplementation {
@ -675,126 +634,58 @@ namespace xna {
}; };
struct RasterizerState::PlatformImplementation { struct RasterizerState::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11RasterizerState> dxRasterizerState = nullptr;
if (dxRasterizerState) {
dxRasterizerState->Release();
dxRasterizerState = nullptr;
}
}
ID3D11RasterizerState* dxRasterizerState = nullptr;
D3D11_RASTERIZER_DESC dxDescription{}; D3D11_RASTERIZER_DESC dxDescription{};
}; };
struct SamplerState::PlatformImplementation { struct SamplerState::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11SamplerState> _samplerState = nullptr;
if (_samplerState) {
_samplerState->Release();
_samplerState = nullptr;
}
}
ID3D11SamplerState* _samplerState = nullptr;
D3D11_SAMPLER_DESC _description{}; D3D11_SAMPLER_DESC _description{};
}; };
struct VertexShader::PlatformImplementation { struct VertexShader::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11VertexShader> _vertexShader = nullptr;
if (_vertexShader) {
_vertexShader->Release();
_vertexShader = nullptr;
}
}
ID3D11VertexShader* _vertexShader = nullptr;
}; };
struct PixelShader::PlatformImplementation { struct PixelShader::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11PixelShader> _pixelShader = nullptr;
if (_pixelShader) {
_pixelShader->Release();
_pixelShader = nullptr;
}
}
ID3D11PixelShader* _pixelShader = nullptr;
}; };
struct SwapChain::PlatformImplementation { struct SwapChain::PlatformImplementation {
~PlatformImplementation() { comptr<IDXGISwapChain1> dxSwapChain{ nullptr };
if (dxSwapChain) {
dxSwapChain->Release();
dxSwapChain = nullptr;
}
}
IDXGISwapChain1* dxSwapChain{ nullptr };
DXGI_SWAP_CHAIN_DESC1 dxDescription{}; DXGI_SWAP_CHAIN_DESC1 dxDescription{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{}; DXGI_SWAP_CHAIN_FULLSCREEN_DESC dxFullScreenDescription{};
bool GetBackBuffer(ID3D11Texture2D*& texture2D) { bool GetBackBuffer(comptr<ID3D11Texture2D>& texture2D) {
if (!dxSwapChain) if (!dxSwapChain)
return false; return false;
const auto hr = dxSwapChain->GetBuffer(0, __uuidof(texture2D), (void**)(&texture2D)); const auto hr = dxSwapChain->GetBuffer(0, __uuidof(texture2D), (void**)texture2D.GetAddressOf());
return !FAILED(hr); return !FAILED(hr);
} }
}; };
struct Texture2D::PlatformImplementation { struct Texture2D::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11Texture2D> dxTexture2D{ nullptr };
if (dxTexture2D) { comptr<ID3D11ShaderResourceView> dxShaderResource{ nullptr };
dxTexture2D->Release();
dxTexture2D = nullptr;
}
if (dxShaderResource) {
dxShaderResource->Release();
dxShaderResource = nullptr;
}
}
ID3D11Texture2D* dxTexture2D{ nullptr };
ID3D11ShaderResourceView* dxShaderResource{ nullptr };
D3D11_SUBRESOURCE_DATA dxSubResource{}; D3D11_SUBRESOURCE_DATA dxSubResource{};
D3D11_TEXTURE2D_DESC dxDescription{}; D3D11_TEXTURE2D_DESC dxDescription{};
D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDescription{}; D3D11_SHADER_RESOURCE_VIEW_DESC dxShaderDescription{};
}; };
struct RenderTarget2D::PlatformImplementation { struct RenderTarget2D::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11RenderTargetView> _renderTargetView = nullptr;
if (_renderTargetView) {
_renderTargetView->Release();
_renderTargetView = nullptr;
}
}
ID3D11RenderTargetView* _renderTargetView = nullptr;
D3D11_RENDER_TARGET_VIEW_DESC _renderTargetDesc{}; D3D11_RENDER_TARGET_VIEW_DESC _renderTargetDesc{};
}; };
struct VertexBuffer::PlatformImplementation { struct VertexBuffer::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11Buffer> dxBuffer = nullptr;
if (dxBuffer) {
dxBuffer->Release();
dxBuffer = nullptr;
}
}
ID3D11Buffer* dxBuffer = nullptr;
UINT size{ 0 }; UINT size{ 0 };
}; };
struct VertexInputLayout::PlatformImplementation { struct VertexInputLayout::PlatformImplementation {
~PlatformImplementation() { comptr<ID3D11InputLayout> _inputLayout{ nullptr };
if (_inputLayout) {
_inputLayout->Release();
_inputLayout = nullptr;
}
}
ID3D11InputLayout* _inputLayout{ nullptr };
std::vector<D3D11_INPUT_ELEMENT_DESC> _description{}; std::vector<D3D11_INPUT_ELEMENT_DESC> _description{};
}; };
@ -934,29 +825,12 @@ namespace xna {
_depthStencilState = xna::DepthStencilState::Default(); _depthStencilState = xna::DepthStencilState::Default();
_rasterizerState = xna::RasterizerState::CullCounterClockwise(); _rasterizerState = xna::RasterizerState::CullCounterClockwise();
_samplerStates = snew<SamplerStateCollection>(); _samplerStates = snew<SamplerStateCollection>();
} }
~PlatformImplementation() {
if (_device) {
_device->Release();
_device = nullptr;
}
if (_context) {
_context->Release();
_device = nullptr;
}
if (_factory) {
_factory->Release();
_factory = nullptr;
}
}
public: public:
ID3D11Device* _device = nullptr; comptr<ID3D11Device> _device = nullptr;
ID3D11DeviceContext* _context = nullptr; comptr<ID3D11DeviceContext> _context = nullptr;
IDXGIFactory1* _factory = nullptr; comptr<IDXGIFactory1> _factory = nullptr;
PBlendState _blendState = nullptr; PBlendState _blendState = nullptr;
PRasterizerState _rasterizerState = nullptr; PRasterizerState _rasterizerState = nullptr;
@ -990,84 +864,29 @@ namespace xna {
}; };
struct SoundEffect::PlatformImplementation { struct SoundEffect::PlatformImplementation {
~PlatformImplementation() {
}
uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr; uptr<DirectX::SoundEffect> _dxSoundEffect = nullptr;
}; };
struct Effect::PlatformImplementation { struct Effect::PlatformImplementation {
~PlatformImplementation() { comptr<ID3DX11Effect> dxEffect = nullptr;
if (dxEffect) {
dxEffect->Release();
dxEffect = nullptr;
}
}
ID3DX11Effect* dxEffect = nullptr;
}; };
struct EffectAnnotation::PlatformImplementation { struct EffectAnnotation::PlatformImplementation {
~PlatformImplementation() { comptr<ID3DX11EffectVariable> dxVariable = nullptr;
if (dxVariable) {
dxVariable->Release();
dxVariable = nullptr;
}
}
ID3DX11EffectVariable* dxVariable = nullptr;
}; };
struct EffectPass::PlatformImplementation { struct EffectPass::PlatformImplementation {
~PlatformImplementation() { comptr<ID3DX11EffectPass> dxPass = nullptr;
if (dxPass) { comptr<ID3D11DeviceContext> dxContext = nullptr;
dxPass->Release();
dxPass = nullptr;
}
if (dxContext) {
dxContext->Release();
dxContext = nullptr;
}
}
ID3DX11EffectPass* dxPass = nullptr;
ID3D11DeviceContext* dxContext = nullptr;
}; };
struct EffectTechnique::PlatformImplementation { struct EffectTechnique::PlatformImplementation {
~PlatformImplementation() { comptr<ID3DX11EffectTechnique> dxTechnique = nullptr;
if (dxTechnique) { comptr<ID3D11DeviceContext> dxContext = nullptr;
dxTechnique->Release();
dxTechnique = nullptr;
}
if (dxContext) {
dxContext->Release();
dxContext = nullptr;
}
}
ID3DX11EffectTechnique* dxTechnique = nullptr;
ID3D11DeviceContext* dxContext = nullptr;
}; };
struct EffectParameter::PlatformImplementation { struct EffectParameter::PlatformImplementation {
PlatformImplementation(){} comptr<ID3DX11EffectVariable> dxVariable = nullptr;
PlatformImplementation(ID3DX11EffectVariable* value) {
dxVariable = value;
dxVariable->AddRef();
}
~PlatformImplementation() {
if (dxVariable) {
dxVariable->Release();
dxVariable = nullptr;
}
}
ID3DX11EffectVariable* dxVariable = nullptr;
}; };
template <typename T> template <typename T>
@ -1076,7 +895,17 @@ namespace xna {
Exception::Throw(ExMessage::InitializeComponent); Exception::Throw(ExMessage::InitializeComponent);
} }
const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_INDEX_BUFFER, &impl->dxBuffer); if (impl->dxBuffer) {
impl->dxBuffer = nullptr;
}
const auto hr = DirectX::CreateStaticBuffer(
m_device->impl->_device.Get(),
data.data(),
data.size(),
sizeof(T),
D3D11_BIND_INDEX_BUFFER,
impl->dxBuffer.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);
@ -1091,7 +920,13 @@ namespace xna {
Exception::Throw(ExMessage::InitializeComponent); Exception::Throw(ExMessage::InitializeComponent);
} }
const auto hr = DirectX::CreateStaticBuffer(m_device->impl->_device, data.data(), data.size(), sizeof(T), D3D11_BIND_VERTEX_BUFFER, &impl->dxBuffer); const auto hr = DirectX::CreateStaticBuffer(
m_device->impl->_device.Get(),
data.data(),
data.size(),
sizeof(T),
D3D11_BIND_VERTEX_BUFFER,
impl->dxBuffer.GetAddressOf());
if (FAILED(hr)) { if (FAILED(hr)) {
Exception::Throw(ExMessage::CreateComponent); Exception::Throw(ExMessage::CreateComponent);