public static Tuple <TEX_FORMAT, TEX_FORMAT_TYPE> ConvertFormat(SurfaceFormat surfaceFormat, SurfaceFormatType surfaceType) { var format = TEX_FORMAT.UNKNOWN; var type = TEX_FORMAT_TYPE.UNORM; Enum.TryParse(surfaceFormat.ToString(), out format); Enum.TryParse(surfaceType.ToString(), out type); return(Tuple.Create(format, type)); }
private string GetSurfaceFormatFriendlyName(SurfaceFormat f) { switch (f) { case SurfaceFormat.Color: return("32-Bit"); default: return($"<{nameof(SurfaceFormat)}.{f.ToString()}>"); } }
/// <summary> /// Gets a temporary render target to be used for intermediate effects. /// </summary> /// <remarks> /// If a <see cref="RenderTarget2D"/> with the surface format you requested does not exist in the pool, /// it will be created for you. If the system fails to create a render target with the requested surface /// format it throws an InvalidOperationException. /// /// The state of the <see cref="RenderTarget2D"/> that you receive is undetermined. You can NOT assume /// that is has been initialized to any state. /// </remarks> /// <param name="format">The <see cref="SurfaceFormat"/> of the render target.</param> /// <returns>A render target fitting the requested specifications.</returns> public RenderTarget2D GetTemporaryRenderTarget(SurfaceFormat format) { RenderTarget2D pooledRT = this.renderTargetPool.Get((rt) => rt.Format == format, () => this.CreateRenderTarget(this.gfxDevice, format)); if (pooledRT.Format != format) { throw new InvalidOperationException("The system does not support " + format.ToString() + "."); } return(pooledRT); }
public override object Read(BinaryReader reader, string file) { SurfaceFormat pixelFormat = (SurfaceFormat)reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); reader.ReadInt32(); int num = reader.ReadInt32(); byte[] array = new byte[num]; int num2 = reader.Read(array, 0, num); string outfbland = MainClass.OUT_DIR + file.Replace("\\", "/"); string outf = outfbland + "." + width + "." + height + "." + pixelFormat.ToString(); System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outf)); System.IO.File.WriteAllBytes(outf, array); if (pixelFormat == SurfaceFormat.Dxt5) { DDSWriter.WriteDDS(outfbland + ".dds", (uint)width, (uint)height, array); Console.WriteLine("Ripped: " + outfbland + ".dds"); } else if (pixelFormat == SurfaceFormat.Color) { var bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var locked = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); if (array.Length != width * height * 4) { throw new Exception(); } unsafe { byte *bytes = (byte *)locked.Scan0; for (int i = 0; i < width * height * 4; i++) { bytes[i] = array[i]; } } bitmap.UnlockBits(locked); bitmap.Save(outfbland + ".png"); Console.WriteLine("Ripped: " + outfbland + ".png"); } else { Console.WriteLine("!!!FAILED!!!: " + pixelFormat + ""); throw new Exception(); } return(new RippedTexture2D()); }
void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) { int width = 0; int height = 0; int refreshRate = 0; SurfaceFormat format = SurfaceFormat.Color; // The Xbox 360 version uses the resolution which set in the Dashboard. width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; refreshRate = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.RefreshRate; format = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Format; if (height == 0) { throw new FormatException("Not support this graphics adapter"); } e.GraphicsDeviceInformation.PresentationParameters.BackBufferFormat = format; e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = height; e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = width; e.GraphicsDeviceInformation.PresentationParameters.FullScreenRefreshRateInHz = refreshRate; e.GraphicsDeviceInformation.PresentationParameters.IsFullScreen = true; graphicsInfo.screenWidth = width; graphicsInfo.screenHeight = height; System.Diagnostics.Debug.WriteLine("[Graphics Settings]"); System.Diagnostics.Debug.WriteLine("Buffer Format : " + format.ToString()); System.Diagnostics.Debug.WriteLine("Buffer Width : " + width.ToString()); System.Diagnostics.Debug.WriteLine("Buffer Height : " + height.ToString()); System.Diagnostics.Debug.WriteLine("Refresh Rate Hz : " + refreshRate.ToString()); }