本文整理汇总了C#中IDeviceContext.MakeCurrent方法的典型用法代码示例。如果您正苦于以下问题:C# IDeviceContext.MakeCurrent方法的具体用法?C# IDeviceContext.MakeCurrent怎么用?C# IDeviceContext.MakeCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDeviceContext
的用法示例。
在下文中一共展示了IDeviceContext.MakeCurrent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCurrent
/// <summary>
/// Set this GraphicsContext current/uncurrent on device different from the one specified at construction time.
/// </summary>
/// <param name="deviceContext">
/// A <see cref="IDeviceContext"/> that specify the device context involved.
/// </param>
/// <param name="flag">
/// A <see cref="Boolean"/> that specify the currency of this GraphicsContext on the
/// device context <paramref name="rDevice"/>.
/// </param>
/// <exception cref="ArgumentException">
/// Exception throw in the case <paramref name="rDevice"/> is <see cref="IntPtr.Zero"/>.
/// </exception>
/// <exception cref="ObjectDisposedException">
/// Exception throw if this GraphicsContext has been disposed. Once the GraphicsContext has been disposed it cannot be current again.
/// </exception>
/// <exception cref="InvalidOperationException">
/// Exception throw if this GraphicsContext cannot be made current/uncurrent on the device context specified by <paramref name="rDevice"/>.
/// </exception>
public void MakeCurrent(IDeviceContext deviceContext, bool flag)
{
if (deviceContext == null)
throw new ArgumentNullException("deviceContext");
if (_DeviceContext == null)
throw new ObjectDisposedException("no context associated with this GraphicsContext");
int threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
if (flag) {
// Make this context current on device
if (deviceContext.MakeCurrent(_RenderContext) == false)
throw new InvalidOperationException("context cannot be current because error " + Marshal.GetLastWin32Error());
// Cache current device context
_CurrentDeviceContext = deviceContext;
// Set current context on this thread (only on success)
lock (_RenderThreadsLock) {
_RenderThreads[threadId] = this;
}
switch (Environment.OSVersion.Platform) {
case PlatformID.Unix:
using (Glx.XLock xLock = new Glx.XLock(((XServerDeviceContext)deviceContext).Display)) {
Gl.SyncDelegates();
}
break;
default:
Gl.SyncDelegates();
break;
}
} else {
// Make this context uncurrent on device
bool res = deviceContext.MakeCurrent(IntPtr.Zero);
// Reset current context on this thread (even on error)
lock (_RenderThreadsLock) {
_RenderThreads[threadId] = null;
}
if (res == false)
throw new InvalidOperationException("context cannot be uncurrent because error " + Marshal.GetLastWin32Error());
}
}