private void Build(object arg) { int data = m_DirtyData; Interlocked.CompareExchange(ref m_DirtyData, 0, data); ushort indices = (ushort)((data >> 8) & 0xFFFF); MeshDirtyFlags flags = (MeshDirtyFlags)(data & 0xFF); bool updateSolid = (flags & MeshDirtyFlags.SolidMesh) == MeshDirtyFlags.SolidMesh; bool updateLiquid = (flags & MeshDirtyFlags.LiquidMesh) == MeshDirtyFlags.LiquidMesh; try { if (updateSolid || updateLiquid) { if (m_ShouldWaitForNeighborChunksLoaded) { m_ShouldWaitForNeighborChunksLoaded = false; WorldManager.Active.ChunkManager.WaitForAllNeighborChunksLoaded(this); } SynchronizationContext context = arg as SynchronizationContext; for (int i = SectionCountInChunk - 1; i > -1; i--) { if ((indices & (1u << i)) == 0) { continue; } if (updateSolid) { m_MeshDataBuffer.BeginRewriting(i); BuildSolidMeshData(m_MeshDataBuffer); m_MeshDataBuffer.ApplyToMesh(m_SolidMeshes, context); m_HasBuildedMesh = true; } if (updateLiquid) { m_MeshDataBuffer.BeginRewriting(i); BuildLiquidMeshData(m_MeshDataBuffer); m_MeshDataBuffer.ApplyToMesh(m_LiquidMeshes, context); } } } } #if !UNITY_EDITOR catch { } #endif finally { m_IsBuildingMesh = false; } }
public void Discard() { if (vertexBuffer != null) { vertexBuffer.Discard(); } if (indexBuffer != null) { indexBuffer.Discard(); } DirtyFlags = MeshDirtyFlags.All; }
private void SetMeshDirty(int dirtySectionIndex, MeshDirtyFlags flags) { int data = m_DirtyData; ushort indices = (ushort)((data >> 8) & 0xFFFF); indices |= (ushort)(1 << dirtySectionIndex); MeshDirtyFlags oldFlags = (MeshDirtyFlags)(data & 0xFF); flags |= oldFlags; Interlocked.Exchange(ref m_DirtyData, (indices << 8) | (int)flags); }
private void UpdateInputLayout() { if (inputLayout == null || (DirtyFlags & MeshDirtyFlags.AttributeLocations) != 0) { var elements = new List <VertexInputElement>(); var stride = Toolbox.SizeOf <T>(); foreach (var elementDescription in GetElementDescriptions()) { elements.Add(new VertexInputElement { Slot = 0, Attribute = AttributeLocations[elements.Count], Stride = stride, Offset = elementDescription.Offset, Format = elementDescription.Format, }); } inputLayout = VertexInputLayout.New(elements.ToArray()); DirtyFlags &= ~MeshDirtyFlags.AttributeLocations; } }
private void UpdateBuffers() { if ((DirtyFlags & MeshDirtyFlags.Vertices) != 0) { if (vertexBuffer == null) { vertexBuffer = new VertexBuffer(true); } vertexBuffer.SetData(Vertices, Vertices?.Length ?? 0); DirtyFlags &= ~MeshDirtyFlags.Vertices; } if ((DirtyFlags & MeshDirtyFlags.Indices) != 0) { if (indexBuffer == null) { indexBuffer = new IndexBuffer(true); } indexBuffer.SetData(Indices, Indices?.Length ?? 0); DirtyFlags &= ~MeshDirtyFlags.Indices; } }
private void UpdateInputLayout() { if (inputLayout == null || (DirtyFlags & MeshDirtyFlags.AttributeLocations) != 0) { var bindings = new[] { new VertexInputLayoutBinding { Slot = 0, Stride = sizeof(T) } }; var attributes = new List <VertexInputLayoutAttribute>(); foreach (var elementDescription in GetElementDescriptions()) { attributes.Add(new VertexInputLayoutAttribute { Slot = 0, Location = AttributeLocations[attributes.Count], Offset = elementDescription.Offset, Format = elementDescription.Format, }); } inputLayout = VertexInputLayout.New(bindings, attributes.ToArray()); DirtyFlags &= ~MeshDirtyFlags.AttributeLocations; } }
private void SetDirtyData(ushort dirtySectionIndices, MeshDirtyFlags flags) { Interlocked.Exchange(ref m_DirtyData, (dirtySectionIndices << 8) | (int)flags); }