0
\$\begingroup\$

I have dumbed the following code down to "stupid simple" for DirectX and still cannot get any cooperation:

g_d3dContext->OMSetRenderTargets(1, g_renderTargetWorld->ColorRenderTargetView.GetAddressOf(), g_depthStencilView.Get());
g_d3dContext->OMSetDepthStencilState(g_States->DepthNone(), 0);
g_d3dContext->OMSetBlendState(g_States->AlphaBlend(), NULL, 0xffffffff);
g_d3dContext->IASetVertexBuffers(0, 2, m_segments->GetLineVertexBuffers(), s_strides, s_offsets);
g_d3dContext->IASetIndexBuffer(m_segments->GetLineIndexBuffer(), DXGI_FORMAT_R16_UINT, 0);
g_d3dContext->IASetInputLayout(s_IL_Polyline.Get());
g_d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ);
g_d3dContext->VSSetShader(g_World_Polyline_VS_Segment.Get(), NULL, 0);
g_d3dContext->GSSetShader(g_World_Polyline_GS_Segment.Get(), NULL, 0);
g_d3dContext->PSSetShader(g_World_Polyline_PS_Segment.Get(), NULL, 0);
g_d3dContext->RSSetState(g_States->CullNone());
//g_d3dContext->DrawIndexed(4 * m_segments->LineCount, 0, 0);
g_d3dContext->DrawIndexedInstanced(4, m_segments->LineCount, 0, 0, 0);
g_d3dContext->GSSetShader(nullptr, NULL, 0);

-The DrawIndexed call draws all segments
-The DrawIndexedInstanced call draws only the first segment

Creating a second instance of this class, DrawIndexedInstanced draws only the first segment of each compound line. Although it is correctly created, filled, and set, I am not even using the per-instance data yet. Manually manipulating the StartIndexOffset parameter causes different, only-one, line segments to be drawn.

PIX is worthless, as usual, but, at least, allowed me to inspect the buffer contents. All of the data is correct and in-place but I cannot get the "gosh-darn" thing to work. After 18 hours of searching and getting nowhere, I'm livid, giving up, and going to bed.

Please help me explain why (4*2) != 4[0:1]

Edit:
This, stupidly, works:

for (char i = 0; i < m_segments->LineCount; i++)
{
    g_d3dContext->DrawIndexedInstanced(4, 1, i * 4, 0, i * 4);
}

So, now: (4[0] + 4[1]) == (4*2) != 4[0:1]

Verifying, again, that the data is all where it needs to be.. Stumped. It's got to be something so obvious, that it's not. I feel like I'm already over-kill on setting every possible state parameter there is and if I comment any one line, it would switch from doesn't work to shouldn't work and I can't debug it.

\$\endgroup\$
1
  • \$\begingroup\$ Can you modify your title to be more descriptive of the problem you're facing? \$\endgroup\$
    – House
    Mar 27 '15 at 8:25
0
\$\begingroup\$

This was a newbie error. I RTFM, but didn't pay close enough attention and, apparently, hadn't used this draw call in this way before.

Specifically:

This draws 8 consecutively-indexed vertices starting at index 0:

g_d3dContext->DrawIndexed(4 * m_segments->LineCount, 0, 0);

This draws the same 4 consecutively-indexed vertices, starting at index 0, LineCount times:

g_d3dContext->DrawIndexedInstanced(4, m_segments->LineCount, 0, 0, 0);

Since my per-instance data doesn't offer a way to translate the pattern of vertices into place, it's drawing the same segment over and over.

To fix this, I will stuff the coordinates from the 4 separate vertices into a single vertex; each vertex will represent an entire segment.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.