Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKissaki <kissaki@gmx.de>2013-12-01 01:00:56 +0400
committerKissaki <kissaki@gmx.de>2014-01-11 01:51:11 +0400
commit9544bec1f927cf2df793e4856deaa9894ea8ffc5 (patch)
tree5b93dd9cee0e8312facd948e3651262c0e21de80 /overlay/D11StateBlock.cpp
parentda6c2444188432bc48edc6be99d8ac5014f54e0a (diff)
Overlay: Add Direct3D 11 support
* Based on an initial patch by Benjamin Jemlich * Effects11 code based on changes by nyet
Diffstat (limited to 'overlay/D11StateBlock.cpp')
-rw-r--r--overlay/D11StateBlock.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/overlay/D11StateBlock.cpp b/overlay/D11StateBlock.cpp
new file mode 100644
index 000000000..2695d2564
--- /dev/null
+++ b/overlay/D11StateBlock.cpp
@@ -0,0 +1,131 @@
+/* Copyright (C) 2011-2013, Nye Liu <nyet@nyet.org>
+ Copyright (C) 2011-2013, Kissaki <kissaki@gmx.de>
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ - Neither the name of the Mumble Developers nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "D11StateBlock.h"
+
+void D11CreateStateBlock(ID3D11DeviceContext *pDeviceContext, D11StateBlock **ppStateBlock)
+{
+ *ppStateBlock = new D11StateBlock(pDeviceContext);
+}
+
+D11StateBlock::D11StateBlock(ID3D11DeviceContext *pDC)
+ : pRasterizerState(0), uiSampleMask(0)
+ , Format(DXGI_FORMAT_UNKNOWN), Topology(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED)
+ , pBlendState(0), pIndexBuffer(0), pInputLayout(0), uiOffset(0)
+ , pDepthStencilView(0) {
+ uiNumViewports = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
+ ZeroMemory(pViewports, sizeof(pViewports));
+ ZeroMemory(pRenderTargetViews, sizeof (pRenderTargetViews));
+ ZeroMemory(fBlendFactor, sizeof (fBlendFactor));
+ ZeroMemory(pVertexBuffers, sizeof (pVertexBuffers));
+ ZeroMemory(uiStrides, sizeof (uiStrides));
+ ZeroMemory(uiOffsets, sizeof (uiOffsets));
+
+ pDeviceContext = pDC;
+ pDeviceContext->AddRef();
+}
+
+D11StateBlock::~D11StateBlock() {
+ ReleaseObjects();
+ pDeviceContext->Release();
+}
+
+void D11StateBlock::Capture()
+{
+ // Release potential references to make sure we have no leaks.
+ ReleaseObjects();
+
+ pDeviceContext->RSGetState(&pRasterizerState);
+ uiNumViewports = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
+ pDeviceContext->RSGetViewports(&uiNumViewports, pViewports);
+ pDeviceContext->OMGetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, &pDepthStencilView);
+ pDeviceContext->OMGetBlendState(&pBlendState, fBlendFactor, &uiSampleMask);
+ pDeviceContext->IAGetInputLayout(&pInputLayout);
+ pDeviceContext->IAGetIndexBuffer(&pIndexBuffer, &Format, &uiOffset);
+ pDeviceContext->IAGetPrimitiveTopology(&Topology);
+ pDeviceContext->IAGetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, pVertexBuffers, uiStrides, uiOffsets);
+}
+
+void D11StateBlock::Apply()
+{
+ pDeviceContext->RSSetState(pRasterizerState);
+ pDeviceContext->RSSetViewports(uiNumViewports, pViewports);
+ pDeviceContext->OMSetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, pDepthStencilView);
+ pDeviceContext->OMSetBlendState(pBlendState, fBlendFactor, uiSampleMask);
+ pDeviceContext->IASetInputLayout(pInputLayout);
+ pDeviceContext->IASetIndexBuffer(pIndexBuffer, Format, uiOffset);
+ pDeviceContext->IASetPrimitiveTopology(Topology);
+ pDeviceContext->IASetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, pVertexBuffers, uiStrides, uiOffsets);
+ ReleaseObjects();
+}
+
+/// Release state information
+void D11StateBlock::ReleaseObjects()
+{
+ if (pRasterizerState) {
+ pRasterizerState->Release();
+ pRasterizerState = NULL;
+ }
+
+ for (int i=0; i<D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
+ if (pRenderTargetViews[i]) {
+ pRenderTargetViews[i]->Release();
+ pRenderTargetViews[i] = NULL;
+ }
+
+
+ if (pDepthStencilView) {
+ pDepthStencilView->Release();
+ pDepthStencilView = NULL;
+ }
+
+ if (pBlendState) {
+ pBlendState->Release();
+ pBlendState = NULL;
+ }
+
+ if (pInputLayout) {
+ pInputLayout->Release();
+ pInputLayout = NULL;
+ }
+
+ if (pIndexBuffer) {
+ pIndexBuffer->Release();
+ pIndexBuffer = NULL;
+ }
+
+ for (int i=0; i<D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++)
+ if (pVertexBuffers[i]) {
+ pVertexBuffers[i]->Release();
+ pVertexBuffers[i] = NULL;
+ }
+
+}