void D2DComponent::BeginDraw(Windows::Foundation::Rect updateRect)
{
	Microsoft::WRL::ComPtr<IDXGISurface> surface;
	POINT offset;
	RECT updateRectNative =
	{
		(LONG)updateRect.Left,
		(LONG)updateRect.Top,
		(LONG)updateRect.Right,
		(LONG)updateRect.Bottom
	};

	HRESULT beginDrawHR = _sisNative->BeginDraw(updateRectNative, &surface, &offset);
	if (beginDrawHR == DXGI_ERROR_DEVICE_REMOVED || beginDrawHR == DXGI_ERROR_DEVICE_RESET)
	{
		CreateDeviceResources();
		BeginDraw(updateRect);
	}
	else
	{
		ThrowIfFailed(beginDrawHR);
	}


	Microsoft::WRL::ComPtr<ID2D1Bitmap1> bitmap;
	ThrowIfFailed(_d2dDeviceContext->CreateBitmapFromDxgiSurface(surface.Get(), nullptr, &bitmap));
	_d2dDeviceContext->BeginDraw();
	_d2dDeviceContext->SetTarget(bitmap.Get());
}
IFACEMETHODIMP CTriColorControlProvider::GetSelection(_Outptr_result_maybenull_ SAFEARRAY * *retVal) 
{ 
    *retVal = nullptr;
    HRESULT hr = CheckDisconnected();
    if (SUCCEEDED(hr))
    {
        TriColorValue controlValue;
        hr = m_control->get_ControlValue(&controlValue);
        if (SUCCEEDED(hr))
        {
            ComPtr<IInspectable> spFragmentProvider;
            hr = m_control->GetTriColorFragmentProvider(controlValue, &spFragmentProvider);
            if (SUCCEEDED(hr))
            {
                *retVal = SafeArrayCreateVector(VT_UNKNOWN, 0, 1);
                if (*retVal != nullptr)
                {
                    long index = 0;
                    hr = SafeArrayPutElement(*retVal, &index, spFragmentProvider.Get());
                    if (FAILED(hr))
                    {
                        SafeArrayDestroy(*retVal);
                        *retVal = nullptr;
                    }
                }
                else
                {
                    hr = E_OUTOFMEMORY;
                }
            }
        }
    }

    return hr; 
}
//-------------------------------------------------------------------
// GetFloatProperty
// 
//-------------------------------------------------------------------
float CObjectFinderEffect::GetFloatProperty(
	Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable *>> &spSetting,
	const HSTRING &key, boolean &found)
{
	float value = 0.0f;

	spSetting->HasKey(key, &found);
	IInspectable* valueAsInsp = NULL;

	if (found)
	{
		spSetting->Lookup(key, &valueAsInsp);
	}

	if (valueAsInsp)
	{
		Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IPropertyValue> pPropertyValue;
		HRESULT hr = valueAsInsp->QueryInterface(IID_PPV_ARGS(&pPropertyValue));

		if (!FAILED(hr))
		{
			hr = pPropertyValue->GetSingle(&value);
		}
	}

	return value;
}
IFACEMETHODIMP CTriColorControlProvider::Navigate(_In_ NavigateDirection direction, _Outptr_result_maybenull_ IRawElementProviderFragment ** retVal)
{
    *retVal = nullptr;
    ComPtr<IInspectable> spFragment;
    HRESULT hr = CheckDisconnected();
    if (SUCCEEDED(hr))
    {
        if (direction == NavigateDirection_Parent)
        {
            hr = m_control->GetAppWindowProvider(&spFragment);
        }
        else if (direction == NavigateDirection_FirstChild)
        {
            hr = m_control->GetTriColorFragmentProvider(TriColorValue::Red, &spFragment);
        }
        else if (direction == NavigateDirection_LastChild)
        {
            hr = m_control->GetTriColorFragmentProvider(TriColorValue::Green, &spFragment);
        }
    }

    if (SUCCEEDED(hr) && spFragment != nullptr)
    {
        hr = spFragment.Get()->QueryInterface(IID_PPV_ARGS(retVal));
    }

    // For the other directions (next, previous) the default of nullptr is correct
    return hr;
}
Esempio n. 5
0
void BasicShapes::CreateVertexBuffer(
    _In_ unsigned int numVertices,
    _In_ BasicVertex *vertexData,
    _Out_ ID3D11Buffer **vertexBuffer
    )
{
    *vertexBuffer = nullptr;
    Microsoft::WRL::ComPtr<ID3D11Buffer> vertexBufferInternal;

    D3D11_BUFFER_DESC VertexBufferDesc;
    VertexBufferDesc.ByteWidth = sizeof(BasicVertex) * numVertices;
    VertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    VertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    VertexBufferDesc.CPUAccessFlags = 0;
    VertexBufferDesc.MiscFlags = 0;
    VertexBufferDesc.StructureByteStride = 0;

    D3D11_SUBRESOURCE_DATA VertexBufferData;
    VertexBufferData.pSysMem = vertexData;
    VertexBufferData.SysMemPitch = 0;
    VertexBufferData.SysMemSlicePitch = 0;

    DX::ThrowIfFailed(
        m_d3dDevice->CreateBuffer(
            &VertexBufferDesc,
            &VertexBufferData,
            &vertexBufferInternal
            )
        );


    *vertexBuffer = vertexBufferInternal.Detach();
}
Esempio n. 6
0
void BasicShapes::CreateIndexBuffer(
    _In_ unsigned int numIndices,
    _In_ unsigned short *indexData,
    _Out_ ID3D11Buffer **indexBuffer
    )
{
    *indexBuffer = nullptr;
    Microsoft::WRL::ComPtr<ID3D11Buffer> indexBufferInternal;

    D3D11_BUFFER_DESC IndexBufferDesc;
    IndexBufferDesc.ByteWidth = sizeof(unsigned short) * numIndices;
    IndexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    IndexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
    IndexBufferDesc.CPUAccessFlags = 0;
    IndexBufferDesc.MiscFlags = 0;
    IndexBufferDesc.StructureByteStride = 0;

    D3D11_SUBRESOURCE_DATA IndexBufferData;
    IndexBufferData.pSysMem = indexData;
    IndexBufferData.SysMemPitch = 0;
    IndexBufferData.SysMemSlicePitch = 0;

    DX::ThrowIfFailed(
        m_d3dDevice->CreateBuffer(
            &IndexBufferDesc,
            &IndexBufferData,
            &indexBufferInternal
            )
        );

    *indexBuffer = indexBufferInternal.Detach();
}
Esempio n. 7
0
plaintext_string winrt_encryption::decrypt() const
{
    // To fully guarantee asynchrony would require significant impact on existing code. This code path
    // is never run on a user's thread and is only done once when setting up a connection.
    auto encrypted = m_buffer.get();
    auto provider = ref new Windows::Security::Cryptography::DataProtection::DataProtectionProvider();
    auto plaintext = pplx::create_task(provider->UnprotectAsync(encrypted)).get();

    // Get access to raw bytes in plain text buffer.
    Microsoft::WRL::ComPtr<IInspectable> bufferInspectable(reinterpret_cast<IInspectable *>(plaintext));
    Microsoft::WRL::ComPtr<Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess;
    bufferInspectable.As(&bufferByteAccess);
    byte * rawPlaintext;
    const auto &result = bufferByteAccess->Buffer(&rawPlaintext);
    if (result != S_OK)
    {
        throw ::utility::details::create_system_error(result);
    }

    // Construct string and zero out memory from plain text buffer.
    auto data = plaintext_string(new std::wstring(
        reinterpret_cast<const std::wstring::value_type *>(rawPlaintext),
        plaintext->Length / 2));
    SecureZeroMemory(rawPlaintext, plaintext->Length);
    return std::move(data);
}
Esempio n. 8
0
Handle Create(size_t hash, const void* data, size_t data_size, ID3D11Device* device) {
  auto cached_handle = g_cache_.Get(hash);
  if (cached_handle.IsValid()) {
    return cached_handle;
  }

  D3D11_BUFFER_DESC bufferDesc;
  ZeroMemory(&bufferDesc, sizeof(bufferDesc));

  bufferDesc.Usage = D3D11_USAGE_DEFAULT;
  bufferDesc.ByteWidth = data_size;
  bufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
  bufferDesc.CPUAccessFlags = 0;
  bufferDesc.MiscFlags = 0;

  D3D11_SUBRESOURCE_DATA bufferData;
  ZeroMemory(&bufferData, sizeof(bufferData));
  bufferData.pSysMem = data;

  Microsoft::WRL::ComPtr<ID3D11Buffer> buffer;
  HRESULT create_buffer_result = device->CreateBuffer(&bufferDesc, &bufferData, buffer.GetAddressOf());

  if (FAILED(create_buffer_result)) {
    DXFW_DIRECTX_TRACE(__FILE__, __LINE__, true, create_buffer_result);
    return {};
  }

  auto new_handle = g_storage_.Add(buffer);
  g_cache_.Set(hash, new_handle);
  return new_handle;
}
Esempio n. 9
0
void Model::Create()
{
	CreateRootSignature();
	CreatePipelineState();

	Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CommandAllocator;
	Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> CommandList;
	Microsoft::WRL::ComPtr<ID3D12Resource> VertexUploadResource;
	Microsoft::WRL::ComPtr<ID3D12Resource> IndexUploadResource;
	GPUFence Fence;

	Fence.Initialize(DeviceContext.GetDevice());
	Utility::ThrowOnFail(DeviceContext.GetDevice()->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&CommandAllocator)));
	Utility::ThrowOnFail(DeviceContext.GetDevice()->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, CommandAllocator.Get(), nullptr, IID_PPV_ARGS(&CommandList)));
	
	UploadVertices(CommandList, VertexUploadResource);
	UploadIndices(CommandList, IndexUploadResource);

	Utility::ThrowOnFail(CommandList->Close());

	ID3D12CommandList * CommandListPointer = CommandList.Get();
	DeviceContext.GetCommandQueue()->ExecuteCommandLists(1, &CommandListPointer);

	Fence.SetAndWait(DeviceContext.GetCommandQueue());
}
HRESULT CompileShaderFromFile(const std::wstring &file
        , const StageInfo &info, ID3D10Blob** ppBlobOut)
{
    DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined(DEBUG) || defined(_DEBUG)
    dwShaderFlags |= D3DCOMPILE_DEBUG;
#endif//defiend(DEBUG) || defined(_DEBUG)
#if defined(NDEBUG) || defined(_NDEBUG)
    dwShaderFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3;
#endif//defined(NDEBUG) || defined(_NDEBUG)

    Microsoft::WRL::ComPtr<ID3DBlob> pErrorBlob;
    auto hr = D3DCompileFromFile(
            file.c_str()
            , NULL
            , D3D_COMPILE_STANDARD_FILE_INCLUDE
            , info.entrypoint.c_str()
            , info.model.c_str()
            , dwShaderFlags
            , 0
            , ppBlobOut
            , pErrorBlob.GetAddressOf() 
            );
    if ( FAILED( hr ) ) {
        if (pErrorBlob) { 
            // エラーメッセージを出力.
            OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() ); 
        }
    }

    return hr;
}
Esempio n. 11
0
	ID3D11DepthStencilView* CreateDepthStencilView(ID3D11Device* pDevice,DWORD dwWidth, DWORD dwHeight)
	{
		HRESULT hr;
		ID3D11DepthStencilView* pDSV = nullptr;
		Microsoft::WRL::ComPtr<ID3D11Texture2D> pDSTexture = nullptr;
		D3D11_TEXTURE2D_DESC DescDepth;
		DescDepth.Width = dwWidth;
		DescDepth.Height = dwHeight;
		DescDepth.MipLevels = 1;
		DescDepth.ArraySize = 1;
		DescDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
		DescDepth.SampleDesc.Count = 1;
		DescDepth.SampleDesc.Quality = 0;
		DescDepth.Usage = D3D11_USAGE_DEFAULT;
		DescDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
		DescDepth.CPUAccessFlags = 0;
		DescDepth.MiscFlags = 0;
		if (FAILED(hr = pDevice->CreateTexture2D(&DescDepth, NULL, &pDSTexture)))
		{
			return nullptr;
		}

		D3D11_DEPTH_STENCIL_VIEW_DESC dsvd;
		ZeroMemory(&dsvd, sizeof(dsvd));
		dsvd.Format = DescDepth.Format;
		dsvd.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
		dsvd.Texture2D.MipSlice = 0;

		if (FAILED(hr = pDevice->CreateDepthStencilView(
			pDSTexture.Get(), &dsvd, &pDSV)))
		{			
			return nullptr;
		}		
		return pDSV;
	}
Esempio n. 12
0
void Model::CreatePipelineState()
{
	Microsoft::WRL::ComPtr<ID3DBlob> VertexShader;
	Microsoft::WRL::ComPtr<ID3DBlob> PixelShader;

	LoadAndCompileShader(VertexShader, PixelShader);

	std::array<D3D12_INPUT_ELEMENT_DESC, 2> InputElementDesc
	{ {
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
	} };

	D3D12_GRAPHICS_PIPELINE_STATE_DESC PipelineStateDesc = {};
	PipelineStateDesc.InputLayout = { InputElementDesc.data(), static_cast<UINT>(InputElementDesc.size()) };
	PipelineStateDesc.pRootSignature = RootSignature.Get();
	PipelineStateDesc.VS = CD3DX12_SHADER_BYTECODE(VertexShader.Get());
	PipelineStateDesc.PS = CD3DX12_SHADER_BYTECODE(PixelShader.Get());
	PipelineStateDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
	PipelineStateDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
	PipelineStateDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
	PipelineStateDesc.SampleMask = UINT_MAX;
	PipelineStateDesc.SampleDesc.Count = 1;
	PipelineStateDesc.NumRenderTargets = 1;
	PipelineStateDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
	PipelineStateDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT;
	PipelineStateDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;

	Utility::ThrowOnFail(DeviceContext.GetDevice()->CreateGraphicsPipelineState(&PipelineStateDesc, IID_PPV_ARGS(&PipelineState)));
}
Esempio n. 13
0
RoundedRectangle::RoundedRectangle(FLOAT x, FLOAT y, FLOAT width, FLOAT height,
	FLOAT xRadius, FLOAT yRadius) : Shape(ShapeType::RoundedRectangle),
		m_X(x),
		m_Y(y),
		m_Width(width + x),
		m_Height(height + y),
		m_XRadius(xRadius),
		m_YRadius(yRadius)
{
	HRESULT hr = E_FAIL;
	const D2D1_ROUNDED_RECT rect = { m_X, m_Y, m_Width, m_Height, m_XRadius, m_YRadius };

	Microsoft::WRL::ComPtr<ID2D1RoundedRectangleGeometry> rectangle;
	hr = Canvas::c_D2DFactory->CreateRoundedRectangleGeometry(rect, rectangle.GetAddressOf());
	if (FAILED(hr))
	{
		LogErrorF(
			L"Could not create rounded rectangle object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i",
			(int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius);
		return;
	}

	hr = rectangle.CopyTo(m_Shape.GetAddressOf());
	if (FAILED(hr)) LogErrorF(
		L"Could not copy rounded rectangle object to shape object. X=%i, Y=%i, W=%i, H=%i, XRadius=%i, YRadius=%i",
		(int)m_X, (int)m_Y, (int)m_Width, (int)m_Height, (int)m_XRadius, (int)m_YRadius);
}
Esempio n. 14
0
HRESULT sound_xaudio2::create_voices(const WAVEFORMATEX &format)
{
	assert(m_xAudio2);
	assert(!m_masterVoice);
	HRESULT result;

	IXAudio2MasteringVoice *temp_master_voice = nullptr;
	HR_RETHR(
		m_xAudio2->CreateMasteringVoice(
			&temp_master_voice,
			format.nChannels,
			sample_rate()));

	m_masterVoice = mastering_voice_ptr(temp_master_voice);

	// create the source voice
	IXAudio2SourceVoice *temp_source_voice = nullptr;
	HR_RETHR(m_xAudio2->CreateSourceVoice(
		&temp_source_voice,
		&format,
		XAUDIO2_VOICE_NOSRC | XAUDIO2_VOICE_NOPITCH,
		1.0,
		this));

	m_sourceVoice = src_voice_ptr(temp_source_voice);

	return S_OK;
}
Esempio n. 15
0
Arc::Arc(FLOAT x1, FLOAT y1, FLOAT x2, FLOAT y2, FLOAT xRadius, FLOAT yRadius, FLOAT angle,
	D2D1_SWEEP_DIRECTION sweep, D2D1_ARC_SIZE size, D2D1_FIGURE_END ending) : Shape(ShapeType::Arc),
	m_StartPoint(D2D1::Point2F(x1, y1)),
	m_ArcSegment(D2D1::ArcSegment(
		D2D1::Point2F(x2, y2),
		D2D1::SizeF(xRadius, yRadius),
		angle,
		sweep,
		size)),
	m_ShapeEnding(ending)
{
	Microsoft::WRL::ComPtr<ID2D1GeometrySink> sink;
	Microsoft::WRL::ComPtr<ID2D1PathGeometry> path;
	HRESULT hr = Canvas::c_D2DFactory->CreatePathGeometry(path.GetAddressOf());
	if (SUCCEEDED(hr))
	{
		hr = path->Open(sink.GetAddressOf());
		if (SUCCEEDED(hr))
		{
			sink->BeginFigure(m_StartPoint, D2D1_FIGURE_BEGIN_FILLED);
			sink->AddArc(m_ArcSegment);
			sink->EndFigure(m_ShapeEnding);
			sink->Close();

			hr = path.CopyTo(m_Shape.GetAddressOf());
			if (SUCCEEDED(hr)) return;
		}
	}

	LogErrorF(L"Could not create arc object. X1=%i, Y1=%i, X2=%i, Y2=%i, XRadius=%i, YRadius=%i, Angle=%i",
		(int)x1, (int)y1, (int)x2, (int)y2, (int)xRadius, (int)yRadius, (int)angle);
}
Esempio n. 16
0
	bool createIB(const Microsoft::WRL::ComPtr<ID3D11Device> &pDevice)
	{
		unsigned int pIndices[] =
		{
			0, 1, 2, 2, 3, 0,
			4, 5, 6, 6, 7, 4,
			8, 9, 10, 10, 11, 8,
			12, 13, 14, 14, 15, 12,
			16, 17, 18, 18, 19, 16,
			20, 21, 22, 22, 23, 20,
		};
		unsigned int isize = sizeof(pIndices);
		m_indices = isize / sizeof(pIndices[0]);

		D3D11_BUFFER_DESC idesc;
		ZeroMemory(&idesc, sizeof(idesc));
		idesc.ByteWidth = isize;
		idesc.Usage = D3D11_USAGE_DEFAULT;
		idesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
		idesc.CPUAccessFlags = 0;

		D3D11_SUBRESOURCE_DATA indexData;
		ZeroMemory(&indexData, sizeof(indexData));
		indexData.pSysMem = pIndices;

		HRESULT hr = pDevice->CreateBuffer(&idesc, &indexData, m_pIndexBuf.GetAddressOf());
		if (FAILED(hr)){
			return false;
		}

		return true;
	}
Esempio n. 17
0
void Shader::Draw(const Microsoft::WRL::ComPtr<ID3D11DeviceContext> &pDeviceContext)
{
    // VS
    pDeviceContext->VSSetShader(m_pVsh.Get(), NULL, 0);

    // PS
    pDeviceContext->PSSetShader(m_pPsh.Get(), NULL, 0);

	// 定数バッファ
	m_constant->UpdateCB(pDeviceContext);
	m_constant->SetCB(pDeviceContext);

	// Texture
	{
		auto v = m_constant->GetSRV("diffuseTexture");
		m_constant->SetSRV(pDeviceContext, v, m_texture->GetSRV());
	}
	{
		auto v = m_constant->GetSampler("diffuseTextureSampler");
		m_constant->SetSampler(pDeviceContext, v, m_texture->GetSampler());
	}

    // IA InputLayout
    pDeviceContext->IASetInputLayout(m_pInputLayout.Get());
    m_IASource->Draw(pDeviceContext);
}
Esempio n. 18
0
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* gdiFamilyName)
{
	Microsoft::WRL::ComPtr<IDWriteGdiInterop> dwGdiInterop;
	HRESULT hr = factory->GetGdiInterop(dwGdiInterop.GetAddressOf());
	if (SUCCEEDED(hr))
	{
		LOGFONT lf = {};
		wcscpy_s(lf.lfFaceName, gdiFamilyName);
		lf.lfHeight = -12;
		lf.lfWeight = FW_DONTCARE;
		lf.lfCharSet = DEFAULT_CHARSET;
		lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
		lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
		lf.lfQuality = ANTIALIASED_QUALITY;
		lf.lfPitchAndFamily = VARIABLE_PITCH;

		IDWriteFont* dwFont;
		hr = dwGdiInterop->CreateFontFromLOGFONT(&lf, &dwFont);
		if (SUCCEEDED(hr))
		{
			return dwFont;
		}
	}

	return nullptr;
}
Esempio n. 19
0
IFACEMETHODIMP CTriColorFragmentProvider::Navigate(_In_ NavigateDirection direction, _Outptr_result_maybenull_ IRawElementProviderFragment ** retVal)
{
    *retVal = nullptr;
    ComPtr<IInspectable> spFragment;
    HRESULT hr = CheckDisconnected();
    if (SUCCEEDED(hr))
    {
        if (direction == NavigateDirection_Parent)
        {
            hr = m_control->GetTriColorControlProvider(&spFragment);
        }
        else if (direction == NavigateDirection_NextSibling)
        {
            if (!TriColorValueHelper::IsLast(m_value))
            {
                hr = m_control->GetTriColorFragmentProvider(TriColorValueHelper::NextValue(m_value), &spFragment);
            }
        }
        else if (direction == NavigateDirection_PreviousSibling)
        {
            if (!TriColorValueHelper::IsFirst(m_value))
            {
                hr = m_control->GetTriColorFragmentProvider(TriColorValueHelper::PreviousValue(m_value), &spFragment);
            }
        }
    }

    if (SUCCEEDED(hr) && spFragment != nullptr)
    {
        hr = spFragment.Get()->QueryInterface(IID_PPV_ARGS(retVal));
    }

    // For the other directions (first child, last child) the default of nullptr is correct
    return hr;
}
ID3D12DescriptorHeap* DynamicDescriptorHeap::RequestDescriptorHeap(void)
{
	std::lock_guard<std::mutex> LockGuard(sm_Mutex);

	while (!sm_RetiredDescriptorHeaps.empty() && g_CommandManager.IsFenceComplete(sm_RetiredDescriptorHeaps.front().first))
	{
		sm_AvailableDescriptorHeaps.push(sm_RetiredDescriptorHeaps.front().second);
		sm_RetiredDescriptorHeaps.pop();
	}

	if (!sm_AvailableDescriptorHeaps.empty())
	{
		ID3D12DescriptorHeap* HeapPtr = sm_AvailableDescriptorHeaps.front();
		sm_AvailableDescriptorHeaps.pop();
		return HeapPtr;
	}
	else
	{
		D3D12_DESCRIPTOR_HEAP_DESC HeapDesc = {};
		HeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
		HeapDesc.NumDescriptors = kNumDescriptorsPerHeap;
		HeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
		HeapDesc.NodeMask = 1;
		Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> HeapPtr;
		ASSERT_SUCCEEDED(g_Device->CreateDescriptorHeap(&HeapDesc, MY_IID_PPV_ARGS(&HeapPtr)));
		sm_DescriptorHeapPool.emplace_back(HeapPtr);
		return HeapPtr.Get();
	}
}
Esempio n. 21
0
HRESULT Trace::GetMediaProperties(ComPtr<ILoggingFields> *pFields,IMFMediaType *pMediaType)
{
	using namespace ABI::Windows::Media::MediaProperties;

	HRESULT hr = CreateLoggingFields(pFields);

	if (pMediaType != nullptr)
	{
		Microsoft::WRL::ComPtr<IMediaEncodingProperties> spMediaProps;

		HRESULT hr = MFCreatePropertiesFromMediaType(pMediaType, IID_PPV_ARGS(&spMediaProps));
		if (FAILED(hr))
			return hr;
		
		HSTRING hsMediaType = 0;
		spMediaProps->get_Type(&hsMediaType);
		HSTRING hsMediaSubType = 0;
		spMediaProps->get_Subtype(&hsMediaSubType);
		(*pFields)->AddString(HStringReference(L"Type").Get(), hsMediaType);
		(*pFields)->AddString(HStringReference(L"SubType").Get(), hsMediaSubType);
		UINT32 samplesPerSecond = 0;
		hr = pMediaType->GetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, &samplesPerSecond);
		if (SUCCEEDED(hr))
			(*pFields)->AddUInt32(HStringReference(L"SampleRate").Get(), samplesPerSecond);
		UINT32 numChannels;
		hr = pMediaType->GetUINT32(MF_MT_AUDIO_NUM_CHANNELS, &numChannels);
		if (SUCCEEDED(hr))
			(*pFields)->AddUInt32(HStringReference(L"Channels").Get(), numChannels);
	}
	else
	{
		(*pFields)->AddEmpty(HStringReference(L"Type").Get());
	}
	return hr;
}
Esempio n. 22
0
void Shape::CreateRadialGradient(ID2D1RenderTarget* target, ID2D1GradientStopCollection* collection,
	Microsoft::WRL::ComPtr<ID2D1Brush>& brush, bool isStroke)
{
	auto swapIfNotDefined = [](D2D1_POINT_2F& pt1, const D2D1_POINT_2F pt2) -> void
	{
		if (pt2.x != FLT_MAX) pt1.x = pt2.x;
		if (pt2.y != FLT_MAX) pt1.y = pt2.y;
	};

	auto bounds = GetBounds(false);
	D2D1_POINT_2F offset = D2D1::Point2F();
	D2D1_POINT_2F center = D2D1::Point2F(((bounds.left + bounds.right) / 2.0f), ((bounds.top + bounds.bottom) / 2.0f));
	D2D1_POINT_2F radius = D2D1::Point2F((bounds.right - bounds.left) / 2.0f, (bounds.bottom - bounds.top) / 2.0f);

	// Offset from actual center of shape
	center = Util::AddPoint2F(center, isStroke ? m_StrokeRadialGradientCenter : m_FillRadialGradientCenter);

	// Check if offset and radii are defined
	swapIfNotDefined(offset, isStroke ? m_StrokeRadialGradientOffset : m_FillRadialGradientOffset);
	swapIfNotDefined(radius, isStroke ? m_StrokeRadialGradientRadius : m_FillRadialGradientRadius);

	Microsoft::WRL::ComPtr<ID2D1RadialGradientBrush> radial;
	HRESULT hr = target->CreateRadialGradientBrush(
		D2D1::RadialGradientBrushProperties(
			center,
			offset,
			radius.x,
			radius.y),
		collection,
		radial.GetAddressOf());

	if (SUCCEEDED(hr)) radial.CopyTo(brush.ReleaseAndGetAddressOf());
}
Esempio n. 23
0
void Shape::CreateSolidBrush(ID2D1RenderTarget* target, Microsoft::WRL::ComPtr<ID2D1Brush>& brush,
	const D2D1_COLOR_F& color)
{
	Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> solid;
	HRESULT hr = target->CreateSolidColorBrush(color, solid.GetAddressOf());

	if (SUCCEEDED(hr)) solid.CopyTo(brush.ReleaseAndGetAddressOf());
}
Esempio n. 24
0
void glClear(GLbitfield mask)
{
    if( g_pD3DContext )
    {
        g_pD3DContext->ClearRenderTargetView( g_pD3DRenderTargetView.Get(), g_ClearColor );
        g_pD3DContext->ClearDepthStencilView( g_pD3DDepthStencilView.Get(), D3D11_CLEAR_DEPTH, 1.0f, 0 );
    }
}
Esempio n. 25
0
void D3DCreateDepthStencilStates()
{
    HRESULT result;

    D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
    ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));

    depthDisabledStencilDesc.DepthEnable = true;
    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
    depthDisabledStencilDesc.StencilEnable = true;
    depthDisabledStencilDesc.StencilReadMask = 0xFF;
    depthDisabledStencilDesc.StencilWriteMask = 0xFF;
    depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
    depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
    depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
    depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
    depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;

    // Test: Enabled    Write: Enabled
    depthDisabledStencilDesc.DepthEnable = true;
    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    result = g_pD3DDevice->CreateDepthStencilState( &depthDisabledStencilDesc, &g_pD3DDepthStencilState_DepthTestEnabled_DepthWriteEnabled );
    if( FAILED( result ) )
    {
        LOGInfo( LOGTag, "Failed to create DepthStencilState\n" );
    }

    // Test: Disabled   Write: Enabled
    depthDisabledStencilDesc.DepthEnable = false;
    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
    result = g_pD3DDevice->CreateDepthStencilState( &depthDisabledStencilDesc, &g_pD3DDepthStencilState_DepthTestDisabled_DepthWriteEnabled );
    if( FAILED( result ) )
    {
        LOGInfo( LOGTag, "Failed to create DepthStencilState\n" );
    }

    // Test: Enabled    Write: Disabled
    depthDisabledStencilDesc.DepthEnable = true;
    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
    result = g_pD3DDevice->CreateDepthStencilState( &depthDisabledStencilDesc, &g_pD3DDepthStencilState_DepthTestEnabled_DepthWriteDisabled );
    if( FAILED( result ) )
    {
        LOGInfo( LOGTag, "Failed to create DepthStencilState\n" );
    }

    // Test: Disabled   Write: Disabled
    depthDisabledStencilDesc.DepthEnable = false;
    depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
    result = g_pD3DDevice->CreateDepthStencilState( &depthDisabledStencilDesc, &g_pD3DDepthStencilState_DepthTestDisabled_DepthWriteDisabled );
    if( FAILED( result ) )
    {
        LOGInfo( LOGTag, "Failed to create DepthStencilState\n" );
    }
}
// Initializes D2D resources used for text rendering.
SampleDebugTextRenderer::SampleDebugTextRenderer(const std::shared_ptr<DX::DeviceResources>& deviceResources) :
Overlay(deviceResources)
{
    ZeroMemory(&m_textMetrics, sizeof(DWRITE_TEXT_METRICS) * XINPUT_MAX_CONTROLLERS);
    ZeroMemory(&m_textMetricsFPS, sizeof(DWRITE_TEXT_METRICS));

    for (unsigned int i = 0; i < 4; i++)
    {
        m_text[i] = L"";
    }
    // Create device-independent resources.
    DX::ThrowIfFailed(
        m_deviceResources->GetDWriteFactory()->CreateTextFormat(
        L"Segoe UI",
        nullptr,
        DWRITE_FONT_WEIGHT_LIGHT,
        DWRITE_FONT_STYLE_NORMAL,
        DWRITE_FONT_STRETCH_NORMAL,
        32.0f,
        L"en-US",
        &m_textFormat
        )
        );

    DX::ThrowIfFailed(
        m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR)
        );

    DX::ThrowIfFailed(
        m_deviceResources->GetD2DFactory()->CreateDrawingStateBlock(&m_stateBlock)
        );


    // Generate static input text height.
    unsigned int lines = 6; // Increase this if you need to display more than 5 separate action types
    std::wstring inputText = L"";
    for (unsigned int i = 0; i < lines; i++) inputText += L"\n";

    Microsoft::WRL::ComPtr<IDWriteTextLayout> layout;
    DX::ThrowIfFailed(
        m_deviceResources->GetDWriteFactory()->CreateTextLayout(
        inputText.c_str(),
        (uint32) inputText.length(),
        m_textFormat.Get(),
        DEBUG_INPUT_TEXT_MAX_WIDTH,
        DEBUG_INPUT_TEXT_MAX_HEIGHT,
        &layout
        )
        );
    DWRITE_TEXT_METRICS metrics;
    DX::ThrowIfFailed(
        layout->GetMetrics(&metrics)
        );
    m_inputTextHeight = metrics.height;

    CreateDeviceDependentResources();
}
Esempio n. 27
0
    HRESULT CallPlmToEnableDebugging()
    {
		// Calling public API. 
		// EnableDebugging() implementation lives in COMBASE.DLL loaded into Explorer.exe's address space. 
		// Explorer's security token is used on invocation. Since Explorer and this code might run under 
		// different users, the following call might fail. 
		HRESULT hr = m_packageDebugSettings->EnableDebugging(m_packageName, m_debuggerString, m_environmentVars);

		// Calling internal API on failure. 
		// It's almost identical code like in EnableDebugging() but it uses a security token of the curent process.
		if (FAILED(hr) && hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
		{
			if (m_debuggerString != nullptr || 
			    m_environmentVars != nullptr)
			{
				// Enable debug on activation
				hr = ::RoEnableDebuggingForPackage(m_packageName, m_debuggerString, m_environmentVars);
				if (FAILED(hr))
				{
					return hr;
				}
			}
			
			// Disable activation timeouts
			Microsoft::WRL::ComPtr<IApplicationActivationManagerPriv> spActivationManager;
			hr = CoCreateInstance(CLSID_ApplicationActivationManager, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spActivationManager));
			if (FAILED(hr))
			{
				return hr;
			}
			if (SUCCEEDED(hr))
			{
				hr = spActivationManager->PutPackageActivationSettings(Windows::Internal::StringReference(m_packageName).Get(), PAS_NORPCTIMEOUTS, PAS_NORPCTIMEOUTS);

				// CImmersiveApplicationDebugControlInternal, which implements IPackageDebugSettings,
				// does the following. We don't have an ISuspendResumeController, so we don't do it.
				// This must be what disables suspend/resume on the app (to aid debugging).
				// We probably don't need it for iDNA.
				//if (SUCCEEDED(hr))
				//{
				//    hr = _spSuspendResumeController->OnDebugModeEnabled(m_packageName);
				//}
			}
			
			// Roll back on failure.
			if (FAILED(hr))
			{
				HRESULT const disableHr = CallPlmToDisableDebugging();
				if (FAILED(disableHr))
				{
					LogError(disableHr, L"CallPlmToDisableDebugging() reported an error while aborting in CallPlmToEnableDebugging() .\n");
				}
			}
		}
		
		return hr;		
    }
Esempio n. 28
0
void MazeWallObstacle::Render( Microsoft::WRL::ComPtr<ID2D1DeviceContext> & d2dContext ) const
{
	Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> brush;
	DX::ThrowIfFailed(d2dContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush));
	D2D1_POINT_2F const pt1 = {(float)m_pt1.m_x, (float)m_pt1.m_y};
	D2D1_POINT_2F const pt2 = {(float)m_pt2.m_x, (float)m_pt2.m_y};

	d2dContext->DrawLine(pt1, pt2, brush.Get());
}
	void PrimitveDrawer::End()
	{

		Microsoft::WRL::ComPtr<ID3D11RasterizerState> pRSState;
		m_pContext->RSGetState(&pRSState);
		m_pContext->RSSetState(m_pStates->CullClockwise());
		m_pDirectXBatch->End();
		m_pContext->RSSetState(pRSState.Get());
	}
Esempio n. 30
0
	bool createVB(const Microsoft::WRL::ComPtr<ID3D11Device> &pDevice)
	{
		// Create VB
		auto size = 0.5f;
		Vertex pVertices[] =
		{
			// x
			{ DirectX::XMFLOAT4(-size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) },
			{ DirectX::XMFLOAT4(-size, -size, size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) },
			{ DirectX::XMFLOAT4(-size, size, size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) },
			{ DirectX::XMFLOAT4(-size, size, -size, 1.0f), DirectX::XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) },

			{ DirectX::XMFLOAT4(size, -size, -size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) },
			{ DirectX::XMFLOAT4(size, size, -size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) },
			{ DirectX::XMFLOAT4(size, size, size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) },
			{ DirectX::XMFLOAT4(size, -size, size, 1.0f), DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) },
			// y
			{ DirectX::XMFLOAT4(-size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) },
			{ DirectX::XMFLOAT4(-size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) },
			{ DirectX::XMFLOAT4(size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) },
			{ DirectX::XMFLOAT4(size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) },

			{ DirectX::XMFLOAT4(-size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 1) },
			{ DirectX::XMFLOAT4(size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 1) },
			{ DirectX::XMFLOAT4(size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(1, 0) },
			{ DirectX::XMFLOAT4(-size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.5f, 0.0f, 1.0f), DirectX::XMFLOAT2(0, 0) },
			// z
			{ DirectX::XMFLOAT4(-size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(0, 1) },
			{ DirectX::XMFLOAT4(-size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(0, 0) },
			{ DirectX::XMFLOAT4(size, size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(1, 0) },
			{ DirectX::XMFLOAT4(size, -size, -size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 0.5f, 1.0f), DirectX::XMFLOAT2(1, 1) },

			{ DirectX::XMFLOAT4(-size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(0, 1) },
			{ DirectX::XMFLOAT4(size, -size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(1, 1) },
			{ DirectX::XMFLOAT4(size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(1, 0) },
			{ DirectX::XMFLOAT4(-size, size, size, 1.0f), DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), DirectX::XMFLOAT2(0, 0) },
		};
		unsigned int vsize = sizeof(pVertices);

		D3D11_BUFFER_DESC vdesc;
		ZeroMemory(&vdesc, sizeof(vdesc));
		vdesc.ByteWidth = vsize;
		vdesc.Usage = D3D11_USAGE_DEFAULT;
		vdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
		vdesc.CPUAccessFlags = 0;

		D3D11_SUBRESOURCE_DATA vertexData;
		ZeroMemory(&vertexData, sizeof(vertexData));
		vertexData.pSysMem = pVertices;

		HRESULT hr = pDevice->CreateBuffer(&vdesc, &vertexData, m_pVertexBuf.GetAddressOf());
		if (FAILED(hr)){
			return false;
		}

		return true;
	}