/// <summary> /// Initializes a new instance of the <see cref="OpenTK.Graphics.GraphicsContext"/> class using /// an external context handle that was created by a third-party library. /// </summary> /// <param name="handle"> /// A valid, unique handle for an external OpenGL context, or <c>ContextHandle.Zero</c> to use the current context. /// It is an error to specify a handle that has been created through OpenTK or that has been passed to OpenTK before. /// </param> /// <param name="getAddress"> /// A <c>GetAddressDelegate</c> instance that accepts the name of an OpenGL function and returns /// a valid function pointer, or <c>IntPtr.Zero</c> if that function is not supported. This delegate should be /// implemented using the same toolkit that created the OpenGL context (i.e. if the context was created with /// SDL_GL_CreateContext(), then this delegate should use SDL_GL_GetProcAddress() to retrieve function /// pointers.) /// </param> /// <param name="getCurrent"> /// A <c>GetCurrentContextDelegate</c> instance that returns the handle of the current OpenGL context, /// or <c>IntPtr.Zero</c> if no context is current on the calling thread. This delegate should be implemented /// using the same toolkit that created the OpenGL context (i.e. if the context was created with /// SDL_GL_CreateContext(), then this delegate should use SDL_GL_GetCurrentContext() to retrieve /// the current context.) /// </param> public GraphicsContext(ContextHandle handle, GetAddressDelegate getAddress, GetCurrentContextDelegate getCurrent) { if (getAddress == null || getCurrent == null) { throw new ArgumentNullException(); } lock (SyncRoot) { // Replace a zero-handle by the current context, if any if (handle == ContextHandle.Zero) { handle = getCurrent(); } // Make sure this handle corresponds to a valid, unique OpenGL context if (handle == ContextHandle.Zero) { throw new GraphicsContextMissingException(); } else if (available_contexts.ContainsKey(handle)) { throw new InvalidOperationException("Context handle has already been added"); } // We have a valid handle for an external OpenGL context, wrap it into a // DummyGLContext instance. implementation = new Platform.Dummy.DummyGLContext(handle, getAddress); GetCurrentContext = getCurrent ?? GetCurrentContext; AddContext(this); } implementation.LoadAll(); }
/// <summary> /// Loads all OpenGL entry points. /// </summary> /// <exception cref="OpenTK.Graphics.GraphicsContextException"> /// Occurs when this instance is not current on the calling thread. /// </exception> public void LoadAll() { if (GraphicsContext.CurrentContext != this) { throw new GraphicsContextException(); } implementation.LoadAll(); }