Represents and provides methods to manipulate an OpenGL render context. More...
Public Member Functions | |
| GraphicsContext (GraphicsMode mode, IWindowInfo window) | |
| Constructs a new GraphicsContext with the specified GraphicsMode and attaches it to the specified window. | |
| GraphicsContext (GraphicsMode mode, IWindowInfo window, int major, int minor, GraphicsContextFlags flags) | |
| Constructs a new GraphicsContext with the specified GraphicsMode, version and flags, and attaches it to the specified window. | |
| GraphicsContext (ContextHandle handle, IWindowInfo window) | |
| Constructs a new GraphicsContext from a pre-existing context created outside of OpenTK. | |
| GraphicsContext (ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, int major, int minor, GraphicsContextFlags flags) | |
| Constructs a new GraphicsContext from a pre-existing context created outside of OpenTK. | |
| void | SwapBuffers () |
| Swaps buffers on a context. This presents the rendered scene to the user. | |
| void | MakeCurrent (IWindowInfo window) |
| Makes the GraphicsContext the current rendering target. | |
| void | Update (IWindowInfo window) |
| Updates the graphics context. This must be called when the render target is resized for proper behavior on Mac OS X. | |
| void | Dispose () |
| Disposes of the GraphicsContext. | |
Static Public Member Functions | |
| static GraphicsContext | CreateDummyContext () |
| Creates a dummy GraphicsContext to allow OpenTK to work with contexts created by external libraries. | |
| static GraphicsContext | CreateDummyContext (ContextHandle handle) |
| Creates a dummy GraphicsContext to allow OpenTK to work with contexts created by external libraries. | |
| static void | Assert () |
| Checks if a GraphicsContext exists in the calling thread and throws a GraphicsContextMissingException if it doesn't. | |
Properties | |
| static IGraphicsContext | CurrentContext [get] |
| Gets the GraphicsContext that is current in the calling thread. | |
| static bool | ShareContexts [get, set] |
| Gets or sets a System.Boolean, indicating whether GraphicsContext resources are shared. | |
| static bool | DirectRendering [get, set] |
| Gets or sets a System.Boolean, indicating whether GraphicsContexts will perform direct rendering. | |
| bool | ErrorChecking [get, set] |
| Gets or sets a System.Boolean, indicating whether automatic error checking should be performed. Influences the debug version of OpenTK.dll, only. | |
| bool | IsCurrent [get] |
| Gets a System.Boolean indicating whether this instance is current in the calling thread. | |
| bool | IsDisposed [get, set] |
| Gets a System.Boolean indicating whether this instance has been disposed. It is an error to access any instance methods if this property returns true. | |
| bool | VSync [get, set] |
| Gets or sets a value indicating whether VSync is enabled. | |
| GraphicsMode | GraphicsMode [get] |
| Gets the GraphicsMode of the context. | |
Represents and provides methods to manipulate an OpenGL render context.
Definition at line 21 of file GraphicsContext.cs.
| OpenTK.Graphics.GraphicsContext.GraphicsContext | ( | GraphicsMode | mode, | |
| IWindowInfo | window | |||
| ) |
Constructs a new GraphicsContext with the specified GraphicsMode and attaches it to the specified window.
| mode | The OpenTK.Graphics.GraphicsMode of the GraphicsContext. | |
| window | The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to. |
Definition at line 59 of file GraphicsContext.cs.
| OpenTK.Graphics.GraphicsContext.GraphicsContext | ( | GraphicsMode | mode, | |
| IWindowInfo | window, | |||
| int | major, | |||
| int | minor, | |||
| GraphicsContextFlags | flags | |||
| ) |
Constructs a new GraphicsContext with the specified GraphicsMode, version and flags, and attaches it to the specified window.
| mode | The OpenTK.Graphics.GraphicsMode of the GraphicsContext. | |
| window | The OpenTK.Platform.IWindowInfo to attach the GraphicsContext to. | |
| major | The major version of the new GraphicsContext. | |
| minor | The minor version of the new GraphicsContext. | |
| flags | The GraphicsContextFlags for the GraphicsContext. |
Different hardware supports different flags, major and minor versions. Invalid parameters will be silently ignored.
Definition at line 74 of file GraphicsContext.cs.
00075 { 00076 lock (SyncRoot) 00077 { 00078 bool designMode = false; 00079 if (mode == null && window == null) 00080 designMode = true; 00081 else if (mode == null) throw new ArgumentNullException("mode", "Must be a valid GraphicsMode."); 00082 else if (window == null) throw new ArgumentNullException("window", "Must point to a valid window."); 00083 00084 // Silently ignore invalid major and minor versions. 00085 if (major <= 0) 00086 major = 1; 00087 if (minor < 0) 00088 minor = 0; 00089 00090 Debug.Print("Creating GraphicsContext."); 00091 try 00092 { 00093 Debug.Indent(); 00094 Debug.Print("GraphicsMode: {0}", mode); 00095 Debug.Print("IWindowInfo: {0}", window); 00096 Debug.Print("GraphicsContextFlags: {0}", flags); 00097 Debug.Print("Requested version: {0}.{1}", major, minor); 00098 00099 IGraphicsContext shareContext = shareContext = FindSharedContext(); 00100 00101 // Todo: Add a DummyFactory implementing IPlatformFactory. 00102 if (designMode) 00103 { 00104 implementation = new Platform.Dummy.DummyGLContext(); 00105 } 00106 else 00107 { 00108 IPlatformFactory factory = null; 00109 switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded) 00110 { 00111 case false: factory = Factory.Default; break; 00112 case true: factory = Factory.Embedded; break; 00113 } 00114 00115 implementation = factory.CreateGLContext(mode, window, shareContext, direct_rendering, major, minor, flags); 00116 // Note: this approach does not allow us to mix native and EGL contexts in the same process. 00117 // This should not be a problem, as this use-case is not interesting for regular applications. 00118 if (GetCurrentContext == null) 00119 GetCurrentContext = factory.CreateGetCurrentGraphicsContext(); 00120 } 00121 00122 available_contexts.Add((this as IGraphicsContextInternal).Context, new WeakReference(this)); 00123 } 00124 finally 00125 { 00126 Debug.Unindent(); 00127 } 00128 } 00129 }
| OpenTK.Graphics.GraphicsContext.GraphicsContext | ( | ContextHandle | handle, | |
| IWindowInfo | window | |||
| ) |
Constructs a new GraphicsContext from a pre-existing context created outside of OpenTK.
| handle | The handle of the existing context. This must be a valid, unique handle that is not known to OpenTK. | |
| window | The window this context is bound to. This must be a valid window obtained through Utilities.CreateWindowInfo. |
| GraphicsContextException | Occurs if handle is identical to a context already registered with OpenTK. |
Definition at line 137 of file GraphicsContext.cs.
| OpenTK.Graphics.GraphicsContext.GraphicsContext | ( | ContextHandle | handle, | |
| IWindowInfo | window, | |||
| IGraphicsContext | shareContext, | |||
| int | major, | |||
| int | minor, | |||
| GraphicsContextFlags | flags | |||
| ) |
Constructs a new GraphicsContext from a pre-existing context created outside of OpenTK.
| handle | The handle of the existing context. This must be a valid, unique handle that is not known to OpenTK. | |
| window | The window this context is bound to. This must be a valid window obtained through Utilities.CreateWindowInfo. | |
| shareContext | A different context that shares resources with this instance, if any. Pass null if the context is not shared or if this is the first GraphicsContext instruct you construct. | |
| major | The major version of the context (e.g. "2" for "2.1"). | |
| minor | The minor version of the context (e.g. "1" for "2.1"). | |
| flags | A bitwise combination of GraphicsContextFlags that describe this context. |
| GraphicsContextException | Occurs if handle is identical to a context already registered with OpenTK. |
Definition at line 152 of file GraphicsContext.cs.
00153 { 00154 lock (SyncRoot) 00155 { 00156 IsExternal = true; 00157 00158 if (handle == ContextHandle.Zero) 00159 { 00160 implementation = new OpenTK.Platform.Dummy.DummyGLContext(handle); 00161 } 00162 else if (available_contexts.ContainsKey(handle)) 00163 { 00164 throw new GraphicsContextException("Context already exists."); 00165 } 00166 else 00167 { 00168 switch ((flags & GraphicsContextFlags.Embedded) == GraphicsContextFlags.Embedded) 00169 { 00170 case false: implementation = Factory.Default.CreateGLContext(handle, window, shareContext, direct_rendering, major, minor, flags); break; 00171 case true: implementation = Factory.Embedded.CreateGLContext(handle, window, shareContext, direct_rendering, major, minor, flags); break; 00172 } 00173 } 00174 00175 available_contexts.Add((implementation as IGraphicsContextInternal).Context, new WeakReference(this)); 00176 00177 (this as IGraphicsContextInternal).LoadAll(); 00178 } 00179 }
| static void OpenTK.Graphics.GraphicsContext.Assert | ( | ) | [static] |
Checks if a GraphicsContext exists in the calling thread and throws a GraphicsContextMissingException if it doesn't.
| GraphicsContextMissingException | Generated when no GraphicsContext is current in the calling thread. |
Definition at line 245 of file GraphicsContext.cs.
00246 { 00247 if (GraphicsContext.CurrentContext == null) 00248 throw new GraphicsContextMissingException(); 00249 }
| static GraphicsContext OpenTK.Graphics.GraphicsContext.CreateDummyContext | ( | ContextHandle | handle | ) | [static] |
Creates a dummy GraphicsContext to allow OpenTK to work with contexts created by external libraries.
| handle | The handle of a context. |
Instances created by this method will not be functional. Instance methods will have no effect.
Definition at line 229 of file GraphicsContext.cs.
00230 { 00231 if (handle == ContextHandle.Zero) 00232 throw new ArgumentOutOfRangeException("handle"); 00233 00234 return new GraphicsContext(handle); 00235 }
| static GraphicsContext OpenTK.Graphics.GraphicsContext.CreateDummyContext | ( | ) | [static] |
Creates a dummy GraphicsContext to allow OpenTK to work with contexts created by external libraries.
Instances created by this method will not be functional. Instance methods will have no effect.
This method requires that a context is current on the calling thread.
Definition at line 212 of file GraphicsContext.cs.
00213 { 00214 ContextHandle handle = GetCurrentContext(); 00215 if (handle == ContextHandle.Zero) 00216 throw new InvalidOperationException("No GraphicsContext is current on the calling thread."); 00217 00218 return CreateDummyContext(handle); 00219 }
| void OpenTK.Graphics.GraphicsContext.Dispose | ( | ) |
Disposes of the GraphicsContext.
Definition at line 475 of file GraphicsContext.cs.
00476 { 00477 this.Dispose(true); 00478 GC.SuppressFinalize(this); 00479 }
| void OpenTK.Graphics.GraphicsContext.MakeCurrent | ( | IWindowInfo | window | ) |
Makes the GraphicsContext the current rendering target.
| window | A valid OpenTK.Platform.IWindowInfo structure. |
You can use this method to bind the GraphicsContext to a different window than the one it was created from.
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 371 of file GraphicsContext.cs.
00372 { 00373 implementation.MakeCurrent(window); 00374 }
| void OpenTK.Graphics.GraphicsContext.SwapBuffers | ( | ) |
Swaps buffers on a context. This presents the rendered scene to the user.
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 359 of file GraphicsContext.cs.
00360 { 00361 implementation.SwapBuffers(); 00362 }
| void OpenTK.Graphics.GraphicsContext.Update | ( | IWindowInfo | window | ) |
Updates the graphics context. This must be called when the render target is resized for proper behavior on Mac OS X.
| window |
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 408 of file GraphicsContext.cs.
00409 { 00410 implementation.Update(window); 00411 }
IGraphicsContext OpenTK.Graphics.GraphicsContext.CurrentContext [static, get] |
Gets the GraphicsContext that is current in the calling thread.
Note: this property will not function correctly when both desktop and EGL contexts are available in the same process. This scenario is very unlikely to appear in practice.
Definition at line 266 of file GraphicsContext.cs.
bool OpenTK.Graphics.GraphicsContext.DirectRendering [static, get, set] |
Gets or sets a System.Boolean, indicating whether GraphicsContexts will perform direct rendering.
If DirectRendering is true, new contexts will be constructed with direct rendering capabilities, if possible. If DirectRendering is false, new contexts will be constructed with indirect rendering capabilities.
This property does not affect existing GraphicsContexts, unless they are recreated.
This property is ignored on Operating Systems without support for indirect rendering, like Windows and OS X.
Definition at line 310 of file GraphicsContext.cs.
bool OpenTK.Graphics.GraphicsContext.ErrorChecking [get, set] |
Gets or sets a System.Boolean, indicating whether automatic error checking should be performed. Influences the debug version of OpenTK.dll, only.
Automatic error checking will clear the OpenGL error state. Set CheckErrors to false if you use the OpenGL error state in your code flow (e.g. for checking supported texture formats).
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 328 of file GraphicsContext.cs.
GraphicsMode OpenTK.Graphics.GraphicsContext.GraphicsMode [get] |
Gets the GraphicsMode of the context.
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 451 of file GraphicsContext.cs.
bool OpenTK.Graphics.GraphicsContext.IsCurrent [get] |
Gets a System.Boolean indicating whether this instance is current in the calling thread.
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 380 of file GraphicsContext.cs.
bool OpenTK.Graphics.GraphicsContext.IsDisposed [get, set] |
Gets a System.Boolean indicating whether this instance has been disposed. It is an error to access any instance methods if this property returns true.
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 389 of file GraphicsContext.cs.
bool OpenTK.Graphics.GraphicsContext.ShareContexts [static, get, set] |
Gets or sets a System.Boolean, indicating whether GraphicsContext resources are shared.
If ShareContexts is true, new GLContexts will share resources. If this value is false, new GLContexts will not share resources.
Changing this value will not affect already created GLContexts.
Definition at line 292 of file GraphicsContext.cs.
bool OpenTK.Graphics.GraphicsContext.VSync [get, set] |
Gets or sets a value indicating whether VSync is enabled.
Implements OpenTK.Graphics.IGraphicsContext.
Definition at line 398 of file GraphicsContext.cs.
1.6.1