RuntimeMeshSectionProxy.cpp
Go to the documentation of this file.
1 // Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved.
2 
5 
6 
7 
8 
10  : UpdateFrequency(CreationData->UpdateFrequency)
11  , VertexFactory(InFeatureLevel, this)
12  , PositionBuffer(CreationData->UpdateFrequency)
13  , TangentsBuffer(CreationData->UpdateFrequency, CreationData->TangentsVertexBuffer.bUsingHighPrecision)
14  , UVsBuffer(CreationData->UpdateFrequency, CreationData->UVsVertexBuffer.bUsingHighPrecision, CreationData->UVsVertexBuffer.NumUVs)
15  , ColorBuffer(CreationData->UpdateFrequency)
16  , bIsVisible(CreationData->bIsVisible)
17  , bCastsShadow(CreationData->bCastsShadow)
18 {
19  check(IsInRenderingThread());
20 
21  PositionBuffer.Reset(CreationData->PositionVertexBuffer.NumVertices);
22  PositionBuffer.SetData(CreationData->PositionVertexBuffer.Data);
23 
24  TangentsBuffer.Reset(CreationData->TangentsVertexBuffer.NumVertices);
25  TangentsBuffer.SetData(CreationData->TangentsVertexBuffer.Data);
26 
27  UVsBuffer.Reset(CreationData->UVsVertexBuffer.NumVertices);
28  UVsBuffer.SetData(CreationData->UVsVertexBuffer.Data);
29 
30  ColorBuffer.Reset(CreationData->ColorVertexBuffer.NumVertices);
31  ColorBuffer.SetData(CreationData->ColorVertexBuffer.Data);
32 
33 
34  IndexBuffer.Reset(CreationData->IndexBuffer.b32BitIndices ? 4 : 2, CreationData->IndexBuffer.NumIndices, UpdateFrequency);
35  IndexBuffer.SetData(CreationData->IndexBuffer.Data);
36 
37  AdjacencyIndexBuffer.Reset(CreationData->IndexBuffer.b32BitIndices ? 4 : 2, CreationData->AdjacencyIndexBuffer.NumIndices, UpdateFrequency);
38  AdjacencyIndexBuffer.SetData(CreationData->AdjacencyIndexBuffer.Data);
39 
40 
41 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 19
42  if (CanRender())
43  {
44 #endif
45  FLocalVertexFactory::FDataType DataType;
46  BuildVertexDataType(DataType);
47 
48  VertexFactory.Init(DataType);
49  VertexFactory.InitResource();
50 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 19
51  }
52 #endif
53 }
54 
56 {
57  check(IsInRenderingThread());
58 
59  PositionBuffer.ReleaseResource();
60  TangentsBuffer.ReleaseResource();
61  UVsBuffer.ReleaseResource();
62  ColorBuffer.ReleaseResource();
63  IndexBuffer.ReleaseResource();
64  AdjacencyIndexBuffer.ReleaseResource();
65  VertexFactory.ReleaseResource();
66 }
67 
69 {
70  return bIsVisible && CanRender();
71 }
72 
74 {
75  if (PositionBuffer.Num() <= 0)
76  {
77  return false;
78  }
79 
81  {
82  return false;
83  }
84 
85  return true;
86 }
87 
89 {
90  return UpdateFrequency == EUpdateFrequency::Infrequent;
91 }
92 
94 {
95  return bCastsShadow;
96 }
97 
98 
99 void FRuntimeMeshSectionProxy::CreateMeshBatch(FMeshBatch& MeshBatch, bool bWantsAdjacencyInfo)
100 {
101  MeshBatch.VertexFactory = &VertexFactory;
102 
103  MeshBatch.Type = bWantsAdjacencyInfo ? PT_12_ControlPointPatchList : PT_TriangleList;
104 
105  MeshBatch.DepthPriorityGroup = SDPG_World;
106  MeshBatch.CastShadow = bCastsShadow;
107 
108  // Make sure that if the material wants adjacency information, that you supply it
109  check(!bWantsAdjacencyInfo || AdjacencyIndexBuffer.Num() > 0);
110 
111  FRuntimeMeshIndexBuffer* CurrentIndexBuffer = bWantsAdjacencyInfo ? &AdjacencyIndexBuffer : &IndexBuffer;
112 
113  int32 NumIndicesPerTriangle = bWantsAdjacencyInfo ? 12 : 3;
114  int32 NumPrimitives = CurrentIndexBuffer->Num() / NumIndicesPerTriangle;
115 
116  FMeshBatchElement& BatchElement = MeshBatch.Elements[0];
117  BatchElement.IndexBuffer = CurrentIndexBuffer;
118  BatchElement.FirstIndex = 0;
119  BatchElement.NumPrimitives = NumPrimitives;
120  BatchElement.MinVertexIndex = 0;
121  BatchElement.MaxVertexIndex = PositionBuffer.Num() - 1;
122 }
123 
124 void FRuntimeMeshSectionProxy::BuildVertexDataType(FLocalVertexFactory::FDataType& DataType)
125 {
126  PositionBuffer.Bind(DataType);
127  TangentsBuffer.Bind(DataType);
128  UVsBuffer.Bind(DataType);
129  ColorBuffer.Bind(DataType);
130 }
131 
133 {
134  check(IsInRenderingThread());
135 
136  // Update position buffer
137  if (!!(UpdateData->BuffersToUpdate & ERuntimeMeshBuffersToUpdate::PositionBuffer))
138  {
139  PositionBuffer.Reset(UpdateData->PositionVertexBuffer.NumVertices);
140  PositionBuffer.SetData(UpdateData->PositionVertexBuffer.Data);
141  }
142 
143  // Update tangent buffer
144  if (!!(UpdateData->BuffersToUpdate & ERuntimeMeshBuffersToUpdate::TangentBuffer))
145  {
146  TangentsBuffer.SetNum(UpdateData->TangentsVertexBuffer.NumVertices);
147  TangentsBuffer.SetData(UpdateData->TangentsVertexBuffer.Data);
148  }
149 
150  // Update uv buffer
151  if (!!(UpdateData->BuffersToUpdate & ERuntimeMeshBuffersToUpdate::UVBuffer))
152  {
153  UVsBuffer.SetNum(UpdateData->UVsVertexBuffer.NumVertices);
154  UVsBuffer.SetData(UpdateData->UVsVertexBuffer.Data);
155  }
156 
157  // Update color buffer
158  if (!!(UpdateData->BuffersToUpdate & ERuntimeMeshBuffersToUpdate::ColorBuffer))
159  {
160  ColorBuffer.SetNum(UpdateData->ColorVertexBuffer.NumVertices);
161  ColorBuffer.SetData(UpdateData->ColorVertexBuffer.Data);
162  }
163 
164  // Update index buffer
165  if (!!(UpdateData->BuffersToUpdate & ERuntimeMeshBuffersToUpdate::IndexBuffer))
166  {
167  IndexBuffer.SetNum(UpdateData->IndexBuffer.NumIndices);
168  IndexBuffer.SetData(UpdateData->IndexBuffer.Data);
169  }
170 
171  // Update index buffer
172  if (!!(UpdateData->BuffersToUpdate & ERuntimeMeshBuffersToUpdate::AdjacencyIndexBuffer))
173  {
174  AdjacencyIndexBuffer.SetNum(UpdateData->AdjacencyIndexBuffer.NumIndices);
175  AdjacencyIndexBuffer.SetData(UpdateData->AdjacencyIndexBuffer.Data);
176  }
177 
178 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 19
179  // If this platform uses manual vertex fetch, we need to update the SRVs
180  if (RHISupportsManualVertexFetch(GMaxRHIShaderPlatform))
181  {
182  FLocalVertexFactory::FDataType DataType;
183  BuildVertexDataType(DataType);
184 
185  VertexFactory.ReleaseResource();
186  VertexFactory.Init(DataType);
187  VertexFactory.InitResource();
188  }
189 #endif
190 }
191 
193 {
194  // Copy visibility/shadow
195  bIsVisible = UpdateData->bIsVisible;
196  bCastsShadow = UpdateData->bCastsShadow;
197 }
FRuntimeMeshVertexFactory VertexFactory
virtual void Bind(FLocalVertexFactory::FDataType &DataType) override
FRuntimeMeshTangentsVertexBuffer TangentsBuffer
virtual void Bind(FLocalVertexFactory::FDataType &DataType) override
virtual void Bind(FLocalVertexFactory::FDataType &DataType) override
FRuntimeMeshUVsVertexBuffer UVsBuffer
void SetNum(int32 NewIndexCount)
TSharedPtr< FRuntimeMeshSectionPropertyUpdateParams, ESPMode::NotThreadSafe > FRuntimeMeshSectionPropertyUpdateParamsPtr
TSharedPtr< FRuntimeMeshSectionUpdateParams, ESPMode::NotThreadSafe > FRuntimeMeshSectionUpdateParamsPtr
void CreateMeshBatch(FMeshBatch &MeshBatch, bool bWantsAdjacencyInfo)
FRuntimeMeshSectionProxy(ERHIFeatureLevel::Type InFeatureLevel, FRuntimeMeshSectionCreationParamsPtr CreationData)
virtual void Bind(FLocalVertexFactory::FDataType &DataType) override
void FinishUpdate_RenderThread(FRuntimeMeshSectionUpdateParamsPtr UpdateData)
FRuntimeMeshIndexBuffer IndexBuffer
static const textual_icon check
Definition: model-views.h:260
void Reset(int32 InIndexSize, int32 InNumIndices, EUpdateFrequency InUpdateFrequency)
void BuildVertexDataType(FLocalVertexFactory::FDataType &DataType)
void FinishPropertyUpdate_RenderThread(FRuntimeMeshSectionPropertyUpdateParamsPtr UpdateData)
FRuntimeMeshPositionVertexBuffer PositionBuffer
void SetData(const TArray< uint8 > &Data)
void Reset(int32 InNumVertices)
TSharedPtr< FRuntimeMeshSectionCreationParams, ESPMode::NotThreadSafe > FRuntimeMeshSectionCreationParamsPtr
FRuntimeMeshIndexBuffer AdjacencyIndexBuffer
void SetData(const TArray< uint8 > &Data)
FRuntimeMeshColorVertexBuffer ColorBuffer
void SetNum(int32 NewVertexCount)
void Init(FLocalVertexFactory::FDataType VertexStructure)


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