//private class ScissorContext : IDisposable //{ // private IntRectangle _previous; // private bool _wasEnabled; // private bool _isDisposed = false; // // public ScissorContext(IntRectangle region) // { // this._wasEnabled = Scissor.IsEnabled; // this._previous = Scissor.Region; // Scissor.Region = region; // Scissor.IsEnabled = true; // } // // ~ScissorContext() // { // Async.Throw(new ObjectDisposedIncorrectlyException("A context returned from GRaff.Graphics.Scissor.Context was garbage collected before Dispose was called.")); // } // // public void Dispose() // { // if (!_isDisposed) // { // GC.SuppressFinalize(this); // _isDisposed = true; // Scissor.Region = _previous; // Scissor.IsEnabled = _wasEnabled; // } // else // throw new ObjectDisposedException("Scissor"); // } //} // public static IDisposable Use(IntRectangle region) { return(UseContext.CreateAt( $"{typeof(Scissor).FullName}.{nameof(Use)}", (enabled: Scissor.IsEnabled, region: Scissor.Region), () => { Scissor.IsEnabled = true; Scissor.Region = region; }, previous => { Scissor.IsEnabled = previous.enabled; Scissor.Region = previous.region; } )); }
public IDisposable Use() { return(UseContext.CreateAt( $"{typeof(BlendMode).FullName}.{nameof(Use)}", Current, () => Current = this, previous => Current = previous )); }
public IDisposable Use() { return(UseContext.CreateAt( $"{typeof(ShaderProgram).FullName}.{nameof(Use)}", ShaderProgram.Current, () => this.Bind(), previous => previous.Bind() )); }
public IDisposable Use() { return(UseContext.CreateAt($"{typeof(Framebuffer).FullName}.{nameof(Use)}", (frameBuffer: Framebuffer.Current, viewContext: View.Framebuffer().Use()), () => GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.Id), capture => { GL.BindFramebuffer(FramebufferTarget.Framebuffer, capture.frameBuffer?.Id ?? 0); capture.viewContext.Dispose(); })); }