如果有一个RBG像素数组来更新每个帧(例如1024x1024)、一个ID3D11RenderTargetView、ID3D11Device和ID3D11DeviceContext,那么将这些像素绘制到呈现视图的最简单方法是什么?
我一直在为一个正方形(两个三角形)创建一个顶点缓冲区的角度,试图使像素成为一个合适的纹理,并弄清楚如何使着色器引用纹理采样器。我一直在学习这个教程https://learn.microsoft.com/en-us/windows/uwp/gaming/applying-textures-to-primitives ..。但老实说,我看不出本教程中有什么能引用纹理数据(在本教程中定义的着色器,在这里)的着色器。
我完全是DirectX新手,但我正在为一个应用程序编写一个插件,在这个插件中给我一个directx11设备/视图/上下文,并且需要用像素数据填充它。非常感谢!
发布于 2022-02-27 04:05:34
如果您能够确保您的暂存资源与呈现目标的精确分辨率和格式相匹配,那么您将得到如下信息:
GetResource获取资源CopyResource。否则,如果您可以依赖Direct3D硬件特征级 10.0或更高版本,最简单的方法是:
USAGE_DYNAMIC创建一个纹理。SamplerState PointSampler : register(s0);
Texture2D<float4> Texture : register(t0);
struct Interpolators
{
float4 Position : SV_Position;
float2 TexCoord : TEXCOORD0;
};
Interpolators main(uint vI : SV_VertexId)
{
Interpolators output;
// We use the 'big triangle' optimization so you only Draw 3 verticies instead of 4.
float2 texcoord = float2((vI << 1) & 2, vI & 2);
output.TexCoord = texcoord;
output.Position = float4(texcoord.x * 2 - 1, -texcoord.y * 2 + 1, 0, 1);
return output;
}和像素着色器:
float4 main(Interpolators In) : SV_Target0
{
return Texture.Sample(PointSampler, In.TexCoord);
}然后用:
ID3D11ShaderResourceView* textures[1] = { texture };
context->PSSetShaderResources(0, 1, textures);
// You need a sampler object.
context->PSSetSamplers(0, 1, &sampler);
// Depending on your desired result, you may need state objects here
context->OMSetBlendState(nullptr, nullptr, 0xffffffff);
context->OMSetDepthStencilState(nullptr, 0);
context->RSSetState(nullptr);
context->IASetInputLayout(nullptr);
contet->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
Draw(3, 0);有关“全屏四角图”的完整源代码,请参见GitHub。
https://stackoverflow.com/questions/71279814
复制相似问题