Hello folks,
I tried to generate a stream output with a geometry shader.
But when I "draw" it, the window turns black.
Could someone show me some sample code on geometry shader with stream out or could someone correct my existing code?
Draw call:
bool GeometrySh::Render(ID3D11DeviceContext* deviceContext, int count)
{
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
unsigned int bufferNumber;
BufferType* dataPtr;
result = deviceContext->Map(m_cBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if(FAILED(result))
{
return false;
}
dataPtr = (BufferType*)mappedResource.pData;
dataPtr->lightdir = D3DXVECTOR4(4.0f, 5.0f, 10.0f, 1.0f);
deviceContext->Unmap(m_cBuffer, 0);
bufferNumber = 0;
deviceContext->GSSetConstantBuffers(bufferNumber, 1, &m_cBuffer);
unsigned int stride;
unsigned int offset;
stride = sizeof(VertexType);
offset = 0;
deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
deviceContext->IASetInputLayout(m_gslayout);
deviceContext->SOSetTargets(1, &m_outBuffer, &offset);
deviceContext->GSSetShader(gsshader, NULL, 0);
deviceContext->PSSetShader(NULL, NULL, 0);
deviceContext->VSSetShader(NULL, NULL, 0);
deviceContext->DrawIndexed(count, 0, 0); // If I disable this line that bug dosen't occur
deviceContext->GSSetShader(NULL, NULL, 0);
ID3D11Buffer* pBuffer[1];
pBuffer[0] = NULL;
deviceContext->SOSetTargets(1, pBuffer, &offset);
return true;
}
Shader code:
cbuffer BufferConType
{
float4 lightdir;
}
struct GIN
{
float4 pos : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
struct GOUT
{
float4 pos : POSITION;
};
[maxvertexcount(3)]
void GS(triangleadj GIN input[6], inout TriangleStream<GOUT> OutputStream)
{
//Test geometry shader
GOUT p;
p.pos = input[0].pos;
p.pos.w = 1.0f;
OutputStream.Append(p);
p.pos = input[2].pos;
p.pos.w = 1.0f;
OutputStream.Append(p);
p.pos = input[4].pos;
p.pos.w = 1.0f;
OutputStream.Append(p);
OutputStream.RestartStrip();
}