/// <inheritdoc/> protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); configuration.Headless = headless; configuration.EnableServiceMode = serviceMode; configuration.IsHardwareInputDisabled = true; configuration.Debug = true; configuration.DebugLevels = DebugLevels.Error | DebugLevels.Warning; configuration.DebugCallback = (uv, level, message) => { System.Diagnostics.Debug.WriteLine(message); }; if (!String.IsNullOrEmpty(audioSubsystem)) { configuration.AudioSubsystemAssembly = audioSubsystem; } if (configureUPF) { PresentationFoundation.Configure(configuration); } return(new OpenGLUltravioletContext(this, configuration)); }
/// <inheritdoc/> protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); configuration.Headless = headless; configuration.EnableServiceMode = serviceMode; configuration.IsHardwareInputDisabled = true; configuration.Debug = true; configuration.DebugLevels = DebugLevels.Error | DebugLevels.Warning; configuration.DebugCallback = (uv, level, message) => { System.Diagnostics.Debug.WriteLine(message); }; if (audioImplementation != null) { configuration.SelectAudioImplementation(audioImplementation.Value); } configurer?.Invoke(configuration); if (plugins != null) { foreach (var plugin in plugins) { configuration.Plugins.Add(plugin); } } return(new OpenGLUltravioletContext(this, configuration)); }
public void Configure(ref OpenGLUltravioletContext context, out IUltravioletWindow window, out ContentManager content) { config = new OpenGLUltravioletConfiguration(); context = new OpenGLUltravioletContext(this, config); window = context.GetPlatform().Windows.GetPrimary(); content = ContentManager.Create("core/assets"); }
/// <summary> /// Called when the application is creating its Ultraviolet context. /// </summary> /// <returns>The Ultraviolet context.</returns> protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); configuration.SupportsHighDensityDisplayModes = true; configuration.SrgbBuffersEnabled = true; configuration.SrgbDefaultForTexture2D = true; configuration.EnableServiceMode = ShouldRunInServiceMode(); configuration.WatchViewFilesForChanges = ShouldDynamicallyReloadContent(); configuration.Plugins.Add(new Ultraviolet.FreeType2.FreeTypeFontPlugin()); #if IMGUI configuration.Plugins.Add(new Ultraviolet.ImGuiViewProvider.ImGuiPlugin()); #else configuration.Plugins.Add(new PresentationFoundationPlugin()); #endif PopulateConfiguration(configuration); #if DEBUG configuration.Debug = true; configuration.DebugLevels = DebugLevels.Error | DebugLevels.Warning; configuration.DebugCallback = (uv, level, message) => { System.Diagnostics.Debug.WriteLine(message); }; #endif return(new OpenGLUltravioletContext(this, configuration)); }
/// <inheritdoc/> protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); configuration.Headless = headless; configuration.EnableServiceMode = serviceMode; configuration.IsHardwareInputDisabled = true; configuration.Debug = true; configuration.DebugLevels = DebugLevels.Error | DebugLevels.Warning; configuration.DebugCallback = (uv, level, message) => { System.Diagnostics.Debug.WriteLine(message); }; configurer?.Invoke(configuration); var needsAudioSubsystem = !(plugins?.Any(x => x is BASSAudioPlugin || x is FMODAudioPlugin) ?? false); if (needsAudioSubsystem) { plugins = plugins ?? new List <UltravioletPlugin>(); plugins.Add(new BASSAudioPlugin()); } foreach (var plugin in plugins) { configuration.Plugins.Add(plugin); } return(new OpenGLUltravioletContext(this, configuration)); }
protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); PresentationFoundation.Configure(configuration); return(new OpenGLUltravioletContext(this, configuration)); }
protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); PopulateConfiguration(configuration); return(new OpenGLUltravioletContext(this, configuration)); }
/// <summary> /// Initializes a new instance of the OpenGLUltravioletWindowInfo class. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="configuration">The Ultraviolet Framework configuration settings for the current context.</param> internal OpenGLUltravioletWindowInfo(UltravioletContext uv, OpenGLUltravioletConfiguration configuration) { Contract.Require(uv, nameof(uv)); Contract.Require(configuration, nameof(configuration)); this.uv = uv; InitializePrimaryWindow(configuration); }
protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration() { EnableServiceMode = true, LoadCompatibilityShim = false }; return(new OpenGLUltravioletContext(this, configuration)); }
protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); PopulateConfiguration(configuration); configuration.Plugins.Add(new ImGuiPlugin()); configuration.Plugins.Add(new FreeTypeFontPlugin()); return(new OpenGLUltravioletContext(this, configuration)); }
/// <summary> /// Called when the application is creating its Ultraviolet context. /// </summary> /// <returns>The Ultraviolet context.</returns> protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); PopulateConfiguration(configuration); #if DEBUG configuration.Debug = true; configuration.DebugLevels = DebugLevels.Error | DebugLevels.Warning; configuration.DebugCallback = (uv, level, message) => { System.Diagnostics.Debug.WriteLine(message); }; #endif return(new OpenGLUltravioletContext(this, configuration)); }
/// <summary> /// Called when the application is creating its Ultraviolet context. /// </summary> /// <returns>The Ultraviolet context.</returns> protected override UltravioletContext OnCreatingUltravioletContext() { var configuration = new OpenGLUltravioletConfiguration(); configuration.EnableServiceMode = ShouldRunInServiceMode(); PopulateConfiguration(configuration); PresentationFoundation.Configure(configuration); #if DEBUG configuration.Debug = true; configuration.DebugLevels = DebugLevels.Error | DebugLevels.Warning; configuration.DebugCallback = (uv, level, message) => { System.Diagnostics.Debug.WriteLine(message); }; configuration.WatchViewFilesForChanges = true; #endif return(new OpenGLUltravioletContext(this, configuration)); }
/// <summary> /// Initializes the context's primary window. /// </summary> /// <param name="configuration">The Ultraviolet Framg</param> private void InitializePrimaryWindow(OpenGLUltravioletConfiguration configuration) { // Retrieve the caption for our window. var caption = Localization.Strings.Contains("WINDOW_CAPTION") ? Localization.Get("WINDOW_CAPTION") : UltravioletStrings.DefaultWindowCaption.Value; // Set the OpenGL attributes for the window we're about to create. if (SDL.GL_SetAttribute(SDL_GLattr.MULTISAMPLEBUFFERS, configuration.MultiSampleBuffers) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.MULTISAMPLESAMPLES, configuration.MultiSampleSamples) < 0) { throw new SDL2Exception(); } // If we're running on Android, we can't create a headless context. var isRunningOnAndroid = (Ultraviolet.Platform == UltravioletPlatform.Android); if (isRunningOnAndroid && configuration.Headless) { throw new InvalidOperationException(OpenGLStrings.CannotCreateHeadlessContextOnAndroid); } // Initialize the hidden master window used to create the OpenGL context. var masterWidth = 0; var masterHeight = 0; var masterFlags = SDL_WindowFlags.OPENGL; if (isRunningOnAndroid) { masterFlags |= SDL_WindowFlags.FULLSCREEN | SDL_WindowFlags.RESIZABLE; } else { masterFlags |= SDL_WindowFlags.HIDDEN; } // Attempt to create the OpenGL window. If that fails, reduce our requirements and try again before failing. var masterptr = SDL.CreateWindow(isRunningOnAndroid ? caption : String.Empty, 0, 0, masterWidth, masterHeight, masterFlags); if (masterptr == IntPtr.Zero) { if (SDL.GL_SetAttribute(SDL_GLattr.MULTISAMPLEBUFFERS, 0) < 0) { throw new SDL2Exception(); } if (SDL.GL_SetAttribute(SDL_GLattr.MULTISAMPLESAMPLES, 0) < 0) { throw new SDL2Exception(); } masterptr = SDL.CreateWindow(isRunningOnAndroid ? caption : String.Empty, 0, 0, masterWidth, masterHeight, masterFlags); if (masterptr == IntPtr.Zero) { throw new SDL2Exception(); } } this.master = new OpenGLUltravioletWindow(Ultraviolet, masterptr); // Set SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT so that enlisted windows // will be OpenGL-enabled and set to the correct pixel format. if (!SDL.SetHint(SDL_Hint.VIDEO_WINDOW_SHARE_PIXEL_FORMAT, masterptr.ToStringHex())) { throw new SDL2Exception(); } // If this is not a headless context, create the primary application window. if (!configuration.Headless) { if (isRunningOnAndroid) { this.windows.Add(this.master); DesignatePrimary(this.master); } else { var flags = configuration.WindowIsVisible ? WindowFlags.None : WindowFlags.Hidden; if (configuration.WindowIsResizable) { flags |= WindowFlags.Resizable; } if (configuration.WindowIsBorderless) { flags |= WindowFlags.Borderless; } var primary = Create(caption, configuration.InitialWindowPosition.X, configuration.InitialWindowPosition.Y, configuration.InitialWindowPosition.Width, configuration.InitialWindowPosition.Height, flags); DesignatePrimary(primary); } } }
/// <summary> /// Initializes a new instance of the <see cref="OpenGLGraphicsCapabilities"/> class. /// </summary> /// <param name="configuration">The configuration settings for the Ultraviolet context.</param> internal unsafe OpenGLGraphicsCapabilities(OpenGLUltravioletConfiguration configuration) { this.MaximumTextureSize = gl.GetInteger(gl.GL_MAX_TEXTURE_SIZE); gl.ThrowIfError(); var viewportDims = stackalloc int[2]; gl.GetIntegerv(gl.GL_MAX_VIEWPORT_DIMS, viewportDims); gl.ThrowIfError(); this.MaximumViewportWidth = viewportDims[0]; this.MaximumViewportHeight = viewportDims[1]; this.SupportsInstancedRendering = gl.IsInstancedRenderingAvailable; this.Supports3DTextures = gl.IsTexture3DAvailable; this.SupportsDepthStencilTextures = gl.IsCombinedDepthStencilAvailable; if (gl.IsGLES2 && !this.SupportsDepthStencilTextures) { // HACK: Guess what? The Visual Studio Emulator for Android flat-out lies about this. // So it seems the only reliable way to determine support for depth/stencil is to // actually try to create one and see if it fails. I hate Android emulators. var rb = gl.GenRenderbuffer(); using (var state = OpenGLState.ScopedBindRenderbuffer(rb, true)) { gl.RenderbufferStorage(gl.GL_RENDERBUFFER, gl.GL_DEPTH24_STENCIL8, 32, 32); this.SupportsDepthStencilTextures = (gl.GetError() == gl.GL_NO_ERROR); } gl.DeleteRenderBuffers(rb); } this.SupportsNonZeroBaseInstance = gl.IsNonZeroBaseInstanceAvailable; this.SupportsIndependentSamplerState = gl.IsSamplerObjectAvailable; this.SupportsIntegerVertexAttributes = gl.IsIntegerVertexAttribAvailable; this.SupportsDoublePrecisionVertexAttributes = gl.IsDoublePrecisionVertexAttribAvailable; this.MinMapBufferAlignment = gl.IsExtensionSupported("GL_ARB_map_buffer_alignment") ? gl.GetInteger(gl.GL_MIN_MAP_BUFFER_ALIGNMENT) : 0; // SRGB is always supported unless we're on GLES2, in which case we need an extension. // If it wasn't explicitly enabled in the configuration, we treat it like it's not supported. this.SrgbEncodingEnabled = configuration.SrgbBuffersEnabled && gl.IsHardwareSrgbSupportAvailable; // There seems to be a bug in the version of Mesa which is distributed // with Ubuntu 16.04 that causes long stalls when using glMapBufferRange. // Testing indicates that this is fixed in 11.2.2. if (configuration.UseBufferMapping) { var version = gl.GetString(gl.GL_VERSION); var versionMatchMesa = Regex.Match(version, "Mesa (?<major>\\d+).(?<minor>\\d+).(?<build>\\d+)"); if (versionMatchMesa != null && versionMatchMesa.Success) { var mesaMajor = Int32.Parse(versionMatchMesa.Groups["major"].Value); var mesaMinor = Int32.Parse(versionMatchMesa.Groups["minor"].Value); var mesaBuild = Int32.Parse(versionMatchMesa.Groups["build"].Value); var mesaVersion = new Version(mesaMajor, mesaMinor, mesaBuild); if (mesaVersion < new Version(11, 2, 2)) { configuration.UseBufferMapping = false; } } } // If we've been explicitly told to disable buffer mapping, override the caps from the driver. if (!gl.IsMapBufferRangeAvailable || !configuration.UseBufferMapping) { this.MinMapBufferAlignment = Int32.MinValue; } }
/// <summary> /// Initializes a new instance of the <see cref="OpenGLGraphicsCapabilities"/> class. /// </summary> /// <param name="configuration">The configuration settings for the Ultraviolet context.</param> internal unsafe OpenGLGraphicsCapabilities(OpenGLUltravioletConfiguration configuration) { this.maximumTextureSize = gl.GetInteger(gl.GL_MAX_TEXTURE_SIZE); gl.ThrowIfError(); var viewportDims = stackalloc int[2]; gl.GetIntegerv(gl.GL_MAX_VIEWPORT_DIMS, viewportDims); gl.ThrowIfError(); this.maximumViewportWidth = viewportDims[0]; this.maximumViewportHeight = viewportDims[1]; this.supportsDepthStencilTextures = !gl.IsGLES2 || gl.IsExtensionSupported("GL_OES_packed_depth_stencil"); if (gl.IsGLES2 && !this.supportsDepthStencilTextures) { // HACK: Guess what? The Visual Studio Emulator for Android flat-out lies about this. // So it seems the only reliable way to determine support for depth/stencil is to // actually try to create one and see if it fails. I hate Android emulators. var rb = gl.GenRenderbuffer(); using (var state = OpenGLState.ScopedBindRenderbuffer(rb, true)) { gl.RenderbufferStorage(gl.GL_RENDERBUFFER, gl.GL_DEPTH24_STENCIL8, 32, 32); this.supportsDepthStencilTextures = (gl.GetError() == gl.GL_NO_ERROR); } gl.DeleteRenderBuffers(rb); } this.SupportsNonZeroBaseInstance = SupportsInstancedRendering && !gl.IsGLES && (gl.IsVersionAtLeast(4, 2) || gl.IsExtensionSupported("GL_ARB_base_instance")); this.SupportsIndependentSamplerState = (gl.IsGLES ? gl.IsVersionAtLeast(3, 0) : gl.IsVersionAtLeast(3, 3)) || gl.IsExtensionSupported("GL_ARB_sampler_objects"); this.SupportsIntegerVertexAttributes = !gl.IsGLES2 || gl.IsExtensionSupported("GL_EXT_gpu_shader4"); this.SupportsDoublePrecisionVertexAttributes = !gl.IsGLES && gl.IsVersionAtLeast(4, 1); this.SupportsMapBufferRange = true; if (gl.IsGLES2) { this.SupportsMapBufferRange = gl.IsExtensionSupported("GL_ARB_map_buffer_range") || gl.IsExtensionSupported("GL_EXT_map_buffer_range"); } this.MinMapBufferAlignment = gl.IsExtensionSupported("GL_ARB_map_buffer_alignment") ? gl.GetInteger(gl.GL_MIN_MAP_BUFFER_ALIGNMENT) : 0; // There seems to be a bug in the version of Mesa which is distributed // with Ubuntu 16.04 that causes long stalls when using glMapBufferRange. // Testing indicates that this is fixed in 11.2.2. var version = gl.GetString(gl.GL_VERSION); var versionMatchMesa = Regex.Match(version, "Mesa (?<major>\\d+).(?<minor>\\d+).(?<build>\\d+)"); if (versionMatchMesa != null && versionMatchMesa.Success) { var mesaMajor = Int32.Parse(versionMatchMesa.Groups["major"].Value); var mesaMinor = Int32.Parse(versionMatchMesa.Groups["minor"].Value); var mesaBuild = Int32.Parse(versionMatchMesa.Groups["build"].Value); var mesaVersion = new Version(mesaMajor, mesaMinor, mesaBuild); if (mesaVersion < new Version(11, 2, 2)) { configuration.UseBufferMapping = false; } } // If we've been explicitly told to disable buffer mapping, override the caps from the driver. if (!configuration.UseBufferMapping) { this.SupportsMapBufferRange = false; } }