I am working on a project that requires some serious drawing and currently I am trying to use the current vertex streams inside the vertex factory to launch a custom shader, but so far it is not working, my current implementation uses a custom vertex declaration and vertex buffer, but obviously is just extra memory, here is what I am attempting:
TArray<FMeshBatch> MeshDescription;
MeshComponent->SceneProxy->GetMeshDescription(0, MeshDescription);
FMeshBatch MeshBatch = MeshDescription[0];
FVertexInputStreamArray VertexStreams;
MeshBatch.VertexFactory->GetStreams(GMaxRHIFeatureLevel, EVertexInputStreamType::Default, VertexStreams);
FMeshBatchElement& MeshBatchElement = MeshBatch.Elements[0];
MeshBatchElement.VertexFactoryUserData = (reinterpret_cast<FLocalVertexFactory*>(const_cast<FVertexFactory*>(MeshBatch.VertexFactory)))->GetUniformBuffer();
const FMeshBatchElement& bElem = MeshBatch.Elements[0];
MeshBatchElement.IndexBuffer = bElem.IndexBuffer;
MeshBatchElement.FirstIndex = bElem.FirstIndex;
MeshBatchElement.NumPrimitives = bElem.NumPrimitives;
MeshBatchElement.MinVertexIndex = bElem.MinVertexIndex;
MeshBatchElement.MaxVertexIndex = bElem.MaxVertexIndex;
RHICmdList.SetStreamSource(0, (FRHIBuffer*)MeshBatchElement.VertexFactoryUserData, 0);
RHICmdList.DrawIndexedPrimitive(bElem.IndexBuffer->IndexBufferRHI, 0, 0, MeshBatchElement.MaxVertexIndex - MeshBatchElement.MinVertexIndex + 1, 0, MeshBatchElement.NumPrimitives / 3, 1);
It does not crash, but it does not work, I am not sure if it is binding the vertex buffers for the UV, maybe that is the only issue