示例#1
0
        public void Texture2D()
        {
            BlittableRGBA[] pixels = new BlittableRGBA[]
            {
                new BlittableRGBA(Color.Red),
                new BlittableRGBA(Color.Green)
            };
            int sizeInBytes = ArraySizeInBytes.Size(pixels);
            Texture2DDescription description = new Texture2DDescription(2, 1, TextureFormat.RedGreenBlueAlpha8, false);

            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (WritePixelBuffer writePixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, sizeInBytes))
                    using (Texture2D texture = Device.CreateTexture2D(description))
                    {
                        writePixelBuffer.CopyFromSystemMemory(pixels);

                        //
                        // Create texture with pixel buffer
                        //
                        texture.CopyFromBuffer(writePixelBuffer, BlittableRGBA.Format, BlittableRGBA.Datatype);

                        //
                        // Read back pixels
                        //
                        using (ReadPixelBuffer readPixelBuffer = texture.CopyToBuffer(BlittableRGBA.Format, BlittableRGBA.Datatype))
                        {
                            BlittableRGBA[] readPixels = readPixelBuffer.CopyToSystemMemory <BlittableRGBA>();

                            Assert.AreEqual(sizeInBytes, readPixelBuffer.SizeInBytes);
                            Assert.AreEqual(pixels[0], readPixels[0]);
                            Assert.AreEqual(pixels[1], readPixels[1]);
                            Assert.AreEqual(description, texture.Description);
                        }
                    }
        }
        public void WritePixelBuffer()
        {
            BlittableRGBA[] pixels = new BlittableRGBA[]
            {
                new BlittableRGBA(Color.Red),
                new BlittableRGBA(Color.Green),
                new BlittableRGBA(Color.Blue),
                new BlittableRGBA(Color.White)
            };
            int sizeInBytes = ArraySizeInBytes.Size(pixels);

            using (GraphicsWindow window = Device.CreateWindow(1, 1))
                using (WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, sizeInBytes))
                {
                    //
                    // Verify creating pixel buffer
                    //
                    Assert.IsNotNull(pixelBuffer);
                    Assert.AreEqual(PixelBufferHint.Stream, pixelBuffer.UsageHint);
                    Assert.AreEqual(sizeInBytes, pixelBuffer.SizeInBytes);

                    //
                    // Verify copying entire buffer between system memory and pixel buffer
                    //
                    pixelBuffer.CopyFromSystemMemory(pixels);

                    BlittableRGBA[] pixels2 = pixelBuffer.CopyToSystemMemory <BlittableRGBA>(0, pixelBuffer.SizeInBytes);
                    Assert.AreEqual(pixels[0], pixels2[0]);
                    Assert.AreEqual(pixels[1], pixels2[1]);
                    Assert.AreEqual(pixels[2], pixels2[2]);

                    //
                    // Verify modiying a subset of the vertex buffer
                    //
                    BlittableRGBA modifiedPixel = new BlittableRGBA(Color.Black);
                    pixelBuffer.CopyFromSystemMemory(new[] { modifiedPixel }, SizeInBytes <BlittableRGBA> .Value);

                    BlittableRGBA[] pixels3 = pixelBuffer.CopyToSystemMemory <BlittableRGBA>(0, pixelBuffer.SizeInBytes);
                    Assert.AreEqual(pixels[0], pixels3[0]);
                    Assert.AreEqual(modifiedPixel, pixels3[1]);
                    Assert.AreEqual(pixels[2], pixels3[2]);
                }
        }
示例#3
0
 public TextureFactory(Context context, BlittableRGBA rgba)
 {
     _context = context;
     _rgba    = rgba;
 }