public Texture2DArrayView(Texture2D resource, ShaderResourceViewDescription.Texture2DArrayResource description)
            {
                _mipMapCount = description.MipLevels;
                _arraySize = description.ArraySize;

				_subresources = new Texture2D.Texture2DSubresource[description.MipLevels * description.ArraySize];

                int counter = 0;
                for (int i = description.FirstArraySlice; i < description.FirstArraySlice + description.ArraySize; i++)
				    for (int j = description.MostDetailedMip; j < description.MostDetailedMip + description.MipLevels; j++)
					    _subresources[counter++] = resource.GetSubresource(i, j);
			}
示例#2
0
        public void MipMapsHaveCorrectDimensionsForNonPowerOfTwoTexture(int mipLevel, int expectedWidth, int expectedHeight)
        {
            // Arrange.
            var texture = new Texture2D(new Device(), new Texture2DDescription
            {
                Width = 5,
                Height = 16,
                ArraySize = 1
            });

            // Act / Assert.
            int actualWidth, actualHeight;
            texture.GetDimensions(mipLevel, out actualWidth, out actualHeight);
            Assert.That(actualWidth, Is.EqualTo(expectedWidth));
            Assert.That(actualHeight, Is.EqualTo(expectedHeight));
        }
示例#3
0
		internal SwapChain(Device device, SwapChainDescription description, ISwapChainPresenter presenter)
            : base(device)
		{
			_description = description;

            presenter.Initialize(description.Width, description.Height);
		    _presenter = presenter;

		    _backBuffer = new Texture2D(device, new Texture2DDescription
			{
				Width = description.Width,
				Height = description.Height,
				MipLevels = 1,
				ArraySize = 1
			});
		}
示例#4
0
		public void TextureHasCorrectNumberOfMipMapLevels(int width, int height, int expectedNumberOfLevels)
		{
			// Arrange.
			var texture = new Texture2D(new Device(), new Texture2DDescription
			{
				Width = width,
				Height = height,
				ArraySize = 1
			});
			int actualWidth, actualHeight, numberOfLevels;

			// Act.
            texture.GetDimensions(0, out actualWidth, out actualHeight, out numberOfLevels);

			// Assert.
            Assert.That(actualWidth, Is.EqualTo(width));
            Assert.That(actualHeight, Is.EqualTo(height));
            Assert.That(numberOfLevels, Is.EqualTo(expectedNumberOfLevels));
		}
示例#5
0
		public static WriteableBitmap CreateBitmapFromTexture(Texture2D texture, int arraySlice, int mipLevel)
		{
		    var subresource = Resource.CalculateSubresource(mipLevel, arraySlice, texture.Description.MipLevels);
            var colors = texture.GetData(subresource);

            var pixelData = new byte[colors.Length * 4];
            for (int i = 0; i < colors.Length; i++)
            {
                pixelData[(i * 4) + 0] = (byte) (colors[i].B * 255.0f);
                pixelData[(i * 4) + 1] = (byte) (colors[i].G * 255.0f);
                pixelData[(i * 4) + 2] = (byte) (colors[i].R * 255.0f);
                pixelData[(i * 4) + 3] = (byte) (colors[i].A * 255.0f);
            }

            int width, height;
            texture.GetDimensions(mipLevel, out width, out height);

            var bitmapSouce = BitmapSource.Create(width, height, 96, 96, PixelFormats.Bgra32, null,
                pixelData, width * PixelFormats.Bgra32.BitsPerPixel / 8);

            return new WriteableBitmap(bitmapSouce);
		}
			public Texture2DArrayView(Texture2D resource, RenderTargetViewDescription.Texture2DArrayResource description)
			{
				_subresources = new Texture2D.Texture2DSubresource[description.ArraySize];
				for (int i = description.FirstArraySlice; i < description.FirstArraySlice + description.ArraySize; i++)
					_subresources[i] = resource.GetSubresource(i, description.MipSlice);
			}
			public Texture2DView(Texture2D resource, RenderTargetViewDescription.Texture2DResource description)
			{
				_subresource = resource.GetSubresource(0, description.MipSlice);
			}
			public Texture2DView(Texture2D resource, ShaderResourceViewDescription.Texture2DResource description)
			{
				_subresources = new Texture2D.Texture2DSubresource[description.MipLevels];
				for (int i = description.MostDetailedMip; i < description.MostDetailedMip + description.MipLevels; i++)
					_subresources[i] = resource.GetSubresource(0, i);
			}
 public Texture2DViewModel(Texture2D texture)
 {
     _texture = texture;
 }
示例#10
0
 public void AddTextureDiffuse(Device device, Texture2D texture)
 {
     DiffuseTexture = texture;
     DiffuseTextureView = device.CreateShaderResourceView(DiffuseTexture);
 }
			public Texture2DView(Texture2D resource, DepthStencilViewDescription.Texture2DResource description)
			{
				_subresource = resource.GetSubresource(0, description.MipSlice);
			}