Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Problem with rendering a simple triangle

$
0
0
Here is the code that is relevant for my problem. Everything else is omitted and is giving no problems. The hlsl that compiles and later it successfully adds to the PSO: struct VSInput { float4 position : mPOSITION; float2 uv : mTEXCOORD; }; struct PSInput { float4 position : SV_POSITION; //float2 uv : TEXCOORD; }; Texture2D g_texture : register(t0); SamplerState g_sampler : register(s0); PSInput VSMain(VSInput input) { PSInput output; output.position = input.position; //output.uv = input.uv; return output; } float4 PSMain(PSInput input) : SV_TARGET { //return g_texture.Sample(g_sampler, input.uv); return float4(1.0, 0.0, 0.0, 1.0); } The part of the C++ I consider relevant to the problem: Vertex triangleVertices[] = { { { 0.0f, 0.25f, 0.0f }, { 0.5f, 0.0f } }, { { 0.25f, -0.25f, 0.0f }, { 1.0f, 1.0f } }, { { -0.25f, -0.25f, 0.0f }, { 0.0f, 1.0f } } }; // FAILED macro is omited D3DCompileFromFile(shadersPath.c_str(), nullptr, nullptr, "VSMain", "vs_5_0", 0, 0, &mvsByteCode, &errors); D3DCompileFromFile(shadersPath.c_str(), nullptr, nullptr, "PSMain", "ps_5_0", 0, 0, &mpsByteCode, &errors); D3D12_INPUT_ELEMENT_DESC mInputLayout[] = { { "mPOSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }, { "mTEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 } }; renderQuadVertexBufferView.BufferLocation = mRenderQuadBufferDefault->GetGPUVirtualAddress(); renderQuadVertexBufferView.StrideInBytes = sizeof(Vertex); renderQuadVertexBufferView.SizeInBytes = sizeof(triangleVertices); mCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mCommandList->IASetVertexBuffers(0, 1, &renderQuadVertexBufferView); // this command executes painting the screen well mCommandList->ClearRenderTargetView(RTVHandleCPU, clearColor, 0, nullptr); // this command does not show the triangle mCommandList->DrawInstanced(3, 1, 0, 0); Before to attempt to render the triangle, I set the state of the vertex buffer to be D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER. Its heap is of the type DEFAULT. Do you see any problem in the shown code? If I can discard this as the source of the problem, I could search in other places.

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>