TextureView CreateSampleTexture() { // Non-mipmapped. TypelessTexture2D texture = new TypelessTexture2D(Usage.Default, TextureUsage.Texture, CPUAccess.None, PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"), 512, 512, 1, GraphicsLocality.DeviceOrSystemMemory, null); // We create data. byte[] data = texture.Map(MapOptions.Write, 0).Data; for (int x = 0; x < 512; x++) { for (int y = 0; y < 512; y++) { int idx = (y * 512 + x) * 4; data[idx] = (byte)((x * 256) / 512); data[idx + 1] = (byte)((y * 256) / 512); data[idx + 2] = (byte)(((x + y) * 256) / 1024); data[idx + 3] = 100; // Semi-Transparent } } texture.UnMap(0); texture.DisposeOnViewDispose = true; return(texture.CreateTexture()); }
public override void UnMap(uint mipmap) { try { AssertNotDisposed(); texture.UnMap(mipmap); } finally { Monitor.Exit(syncRoot); } }