当前位置: 首页>>代码示例>>C#>>正文


C# IDeviceContext.MakeCurrent方法代码示例

本文整理汇总了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());
			}
		}
开发者ID:rhynodegreat,项目名称:OpenGL.Net,代码行数:65,代码来源:GraphicsContext.cs


注:本文中的IDeviceContext.MakeCurrent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。