3 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
6 using System.Runtime.InteropServices;
7 using System.Threading;
9 #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
10 using OpenTK.Graphics.ES30;
12 using OpenTK.Graphics.OpenGL;
15 namespace SiliconStudio.
Paradox.Graphics
21 internal struct UseOpenGLCreationContext : IDisposable
23 private readonly
bool useDeviceCreationContext;
24 private readonly
bool needUnbindContext;
26 private readonly
bool asyncCreationLockTaken;
27 private readonly
object asyncCreationLockObject;
29 private readonly IGraphicsContext deviceCreationContext;
31 #if SILICONSTUDIO_PLATFORM_ANDROID
32 private readonly IGraphicsContext androidDeviceCreationContext;
33 private bool tegraWorkaround;
36 public bool UseDeviceCreationContext
38 get {
return useDeviceCreationContext; }
41 public UseOpenGLCreationContext(GraphicsDevice graphicsDevice)
44 #if SILICONSTUDIO_PLATFORM_ANDROID
47 if (GraphicsDevice.EglGetCurrentContext() == IntPtr.Zero)
48 #elif SILICONSTUDIO_PLATFORM_IOS
49 if (MonoTouch.OpenGLES.EAGLContext.CurrentContext == null)
51 if (GraphicsContext.CurrentContext == null)
54 needUnbindContext =
true;
55 useDeviceCreationContext =
true;
57 #if SILICONSTUDIO_PLATFORM_ANDROID
58 tegraWorkaround = graphicsDevice.Workaround_Context_Tegra2_Tegra3;
63 useDeviceCreationContext =
false;
64 graphicsDevice.AsyncPendingTaskWaiting =
true;
70 asyncCreationLockObject = graphicsDevice.asyncCreationLockObject;
71 Monitor.Enter(graphicsDevice.asyncCreationLockObject, ref asyncCreationLockTaken);
73 #if SILICONSTUDIO_PLATFORM_ANDROID
75 graphicsDevice.AsyncPendingTaskWaiting =
false;
79 androidDeviceCreationContext = graphicsDevice.androidAsyncDeviceCreationContext;
80 if (androidDeviceCreationContext != null)
81 androidDeviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
85 deviceCreationContext = graphicsDevice.deviceCreationContext;
86 deviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
94 if (needUnbindContext)
98 #if SILICONSTUDIO_PLATFORM_ANDROID
102 if (androidDeviceCreationContext != null)
103 androidDeviceCreationContext.MakeCurrent(null);
107 GraphicsDevice.UnbindGraphicsContext(deviceCreationContext);
113 if (asyncCreationLockTaken)
115 #if SILICONSTUDIO_PLATFORM_ANDROID
119 Monitor.Pulse(asyncCreationLockObject);
122 Monitor.Exit(asyncCreationLockObject);