Ejemplo n.º 1
0
        private ShaderResourceView Create1By1Tex(Device device, Color color) {
            var desc2 = new Texture2DDescription {
                SampleDescription = new SampleDescription(1, 0),
                Width = 1,
                Height = 1,
                MipLevels = 1,
                ArraySize = 1,
                Format = Format.R8G8B8A8_UNorm,
                Usage = ResourceUsage.Dynamic,
                BindFlags = BindFlags.ShaderResource,
                CpuAccessFlags = CpuAccessFlags.Write
            };
            var texture = new Texture2D(device, desc2);

            DataStream dataStream;
            var db = device.ImmediateContext.MapSubresource(texture, 0, 0, MapMode.WriteDiscard, MapFlags.None, out dataStream);
            dataStream.Write(color);
            Utilities.Dispose(ref dataStream);
            device.ImmediateContext.UnmapSubresource(texture, 0);

            return texture.AsShaderResourceView();
        }