public ContentLoader()
 {
     materialTextureStorage = new TextureStorage();
     shapeTextureStorage = new TextureStorage();
     //    colorConfiguration = new MaterialConfiguration<ColorContent>();
     //    colorConfiguration.nodeName = "color";
     //    materialTextureConfiguration = new MaterialConfiguration<IndexContent>();
     //    tileTextureConfiguration = new TileConfiguration<IndexContent>();
 }
Example #2
0
        public void Remove(BlockCoordinates coordinates)
        {
            lock (_writeLock)
            {
                if (BlockIndices.Remove(coordinates, out var indices))
                {
                    foreach (var vertex in indices)
                    {
                        TextureStorage.DecrementUsage(vertex.TexCoords);
                        Interlocked.Decrement(ref _vertexCount);
                        //FreeIndex(index);
                    }

                    // ApplyIntermediate();

                    HasChanges = true;
                }
            }
        }
        /// <summary>
        /// Create a new renderer.
        /// </summary>
        /// <param name="graphicsDevice">The <see cref="global::Veldrid.GraphicsDevice"/> to render with.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="graphicsDevice"/> is <c>null</c>.</exception>
        public VeldridRenderer(GraphicsDevice graphicsDevice, TextureStorage <Texture> textureStorage)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException(nameof(graphicsDevice));
            }

            GraphicsDevice = graphicsDevice;
            _currentTarget = GraphicsDevice.SwapchainFramebuffer;

            CreateResources();

            _pipelines           = new Dictionary <OutputDescription, Pipeline>();
            _textureStorage      = textureStorage;
            _textureViews        = new TextureView[32];
            _textureResourceSets = new ResourceSet[32];
            // We lazily create and cache texture views and resource sets when required.
            // When a texture is destroyed the matching cached values are destroyed as well.
            _textureStorage.TextureDestroyed += (s, a) => RemoveTextureResourceSet(a.TextureId);
        }
Example #4
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;
            }
        }
Example #5
0
 public TextureStorageContainer(TextureStorage material, TextureStorage shape, TextureStorage special)
 {
     materialStore = material;
     shapeStore    = shape;
     specialStore  = special;
 }
Example #6
0
 public TextureStorageContainer(TextureStorage material, TextureStorage shape)
 {
     materialStore = material;
     shapeStore = shape;
 }
Example #7
0
 public TextureStorageContainer(TextureStorage material, TextureStorage shape)
 {
     materialStore = material;
     shapeStore    = shape;
 }
Example #8
0
 public static TextureData Pick(this TextureStorage storage, int index)
 {
     return(storage.Textures[index]);
 }
Example #9
0
 public static TextureData RandomPick(this TextureStorage storage)
 {
     return(storage.Textures[Random.Range(0, storage.Textures.Count)]);
 }
Example #10
0
 public static TextureData First(this TextureStorage storage, string name)
 {
     return(storage.Textures.First(texture => texture.Name == name));
 }
Example #11
0
 public TextureStorageContainer(TextureStorage material, TextureStorage shape, TextureStorage special)
 {
     materialStore = material;
     shapeStore = shape;
     specialStore = special;
 }
Example #12
0
    public void Awake()
    {
        materialTextureStorage = new TextureStorage();
        shapeTextureStorage = new TextureStorage();
        specialTextureStorage = new TextureStorage();
        materialColors = new MaterialMatcher<ColorContent>();
        materialTextures = new MaterialMatcher<TextureContent>();

        DefaultMatTexIndex = materialTextureStorage.AddTexture(CreateFlatTexture(new Color(0.5f, 0.5f, 0.5f, 0)));
        DefaultShapeTexIndex = shapeTextureStorage.AddTexture(CreateFlatTexture(new Color(1f, 0.5f, 1f, 0.5f)));
        defaultSpecialTexIndex = specialTextureStorage.AddTexture(Texture2D.blackTexture);
    }
Example #13
0
 /// <summary>
 /// Loads textures from storage.
 /// </summary>
 /// <param name="textureStorage">Texture storage.</param>
 public void LoadTextures(TextureStorage textureStorage)
 {
     _textureStorage = textureStorage;
 }
Example #14
0
 public ContentLoader()
 {
     materialTextureStorage = new TextureStorage();
     shapeTextureStorage = new TextureStorage();
     materialColors = new MaterialMatcher<ColorContent>();
     materialTextures = new MaterialMatcher<TextureContent>();
 }
Example #15
0
 /// <summary>
 /// Loads textures from storage.
 /// </summary>
 /// <param name="textureStorage">Texture storage.</param>
 public void LoadTextures(TextureStorage textureStorage)
 {
     _textureStorage = textureStorage;
 }
Example #16
0
        /// <summary>
        ///     Allows the game to perform any initialization it needs to before starting to run.
        ///     This is where it can query for any required services and load any non-graphic
        ///     related content.  Calling base.Initialize will enumerate through any components
        ///     and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            textureStorage = new TextureStorage(Content);

            base.Initialize();
        }