Example #1
0
        public void AddVertex(BlockCoordinates blockCoordinates,
                              Vector3 position,
                              Vector2 textureCoordinates,
                              Color color,
                              byte blockLight,
                              byte skyLight)
        {
            lock (_writeLock)
            {
                //Add(blockCoordinates, position, textureCoordinates, color, blockLight, skyLight);
                var textureIndex = TextureStorage.GetIndex(textureCoordinates);

                if (textureIndex == -1)
                {
                    textureIndex = TextureStorage.Add(textureCoordinates);
                }

                TextureStorage.IncreaseUsage(textureIndex);

                var vertexData = new VertexData(
                    position, (ushort)textureIndex, color.PackedValue, (byte)blockLight,
                    skyLight);

                Interlocked.Increment(ref _vertexCount);

                if (BlockIndices.TryGetValue(blockCoordinates, out var list))
                {
                    list.Add(vertexData);
                }
                else
                {
                    BlockIndices.Add(blockCoordinates, new List <VertexData>()
                    {
                        vertexData
                    });
                }

                HasChanges = true;
            }
        }