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


C# IDeviceContext.CreateContextAttrib方法代码示例

本文整理汇总了C#中IDeviceContext.CreateContextAttrib方法的典型用法代码示例。如果您正苦于以下问题:C# IDeviceContext.CreateContextAttrib方法的具体用法?C# IDeviceContext.CreateContextAttrib怎么用?C# IDeviceContext.CreateContextAttrib使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDeviceContext的用法示例。


在下文中一共展示了IDeviceContext.CreateContextAttrib方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GraphicsContext


//.........这里部分代码省略.........
						cAttributes.AddRange(new int[] {
							Wgl.CONTEXT_PROFILE_MASK_ARB, unchecked((int)contextProfile)
						});
					}

					#endregion

					#region Context Flags

					uint contextFlags = 0;

					// Check binary compatibility between WGL and GLX
					Debug.Assert(Wgl.CONTEXT_FLAGS_ARB == Glx.CONTEXT_FLAGS_ARB);
					Debug.Assert(Wgl.CONTEXT_FORWARD_COMPATIBLE_BIT_ARB == Glx.CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
					Debug.Assert(Wgl.CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB == Glx.CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
					Debug.Assert(Wgl.CONTEXT_DEBUG_BIT_ARB == Glx.CONTEXT_DEBUG_BIT_ARB);
					Debug.Assert(Wgl.CONTEXT_ROBUST_ACCESS_BIT_ARB == Glx.CONTEXT_ROBUST_ACCESS_BIT_ARB);
					Debug.Assert(Wgl.CONTEXT_RESET_ISOLATION_BIT_ARB == Glx.CONTEXT_RESET_ISOLATION_BIT_ARB);

					if (((flags & GraphicsContextFlags.CompatibilityProfile) != 0) && (_CurrentCaps.GlExtensions.Compatibility_ARB == false))
						throw new NotSupportedException("compatibility profile not supported");
					if (((flags & GraphicsContextFlags.Robust) != 0) && (_CurrentCaps.GlExtensions.Robustness_ARB == false && _CurrentCaps.GlExtensions.Robustness_EXT == false))
						throw new NotSupportedException("robust profile not supported");

					// Context flags: debug context
					if ((flags & GraphicsContextFlags.Debug) != 0)
						contextFlags |= Wgl.CONTEXT_DEBUG_BIT_ARB;
					// Context flags: forward compatible context
					if ((flags & GraphicsContextFlags.ForwardCompatible) != 0)
						contextFlags |= Wgl.CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
					// Context flags: robust behavior
					if ((flags & GraphicsContextFlags.Robust) != 0)
						contextFlags |= Wgl.CONTEXT_ROBUST_ACCESS_BIT_ARB;
					// Context flags: reset isolation
					if ((flags & GraphicsContextFlags.ResetIsolation) != 0)
						contextFlags |= Wgl.CONTEXT_RESET_ISOLATION_BIT_ARB;

					if (contextFlags != 0) {
						cAttributes.AddRange(new int[] {
							Wgl.CONTEXT_FLAGS_ARB, unchecked((int)contextFlags)
						});
					}

					#endregion

					// End of attributes
					cAttributes.Add(0);

					// Create rendering context
					int[] contextAttributes = cAttributes.ToArray();

					_RenderContext = _DeviceContext.CreateContextAttrib(sharedContextHandle, contextAttributes);
					Debug.Assert(_RenderContext != IntPtr.Zero);
				} else {
					// Create rendering context
					_RenderContext = _DeviceContext.CreateContext(sharedContextHandle);
					Debug.Assert(_RenderContext != IntPtr.Zero);
				}

				if (_RenderContext == IntPtr.Zero)
					throw new InvalidOperationException(String.Format("unable to create context {0}", version));

				// Allow the creation of a GraphicsContext while another GraphicsContext is currently current to the
				// calling thread: restore currency after the job get done
				GraphicsContext prevContext = GetCurrentContext();
				IDeviceContext prevContextDevice = (prevContext != null) ? prevContext._CurrentDeviceContext : null;

				// This will cause OpenGL operation flushed... not too bad
				MakeCurrent(deviceContext, true);

				// Get the current OpenGL implementation supported by this GraphicsContext
				_Version = KhronosVersion.Parse(Gl.GetString(StringName.Version));
				// Get the current OpenGL Shading Language implementation supported by this GraphicsContext
				_ShadingVersion = KhronosVersion.Parse(Gl.GetString(StringName.ShadingLanguageVersion));
				// Query context capabilities
				_CapsStack.Push(GraphicsCapabilities.Query(this, deviceContext));

				// Determine this GraphicsContext object namespace
				if (sharedContext != null) {
					// Sharing same object name space
					_ObjectNameSpace = sharedContext._ObjectNameSpace;
				} else {
					// Reserved object name space
					_ObjectNameSpace = Guid.NewGuid();
				}

				// Create shader include library (GLSL #include support)
				_ShaderIncludeLibrary = new ShaderIncludeLibrary();
				_ShaderIncludeLibrary.Create(this);

				// Restore previous current context, if any. Otherwise, make uncurrent
				if (prevContext != null)
					prevContext.MakeCurrent(prevContextDevice, true);
				else
					MakeCurrent(deviceContext, false);
			} catch {
				// Rethrow the exception
				throw;
			}
		}
开发者ID:rhynodegreat,项目名称:OpenGL.Net,代码行数:101,代码来源:GraphicsContext.cs


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