发布到纹理D3D11的问题

时间:2019-05-21 03:39:06

标签: c++ directx directx-11 direct3d

我正在尝试在D3D11中渲染纹理,但是每当这样做时,纹理的数据都是空的,什么也没画。我通过以下功能创建并渲染到纹理:

data.values().stream()
    .map(m -> m.get("quantity"))
    .filter(qty -> qty != null && qty != "")
    .mapToDouble(qty -> Double.valueOf(qty.toString()))
    .sum();

draw函数定义如下:

_TextureBufferDescription.Width = int( vecMax.x - vecMin.x );
_TextureBufferDescription.Height = int( vecMax.y - vecMin.y );
_TextureBufferDescription.MipLevels = 1;
_TextureBufferDescription.ArraySize = 1;
_TextureBufferDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
_TextureBufferDescription.SampleDesc.Count = 1;
_TextureBufferDescription.SampleDesc.Quality = 0;
_TextureBufferDescription.Usage = D3D11_USAGE_DEFAULT;
_TextureBufferDescription.BindFlags = D3D11_BIND_RENDER_TARGET;
_TextureBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
_TextureBufferDescription.MiscFlags = 0;

_TextureDescription.Width = int( vecMax.x - vecMin.x );
_TextureDescription.Height = int( vecMax.y - vecMin.y );
_TextureDescription.MipLevels = 1;
_TextureDescription.ArraySize = 1;
_TextureDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
_TextureDescription.SampleDesc.Count = 1;
_TextureDescription.SampleDesc.Quality = 0;
_TextureDescription.Usage = D3D11_USAGE_STAGING;
_TextureDescription.BindFlags = 0;
_TextureDescription.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
_TextureDescription.MiscFlags = 0;

_RenderTargetViewDescription.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
_RenderTargetViewDescription.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
_RenderTargetViewDescription.Texture2D.MipSlice = 0;

_Drawing.pDevice->CreateTexture2D( &_TextureBufferDescription, nullptr, &pRenderedTextureBuffer );
_Drawing.pDevice->CreateTexture2D( &_TextureDescription, nullptr, &pRenderedTexture );
_Drawing.pDevice->CreateRenderTargetView( pRenderedTextureBuffer, &_RenderTargetViewDescription, &pNewRenderTarget );
_Drawing.pContext->OMSetRenderTargets( 1, &pNewRenderTarget, _Drawing.pDepthStencilView );
_Drawing.pContext->ClearRenderTargetView( pNewRenderTarget, D3DXCOLOR( 0.f, 0.f, 0.f, 0.f ) );
Draw( );
_Drawing.pContext->OMSetRenderTargets( 1, &_Drawing.pRenderTargetView, _Drawing.pDepthStencilView );
_Drawing.pContext->CopyResource( pRenderedTexture, pRenderedTextureBuffer );
pNewRenderTarget->Release( );

return pRenderedTexture;

所有函数都返回S_OK,因此似乎没有一个出现故障。创建的所有内容都不是nullptr。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

我不确定,但我只是想知道, 您不需要在此处设置任何暂存资源或CPUaccessFlag,因为您无需从CPU中读取数据。

和 我认为您传递给着色器的pTexture应该不是资源,而是srv。

,如果我可以看到着色器代码,将很有帮助。 我假设您用Texture2D 类型定义了纹理变量,