/// <summary> /// Initialize LTS information for the calling thread. /// </summary> public static void InitializeThread() { #if !MONODROID if (Egl.IsRequired == false) { switch (Platform.CurrentPlatformId) { case Platform.Id.WindowsNT: Wgl.BindAPI(); break; case Platform.Id.Linux: Glx.BindAPI(); break; case Platform.Id.MacOS: if (Glx.IsRequired) { Glx.BindAPI(); } else { throw new NotSupportedException("platform MacOS not supported without Glx.IsRequired=true"); } break; case Platform.Id.Android: Egl.BindAPI(); break; default: throw new NotSupportedException(String.Format("platform {0} not supported", Platform.CurrentPlatformId)); } } else #endif Egl.BindAPI(); }
/// <summary> /// Initialize OpenGL namespace static environment. This method shall be called before any other classes methods. /// </summary> public static void Initialize() { if (_Initialized == true) { return; // Already initialized } _Initialized = true; #if !NETSTANDARD1_1 // Optional initialization string envGlInit = Environment.GetEnvironmentVariable("OPENGL_NET_INIT"); if (envGlInit != null && envGlInit == "NO") { return; } #endif // Environment options LogComment("OpenGL.Net is initializing"); // Loader function OS API GL API // ------------------------------------------------------ // Supported platform: Windows // wglGetProcAddress WGL GL // wglGetProcAddress WGL GLES2+ (with WGL_create_context_es(2)?_profile_EXT) // eglGetProcAddress EGL(Angle) GLES2+ // ------------------------------------------------------ // Supported platform: Linux // glXGetProcAddress GLX GL // glXGetProcAddress GLX GLES2+ (with GLX_create_context_es(2)?_profile_EXT) // eglGetProcAddress EGL GLES2+ // ------------------------------------------------------ // Supported platform: Android // eglGetProcAddress EGL GL // eglGetProcAddress EGL GLES2+ try { #if !MONODROID // Determine whether use EGL as device context backend if (Egl.IsAvailable) { switch (Platform.CurrentPlatformId) { case Platform.Id.Linux: if (Glx.IsAvailable == false) { Egl.IsRequired = true; } break; } } #endif // Create native window for getting preliminary information on desktop systems // This instance will be used for creating contexts without explictly specify a window _NativeWindow = DeviceContext.CreateHiddenWindow(); // Create device context using (DeviceContext windowDevice = DeviceContext.Create()) { // Create basic OpenGL context IntPtr renderContext = windowDevice.CreateSimpleContext(); if (renderContext == IntPtr.Zero) { throw new NotImplementedException("unable to create a simple context"); } // Make contect current if (windowDevice.MakeCurrent(renderContext) == false) { throw new InvalidOperationException("unable to make current", windowDevice.GetPlatformException()); } #if !MONODROID // Reload platform function pointers, if required if (Egl.IsRequired == false) { switch (Platform.CurrentPlatformId) { case Platform.Id.WindowsNT: Wgl.BindAPI(); break; } } #endif // Query OpenGL informations string glVersion = GetString(StringName.Version); _CurrentVersion = KhronosVersion.Parse(glVersion); // Query OpenGL extensions (current OpenGL implementation, CurrentCaps) _CurrentExtensions = new Extensions(); _CurrentExtensions.Query(); // Query platform extensions windowDevice.QueryPlatformExtensions(); // Query OpenGL limits _CurrentLimits = Limits.Query(Gl.CurrentVersion, _CurrentExtensions); // Obtain current OpenGL Shading Language version string glslVersion = null; switch (_CurrentVersion.Api) { case KhronosVersion.ApiGl: if (_CurrentVersion >= Version_200 || _CurrentExtensions.ShadingLanguage100_ARB) { glslVersion = GetString(StringName.ShadingLanguageVersion); } break; case KhronosVersion.ApiGles2: glslVersion = GetString(StringName.ShadingLanguageVersion); break; } if (glslVersion != null) { _CurrentShadingVersion = GlslVersion.Parse(glslVersion, _CurrentVersion.Api); } // Vendor/Render information _Vendor = GetString(StringName.Vendor); _Renderer = GetString(StringName.Renderer); if (EnvDebug || EnvExperimental) { Debug.Assert(CurrentVersion != null && CurrentExtensions != null); CheckExtensionCommands <Gl>(CurrentVersion, CurrentExtensions, EnvExperimental); } // Before deletion, make uncurrent windowDevice.MakeCurrent(IntPtr.Zero); // Detroy context if (windowDevice.DeleteContext(renderContext) == false) { throw new InvalidOperationException("unable to delete OpenGL context"); } } LogComment("OpenGL.Net has been initialized"); } catch (Exception excepton) { _InitializationException = excepton; LogComment("Unable to initialize OpenGL.Net: {0}", _InitializationException.ToString()); } }