RuntimeMeshRendering.cpp
Go to the documentation of this file.
1 // Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved.
2 
3 #include "RuntimeMeshRendering.h"
6 
7 
9  : UsageFlags(InUpdateFrequency == EUpdateFrequency::Frequent? BUF_Dynamic : BUF_Static)
10  , VertexSize(InVertexSize)
11  , NumVertices(0)
12  , ShaderResourceView(nullptr)
13 {
14 }
15 
16 void FRuntimeMeshVertexBuffer::Reset(int32 InNumVertices)
17 {
18  NumVertices = InNumVertices;
19  ReleaseResource();
20  InitResource();
21 }
22 
24 {
25  if (VertexSize > 0 && NumVertices > 0)
26  {
27  // Create the vertex buffer
28  FRHIResourceCreateInfo CreateInfo;
29  VertexBufferRHI = RHICreateVertexBuffer(GetBufferSize(), UsageFlags | BUF_ShaderResource, CreateInfo);
30 
31 
32 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 19
33  if (RHISupportsManualVertexFetch(GMaxRHIShaderPlatform))
34  {
35  CreateSRV();
36  }
37 #endif
38  }
39 }
40 
41 /* Set the size of the vertex buffer */
42 void FRuntimeMeshVertexBuffer::SetNum(int32 NewVertexCount)
43 {
44  // Make sure we're not already the right size
45  if (NewVertexCount != NumVertices)
46  {
47  NumVertices = NewVertexCount;
48 
49  // Rebuild resource
50  ReleaseResource();
51  InitResource();
52  }
53 }
54 
55 /* Set the data for the vertex buffer */
56 void FRuntimeMeshVertexBuffer::SetData(const TArray<uint8>& Data)
57 {
58  check(Data.Num() == GetBufferSize());
59 
60  if (GetBufferSize() > 0)
61  {
62  check(VertexBufferRHI.IsValid());
63 
64  // Lock the vertex buffer
65  void* Buffer = RHILockVertexBuffer(VertexBufferRHI, 0, Data.Num(), RLM_WriteOnly);
66 
67  // Write the vertices to the vertex buffer
68  FMemory::Memcpy(Buffer, Data.GetData(), Data.Num());
69 
70  // Unlock the vertex buffer
71  RHIUnlockVertexBuffer(VertexBufferRHI);
72  }
73 }
74 
75 
77  : NumIndices(0), IndexSize(-1), UsageFlags(EBufferUsageFlags::BUF_None)
78 {
79 }
80 
81 void FRuntimeMeshIndexBuffer::Reset(int32 InIndexSize, int32 InNumIndices, EUpdateFrequency InUpdateFrequency)
82 {
83  IndexSize = InIndexSize;
84  NumIndices = InNumIndices;
85  UsageFlags = InUpdateFrequency == EUpdateFrequency::Frequent ? BUF_Dynamic : BUF_Static;
86  ReleaseResource();
87  InitResource();
88 }
89 
91 {
92  if (IndexSize > 0 && NumIndices > 0)
93  {
94  // Create the index buffer
95  FRHIResourceCreateInfo CreateInfo;
96  IndexBufferRHI = RHICreateIndexBuffer(IndexSize, GetBufferSize(), BUF_Dynamic, CreateInfo);
97  }
98 }
99 
100 /* Set the size of the index buffer */
101 void FRuntimeMeshIndexBuffer::SetNum(int32 NewIndexCount)
102 {
103  // Make sure we're not already the right size
104  if (NewIndexCount != NumIndices)
105  {
106  NumIndices = NewIndexCount;
107 
108  // Rebuild resource
109  ReleaseResource();
110  InitResource();
111  }
112 }
113 
114 /* Set the data for the index buffer */
115 void FRuntimeMeshIndexBuffer::SetData(const TArray<uint8>& Data)
116 {
117  check(Data.Num() == GetBufferSize());
118 
119  if (GetBufferSize() > 0)
120  {
121  check(IndexBufferRHI.IsValid());
122 
123  // Lock the index buffer
124  void* Buffer = RHILockIndexBuffer(IndexBufferRHI, 0, Data.Num(), RLM_WriteOnly);
125 
126  // Write the indices to the vertex buffer
127  FMemory::Memcpy(Buffer, Data.GetData(), Data.Num());
128 
129  // Unlock the index buffer
130  RHIUnlockIndexBuffer(IndexBufferRHI);
131  }
132 }
133 
134 
135 
136 
138  : FLocalVertexFactory(
139 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 19
140  InFeatureLevel, "FRuntimeMeshVertexFactory"
141 #endif
142  )
143  , SectionParent(InSectionParent)
144 {
145 }
146 
148 void FRuntimeMeshVertexFactory::Init(FLocalVertexFactory::FDataType VertexStructure)
149 {
150  if (IsInRenderingThread())
151  {
152  SetData(VertexStructure);
153  }
154  else
155  {
156  // Send the command to the render thread
157  // HORU: 4.22 rendering
158  ENQUEUE_RENDER_COMMAND(InitRuntimeMeshVertexFactory)(
159  [this, VertexStructure](FRHICommandListImmediate & RHICmdList)
160  {
161  Init(VertexStructure);
162  }
163  );
164  }
165 }
166 
167 /* Gets the section visibility for static sections */
168 
169 
170 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 19
171 uint64 FRuntimeMeshVertexFactory::GetStaticBatchElementVisibility(const class FSceneView& View, const struct FMeshBatch* Batch, const void* InViewCustomData) const
172 #else
173 uint64 FRuntimeMeshVertexFactory::GetStaticBatchElementVisibility(const class FSceneView& View, const struct FMeshBatch* Batch) const
174 #endif
175 {
176  return SectionParent->ShouldRender();
177 }
const EBufferUsageFlags UsageFlags
FRuntimeMeshVertexFactory(ERHIFeatureLevel::Type InFeatureLevel, FRuntimeMeshSectionProxy *InSectionParent)
EUpdateFrequency
void SetNum(int32 NewIndexCount)
virtual void InitRHI() override
static const textual_icon check
Definition: model-views.h:260
void Reset(int32 InIndexSize, int32 InNumIndices, EUpdateFrequency InUpdateFrequency)
void SetData(const TArray< uint8 > &Data)
void Reset(int32 InNumVertices)
FRuntimeMeshVertexBuffer(EUpdateFrequency InUpdateFrequency, int32 InVertexSize)
FRuntimeMeshSectionProxy * SectionParent
void SetData(const TArray< uint8 > &Data)
virtual void InitRHI() override
void SetNum(int32 NewVertexCount)
void Init(FLocalVertexFactory::FDataType VertexStructure)
virtual uint64 GetStaticBatchElementVisibility(const class FSceneView &View, const struct FMeshBatch *Batch) const


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41