Esempio n. 1
0
        private static StaticBuffer <ushort> CreateIndexBuffer(GraphicsDevice graphicsDevice, int maxParticles)
        {
            var uploadBatch = new ResourceUploadBatch(graphicsDevice);

            uploadBatch.Begin();

            var indices      = new ushort[maxParticles * 2 * 3]; // Two triangles per particle.
            var indexCounter = 0;

            for (ushort i = 0; i < maxParticles * 4; i += 4)
            {
                indices[indexCounter++] = (ushort)(i + 0);
                indices[indexCounter++] = (ushort)(i + 2);
                indices[indexCounter++] = (ushort)(i + 1);

                indices[indexCounter++] = (ushort)(i + 1);
                indices[indexCounter++] = (ushort)(i + 2);
                indices[indexCounter++] = (ushort)(i + 3);
            }

            var result = StaticBuffer.Create(
                graphicsDevice,
                uploadBatch,
                indices);

            uploadBatch.End();

            return(result);
        }
Esempio n. 2
0
        public T Load <T>(
            string filePath,
            ResourceUploadBatch uploadBatch,
            LoadOptions options = null)
            where T : class
        {
            if (_cachedObjects.TryGetValue(filePath, out var asset))
            {
                return((T)asset);
            }

            var type = typeof(T);

            if (!_contentLoaders.TryGetValue(type, out var contentLoader))
            {
                throw new Exception($"Could not finder content loader for type '{type.FullName}'");
            }

            FileSystemEntry entry = null;

            foreach (var testFilePath in contentLoader.GetPossibleFilePaths(filePath))
            {
                entry = _fileSystem.GetFile(testFilePath);
                if (entry != null)
                {
                    break;
                }
            }

            if (entry != null)
            {
                var createdUploadBatch = false;
                if (uploadBatch == null)
                {
                    uploadBatch = new ResourceUploadBatch(GraphicsDevice);
                    uploadBatch.Begin();
                    createdUploadBatch = true;
                }

                asset = contentLoader.Load(entry, this, uploadBatch);
                if (asset is IDisposable d)
                {
                    AddDisposable(d);
                }

                if (createdUploadBatch)
                {
                    uploadBatch.End();
                }
            }
            else
            {
                asset = contentLoader.PlaceholderValue;
            }

            _cachedObjects.Add(filePath, asset);

            return((T)asset);
        }
Esempio n. 3
0
        public TextureLoader(GraphicsDevice graphicsDevice)
        {
            var uploadBatch = new ResourceUploadBatch(graphicsDevice);

            uploadBatch.Begin();

            PlaceholderValue = AddDisposable(Texture.CreatePlaceholderTexture2D(
                                                 graphicsDevice,
                                                 uploadBatch));

            uploadBatch.End();
        }