SharpDX (DX11)를 사용하여 하나의 삼각형을 화면에 그립니다. 어떤 이유로 든 삼각형은 두 번째 프레임마다 그려지는 것처럼 보입니다. 내 장치 초기화 코드는 다음과 같습니다메쉬가 두 번째 프레임마다 만 표시되는 이유는 무엇입니까?
이public void Init()
{
renderForm = new RenderForm(Engine.GameTitle);
renderForm.ClientSize = new Size(Engine.Settings.Screen.Width, Engine.Settings.Screen.Height);
renderForm.MaximizeBox = false;
var desc = new SwapChainDescription()
{
BufferCount = 2,
ModeDescription = new ModeDescription(renderForm.ClientSize.Width, renderForm.ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = renderForm.Handle,
SampleDescription = new SampleDescription(1, 0),
SwapEffect = SwapEffect.Sequential,
Usage = Usage.RenderTargetOutput
};
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, desc, out device, out swapChain);
deviceContext = device.ImmediateContext;
var factory = swapChain.GetParent<Factory>();
factory.MakeWindowAssociation(renderForm.Handle, WindowAssociationFlags.IgnoreAll);
backBuffer = Texture2D.FromSwapChain<Texture2D>(swapChain, 0);
renderView = new RenderTargetView(device, backBuffer);
backBuffer.Dispose();
deviceContext.OutputMerger.SetTargets(renderView);
deviceContext.Rasterizer.SetViewports(new Viewport(0, 0, renderForm.ClientSize.Width, renderForm.ClientSize.Height, 0.0f, 1.0f));
ProjectionMatrix = Matrix.PerspectiveFovLH(
(float)(Math.PI/4),
(float)(renderForm.ClientSize.Width/renderForm.ClientSize.Height),
nearPlane,
farPlane);
WorldMatrix = Matrix.Identity;
renderForm.Location = new Point(Screen.PrimaryScreen.Bounds.Width/2 - Engine.Settings.Screen.Width/2, Screen.PrimaryScreen.Bounds.Height/2 - Engine.Settings.Screen.Height/2);
}
삼각형을 렌더링하는 코드는 다음과 같습니다
는public void Render()
{
DeviceContext context = D3DRenderer.Instance.GetDevice().ImmediateContext;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer, Utilities.SizeOf<Vertex>(), 0));
context.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0);
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
}
public void RenderShader(int indexCount)
{
device.ImmediateContext.DrawIndexed(indexCount, 0, 0);
}
반면 렌더링() RenderShader 전에()가 호출됩니다. Direct3D의 경고를 제외한 모든 함수에 의해 리턴 에러 메시지도 없다 :
가 D3D11 경고 : ID3D11DeviceContext :: DrawIndexed : 버텍스 셰이더 유닛의 슬롯 0의 정수 버퍼의 크기가 너무 작아 (64 바이트 제공이 적어도 192 바이트 예상).
내 MatrixBuffer 구조는 다음과 같습니다
[StructLayout(LayoutKind.Sequential)]
internal struct MatrixBuffer
{
public Matrix world;
public Matrix view;
public Matrix projection;
}
내가 그것을 올바르게 백 버퍼를 교환하지에 문제가 아닙니다 확인하기 위해 다른 색깔로 다른 모든 프레임 백 버퍼를 삭제하고있다. 이것은 잘 작동합니다.
저는 왜 이것이 지금 제대로 작동하지 않는지에 대해 매우 당혹 스럽습니다. 나는 누군가가 이것에 대한 답을 알고 있기를 바랍니다.
잘못된 상수 버퍼 크기를 지정했을 수 있습니다. 이것을 확인하십시오. 그러나이 문제가 귀하의 문제의 원인인지 의심 스럽습니다. 렌더 루프 내에서 두 개 이상의'Present' 호출을 가지고 있습니까? –
사실, 그랬습니다. 나는 그것을 바꿨고 경고는 사라졌다. 그러나, 당신이 짐작했듯이, 이것은 문제의 원인이 아닙니다. 현재() - 아니오, 단지 하나. 지금 나는 내가 읽고있는 래스터 텍 튜토리얼에서 조정 한 모든 코드 라인을 되 돌린 시점에있다. 자습서의 코드가 잘 작동하고 있습니다. (다른 코드에서도 마찬가지입니다.) 다른 솔루션에서는 그렇지 않습니다. 지금 자습서를 기반으로 사용하여 직접 코드를 전송하고 정확한 오류를 확인할 수 있습니다. 팝업됩니다. –