/// <summary> /// Creates a texture that contains the data from the given sampled figure using the given view. /// </summary> public static unsafe Texture Create(SampledFigure Figure, View View, Format Format, int Width, int Height) { Texture tex; byte[] data = new byte[Width * Height * 4]; fixed (byte* ptr = data) { WriteImageARGB(Figure, View, Width, Height, ptr); tex = Create(); SetImage(Format, 0, Width, Height, ptr); GenerateMipmap(); SetFilterMode(TextureMinFilter.LinearMipmapLinear, TextureMagFilter.Linear); } return tex; }
/// <summary> /// Writes a 32bpp ARGB image for the given view of a sampled figure. /// </summary> public static unsafe void WriteImageARGB(SampledFigure Figure, View View, int Width, int Height, byte* Data) { Point xdelta = View.Right / Width; Point ydelta = View.Down / Height; Point offset = View.Offset + xdelta * 0.5 + ydelta * 0.5; for (int x = 0; x < Width; x++) { Point tpos = offset + xdelta * x; for (int y = 0; y < Height; y++) { Point pos = tpos + ydelta * y; GColor col = Figure.GetColor(pos); Data[3] = (byte)(col.A * 255.0); Data[2] = (byte)(col.R * 255.0); Data[1] = (byte)(col.G * 255.0); Data[0] = (byte)(col.B * 255.0); Data += 4; } } }