/// <summary> /// Initializes a new instance of the <see cref="SDL2UltravioletContext"/> class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> protected unsafe SDL2UltravioletContext(IUltravioletHost host, UltravioletConfiguration configuration) : base(host, configuration) { eventFilter = new SDL_EventFilter(SDLEventFilter); eventFilterPtr = Marshal.GetFunctionPointerForDelegate(eventFilter); SDL_SetEventFilter(eventFilterPtr, IntPtr.Zero); }
/// <summary> /// Initializes a new instance of the <see cref="UltravioletHostCore"/> class. /// </summary> /// <param name="host">The Ultraviolet host.</param> public UltravioletHostCore(IUltravioletHost host) { Contract.Require(host, nameof(host)); this.host = host; this.tickTimer.Start(); }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletContext class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> public OpenGLUltravioletContext(IUltravioletHost host, OpenGLUltravioletConfiguration configuration) : base(host, configuration) { Contract.Require(configuration, nameof(configuration)); IsHardwareInputDisabled = configuration.IsHardwareInputDisabled; if (!InitSDL(configuration)) { throw new SDL2Exception(); } InitOpenGLVersion(configuration, out var versionRequested, out var versionRequired, out var isGLEs); if (!configuration.EnableServiceMode) { InitOpenGLAttributes(configuration, isGLEs); } var sdlAssembly = typeof(SDLNative).Assembly; InitializeFactoryMethodsInAssembly(sdlAssembly); var sdlconfig = new SDL2PlatformConfiguration(); sdlconfig.RenderingAPI = SDL2PlatformRenderingAPI.OpenGL; sdlconfig.MultiSampleBuffers = configuration.MultiSampleBuffers; sdlconfig.MultiSampleSamples = configuration.MultiSampleSamples; sdlconfig.SrgbBuffersEnabled = configuration.SrgbBuffersEnabled; this.platform = IsRunningInServiceMode ? (IUltravioletPlatform) new DummyUltravioletPlatform(this) : new SDL2UltravioletPlatform(this, configuration, sdlconfig); PumpEvents(); if (IsRunningInServiceMode) { this.graphics = new DummyUltravioletGraphics(this); this.audio = new DummyUltravioletAudio(this); this.input = new DummyUltravioletInput(this); } else { this.graphics = new OpenGLUltravioletGraphics(this, configuration, versionRequested, versionRequired); ((OpenGLUltravioletGraphics)this.graphics).ResetDeviceStates(); this.audio = InitializeAudioSubsystem(configuration); this.input = new SDL2UltravioletInput(this); } this.content = new UltravioletContent(this); this.content.RegisterImportersAndProcessors(new[] { sdlAssembly, AudioSubsystemAssembly }); this.content.Importers.RegisterImporter <XmlContentImporter>("prog"); this.ui = new UltravioletUI(this, configuration); PumpEvents(); InitializeContext(); InitializeViewProvider(configuration); InitializePlugins(configuration); }
/// <summary> /// Initializes a new instance of the <see cref="UltravioletContext"/> class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> public UltravioletContext(IUltravioletHost host, UltravioletConfiguration configuration) { Contract.Require(host, nameof(host)); Contract.Require(configuration, nameof(configuration)); if (configuration.GraphicsConfiguration == null) { throw new InvalidOperationException(UltravioletStrings.MissingGraphicsConfiguration); } AcquireContext(); this.IsRunningInServiceMode = configuration.EnableServiceMode; this.IsHardwareInputDisabled = configuration.IsHardwareInputDisabled; this.Properties = new UltravioletContextProperties(); this.Properties.SupportsHighDensityDisplayModes = configuration.SupportsHighDensityDisplayModes; this.Properties.SrgbDefaultForSurface2D = configuration.GraphicsConfiguration.SrgbDefaultForSurface2D; this.Properties.SrgbDefaultForSurface3D = configuration.GraphicsConfiguration.SrgbDefaultForSurface3D; this.Properties.SrgbDefaultForTexture2D = configuration.GraphicsConfiguration.SrgbDefaultForTexture2D; this.Properties.SrgbDefaultForTexture3D = configuration.GraphicsConfiguration.SrgbDefaultForTexture3D; this.Properties.SrgbDefaultForRenderBuffer2D = configuration.GraphicsConfiguration.SrgbDefaultForRenderBuffer2D; if (UltravioletPlatformInfo.CurrentRuntime == UltravioletRuntime.CoreCLR) { this.Properties.SupportsHighDensityDisplayModes = false; } this.host = host; this.thread = Thread.CurrentThread; this.messages = new LocalMessageQueue <UltravioletMessageID>(); this.messages.Subscribe(this, UltravioletMessages.Quit); this.syncContext = new UltravioletSynchronizationContext(this); ChangeSynchronizationContext(syncContext); this.taskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); this.taskFactory = new TaskFactory(taskScheduler); InitializeFactory(configuration); }
/// <summary> /// Initializes a new instance of the <see cref="SDL2UltravioletContext"/> class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> public unsafe SDL2UltravioletContext(IUltravioletHost host, SDL2UltravioletConfiguration configuration) : base(host, configuration) { Contract.Require(configuration, nameof(configuration)); if (!InitSDL(configuration)) { throw new SDL2Exception(); } this.onWindowDrawing = (context, time, window) => ((SDL2UltravioletContext)context).OnWindowDrawing(time, window); this.onWindowDrawn = (context, time, window) => ((SDL2UltravioletContext)context).OnWindowDrawn(time, window); eventFilter = new SDL_EventFilter(SDLEventFilter); eventFilterPtr = Marshal.GetFunctionPointerForDelegate(eventFilter); SDL_SetEventFilter(eventFilterPtr, IntPtr.Zero); LoadSubsystemAssemblies(configuration); this.swapChainManager = IsRunningInServiceMode ? new DummySwapChainManager(this) : SwapChainManager.Create(); this.platform = InitializePlatformSubsystem(configuration); this.graphics = InitializeGraphicsSubsystem(configuration); if (!this.platform.IsPrimaryWindowInitialized) { throw new InvalidOperationException(UltravioletStrings.PrimaryWindowMustBeInitialized); } this.audio = InitializeAudioSubsystem(configuration); this.input = InitializeInputSubsystem(); this.content = InitializeContentSubsystem(); this.ui = InitializeUISubsystem(configuration); PumpEvents(); InitializeContext(); InitializeViewProvider(configuration); InitializePlugins(configuration); }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletContext class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> public OpenGLUltravioletContext(IUltravioletHost host, OpenGLUltravioletConfiguration configuration) : base(host, configuration) { Contract.Require(configuration, nameof(configuration)); this.IsHardwareInputDisabled = configuration.IsHardwareInputDisabled; var sdlFlags = configuration.EnableServiceMode ? SDL_Init.TIMER | SDL_Init.EVENTS : SDL_Init.TIMER | SDL_Init.VIDEO | SDL_Init.JOYSTICK | SDL_Init.GAMECONTROLLER | SDL_Init.EVENTS; if (SDL.Init(sdlFlags) != 0) { throw new SDL2Exception(); } var isGLES = (Platform == UltravioletPlatform.Android || Platform == UltravioletPlatform.iOS); var versionRequired = isGLES ? new Version(2, 0) : new Version(3, 1); var versionRequested = isGLES ? configuration.MinimumOpenGLESVersion : configuration.MinimumOpenGLVersion; if (versionRequested == null || versionRequested < versionRequired) { if (isGLES) { versionRequested = Platform == UltravioletPlatform.Android ? new Version(2, 0) : new Version(3, 0); } else { versionRequested = versionRequired; } } if (!configuration.EnableServiceMode) { var profile = isGLES ? SDL_GLprofile.ES : SDL_GLprofile.CORE; if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_PROFILE_MASK, (Int32)profile) < 0) { throw new SDL2Exception(); } // NOTE: Asking for an ES 3.0 context in the emulator will return a valid // context pointer, but actually using it will cause segfaults. It seems like // the best thing to do on Android is just not ask for a specific version, // and trust the OS to give you the highest version it supports. if (Platform != UltravioletPlatform.Android) { if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, versionRequested.Major) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, versionRequested.Minor) < 0) { throw new SDL2Exception(); } } if (SDL.GL_SetAttribute(SDL_GLattr.DEPTH_SIZE, configuration.BackBufferDepthSize) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.STENCIL_SIZE, configuration.BackBufferStencilSize) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.RETAINED_BACKING, 0) < 0) { throw new SDL2Exception(); } if (configuration.Use32BitFramebuffer) { if (SDL.GL_SetAttribute(SDL_GLattr.RED_SIZE, 8) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.GREEN_SIZE, 8) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.BLUE_SIZE, 8) < 0) { throw new SDL2Exception(); } } else { if (SDL.GL_SetAttribute(SDL_GLattr.RED_SIZE, 5) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.GREEN_SIZE, 6) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.BLUE_SIZE, 5) < 0) { throw new SDL2Exception(); } } } this.platform = IsRunningInServiceMode ? (IUltravioletPlatform) new DummyUltravioletPlatform(this) : new OpenGLUltravioletPlatform(this, configuration); PumpEvents(); this.graphics = IsRunningInServiceMode ? (IUltravioletGraphics) new DummyUltravioletGraphics(this) : new OpenGLUltravioletGraphics(this, configuration, versionRequested); if (!IsRunningInServiceMode) { ((OpenGLUltravioletGraphics)graphics).ResetDeviceStates(); } this.audio = IsRunningInServiceMode ? new DummyUltravioletAudio(this) : InitializeAudioSubsystem(configuration); this.input = IsRunningInServiceMode ? (IUltravioletInput)(new DummyUltravioletInput(this)) : new SDL2UltravioletInput(this); this.content = new UltravioletContent(this); this.ui = new UltravioletUI(this, configuration); this.content.RegisterImportersAndProcessors(new[] { typeof(SDL2.Native.SDL).Assembly, String.IsNullOrEmpty(configuration.AudioSubsystemAssembly) ? null : Assembly.Load(configuration.AudioSubsystemAssembly), String.IsNullOrEmpty(configuration.ViewProviderAssembly) ? null : Assembly.Load(configuration.ViewProviderAssembly) }); this.content.Importers.RegisterImporter <XmlContentImporter>("prog"); PumpEvents(); unsafe { eventFilter = new SDL.EventFilter(SDLEventFilter); eventFilterPtr = Marshal.GetFunctionPointerForDelegate(eventFilter); SDL.SetEventFilter(eventFilterPtr, IntPtr.Zero); } InitializeContext(); InitializeViewProvider(configuration); }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletContext class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> public OpenGLUltravioletContext(IUltravioletHost host) : this(host, OpenGLUltravioletConfiguration.Default) { }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletContext class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> public OpenGLUltravioletContext(IUltravioletHost host, OpenGLUltravioletConfiguration configuration) : base(host, configuration) { Contract.Require(configuration, nameof(configuration)); this.IsHardwareInputDisabled = configuration.IsHardwareInputDisabled; var sdlFlags = configuration.EnableServiceMode ? SDL_Init.TIMER | SDL_Init.EVENTS : SDL_Init.TIMER | SDL_Init.VIDEO | SDL_Init.JOYSTICK | SDL_Init.GAMECONTROLLER | SDL_Init.EVENTS; if (SDL.Init(sdlFlags) != 0) { throw new SDL2Exception(); } var isGLES = (Platform == UltravioletPlatform.Android); var versionRequired = isGLES ? new Version(2, 0) : new Version(3, 1); var versionRequested = isGLES ? configuration.MinimumOpenGLESVersion : configuration.MinimumOpenGLVersion; if (versionRequested == null || versionRequested < versionRequired) { versionRequested = versionRequired; } if (!configuration.EnableServiceMode) { var profile = isGLES ? SDL_GLprofile.ES : SDL_GLprofile.CORE; if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_PROFILE_MASK, (Int32)profile) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, versionRequested.Major) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, versionRequested.Minor) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.DEPTH_SIZE, configuration.BackBufferDepthSize) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.STENCIL_SIZE, configuration.BackBufferStencilSize) < 0) { throw new SDL2Exception(); } } this.platform = IsRunningInServiceMode ? (IUltravioletPlatform)(new DummyUltravioletPlatform(this)) : new OpenGLUltravioletPlatform(this, configuration); PumpEvents(); this.graphics = IsRunningInServiceMode ? (IUltravioletGraphics)(new DummyUltravioletGraphics(this)) : new OpenGLUltravioletGraphics(this, configuration); this.audio = IsRunningInServiceMode ? new DummyUltravioletAudio(this) : InitializeAudioSubsystem(configuration); this.input = IsRunningInServiceMode ? (IUltravioletInput)(new DummyUltravioletInput(this)) : new SDL2UltravioletInput(this); this.content = new UltravioletContent(this); this.ui = new UltravioletUI(this, configuration); this.content.RegisterImportersAndProcessors(new[] { typeof(SDL2.Native.SDL).Assembly, String.IsNullOrEmpty(configuration.AudioSubsystemAssembly) ? null : Assembly.Load(configuration.AudioSubsystemAssembly), String.IsNullOrEmpty(configuration.ViewProviderAssembly) ? null : Assembly.Load(configuration.ViewProviderAssembly) }); this.content.Importers.RegisterImporter <XmlContentImporter>("prog"); PumpEvents(); InitializeContext(); InitializeViewProvider(configuration); }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletContext class. /// </summary> /// <param name="host">The object that is hosting the Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for this context.</param> public OpenGLUltravioletContext(IUltravioletHost host, OpenGLUltravioletConfiguration configuration) : base(host, configuration) { Contract.Require(configuration, nameof(configuration)); this.IsHardwareInputDisabled = configuration.IsHardwareInputDisabled; var sdlFlags = configuration.EnableServiceMode ? SDL_Init.TIMER | SDL_Init.EVENTS : SDL_Init.TIMER | SDL_Init.VIDEO | SDL_Init.JOYSTICK | SDL_Init.GAMECONTROLLER | SDL_Init.EVENTS; if (SDL.Init(sdlFlags) != 0) throw new SDL2Exception(); var isGLES = (Platform == UltravioletPlatform.Android || Platform == UltravioletPlatform.iOS); var versionRequired = isGLES ? new Version(2, 0) : new Version(3, 1); var versionRequested = isGLES ? configuration.MinimumOpenGLESVersion : configuration.MinimumOpenGLVersion; if (versionRequested == null || versionRequested < versionRequired) { if (isGLES) { versionRequested = Platform == UltravioletPlatform.Android ? new Version(2, 0) : new Version(3, 0); } else { versionRequested = versionRequired; } } if (!configuration.EnableServiceMode) { var profile = isGLES ? SDL_GLprofile.ES : SDL_GLprofile.CORE; if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_PROFILE_MASK, (Int32)profile) < 0) throw new SDL2Exception(); // NOTE: Asking for an ES 3.0 context in the emulator will return a valid // context pointer, but actually using it will cause segfaults. It seems like // the best thing to do on Android is just not ask for a specific version, // and trust the OS to give you the highest version it supports. if (Platform != UltravioletPlatform.Android) { if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MAJOR_VERSION, versionRequested.Major) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.CONTEXT_MINOR_VERSION, versionRequested.Minor) < 0) throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.DEPTH_SIZE, configuration.BackBufferDepthSize) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.STENCIL_SIZE, configuration.BackBufferStencilSize) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.RETAINED_BACKING, 0) < 0) throw new SDL2Exception(); if (configuration.Use32BitFramebuffer) { if (SDL.GL_SetAttribute(SDL_GLattr.RED_SIZE, 8) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.GREEN_SIZE, 8) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.BLUE_SIZE, 8) < 0) throw new SDL2Exception(); } else { if (SDL.GL_SetAttribute(SDL_GLattr.RED_SIZE, 5) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.GREEN_SIZE, 6) < 0) throw new SDL2Exception(); if (SDL.GL_SetAttribute(SDL_GLattr.BLUE_SIZE, 5) < 0) throw new SDL2Exception(); } } this.platform = IsRunningInServiceMode ? (IUltravioletPlatform)new DummyUltravioletPlatform(this) : new OpenGLUltravioletPlatform(this, configuration); PumpEvents(); this.graphics = IsRunningInServiceMode ? (IUltravioletGraphics)new DummyUltravioletGraphics(this) : new OpenGLUltravioletGraphics(this, configuration, versionRequested); if (!IsRunningInServiceMode) ((OpenGLUltravioletGraphics)graphics).ResetDeviceStates(); this.audio = IsRunningInServiceMode ? new DummyUltravioletAudio(this) : InitializeAudioSubsystem(configuration); this.input = IsRunningInServiceMode ? (IUltravioletInput)(new DummyUltravioletInput(this)) : new SDL2UltravioletInput(this); this.content = new UltravioletContent(this); this.ui = new UltravioletUI(this, configuration); this.content.RegisterImportersAndProcessors(new[] { typeof(SDL2.Native.SDL).Assembly, String.IsNullOrEmpty(configuration.AudioSubsystemAssembly) ? null : Assembly.Load(configuration.AudioSubsystemAssembly), String.IsNullOrEmpty(configuration.ViewProviderAssembly) ? null : Assembly.Load(configuration.ViewProviderAssembly) }); this.content.Importers.RegisterImporter<XmlContentImporter>("prog"); PumpEvents(); unsafe { eventFilter = new SDL.EventFilter(SDLEventFilter); eventFilterPtr = Marshal.GetFunctionPointerForDelegate(eventFilter); SDL.SetEventFilter(eventFilterPtr, IntPtr.Zero); } InitializeContext(); InitializeViewProvider(configuration); }