x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 https://forums.unrealengine.com/showthread.php?1552-Generate-Procedural-Mesh 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!

Product Version: Not Selected
Tags:
more ▼

asked Mar 02 '15 at 07:16 AM in Rendering

avatar image

ernesernesto
48 10 13 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Mar 02 '15 at 09:14 PM

avatar image

DanielW STAFF
1.9k 31 11 74

avatar image ernesernesto Mar 04 '15 at 03:38 AM

Hi Daniel, 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!

avatar image ernesernesto Mar 04 '15 at 03:42 AM

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

}

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question