From f8d89e597d6f0b166dbbe728e70d2c42554e8d00 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Thu, 4 Jun 2009 10:34:12 +0000 Subject: [PATCH] GraphicsContext.GetCurrentContext now returns an IGraphicsContext instead of a GraphicsContext. Fixed Texture2D finalizer. Removed GraphicsContext.[Enter|Exit]BeginRegion(). GL.Begin|End now calls IGraphicsContext.ErrorChecking = false. --- Source/OpenTK/Graphics/GL/ErrorHelper.cs | 4 ++-- Source/OpenTK/Graphics/GL/GL.cs | 4 ++-- Source/OpenTK/Graphics/GraphicsContext.cs | 21 +++---------------- .../Utilities/Graphics/IGraphicsResource.cs | 2 +- Source/Utilities/Graphics/Texture2D.cs | 13 +++++++----- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Source/OpenTK/Graphics/GL/ErrorHelper.cs b/Source/OpenTK/Graphics/GL/ErrorHelper.cs index b48ed4cd..a9947c25 100644 --- a/Source/OpenTK/Graphics/GL/ErrorHelper.cs +++ b/Source/OpenTK/Graphics/GL/ErrorHelper.cs @@ -51,12 +51,12 @@ namespace OpenTK.Graphics #region Constructors - public ErrorHelper(GraphicsContext context) + public ErrorHelper(IGraphicsContext context) { if (context == null) throw new GraphicsContextMissingException(); - Context = context; + Context = (GraphicsContext)context; Context.ResetErrors(); } diff --git a/Source/OpenTK/Graphics/GL/GL.cs b/Source/OpenTK/Graphics/GL/GL.cs index 1edc955e..26969ba8 100644 --- a/Source/OpenTK/Graphics/GL/GL.cs +++ b/Source/OpenTK/Graphics/GL/GL.cs @@ -24592,7 +24592,7 @@ namespace OpenTK.Graphics #if DEBUG using (new ErrorHelper(GraphicsContext.CurrentContext)) { - GraphicsContext.CurrentContext.EnterBeginRegion(); + GraphicsContext.CurrentContext.ErrorChecking = false; #endif Delegates.glBegin((OpenTK.Graphics.BeginMode)mode); #if DEBUG @@ -36110,7 +36110,7 @@ namespace OpenTK.Graphics #endif Delegates.glEnd(); #if DEBUG - GraphicsContext.CurrentContext.ExitBeginRegion(); + GraphicsContext.CurrentContext.ErrorChecking = true; } #endif } diff --git a/Source/OpenTK/Graphics/GraphicsContext.cs b/Source/OpenTK/Graphics/GraphicsContext.cs index 91668019..cab18135 100644 --- a/Source/OpenTK/Graphics/GraphicsContext.cs +++ b/Source/OpenTK/Graphics/GraphicsContext.cs @@ -184,7 +184,7 @@ namespace OpenTK.Graphics /// /// Gets the GraphicsContext that is current in the calling thread. /// - public static GraphicsContext CurrentContext + public static IGraphicsContext CurrentContext { get { @@ -240,29 +240,14 @@ namespace OpenTK.Graphics #region --- Internal Members --- - bool inside_begin_region; List error_list = new List(); - // Indicates that we entered a GL.Begin() - GL.End() region. - [Conditional("DEBUG")] - internal void EnterBeginRegion() - { - inside_begin_region = true; - } - - // Indicates that we left a GL.Begin() - GL.End() region. - [Conditional("DEBUG")] - internal void ExitBeginRegion() - { - inside_begin_region = false; - } - // Retrieve all OpenGL errors to clear the error list. // See http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/geterror.html [Conditional("DEBUG")] internal void ResetErrors() { - if (check_errors && !inside_begin_region) + if (check_errors) { while (GL.GetError() != ErrorCode.NoError) { } @@ -273,7 +258,7 @@ namespace OpenTK.Graphics [Conditional("DEBUG")] internal void CheckErrors() { - if (check_errors && !inside_begin_region) + if (check_errors) { error_list.Clear(); ErrorCode error; diff --git a/Source/Utilities/Graphics/IGraphicsResource.cs b/Source/Utilities/Graphics/IGraphicsResource.cs index 6453b4e4..e6f79d20 100644 --- a/Source/Utilities/Graphics/IGraphicsResource.cs +++ b/Source/Utilities/Graphics/IGraphicsResource.cs @@ -39,7 +39,7 @@ namespace OpenTK.Graphics /// /// Gets the GraphicsContext that owns this resource. /// - GraphicsContext Context { get; } + IGraphicsContext Context { get; } /// /// Gets the Id of this IGraphicsResource. diff --git a/Source/Utilities/Graphics/Texture2D.cs b/Source/Utilities/Graphics/Texture2D.cs index f6ee304b..3a85f35f 100644 --- a/Source/Utilities/Graphics/Texture2D.cs +++ b/Source/Utilities/Graphics/Texture2D.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Imaging; +using System.Diagnostics; namespace OpenTK.Graphics { @@ -37,7 +38,7 @@ namespace OpenTK.Graphics { #region Fields - GraphicsContext context; + IGraphicsContext context; int id; int width, height; bool disposed; @@ -250,7 +251,7 @@ namespace OpenTK.Graphics #region IGraphicsResource.Context - GraphicsContext IGraphicsResource.Context { get { return context; } } + IGraphicsContext IGraphicsResource.Context { get { return context; } } #endregion @@ -301,15 +302,17 @@ namespace OpenTK.Graphics { GL.DeleteTexture(id); } + else + { + Debug.Print("[Warning] {0} leaked.", this); + } disposed = true; } } ~Texture2D() { - GraphicsContext context = (this as IGraphicsResource).Context; - if (context != null) - (context as IGraphicsContextInternal).RegisterForDisposal(this); + Dispose(false); } #endregion