Tutorial14 Dx10

Tutorial 14 - DXSDK - Gerenciamento de estados

Este tutorial demonstra como lidar com os estados do pipeline, os quais interagem com o buffer de profundidade, o buffer stencil e mudam a maneira como os primitivos da cena são renderizados

// Gerenciamento de estado de Render
 
#include "DXUT.h"
#include "DXUTcamera.h"
#include "DXUTgui.h"
#include "DXUTsettingsDlg.h"
#include "DXUTmisc.h"
#include "SDKmisc.h"
#include "SDKmesh.h"
 
#define DEG2RAD( a ) ( a * D3DX_PI / 180.0f )
 
WCHAR* g_szQuadTechniques[] = {
    L"RenderQuadSolid",
    L"RenderQuadSrcAlphaAdd",
    L"RenderQuadSrcAlphaSub",
    L"RenderQuadSrcColorAdd",
    L"RenderQuadSrcColorSub",
};
 
#define MAX_QUAD_TECHNIQUES 5
 
WCHAR* g_szDepthStencilModes[] = 
{
    L"DepthOff/StencilOff",
    L"DepthLess/StencilOff",
    L"DepthGreater/StencilOff",
 
    L"DepthOff/StencilOnFail",
    L"DepthLess/StencilOnFail",
    L"DepthGreater/StencilOnFail",
 
    L"DepthOff/StencilOnPass",
    L"DepthOff/StencilOnPass",
    L"DepthOff/StencilOnPass",
};
 
#define MAX_DEPTH_STENCIL_MODES 9
 
WCHAR* g_szRasterizerModes[] =
{
    L"CullOff/FillSolid",
    L"CullFront/FillSolid",
    L"CullBack/FillSolid",
 
    L"CullOff/FillWire",
    L"CullFront/FillWire",
    L"CullBack/FillWire",
};
 
#define MAX_RASTERIZER_MODES 6
 
/* Estaria incluso no Resource.h */
#define IDS_APP_TITLE           103
 
#define IDR_MAINFRAME           128
#define IDD_TUTORIAL1_DIALOG    102
#define IDD_ABOUTBOX            103
#define IDM_ABOUT               104
#define IDM_EXIT                105
#define IDI_TUTORIAL1           107
#define IDI_SMALL               108
#define IDC_TUTORIAL1           109
#define IDC_MYICON              2
#define IDC_STATIC              -1
 
// Variáveis globais 
CModelViewerCamera    g_Camera;    // Uma câmera de visualização do modelo
CDXUTDialogResourceManager    g_DialogResourceManager;    // gerente para recursos compartilhados de diálogos
CD3DSettingsDlg    g_D3DSettingsDialog;    // diálogo de configurações do dispositivo
CDXUTDialog    g_HUD;    // gerencia a UI 3D
CDXUTDialog    g_SampleUI;    // diálogo para controles específicos da amostra
 
ID3DX10Font*    g_pFont = NULL;    // Fonte para desenho de texto
ID3DX10Sprite*    g_pSprite = NULL;    // SPrite para desenho de texto em lote
CDXUTTextHelper*    g_pTxtHelper = NULL;
ID3D10Effect*    g_pEffect = NULL;    // interface de efeito D3DX
ID3D10InputLayout*    g_pSceneLayout = NULL;    // Leiaute de vértice da cena
ID3D10InputLayout*    g_pQuadLayout = NULL;    // Leiaute de vértice do Quad
ID3D10Buffer*    g_pScreenQuadVB = NULL;    // Quad da tela
CDXUTSDKMesh    g_Mesh;
ID3D10ShaderResourceView*    g_pScreenRV[2] = {NULL};
 
UINT    g_eSceneDepthStencilMode = 0;
ID3D10DepthStencilState*    g_pDepthStencilStates[MAX_DEPTH_STENCIL_MODES]; // estados de profundidade estêncil para não FX
// gerenciamento de estado do estêncil de profundidade
UINT    g_eSceneRasterizerMode = 0;
ID3D10RasterizerState*    g_pRasterStates[MAX_RASTERIZER_MODES];    // estados do rasterizador para não FX
// gerenciamento de estado do rasterizador
UINT    g_eQuadRenderMode = 0;
ID3D10EffectTechnique*    g_pTechniqueQuad[MAX_QUAD_TECHNIQUES];    // para técnicas de Quad do arquivo FX
// gerenciamento de estado de mistura alfa baseado em FX
ID3D10EffectTechnique*    g_pTechniqueScene = NULL;    // técnica FX para renderizar a cena
ID3D10EffectTechnique*    g_pTechniqueRenderWithStencil = NULL;    // técnica FX para renderizar usando profundidade baseada em FX
// gerenciamento de estado estêncil
 
ID3D10EffectShaderResourceVariable*    g_ptxDiffuseVariable = NULL;
ID3D10EffectMatrixVariable* g_pWorldVariable = NULL;
ID3D10EffectMatrixVariable* g_pViewVariable = NULL;
ID3D10EffectMatrixVariable* g_pProjectionVariable = NULL;
ID3D10EffectScalarVariable*    g_pPuffiness = NULL;
D3DXMATRIX    g_World;
bool g_bSpinning = true;
float g_fModelPuffiness = 0.0f;
 
// estrutura descrevendo nosso vértice no espaço da tela
struct SCREEN_VERTEX
{
    D3DXVECTOR4 pos;
    D3DXVECTOR2 tex;
};
 
// IDs de controle da UI
#define IDC_TOGGLEFULLSCREEN    1
#define IDC_TOGGLEREF           2
#define IDC_CHANGEDEVICE        3
#define IDC_TOGGLESPIN          4
#define IDC_QUADRENDER_MODE     5
#define IDC_SCENEDEPTHSTENCIL_MODE    6
#define IDC_SCENERASTERIZER_MODE      7
#define IDC_TOGGLEWARP          8
 
// Protótipos das funções
bool CALLBACK IsD3D10DeviceAcceptable( UINT adapter, UINT output, D3D10_DRIVER_TYPE DeviceType,
                                      DXGI_FORMAT BufferFormat, bool bWindowed, void *pUserContext );
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBufferSurfaceDesc, 
                                     void* pUserContext);
HRESULT CALLBACK OnD3D10ResizeSwapChain( ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                    const DXGI_SURFACE_DESC* pBufferSurfaceDesc, void* pUserContext);
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext );
void CALLBACK OnD3D10ReleasingSwapChain( void* pUserContext );
void CALLBACK OnD3D10DestroyDevice( void* pUserContext );
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void *pUserContext );
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool *pbNoFurtherProcessing,
                         void* pUserContext);
void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void *pUserContext );
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void *pUserContext );
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void *pUserContext );
 
void RenderText();
void InitApp();
void LoadQuadTechniques();
void LoadDepthStencilStates( ID3D10Device *pd3dDevice );
void LoadRasterizerStates( ID3D10Device *pd3dDevice );
 
// Ponto de entrada para o programa. Inicializa tudo e entra em um loop de processamento de
// mensagem. Tempo ocioso é usado para renderizar a cena
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow ){
    // Habilita checagem de memória em tempo de execução para construções debug.
#if defined( DEBUG ) | defined( _DEBUG )
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
 
    // DXUT criará e usará o melhor equipamento disponível (ou D3D9 ou D3D10)
    // que está disponível no sistema dependendo de quais 
    // CALLBACKS D3D são configurados abaixo
 
    // Configure callbacks DXUT
    DXUTSetCallbackD3D10DeviceAcceptable( IsD3D10DeviceAcceptable );
    DXUTSetCallbackD3D10DeviceCreated( OnD3D10CreateDevice );
    DXUTSetCallbackD3D10SwapChainResized( OnD3D10ResizeSwapChain );
    DXUTSetCallbackD3D10SwapChainReleasing( OnD3D10ReleasingSwapChain );
    DXUTSetCallbackD3D10DeviceDestroyed( OnD3D10DestroyDevice );
    DXUTSetCallbackD3D10FrameRender( OnD3D10FrameRender );
 
    DXUTSetCallbackMsgProc( MsgProc );
    DXUTSetCallbackKeyboard( OnKeyboard );
    DXUTSetCallbackFrameMove( OnFrameMove );
    DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );
 
    DXUTInit( true, true, NULL );    // Parse da linha de comando, mostra caixas de mensagem no erro, sem parâmetros de linha de comando extra
    DXUTSetCursorSettings(true, true );    // Mostre o cursor e recorte ele (clip) quando em modo de tela cheia
 
    InitApp();
 
    DXUTCreateWindow( L"Tutorial14" );
    DXUTCreateDevice( true, 640, 480 );
    DXUTMainLoop();    // Entra dentro do loop de renderização DXUT
 
    return DXUTGetExitCode();
}
 
// Inicializa a aplicação
void InitApp()
{
    g_fModelPuffiness = 0.0f;
    g_bSpinning = true;
 
    g_D3DSettingsDialog.Init( &g_DialogResourceManager );
    g_HUD.Init( &g_DialogResourceManager );
    g_SampleUI.Init( &g_DialogResourceManager );
 
    g_HUD.SetCallback( OnGUIEvent );    int iY = 10;
    g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Mudar para tela cheia", 35, iY, 125, 22 );
    g_HUD.AddButton( IDC_CHANGEDEVICE, L"Mudar dispositivo (F2)", 35, iY += 24, 125, 22, VK_F2 );
    g_HUD.AddButton( IDC_TOGGLEREF, L"Mudar para REF (F3)", 35, iY += 24, 125, 22, VK_F3 );
    g_HUD.AddButton( IDC_TOGGLEWARP, L"Mudar para WARP( F4 )", 35, iY+= 24, 125, 22, VK_F4 );
 
    g_SampleUI.SetCallback( OnGUIEvent);    
 
    CDXUTComboBox* pComboBox = NULL;
 
    iY = 0;
    g_SampleUI.AddStatic( IDC_STATIC, L"Modo de Rederizar (Q)uad", 0, iY, 200, 25 );
    iY += 25;
    g_SampleUI.AddComboBox( IDC_QUADRENDER_MODE, 0, iY, 220, 24, 'Q', false, &pComboBox );
    if( pComboBox )
        pComboBox->SetDropHeight( 150 );
 
    iY += 40;
    g_SampleUI.AddStatic( IDC_STATIC, L"Modo de(R)asterizador da cena", 0, iY, 200, 25 );
    iY += 25;
    g_SampleUI.AddComboBox( IDC_SCENERASTERIZER_MODE, 0, iY, 220, 24, 'R', false, &pComboBox );
    if( pComboBox )
        pComboBox->SetDropHeight( 150 );
 
    iY += 40;
    g_SampleUI.AddStatic( IDC_STATIC, L"Profundidade da cena/ Modo e(S)têncil", 0, iY, 200, 25 );
    iY += 25;
    g_SampleUI.AddComboBox( IDC_SCENEDEPTHSTENCIL_MODE, 0, iY, 220, 24, 'S', false, &pComboBox );
    if( pComboBox )
        pComboBox->SetDropHeight( 150 );
 
    iY += 24;
    g_SampleUI.AddCheckBox( IDC_TOGGLESPIN, L"Girar", 35, iY += 24, 125, 22, g_bSpinning );
}
 
// Rejeita quaisquer dispositivos D3D10 que não são aceitáveis por retornar falso
bool CALLBACK IsD3D10DeviceAcceptable( UINT adapter, UINT output, D3D10_DRIVER_TYPE DeviceType,
                                      DXGI_FORMAT BufferFormat, bool bWindowed, void *pUserContext ){
      return true;
}
 
// Crie quaisquer recursos que não são dependentes do buffer de trás
HRESULT CALLBACK OnD3D10CreateDevice( ID3D10Device* pd3dDevice, const DXGI_SURFACE_DESC* pBufferSurfaceDesc,
                                      void* pUserContext )
{
    HRESULT hr;
 
    V_RETURN( g_DialogResourceManager.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( g_D3DSettingsDialog.OnD3D10CreateDevice( pd3dDevice ) );
    V_RETURN( D3DX10CreateFont( pd3dDevice, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
        OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
        L"Arial", &g_pFont ) );
 
    V_RETURN( D3DX10CreateSprite( pd3dDevice, 512, &g_pSprite ) );
    g_pTxtHelper = new CDXUTTextHelper( NULL, NULL, g_pFont, g_pSprite, 15 );
 
    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
    // Configura a opção D3D10_SHADER_DEBUG para embutir informãção de debug nos shaders.
    // Configurar esta opção melhora a experiência de debugação do shader, mas ainda permite
    // que os shaders sejam otimizados para executar à maneira que eles executarão na 
    // configuração release deste programa.
    dwShaderFlags |= D3D10_SHADER_DEBUG;
    #endif
 
    // Ache o arquivo de efeito D3DX
    WCHAR str[MAX_PATH];
    V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, L"..\\Tutorial14.fx" ) );
    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL,
                                              NULL, &g_pEffect, NULL, NULL ) );
 
    // Obtém os manipuladores das técnicas
    g_pTechniqueScene = g_pEffect->GetTechniqueByName( "RenderScene" );
    g_pTechniqueRenderWithStencil = g_pEffect->GetTechniqueByName( "RenderWithStencil" );
    LoadQuadTechniques();
    LoadDepthStencilStates( pd3dDevice );
    LoadRasterizerStates( pd3dDevice );
 
    // Obtém as variáveis
    g_ptxDiffuseVariable = g_pEffect->GetVariableByName( "g_txDiffuse" )->AsShaderResource();
    g_pWorldVariable = g_pEffect->GetVariableByName( "World" )->AsMatrix();
    g_pViewVariable = g_pEffect->GetVariableByName( "View" )->AsMatrix();
    g_pProjectionVariable = g_pEffect->GetVariableByName( "Projection" )->AsMatrix();
    g_pPuffiness = g_pEffect->GetVariableByName( "Puffiness" )->AsScalar();
 
    // Configura o inchaço
    g_pPuffiness->SetFloat( g_fModelPuffiness );
 
    // Define o leiaute de entrada
    const D3D10_INPUT_ELEMENT_DESC layout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );
 
    // Cria o leiaute de entrada
    D3D10_PASS_DESC PassDesc;
    g_pTechniqueScene->GetPassByIndex( 0 )->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( layout, numElements, PassDesc.pIAInputSignature,
        PassDesc.IAInputSignatureSize, &g_pSceneLayout ) );
 
    // Carrega a malha
    V_RETURN( g_Mesh.Create( pd3dDevice, L"..\\Media\\Tiny\\tiny.sdkmesh", true ) );
 
    // Initializa as matrizes do mundo
    D3DXMatrixIdentity( &g_World );
 
    // Cria um quad de tela
    const D3D10_INPUT_ELEMENT_DESC quadLayout[] =
    {
        { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    };
 
    g_pTechniqueQuad[0]->GetPassByIndex(0)->GetDesc( &PassDesc );
    V_RETURN( pd3dDevice->CreateInputLayout( quadLayout, 2, PassDesc.pIAInputSignature,  
        PassDesc.IAInputSignatureSize, &g_pQuadLayout ) );
 
    SCREEN_VERTEX svQuad[4];
    float fSize = 1.0f;
    svQuad[0].pos = D3DXVECTOR4( -fSize, fSize, 0.0f, 1.0f );
    svQuad[0].tex = D3DXVECTOR2( 0.0f, 0.0f );
    svQuad[1].pos = D3DXVECTOR4( fSize, fSize, 0.0f, 1.0f );
    svQuad[1].tex = D3DXVECTOR2( 1.0f, 0.0f );
    svQuad[2].pos = D3DXVECTOR4( -fSize, -fSize, 0.0f, 1.0f );
    svQuad[2].tex = D3DXVECTOR2( 0.0f, 1.0f );
    svQuad[3].pos = D3DXVECTOR4( fSize, -fSize, 0.0f, 1.0f );
    svQuad[3].tex = D3DXVECTOR2( 1.0f, 1.0f );
 
    D3D10_BUFFER_DESC vbdesc =
    {
        4 * sizeof( SCREEN_VERTEX ),
        D3D10_USAGE_DEFAULT,
        D3D10_BIND_VERTEX_BUFFER,
        0, 0
    };
 
    D3D10_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = svQuad;
    InitData.SysMemPitch = 0;
    InitData.SysMemSlicePitch = 0;
    V_RETURN( pd3dDevice->CreateBuffer( &vbdesc, &InitData, &g_pScreenQuadVB ) );
 
    // Carrega a txetura para o quad de tela
    WCHAR* szScreenTextures[] =
    {
        L"..\\Media\\misc\\MarbleClouds.dds",
        L"..\\Media\\misc\\NormTest.dds"
    };
 
    for( int i = 0; i < 2; i++ ){
        V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, szScreenTextures[i] ) );
        V_RETURN( D3DX10CreateShaderResourceViewFromFile( pd3dDevice, str, NULL, NULL, &g_pScreenRV[i], NULL ) );
    }
 
    // Inicializa a câmera
    D3DXVECTOR3 Eye( 0.0f, 0.0f, -800.0f );
    D3DXVECTOR3 At( 0.0f, 0.0f, 0.0f );
    g_Camera.SetViewParams( &Eye, &At );
 
    return S_OK;
}
 
// Cria quaisquer recursos D3D10 que dependam do buffer de trás
HRESULT CALLBACK OnD3D10ResizeSwapChain( ID3D10Device* pd3dDevice, IDXGISwapChain *pSwapChain,
                                        const DXGI_SURFACE_DESC *pBufferSurfaceDesc, void *pUserContext)
{
    HRESULT hr;
 
    V_RETURN( g_DialogResourceManager.OnD3D10ResizedSwapChain( pd3dDevice, pBufferSurfaceDesc ) );
    V_RETURN( g_D3DSettingsDialog.OnD3D10ResizedSwapChain( pd3dDevice, pBufferSurfaceDesc ) );
 
    // Configura os parâmetros de projeção da câmera
    float fAspect = static_cast<float>( pBufferSurfaceDesc->Width) / static_cast<float>( pBufferSurfaceDesc->Height );
    g_Camera.SetProjParams( D3DX_PI / 4, fAspect, 0.1f, 5000.0f );
    g_Camera.SetWindow( pBufferSurfaceDesc->Width, pBufferSurfaceDesc->Height );
    g_Camera.SetButtonMasks( MOUSE_MIDDLE_BUTTON, MOUSE_WHEEL, MOUSE_LEFT_BUTTON );
 
    g_HUD.SetLocation( pBufferSurfaceDesc->Width -170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBufferSurfaceDesc->Width - 170, pBufferSurfaceDesc->Height - 300 );
    g_SampleUI.SetSize( 170, 300 );
 
    return S_OK;
}
 
// Renderiza a cena usando o dispositivo D3D10
void CALLBACK OnD3D10FrameRender( ID3D10Device *pd3dDevice, double fTime, float fElapsedTime, void *pUserContext )
{
    // Se o diálogo de configurações está sendo mostrado, então
    // renderiza ele ao invés de renderizar a cena da aplicação
    if( g_D3DSettingsDialog.IsActive() )
    {
        g_D3DSettingsDialog.OnRender( fElapsedTime );
        return;
    }
 
    // Limpa o buffer de trás
    float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f };    // vermelho, verde, azul, alfa
    ID3D10RenderTargetView *pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView(pRTV, ClearColor );
 
    // limpa o stencil de profundidade
    ID3D10DepthStencilView *pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH | D3D10_CLEAR_STENCIL, 1.0, 0 );
 
    // Atualiza as variáveis que mudam uma vez por quadro
    g_pWorldVariable->SetMatrix( (float* )&g_World );
    g_pViewVariable->SetMatrix( (float*) g_Camera.GetViewMatrix() );
    g_pProjectionVariable->SetMatrix( (float*) g_Camera.GetProjMatrix() );
 
    // Atualize o modo de seleção (Cull mode) (método não FX)
    pd3dDevice->RSSetState( g_pRasterStates[ g_eSceneRasterizerMode ] );
 
    // Atualiza os estados de profundidade estêncil (método não FX)
    pd3dDevice->OMSetDepthStencilState( g_pDepthStencilStates[ g_eSceneDepthStencilMode ], 0 );
 
    // Renderiza a malha
    pd3dDevice->IASetInputLayout( g_pSceneLayout );
 
    UINT Strides[1];
    UINT Offsets[1];
    ID3D10Buffer* pVB[1];
    pVB[0] = g_Mesh.GetVB10( 0, 0 );
    Strides[0] = ( UINT ) g_Mesh.GetVertexStride(0,0);
    Offsets[0] = 0;
    pd3dDevice->IASetVertexBuffers(0, 1, pVB, Strides, Offsets);
    pd3dDevice->IASetIndexBuffer( g_Mesh.GetIB10( 0 ), g_Mesh.GetIBFormat10( 0 ), 0 );
 
    D3D10_TECHNIQUE_DESC techDesc;    
    g_pTechniqueScene->GetDesc( &techDesc );
    SDKMESH_SUBSET* pSubset = NULL;
    ID3D10ShaderResourceView* pDiffuseRV = NULL;
    D3D10_PRIMITIVE_TOPOLOGY PrimType;
 
    for( UINT p = 0; p < techDesc.Passes; ++p ){
        for( UINT subset = 0; subset < g_Mesh.GetNumSubsets( 0 ); ++subset ){
            pSubset = g_Mesh.GetSubset( 0, subset );
 
            PrimType = g_Mesh.GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE ) pSubset->PrimitiveType );
            pd3dDevice->IASetPrimitiveTopology( PrimType );
 
            pDiffuseRV = g_Mesh.GetMaterial( pSubset->MaterialID )->pDiffuseRV10;
            g_ptxDiffuseVariable->SetResource( pDiffuseRV );
 
            g_pTechniqueScene->GetPassByIndex( p )->Apply( 0 );
            pd3dDevice->DrawIndexed( ( UINT ) pSubset->IndexCount, 0, ( UINT ) pSubset->VertexStart );
        }
    }
 
    // a classe de malha também tinha um método render que permite renderizar a malha com as opções mais comuns
    // g_pMesh.Render( pd3dDevice, g_pTechnique, g_ptxDiffuseVariable );
 
    // Reseta a transformação do Mundo
    D3DXMATRIX mWorld;
    D3DXMatrixScaling( &mWorld, 150.0f, 150.0f, 1.0f );
    g_pWorldVariable->SetMatrix( (float*) &mWorld );
 
    // Renderiza o quadrado no espaço da tela
    ID3D10EffectTechnique* pTech = g_pTechniqueQuad[ g_eQuadRenderMode ];
    g_ptxDiffuseVariable->SetResource( g_pScreenRV[0] );
    UINT strides = sizeof( SCREEN_VERTEX );
    UINT offsets = 0;
    ID3D10Buffer* pBuffers[1] = { g_pScreenQuadVB };
 
    pd3dDevice->IASetInputLayout( g_pQuadLayout );
    pd3dDevice->IASetVertexBuffers( 0, 1, pBuffers, &strides, &offsets );
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
 
    pTech->GetDesc( &techDesc );
 
    for( UINT uiPass = 0; uiPass < techDesc.Passes; uiPass++ ){
        pTech->GetPassByIndex( 0 )->Apply( 0 );
 
        pd3dDevice->Draw( 4, 0 );
    }
 
    // renderiza o quadrado no espaço da tela de novo, mas desta vez com uma 
    // textura diferente e somente renderize onde o buffer stencil é diferente de 0
    // Olhe no arquivo FX para as configurações de estado
    pTech = g_pTechniqueRenderWithStencil;
    g_ptxDiffuseVariable->SetResource( g_pScreenRV[1] );
    pd3dDevice->IASetInputLayout( g_pQuadLayout );
    pd3dDevice->IASetVertexBuffers( 0, 1, pBuffers, &strides, &offsets );
    pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP );
 
    pTech->GetDesc( &techDesc );
    for( UINT uiPass = 0; uiPass < techDesc.Passes; uiPass++ ){
        pTech->GetPassByIndex( 0 )->Apply( 0 );
 
        pd3dDevice->Draw( 4, 0 );
    }
 
    // Reconfigure nosso modo de seleção (método não FX)
    pd3dDevice->RSSetState( g_pRasterStates[ 0 ] );
 
    // Reconfigure o Estado de Profundidade Estêncil
    pd3dDevice->OMSetDepthStencilState( g_pDepthStencilStates[ 1 ], 0 );
 
    // Renderiza a UI
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );
 
    RenderText();
}
 
// Renderiza a ajuda e o texto das estatísticas
void RenderText()
{
    g_pTxtHelper->Begin();
    g_pTxtHelper->SetInsertionPos( 2, 0 );
    g_pTxtHelper->SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );
    g_pTxtHelper->DrawTextLine( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );
    g_pTxtHelper->DrawTextLine( DXUTGetDeviceStats() );
    g_pTxtHelper->End();
}
 
// Libera recursos D3D10 criados em OnD3D10ResizedSwapChain 
void CALLBACK OnD3D10ReleasingSwapChain( void *pUserContext ){
    g_DialogResourceManager.OnD3D10ReleasingSwapChain();
}
 
// Libera recursos D3D10 criados em OnD3D10CreateDevice 
void CALLBACK OnD3D10DestroyDevice( void *pUserContext ){
    g_DialogResourceManager.OnD3D10DestroyDevice();
    g_D3DSettingsDialog.OnD3D10DestroyDevice();
    DXUTGetGlobalResourceCache().OnDestroyDevice();
    SAFE_RELEASE( g_pFont );
    SAFE_RELEASE( g_pSprite );
    SAFE_DELETE( g_pTxtHelper );
    SAFE_RELEASE( g_pSceneLayout );
    SAFE_RELEASE( g_pQuadLayout );
    SAFE_RELEASE( g_pEffect );
    SAFE_RELEASE( g_pScreenQuadVB );
 
    for( int i = 0; i < 2; i++ ){
        SAFE_RELEASE( g_pScreenRV[i] );
    }
 
    g_Mesh.Destroy();
 
    for( UINT i = 0; i < MAX_DEPTH_STENCIL_MODES; i++ ){
        SAFE_RELEASE( g_pDepthStencilStates[i] );
    }
 
    for( UINT i = 0; i < MAX_RASTERIZER_MODES; i++ ){
        SAFE_RELEASE( g_pRasterStates[i] );
    }
}
 
// Chamado imediatamente antes de criar um dispositivo D3D9 oy D3D10, permitindo o aplicativo modificar
// as configurações do dispositivo como necessário
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings *pDeviceSettings, void *pUserContext ){
    pDeviceSettings->d3d10.AutoDepthStencilFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
    return true;
}
 
// Manuseia atualizações para a cena. Isto é chamado indiferentemente de qual API D3D é usada
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void *pUsetContex ){
    // Atualiza a posição da câmera baseada na entrada do usuário
    g_Camera.FrameMove( fElapsedTime );
 
    if( g_bSpinning ){
        D3DXMatrixRotationY( &g_World, 60.0f * DEG2RAD( (float) fTime ) );
    } else {
        D3DXMatrixRotationY( &g_World, DEG2RAD( 180.0f ) );
    }
 
    D3DXMATRIX mRot;
    D3DXMatrixRotationX( &mRot, DEG2RAD( -90.0f ) );
    g_World = mRot * g_World;
}
 
// Manuseia as mensagens para a aplicação
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, 
                         bool *pbNoFurtherProcessing, void *pUserContext )
{
    // Passa as mensagens para as chamadas do gerenciador de recurso de diálogo para que
    // o estado da GUI seja atualizado corretamente
    *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
 
    if( *pbNoFurtherProcessing ) return 0;
 
    // Passe as mensagens para a configuração de diálogo se ela ainda estiver ativa
    if( g_D3DSettingsDialog.IsActive() ){
        g_D3DSettingsDialog.MsgProc( hWnd, uMsg, wParam, lParam );
        return 0;
    }
 
    // Dê aos diálogos uma chance de manusear a mensagem primeiro
    *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing ) return 0;
    *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing ) return 0;
 
    // Passe todas as mensagens de janela restantes para a cãmera para que ela possa respodner à entrada do usuário
    g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
 
    return 0;
}
 
// Manuseia pressionamentos do teclado
void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void *pUserContext  ){
    if( bKeyDown )
    {
        switch( nChar )
        {
        case VK_F1:
            break;
        }
    }
}
 
// Manuseia os eventos da GUI
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl *pControl, void *pUserContext )
{
    switch( nControlID ){
        case IDC_TOGGLEFULLSCREEN:
            DXUTToggleFullScreen(); break;
        case IDC_TOGGLEREF:
            DXUTToggleREF(); break;
        case IDC_CHANGEDEVICE:
            g_D3DSettingsDialog.SetActive( !g_D3DSettingsDialog.IsActive() ); break;
        case IDC_TOGGLEWARP:
            DXUTToggleWARP(); break;
        case IDC_TOGGLESPIN:{
            g_bSpinning = g_SampleUI.GetCheckBox( IDC_TOGGLESPIN )->GetChecked();
            break;
        }
        case IDC_QUADRENDER_MODE:
        {
            CDXUTComboBox* pComboBox = NULL;
            pComboBox = ( CDXUTComboBox* )pControl;
            g_eQuadRenderMode = (UINT) PtrToInt( pComboBox->GetSelectedData() );
            break;
        }
        case IDC_SCENEDEPTHSTENCIL_MODE:
        {
            CDXUTComboBox* pComboBox = NULL;
            pComboBox = ( CDXUTComboBox* )pControl;
            g_eSceneDepthStencilMode = (UINT) PtrToInt( pComboBox->GetSelectedData() );
            break;
        }
        case IDC_SCENERASTERIZER_MODE:
        {
            CDXUTComboBox* pComboBox = NULL;
            pComboBox = ( CDXUTComboBox* )pControl;
            g_eSceneRasterizerMode = (UINT) PtrToInt( pComboBox->GetSelectedData() );
            break;
        }
    }
}
 
// LoadQuadTechniques
// Carrega as técnicas para renderizar o quad do arquivo FX. As técnicas no
// arquivo FX contêm a configuração de estado de mistura alfa
void LoadQuadTechniques()
{
    for( UINT i = 0; i < MAX_QUAD_TECHNIQUES; i++ ){
        char mbstr[MAX_PATH];
        WideCharToMultiByte( CP_ACP, 0, g_szQuadTechniques[i], -1, mbstr, MAX_PATH, 0, 0 );
        g_pTechniqueQuad[i] = g_pEffect->GetTechniqueByName( mbstr );
 
        g_SampleUI.GetComboBox( IDC_QUADRENDER_MODE )->AddItem( g_szQuadTechniques[i], (void*) (UINT64) i );
    }
}
 
// LoadDepthStencilStates
// Cria um conjunto de estados de profundidade estêncil para gerenciamento de estado não-FX. Estes estados
// mais tarde serão configurados usando OMSetDepthStencilState em OnD3D10FrameRender.
void LoadDepthStencilStates( ID3D10Device* pd3dDevice ){
    BOOL bDepthEnable[ MAX_DEPTH_STENCIL_MODES ] = 
    {
        FALSE,
        TRUE,
        TRUE,
        FALSE,
        TRUE,
        TRUE,
        FALSE,
        TRUE,
        TRUE
    };
 
    BOOL bStencilEnable[ MAX_DEPTH_STENCIL_MODES ] = 
    {
        FALSE,
        FALSE,
        FALSE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
        TRUE,
        TRUE
    };
 
    D3D10_COMPARISON_FUNC compFunc[ MAX_DEPTH_STENCIL_MODES ] = 
    {
        D3D10_COMPARISON_LESS,
        D3D10_COMPARISON_LESS,
        D3D10_COMPARISON_GREATER,
        D3D10_COMPARISON_LESS,
        D3D10_COMPARISON_LESS,
        D3D10_COMPARISON_GREATER,
        D3D10_COMPARISON_LESS,
        D3D10_COMPARISON_LESS,
        D3D10_COMPARISON_GREATER,
    };
 
    D3D10_STENCIL_OP FailOp[ MAX_DEPTH_STENCIL_MODES ] =
    {
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
 
        D3D10_STENCIL_OP_INCR,
        D3D10_STENCIL_OP_INCR,
        D3D10_STENCIL_OP_INCR,
 
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
    };
 
    D3D10_STENCIL_OP PassOp[ MAX_DEPTH_STENCIL_MODES ] =
    {
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
 
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
        D3D10_STENCIL_OP_KEEP,
 
        D3D10_STENCIL_OP_INCR,
        D3D10_STENCIL_OP_INCR,
        D3D10_STENCIL_OP_INCR,
    };
 
    for( UINT i = 0; i < MAX_DEPTH_STENCIL_MODES; i++ )
    {
        D3D10_DEPTH_STENCIL_DESC dsDesc;
        dsDesc.DepthEnable = bDepthEnable[i];
        dsDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
        dsDesc.DepthFunc = compFunc[i];
 
        // parâmetros de teste do estêncil
        dsDesc.StencilEnable = bStencilEnable[i];
        dsDesc.StencilReadMask = 0xFF;
        dsDesc.StencilWriteMask = 0xFF;
 
        // operações estêncil se pixel está encarando de frente
        dsDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
        dsDesc.FrontFace.StencilDepthFailOp = FailOp[i];
        dsDesc.FrontFace.StencilPassOp = PassOp[i];
        dsDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
 
        // operações estêncil se pixel está encarando de trás
        dsDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP;
        dsDesc.BackFace.StencilDepthFailOp = FailOp[i];
        dsDesc.BackFace.StencilPassOp = PassOp[i];
        dsDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
 
        // Cria o estado de profundidade estêncil
        pd3dDevice->CreateDepthStencilState( &dsDesc, &g_pDepthStencilStates[i] );
 
        g_SampleUI.GetComboBox( IDC_SCENEDEPTHSTENCIL_MODE )->AddItem( g_szDepthStencilModes[i],
            ( void* ) (UINT64 ) i );
    }
}
 
// LoadRasterizerStates
// Crie um conjunto de estados de rasterizador para gerenciamento de estado não-FX. Estes 
// estados serão configurados mais tarde por usar RSSetState em OND3DFrameRender.
void LoadRasterizerStates( ID3D10Device* pd3dDevice ){
    D3D10_FILL_MODE fill[MAX_RASTERIZER_MODES] = 
    {
        D3D10_FILL_SOLID,
        D3D10_FILL_SOLID,
        D3D10_FILL_SOLID,
        D3D10_FILL_WIREFRAME,
        D3D10_FILL_WIREFRAME,
        D3D10_FILL_WIREFRAME
    };
 
    D3D10_CULL_MODE cull[MAX_RASTERIZER_MODES]=
    {
        D3D10_CULL_NONE,
        D3D10_CULL_FRONT,
        D3D10_CULL_BACK,
        D3D10_CULL_NONE,
        D3D10_CULL_FRONT,
        D3D10_CULL_BACK
    };
 
    for( UINT i = 0; i < MAX_RASTERIZER_MODES; i++ ){
        D3D10_RASTERIZER_DESC rasterizerState;
        rasterizerState.FillMode = fill[i];
        rasterizerState.CullMode = cull[i];
        rasterizerState.FrontCounterClockwise = false;
        rasterizerState.DepthBias = false;
        rasterizerState.DepthBiasClamp = 0;
        rasterizerState.SlopeScaledDepthBias = 0;
        rasterizerState.DepthClipEnable = true;
        rasterizerState.ScissorEnable = false;
        rasterizerState.MultisampleEnable = false;
        rasterizerState.AntialiasedLineEnable = false;
        pd3dDevice->CreateRasterizerState( &rasterizerState, &g_pRasterStates[i] );
 
        g_SampleUI.GetComboBox( IDC_SCENERASTERIZER_MODE )->AddItem( g_szRasterizerModes[i] ,
            (void *) (UINT64) i );
    }
}

E o shader acompanhante

//--------------------------------------------------------------------------------------
// File: Tutorial14.fx
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
 
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
Texture2D g_txDiffuse;
SamplerState samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Wrap;
    AddressV = Wrap;
};
 
cbuffer cbConstant
{
    float3 vLightDir = float3(-0.577,0.577,-0.577);
};
 
cbuffer cbChangesEveryFrame
{
    matrix World;
    matrix View;
    matrix Projection;
};
 
struct VS_INPUT
{
    float3 Pos          : POSITION;         //position
    float3 Norm         : NORMAL;           //normal
    float2 Tex          : TEXCOORD0;        //texture coordinate
};
 
struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float3 Norm : TEXCOORD0;
    float2 Tex : TEXCOORD1;
};
 
struct QUADVS_INPUT
{
    float4 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};
 
struct QUADVS_OUTPUT
{
    float4 Pos : SV_POSITION;              // Transformed position
    float2 Tex : TEXCOORD0;
};
 
//--------------------------------------------------------------------------------------
// Blending States
//--------------------------------------------------------------------------------------
BlendState NoBlending
{
    BlendEnable[0] = FALSE;
};
 
BlendState SrcAlphaBlendingAdd
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = ONE;
    BlendOp = ADD;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};
 
BlendState SrcAlphaBlendingSub
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = ONE;
    BlendOp = SUBTRACT;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};
 
BlendState SrcColorBlendingAdd
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_COLOR;
    DestBlend = ONE;
    BlendOp = ADD;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};
 
BlendState SrcColorBlendingSub
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_COLOR;
    DestBlend = ONE;
    BlendOp = SUBTRACT;
    SrcBlendAlpha = ZERO;
    DestBlendAlpha = ZERO;
    BlendOpAlpha = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};
 
//--------------------------------------------------------------------------------------
// Depth/Stencil States
//--------------------------------------------------------------------------------------
DepthStencilState RenderWithStencilState
{
    DepthEnable = false;
    DepthWriteMask = ZERO;
    DepthFunc = Less;
 
    // Setup stencil states
    StencilEnable = true;
    StencilReadMask = 0xFF;
    StencilWriteMask = 0x00;
 
    FrontFaceStencilFunc = Not_Equal;
    FrontFaceStencilPass = Keep;
    FrontFaceStencilFail = Zero;
 
    BackFaceStencilFunc = Not_Equal;
    BackFaceStencilPass = Keep;
    BackFaceStencilFail = Zero;
};
 
//--------------------------------------------------------------------------------------
// Scene Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
    PS_INPUT output = (PS_INPUT)0;
 
    output.Pos = mul( float4(input.Pos,1), World );
    output.Pos = mul( output.Pos, View );
    output.Pos = mul( output.Pos, Projection );
    output.Norm = mul( input.Norm, World );
    output.Tex = input.Tex;
 
    return output;
}
 
//-----------------------------------------------------------------------------
// Quad Vertex Shaders
//-----------------------------------------------------------------------------
QUADVS_OUTPUT QuadVS( QUADVS_INPUT Input )
{
    QUADVS_OUTPUT Output;
    Output.Pos = mul( Input.Pos, World );
    Output.Pos = mul( Output.Pos, View );
    Output.Pos = mul( Output.Pos, Projection );
    Output.Tex = Input.Tex;
    return Output;
}
 
QUADVS_OUTPUT ScreenQuadVS( QUADVS_INPUT Input )
{
    QUADVS_OUTPUT Output;
    Output.Pos = Input.Pos;
    Output.Tex = Input.Tex;
    return Output;
}
 
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( PS_INPUT input) : SV_Target
{
    // Calculate lighting assuming light color is <1,1,1,1>
    float fLighting = saturate( dot( input.Norm, vLightDir ) );
    float4 outputColor = g_txDiffuse.Sample( samLinear, input.Tex ) * fLighting;
    outputColor.a = 1;
    return outputColor;
}
 
//--------------------------------------------------------------------------------------
// Quad Pixel Shader
//--------------------------------------------------------------------------------------
float4 QuadPS( QUADVS_OUTPUT input) : SV_Target
{
    return g_txDiffuse.Sample( samLinear, input.Tex );
}
 
//--------------------------------------------------------------------------------------
// Scene Techniques
//--------------------------------------------------------------------------------------
technique10 RenderScene
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, PS() ) );        
        SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }
}
 
//--------------------------------------------------------------------------------------
// RenderWithStencil - set the depth stencil state inside of the technique
//--------------------------------------------------------------------------------------
technique10 RenderWithStencil
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, ScreenQuadVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );     
 
        SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
        SetDepthStencilState( RenderWithStencilState, 0 );
    }
}
 
//--------------------------------------------------------------------------------------
// Quad Techniques:  Alpha blending state is set inside the technique
//--------------------------------------------------------------------------------------
technique10 RenderQuadSolid
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );     
 
        SetBlendState( NoBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }
}
 
//--------------------------------------------------------------------------------------
technique10 RenderQuadSrcAlphaAdd
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );   
 
        SetBlendState( SrcAlphaBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }
}
 
//--------------------------------------------------------------------------------------
technique10 RenderQuadSrcAlphaSub
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );   
 
        SetBlendState( SrcAlphaBlendingSub, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }
}
 
//--------------------------------------------------------------------------------------
technique10 RenderQuadSrcColorAdd
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );   
 
        SetBlendState( SrcColorBlendingAdd, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }
}
 
//--------------------------------------------------------------------------------------
technique10 RenderQuadSrcColorSub
{
    pass P0
    {
        SetVertexShader( CompileShader( vs_4_0, QuadVS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, QuadPS() ) );   
 
        SetBlendState( SrcColorBlendingSub, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.