public UseOpenGLCreationContext(GraphicsDevice graphicsDevice) : this() { #if SILICONSTUDIO_PLATFORM_ANDROID // Unfortunately, android seems to not use GraphicsContext.CurrentContext to register its AndroidGraphicsContext, // so let's query EGL directly. if (GraphicsDevice.EglGetCurrentContext() == IntPtr.Zero) #elif SILICONSTUDIO_PLATFORM_IOS if (OpenGLES.EAGLContext.CurrentContext == null) #else if (GraphicsContext.CurrentContext == null) #endif { needUnbindContext = true; useDeviceCreationContext = true; #if SILICONSTUDIO_PLATFORM_ANDROID tegraWorkaround = graphicsDevice.Workaround_Context_Tegra2_Tegra3; // Notify main rendering thread there is some pending async work to do if (tegraWorkaround) { useDeviceCreationContext = false; // We actually use real main context, so states will be kept graphicsDevice.AsyncPendingTaskWaiting = true; } #endif // Lock, since there is only one deviceCreationContext. // TODO: Support multiple deviceCreationContext (TLS creation of context was crashing, need to investigate why) asyncCreationLockObject = graphicsDevice.asyncCreationLockObject; Monitor.Enter(graphicsDevice.asyncCreationLockObject, ref asyncCreationLockTaken); #if SILICONSTUDIO_PLATFORM_ANDROID if (tegraWorkaround) { graphicsDevice.AsyncPendingTaskWaiting = false; } // On android, bind the actual android context // The deviceCreationContext is a dummy one, so that CurrentContext works. androidDeviceCreationContext = graphicsDevice.androidAsyncDeviceCreationContext; if (androidDeviceCreationContext != null) { androidDeviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo); } #endif // Bind the context deviceCreationContext = graphicsDevice.deviceCreationContext; deviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo); } }