summaryrefslogtreecommitdiffstats
path: root/Tests/TestApp/src/TestBlendState.cpp
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-02-15 07:22:18 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-02-15 07:22:18 +0000
commit5c9450e283d0889987e39ebd13b5a29c110d9e88 (patch)
treefc8c9eb710106d57fe0f18816da9948d10ad7832 /Tests/TestApp/src/TestBlendState.cpp
parentFixed formatting of cmake files + some minor updates (diff)
downloadDiligentEngine-5c9450e283d0889987e39ebd13b5a29c110d9e88.tar.gz
DiligentEngine-5c9450e283d0889987e39ebd13b5a29c110d9e88.zip
Added tests
Diffstat (limited to 'Tests/TestApp/src/TestBlendState.cpp')
-rw-r--r--Tests/TestApp/src/TestBlendState.cpp250
1 files changed, 250 insertions, 0 deletions
diff --git a/Tests/TestApp/src/TestBlendState.cpp b/Tests/TestApp/src/TestBlendState.cpp
new file mode 100644
index 0000000..a01a2fa
--- /dev/null
+++ b/Tests/TestApp/src/TestBlendState.cpp
@@ -0,0 +1,250 @@
+/* Copyright 2015-2017 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+// EngineSandbox.cpp : Defines the entry point for the application.
+//
+
+#include "pch.h"
+#include "TestBlendState.h"
+#include "ConvenienceFunctions.h"
+
+using namespace Diligent;
+
+void TestBlendState::CreateTestBS( BlendStateDesc &BSDesc )
+{
+ RefCntAutoPtr<IPipelineState> pPS0;
+ m_pDevice->CreatePipelineState( m_PSODesc, &pPS0 );
+ m_pDeviceContext->SetPipelineState(pPS0);
+#if 0
+ BSDesc.Name = "TestBS2";
+ m_pDevice->CreateBlendState( BSDesc, &pBS2 );
+ assert( pBS == pBS2 );
+ float BlendFactors[4] = { 0.8f, 0.2f, 0.3f, 0.6f };
+ m_pDeviceContext->SetBlendState( pBS );
+ m_pDeviceContext->SetBlendState( pBS2, BlendFactors );
+ m_pDeviceContext->SetBlendState( pBS2, BlendFactors, 0x12F5BA3D );
+ m_pDeviceContext->SetBlendState( pBS2, BlendFactors, 0x12F5BA3D );
+#endif
+}
+
+TestBlendState::TestBlendState( IRenderDevice *pDevice, IDeviceContext *pContext ) :
+ TestPipelineStateBase(pDevice),
+ m_pDeviceContext(pContext)
+{
+ m_PSODesc.Name = "PSO-TestBlendStates";
+ BlendStateDesc &BSDesc = m_PSODesc.GraphicsPipeline.BlendDesc;
+ BSDesc.RenderTargets[0].BlendEnable = True;
+ CreateTestBS( BSDesc );
+
+ BSDesc.AlphaToCoverageEnable = !BSDesc.AlphaToCoverageEnable;
+ CreateTestBS( BSDesc );
+
+ BSDesc.IndependentBlendEnable = !BSDesc.IndependentBlendEnable;
+ CreateTestBS( BSDesc );
+
+ BSDesc.AlphaToCoverageEnable = False;
+ BSDesc.IndependentBlendEnable = True;
+
+ const BLEND_FACTOR AlphaBlendFactors[] =
+ {
+ BLEND_FACTOR_ZERO,
+ BLEND_FACTOR_ONE,
+ BLEND_FACTOR_SRC_ALPHA,
+ BLEND_FACTOR_INV_SRC_ALPHA,
+ BLEND_FACTOR_DEST_ALPHA,
+ BLEND_FACTOR_INV_DEST_ALPHA,
+ BLEND_FACTOR_SRC_ALPHA_SAT,
+ BLEND_FACTOR_BLEND_FACTOR,
+ BLEND_FACTOR_INV_BLEND_FACTOR,
+ BLEND_FACTOR_SRC1_ALPHA,
+ BLEND_FACTOR_INV_SRC1_ALPHA,
+ };
+
+
+ for( int i = 0; i < BlendStateDesc::MaxRenderTargets; ++i )
+ {
+ auto &RT = BSDesc.RenderTargets[i];
+ RT.BlendEnable = True;
+ for( auto bf = BLEND_FACTOR_UNDEFINED + 1; bf < BLEND_FACTOR_NUM_FACTORS; ++bf )
+ {
+ if( i > 0 &&
+ (bf == BLEND_FACTOR_SRC1_COLOR ||
+ bf == BLEND_FACTOR_INV_SRC1_COLOR ||
+ bf == BLEND_FACTOR_SRC1_ALPHA ||
+ bf == BLEND_FACTOR_INV_SRC1_ALPHA) )
+ continue;
+ RT.SrcBlend = static_cast<BLEND_FACTOR>( bf );
+ CreateTestBS( BSDesc );
+ }
+
+ for( auto bf = BLEND_FACTOR_UNDEFINED + 1; bf < BLEND_FACTOR_NUM_FACTORS; ++bf )
+ {
+ if( i > 0 &&
+ (bf == BLEND_FACTOR_SRC1_COLOR ||
+ bf == BLEND_FACTOR_INV_SRC1_COLOR ||
+ bf == BLEND_FACTOR_SRC1_ALPHA ||
+ bf == BLEND_FACTOR_INV_SRC1_ALPHA) )
+ continue;
+
+ RT.DestBlend = static_cast<BLEND_FACTOR>( bf );
+ CreateTestBS( BSDesc );
+ }
+
+ RT.SrcBlend = BLEND_FACTOR_SRC_COLOR;
+ RT.DestBlend = BLEND_FACTOR_INV_SRC_COLOR;
+ RT.SrcBlendAlpha = BLEND_FACTOR_SRC_ALPHA;
+ RT.DestBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
+ for( auto bo = BLEND_OPERATION_UNDEFINED + 1; bo < BLEND_OPERATION_NUM_OPERATIONS; ++bo )
+ {
+ RT.BlendOp = static_cast<BLEND_OPERATION>( bo );
+ CreateTestBS( BSDesc );
+ }
+
+ for( auto bf = 0; bf < _countof(AlphaBlendFactors); ++bf )
+ {
+ auto AlphaBlend = AlphaBlendFactors[bf];
+ if( i > 0 && (AlphaBlend == BLEND_FACTOR_SRC1_ALPHA || AlphaBlend == BLEND_FACTOR_INV_SRC1_ALPHA) )
+ continue;
+
+ RT.SrcBlendAlpha = AlphaBlend;
+ CreateTestBS( BSDesc );
+ }
+
+ for( auto bf = 0; bf < _countof(AlphaBlendFactors); ++bf )
+ {
+ auto AlphaBlend = AlphaBlendFactors[bf];
+ if( i > 0 && (AlphaBlend == BLEND_FACTOR_SRC1_ALPHA || AlphaBlend == BLEND_FACTOR_INV_SRC1_ALPHA) )
+ continue;
+
+ RT.DestBlendAlpha = AlphaBlend;
+ CreateTestBS( BSDesc );
+ }
+
+ RT.SrcBlend = BLEND_FACTOR_SRC_COLOR;
+ RT.DestBlend = BLEND_FACTOR_INV_SRC_COLOR;
+ RT.SrcBlendAlpha = BLEND_FACTOR_SRC_ALPHA;
+ RT.DestBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
+ for( auto bo = BLEND_OPERATION_UNDEFINED + 1; bo < BLEND_OPERATION_NUM_OPERATIONS; ++bo )
+ {
+ RT.BlendOpAlpha = static_cast<BLEND_OPERATION>( bo );
+ CreateTestBS( BSDesc );
+ }
+
+ RT.RenderTargetWriteMask = COLOR_MASK_BLUE;
+ CreateTestBS( BSDesc );
+
+ RT.RenderTargetWriteMask |= COLOR_MASK_RED;
+ CreateTestBS( BSDesc );
+
+ RT.RenderTargetWriteMask |= COLOR_MASK_GREEN;
+ CreateTestBS( BSDesc );
+
+ RT.RenderTargetWriteMask |= COLOR_MASK_ALPHA;
+ CreateTestBS( BSDesc );
+ }
+
+ auto pScript = CreateRenderScriptFromFile( "BlendStateTest.lua", pDevice, pContext, [&]( Diligent::ScriptParser *pScriptParser )
+ {
+ BSDesc = BlendStateDesc();
+ BSDesc.IndependentBlendEnable = True;
+ BSDesc.AlphaToCoverageEnable = False;
+ BSDesc.RenderTargets[0].BlendEnable = True;
+ BSDesc.RenderTargets[0].SrcBlend = BLEND_FACTOR_ZERO;
+ BSDesc.RenderTargets[0].DestBlend = BLEND_FACTOR_ONE;
+ BSDesc.RenderTargets[0].BlendOp = BLEND_OPERATION_ADD;
+ BSDesc.RenderTargets[0].SrcBlendAlpha = BLEND_FACTOR_SRC_ALPHA;
+ BSDesc.RenderTargets[0].DestBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
+ BSDesc.RenderTargets[0].BlendOpAlpha = BLEND_OPERATION_SUBTRACT;
+ BSDesc.RenderTargets[0].RenderTargetWriteMask = COLOR_MASK_RED;
+
+ BSDesc.RenderTargets[1].BlendEnable = True;
+ BSDesc.RenderTargets[1].SrcBlend = BLEND_FACTOR_SRC_ALPHA;
+ BSDesc.RenderTargets[1].DestBlend = BLEND_FACTOR_INV_SRC_ALPHA;
+ BSDesc.RenderTargets[1].BlendOp = BLEND_OPERATION_REV_SUBTRACT;
+ BSDesc.RenderTargets[1].SrcBlendAlpha = BLEND_FACTOR_DEST_ALPHA;
+ BSDesc.RenderTargets[1].DestBlendAlpha = BLEND_FACTOR_INV_DEST_ALPHA;
+ BSDesc.RenderTargets[1].BlendOpAlpha = BLEND_OPERATION_MIN;
+ BSDesc.RenderTargets[1].RenderTargetWriteMask = COLOR_MASK_GREEN;
+
+ BSDesc.RenderTargets[2].BlendEnable = True;
+ BSDesc.RenderTargets[2].SrcBlend = BLEND_FACTOR_DEST_COLOR;
+ BSDesc.RenderTargets[2].DestBlend = BLEND_FACTOR_INV_DEST_COLOR;
+ BSDesc.RenderTargets[2].BlendOp = BLEND_OPERATION_MAX;
+ BSDesc.RenderTargets[2].SrcBlendAlpha = BLEND_FACTOR_SRC_ALPHA_SAT;
+ BSDesc.RenderTargets[2].DestBlendAlpha = BLEND_FACTOR_BLEND_FACTOR;
+ BSDesc.RenderTargets[2].BlendOpAlpha = BLEND_OPERATION_ADD;
+ BSDesc.RenderTargets[2].RenderTargetWriteMask = COLOR_MASK_BLUE;
+
+ BSDesc.RenderTargets[3].BlendEnable = True;
+ BSDesc.RenderTargets[3].SrcBlend = BLEND_FACTOR_INV_BLEND_FACTOR;
+ BSDesc.RenderTargets[3].DestBlend = BLEND_FACTOR_SRC_COLOR;
+ BSDesc.RenderTargets[3].BlendOp = BLEND_OPERATION_MAX;
+ BSDesc.RenderTargets[3].SrcBlendAlpha = BLEND_FACTOR_INV_SRC_ALPHA;
+ BSDesc.RenderTargets[3].DestBlendAlpha = BLEND_FACTOR_SRC_ALPHA;
+ BSDesc.RenderTargets[3].BlendOpAlpha = BLEND_OPERATION_ADD;
+ BSDesc.RenderTargets[3].RenderTargetWriteMask = COLOR_MASK_ALPHA;
+
+ RefCntAutoPtr<IPipelineState> pPSO;
+ pDevice->CreatePipelineState( m_PSODesc, &pPSO);
+ pScriptParser->SetGlobalVariable( "TestGlobalPSO", pPSO );
+ }
+ );
+ {
+ RefCntAutoPtr<IPipelineState> pPSOFromScript, pPSOFromScript2;
+ pScript->GetPipelineStateByName( "PSO_TestBlendState", &pPSOFromScript );
+ //pScript->GetPipelineStateByName( "TestPSO2", &pPSOFromScript2 );
+ //assert( pPSOFromScript == pBSFromScript2 );
+ const auto &PSODesc = pPSOFromScript->GetDesc();
+ const auto &BSDesc = PSODesc.GraphicsPipeline.BlendDesc;
+
+ assert( strcmp(PSODesc.Name, "TestPSO_FromScript") == 0 );
+ assert( BSDesc.IndependentBlendEnable == true );
+ assert( BSDesc.AlphaToCoverageEnable == false );
+ const auto &RT1 = BSDesc.RenderTargets[0];
+ assert( RT1.BlendEnable == true);
+ assert( RT1.SrcBlend == BLEND_FACTOR_ZERO);
+ assert( RT1.DestBlend == BLEND_FACTOR_SRC_COLOR);
+ assert( RT1.BlendOp == BLEND_OPERATION_ADD);
+ assert( RT1.SrcBlendAlpha == BLEND_FACTOR_SRC_ALPHA);
+ assert( RT1.DestBlendAlpha == BLEND_FACTOR_INV_SRC_ALPHA);
+ assert( RT1.BlendOpAlpha == BLEND_OPERATION_SUBTRACT);
+ assert( RT1.RenderTargetWriteMask == (COLOR_MASK_GREEN | COLOR_MASK_RED) );
+
+ const auto& RT3 = BSDesc.RenderTargets[2];
+ assert(RT3.BlendEnable == true);
+ assert(RT3.SrcBlend == BLEND_FACTOR_INV_DEST_ALPHA);
+ assert(RT3.DestBlend == BLEND_FACTOR_INV_DEST_COLOR);
+ assert(RT3.BlendOp == BLEND_OPERATION_ADD);
+ assert(RT3.SrcBlendAlpha == BLEND_FACTOR_BLEND_FACTOR);
+ assert(RT3.DestBlendAlpha == BLEND_FACTOR_INV_SRC_ALPHA);
+ assert(RT3.BlendOpAlpha == BLEND_OPERATION_SUBTRACT);
+ assert(RT3.RenderTargetWriteMask == (COLOR_MASK_BLUE | COLOR_MASK_ALPHA) );
+ }
+
+ {
+ BSDesc = BlendStateDesc();
+ RefCntAutoPtr<IPipelineState> pPSO;
+ m_pDevice->CreatePipelineState(m_PSODesc, &pPSO );
+ pScript->Run( m_pDeviceContext, "TestPSOArg", pPSO );
+ }
+}