示例#1
0
        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 Image CloneSameType(PixelFormat fmt, uint width, uint height,
                                            uint depth, uint faces, uint mipmaps)
        {
            lock (syncRoot)
            {
                AssertNotDisposed();

                // We clone the same image and the view.
                TypelessTexture2D baseTexture = texture2D.CloneSameType(fmt, width,
                                                                        height, depth, faces, mipmaps) as TypelessTexture2D;

                // And create the view (mostDetailed and mipmapCount may be clamped).
                return(baseTexture.CreateTexture(format, mostDetailedMipmap, mipmapCount));
            }
        }