Where to do call DrawIndexedPrimitiveUP

Hi Guys,

I’m currently creating a ocean plane mesh with LOD like the NVIDIA demo in 2008 in c++ with the hope of
digging into unreal engine rendering system,

Using information from Generate Procedural Mesh - C++ - Epic Developer Community Forums to generate a plane for the ocean surface.

I’m at the part where in the NVIDIA demo code, it do the d3d11Context->DrawIndexed() call

AFAIK the same call can be done in Unreal Engine with, DrawIndexedPrimitiveUP(), but I can’t seem to locate the first parameter to pass, which is a RHICmdList

Here’s my code,

//Declarations

class FOceanMeshVertexBuffer : public FVertexBuffer 
{
public:

	TArray<FVector> Vertices;
	virtual void InitRHI() override;
};

class FOceanMeshIndexBuffer : public FIndexBuffer 
{
public:
	TArray<unsigned long> Indices;

	virtual void InitRHI() override;
};

////////

void FOceanMeshSceneProxy::DrawDynamicElements(FPrimitiveDrawInterface* PDI, const FSceneView* View)
{
	QUICK_SCOPE_CYCLE_COUNTER(STAT_GeneratedMeshSceneProxy_DrawDynamicElements);

	const bool bWireframe = AllowDebugViewmodes() && View->Family->EngineShowFlags.Wireframe;

	FColoredMaterialRenderProxy WireframeMaterialInstance(
		GEngine->WireframeMaterial ? GEngine->WireframeMaterial->GetRenderProxy(IsSelected()) : NULL,
		FLinearColor(0, 0.5f, 1.f)
		);

	DrawIndexedPrimitiveUP(RHICmdList, PT_TriangleList, 0, VertexBuffer.Vertices.Num(), IndexBuffer.Indices.Num() / 3, IndexBuffer, sizeof(unsigned long), VertexBuffer, sizeof(FVector)); //can't do it here, can't find the RHICmdList

}

What I’m wondering is where do I should do the DrawIndexedPrimitiveUP call? I think what I did there is safe since it happens on RenderThread (I checked on visual studio threads window).

Comments from Unreal Dev would be really helpful, so I could know if what I did is “the right way to do it” in unreal.

Thanks!

Unfortunately it’s not that simple. DrawDynamicElements is a callback to the engine module so it knows nothing of renderer internals like the command list. All DrawDynamicElements can do is submit an FMeshBatch description of something to draw, and FMeshDrawingPolicy::DrawMesh will make the actual call to DrawIndexedPrimitiveUP. Sometimes you have to modify FMeshBatch to pass through the data that you want.

Note that in newer builds, DrawDynamicElements is replaced with GetDynamicMeshElements, which is only called once at the beginning of the frame instead of every pass.

Hi ,
I tried using GetDynamicMeshElements, modify the MeshBatch and it succeed drawing the mesh, but going this way, I can’t make batched element correspond with specific vertex shader and pixel shader that I made and then calling the DrawIndexed, how would I do that?

or should I simply use the ENQUEUE_UNIQUE_RENDER_COMMAND macro?

Can you give me a direction on how to do it properly?

Thanks again for the help though!

pseudocode for clarification

virtual void SomeUnrealVirtualFunctionThatIsCalledPerFrame

{

Create Vertex Buffer
Create Index Buffer
Set Vertex Shader
Set Pixel Shader

Set Shader Resources, samplers, constant buffers etc
Set Render State

Set PrimitiveTopology
Draw Indexed

}