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 Mipmap Map(MapOptions op, uint mipmap, uint face, bool uncompress) { Monitor.Enter(syncRoot); try { AssertNotDisposed(); return(texture.Map(op, mipmap, face, uncompress)); } catch (Exception) { Monitor.Exit(syncRoot); throw; } }
public override Mipmap Map(MapOptions op, uint mipmap, uint face, bool uncompress) { Monitor.Enter(syncRoot); try { AssertNotDisposed(); // We map the mipmap (no need to lock). return(texture2D.Map(op, mostDetailedMipmap + mipmap, face, uncompress)); } catch (Exception) { Monitor.Exit(syncRoot); throw; } }