0

我试图渲染到纹理以将其用于后处理。我已经阅读了很多关于这些东西的教程并且现在已经为自己尝试过,但显然我做错了什么。我已经在问关于这个主题的另一个问题,但由于这个问题是一个不同的问题,我认为创建一个新问题是一个更好的主意。所以首先这些是我一遍又一遍的错误消息:

D3D11: ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:400,h:300,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1280,h:720,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Rasterization Unit is enabled (PixelShader is not NULL or Depth/Stencil test is enabled and RasterizedStream is not D3D11_SO_NO_RASTERIZED_STREAM) but position is not provided by the last shader before the Rasterization Unit. [ EXECUTION ERROR #362: DEVICE_DRAW_POSITION_NOT_PRESENT ]

和:

D3D11: ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (RADIUS,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Vertex Shader - Geometry Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (TEXTUREINDEX,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::Draw: Geometry Shader - Pixel Shader linkage error: Signatures between stages are incompatible. The input stage requires Semantic/Index (POSITION,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]
D3D11: ERROR: ID3D11DeviceContext::OMSetRenderTargets: The RenderTargetView at slot 0 is not compatable with the DepthStencilView. DepthStencilViews may only be used with RenderTargetViews if the effective dimensions of the Views are equal, as well as the Resource types, multisample count, and multisample quality. The RenderTargetView at slot 0 has (w:400,h:300,as:1), while the Resource is a Texture2D with (mc:1,mq:0). The DepthStencilView has (w:1280,h:720,as:1), while the Resource is a Texture2D with (mc:1,mq:0). D3D11_RESOURCE_MISC_TEXTURECUBE factors into the Resource type, unless GetFeatureLevel() returns D3D_FEATURE_LEVEL_10_1 or greater. [ STATE_SETTING ERROR #388: OMSETRENDERTARGETS_INVALIDVIEW ]

我很确定我误解了这个渲染目标切换和东西的一个主要方面。创建我的 DirectX 设备时,我也在创建这个:

    D3D11_TEXTURE2D_DESC textureDesc;
    D3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDesc;
    D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;

    ZeroMemory(&textureDesc, sizeof(textureDesc));

    textureDesc.Width = 800/2;
    textureDesc.Height = 600/2;
    textureDesc.MipLevels = 1;
    textureDesc.ArraySize = 1;
    textureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
    textureDesc.SampleDesc.Count = 1;
    textureDesc.Usage = D3D11_USAGE_DEFAULT;
    textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
    textureDesc.CPUAccessFlags = 0;
    textureDesc.MiscFlags = 0;


    pDevice->CreateTexture2D(&textureDesc, NULL, &renderTargetTextureMap);

    renderTargetViewDesc.Format = textureDesc.Format;
    renderTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
    renderTargetViewDesc.Texture2D.MipSlice = 0;

    .
    pDevice->CreateRenderTargetView(renderTargetTextureMap, &renderTargetViewDesc, &renderTargetViewMap);

    shaderResourceViewDesc.Format = textureDesc.Format;
    shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
    shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
    shaderResourceViewDesc.Texture2D.MipLevels = 1;

    pDevice->CreateShaderResourceView(renderTargetTextureMap, &shaderResourceViewDesc, &shaderResourceViewMap);

    D3DVERTEX quad[4] = {
        {D3DXVECTOR3(0,0,0), D3DXVECTOR2(0,0)},
        {D3DXVECTOR3(1,1,0), D3DXVECTOR2(1,1)},
        {D3DXVECTOR3(1,0,0), D3DXVECTOR2(1,0)},
        {D3DXVECTOR3(0,1,0), D3DXVECTOR2(0,1)}};

    HRESULT hr;

    D3D11_SUBRESOURCE_DATA InitData;
    InitData.pSysMem = &quad[0];
    InitData.SysMemPitch = sizeof(D3DVERTEX);
    InitData.SysMemSlicePitch = 0;

    D3D11_BUFFER_DESC bufferDesc;
    bufferDesc.Usage            = D3D11_USAGE_DEFAULT;
    bufferDesc.ByteWidth        = 4 * InitData.SysMemPitch;
    bufferDesc.BindFlags        = D3D11_BIND_VERTEX_BUFFER;
    bufferDesc.CPUAccessFlags   = 0;
    bufferDesc.MiscFlags        = 0;

    V_RETURN(pDevice->CreateBuffer( &bufferDesc, &InitData, &m_pVertexBuffer ));

    const D3D11_INPUT_ELEMENT_DESC layout[] = // http://msdn.microsoft.com/en-us/library/bb205117%28v=vs.85%29.aspx
    {
        { "POSITION",          0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD",          0, DXGI_FORMAT_R32G32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    };
    UINT numElements = sizeof( layout ) / sizeof( layout[0] );
    D3DX11_PASS_DESC passDesc;
    m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->GetDesc(&passDesc);

    V_RETURN( pDevice->CreateInputLayout( layout, numElements, passDesc.pIAInputSignature,
              passDesc.IAInputSignatureSize, &m_pInputLayout ) );

所以我正在创建一个 ShaderResourceView 和一个 RenderTargetView 以及一个带有顶点缓冲区的立方体来绘制这个将绘制纹理的立方体。

现在,在所有其他东西被绘制之后的每一帧更新中,我都使用这个:

    pDevice->GetImmediateContext(&pd3dImmediateContext);
    pd3dImmediateContext->OMSetRenderTargets( 1, &renderTargetViewMap, pDSV );

    pd3dImmediateContext->ClearRenderTargetView(renderTargetViewMap, g_ClearColor);
    ID3D11Buffer* vbs[] = { m_pVertexBuffer, };
    unsigned int strides[] = { sizeof(D3DVERTEX), }, offsets[] = { 0, };

    pd3dImmediateContext->IASetVertexBuffers(0,1, vbs, strides, offsets);
    pd3dImmediateContext->IASetInputLayout(m_pInputLayout);
    pd3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);

    //TODO: Move to header file.
    ID3DX11EffectShaderResourceVariable* g_SpriteEV;

    g_SpriteEV = m_pEffect->GetVariableByName("g_PostProcessTex")->AsShaderResource();

    g_SpriteEV->SetResource(shaderResourceViewMap);
    m_pEffect->GetTechniqueByName("Render")->GetPassByName("P0_PP")->Apply(0, pd3dImmediateContext);

    pd3dImmediateContext->Draw(4, 0);   

我没有明确创建 depthStencilView 我猜这是我的主要错误。但我不知道如何创造这样的权利。我对这一切在后台如何运作感到非常困惑……也许有人愿意解释一下。我在这里做任何事情还是这只是错误的?:p

感谢任何关心帮助的人。

4

1 回答 1

0

认为我能够在本教程的帮助下做到这一点: http ://www.rastertek.com/dx11tut22.html

于 2012-07-01T19:47:09.663 回答