Пример #1
0
        /// <summary>
        /// Finds the best set of DPI values to use when loading the font for the specified density bucket.
        /// </summary>
        private static void GetBestScreenDensityMatch(UltravioletContext uv, ScreenDensityBucket bucket, out Single dpiX, out Single dpiY)
        {
            dpiX = 96f;
            dpiY = 96f;

            var bestMatchFound = false;
            var bestMatchScale = Single.MaxValue;

            foreach (var display in uv.GetPlatform().Displays)
            {
                if (display.DensityBucket == bucket)
                {
                    if (display.DensityScale < bestMatchScale)
                    {
                        bestMatchFound = true;
                        bestMatchScale = display.DensityScale;
                        dpiX           = display.DpiX;
                        dpiY           = display.DpiY;
                    }
                }
            }

            if (bestMatchFound)
            {
                return;
            }

            dpiX = dpiY = ScreenDensityService.GuessDensityFromBucket(bucket);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UIScreenStackCollection"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public UIScreenStackCollection(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var windows = uv.GetPlatform().Windows;

            foreach (var window in windows)
            {
                CreateScreenStack(window);
            }

            windows.WindowCreated   += WindowInfo_WindowCreated;
            windows.WindowDestroyed += WindowInfo_WindowDestroyed;

            this.spriteBatch = SpriteBatch.Create();
        }
Пример #3
0
        /// <summary>
        /// Attempts to create an OpenGL context.
        /// </summary>
        private static IntPtr?TryCreateOpenGLContext(UltravioletContext uv, Version versionRequested, Version versionRequired, Boolean debug, Boolean throwOnFailure)
        {
            if (debug)
            {
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, (int)SDL_GL_CONTEXT_DEBUG_FLAG);
            }
            else
            {
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
            }

            var masterptr           = ((SDL2UltravioletWindowInfo)uv.GetPlatform().Windows).GetMasterPointer();
            var gles                = (uv.Platform == UltravioletPlatform.Android || uv.Platform == UltravioletPlatform.iOS);
            var versionArray        = gles ? KnownOpenGLESVersions : KnownOpenGLVersions;
            var versionMin          = versionRequested ?? versionRequired;
            var versionCurrent      = versionRequested ?? versionArray[0];
            var versionCurrentIndex = Array.IndexOf(versionArray, versionCurrent);

            IntPtr context;

            do
            {
                if (versionCurrent < versionMin)
                {
                    if (throwOnFailure)
                    {
                        throw new InvalidOperationException(OpenGLStrings.DoesNotMeetMinimumVersionRequirement.Format(versionMin.Major, versionMin.Minor));
                    }

                    return(null);
                }

                if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, versionCurrent.Major) < 0)
                {
                    throw new SDL2Exception();
                }

                if (SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, versionCurrent.Minor) < 0)
                {
                    throw new SDL2Exception();
                }

                versionCurrent = versionArray[++versionCurrentIndex];
            }while ((context = SDL_GL_CreateContext(masterptr)) == IntPtr.Zero);

            return(context);
        }
Пример #4
0
        /// <summary>
        /// Enlists the panel in the specified Ultraviolet context.
        /// </summary>
        /// <param name="uv">The Ultraviolet context in which to enlist the panel.</param>
        private void CreateUltravioletWindow(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            if (this.uv != null)
            {
                throw new InvalidOperationException(WindowsFormsStrings.PanelAlreadyEnlisted);
            }

            OnCreatingUltravioletWindow(EventArgs.Empty);

            this.uv = uv;

            this.uvWindow          = uv.GetPlatform().Windows.CreateFromNativePointer(this.Handle);
            this.uvWindow.Drawing += uvWindow_Drawing;

            OnCreatedUltravioletWindow(EventArgs.Empty);
        }
Пример #5
0
        /// <summary>
        /// Applies the specified settings.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public void Apply(UltravioletContext uv)
        {
            var primary = uv.GetPlatform().Windows.GetPrimary();

            if (primary == null)
            {
                return;
            }

            primary.SetWindowState(WindowState);
            primary.SetWindowMode(WindowMode);
            primary.WindowedClientSize               = WindowedPosition.Size;
            primary.WindowedPosition                 = WindowedPosition.Location;
            primary.GrabsMouseWhenWindowed           = GrabsMouseWhenWindowed;
            primary.GrabsMouseWhenFullscreenWindowed = GrabsMouseWhenFullscreenWindowed;
            primary.GrabsMouseWhenFullscreen         = GrabsMouseWhenFullscreen;
            primary.SynchronizeWithVerticalRetrace   = SynchronizeWithVerticalRetrace;

            if (FullscreenDisplayMode != null)
            {
                primary.SetFullscreenDisplayMode(FullscreenDisplayMode);
            }
        }
Пример #6
0
        /// <summary>
        /// Creates a set of window settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The window settings which were retrieved.</returns>
        public static UltravioletApplicationWindowSettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, nameof(uv));

            var primary = uv.GetPlatform().Windows.GetPrimary();

            if (primary == null)
            {
                return(null);
            }

            var settings = new UltravioletApplicationWindowSettings();

            settings.WindowState                      = primary.GetWindowState();
            settings.WindowMode                       = primary.GetWindowMode();
            settings.WindowedPosition                 = new Rectangle(primary.WindowedPosition, primary.WindowedClientSize);
            settings.FullscreenDisplayMode            = primary.GetFullscreenDisplayMode();
            settings.GrabsMouseWhenWindowed           = primary.GrabsMouseWhenWindowed;
            settings.GrabsMouseWhenFullscreenWindowed = primary.GrabsMouseWhenFullscreenWindowed;
            settings.GrabsMouseWhenFullscreen         = primary.GrabsMouseWhenFullscreen;
            settings.SynchronizeWithVerticalRetrace   = primary.SynchronizeWithVerticalRetrace;

            return(settings);
        }
        /// <summary>
        /// Creates a set of window settings from the current application state.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <returns>The window settings which were retrieved.</returns>
        public static UltravioletApplicationWindowSettings FromCurrentSettings(UltravioletContext uv)
        {
            Contract.Require(uv, "uv");

            var primary = uv.GetPlatform().Windows.GetPrimary();
            if (primary == null)
                return null;

            var settings = new UltravioletApplicationWindowSettings();

            settings.WindowState                    = primary.GetWindowState();
            settings.WindowMode                     = primary.GetWindowMode();
            settings.WindowedPosition               = new Rectangle(primary.WindowedPosition, primary.WindowedClientSize);
            settings.FullscreenDisplayMode          = primary.GetFullscreenDisplayMode();
            settings.SynchronizeWithVerticalRetrace = primary.SynchronizeWithVerticalRetrace;

            return settings;
        }
        /// <summary>
        /// Applies the specified settings.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public void Apply(UltravioletContext uv)
        {
            var primary = uv.GetPlatform().Windows.GetPrimary();
            if (primary == null)
                return;

            primary.SetWindowState(WindowState);
            primary.SetWindowMode(WindowMode);
            primary.WindowedPosition               = WindowedPosition.Location;
            primary.WindowedClientSize             = WindowedPosition.Size;
            primary.SynchronizeWithVerticalRetrace = SynchronizeWithVerticalRetrace;

            if (FullscreenDisplayMode != null)
            {
                primary.SetFullscreenDisplayMode(FullscreenDisplayMode);
            }
        }
Пример #9
0
        /// <summary>
        /// Enlists the panel in the specified Ultraviolet context.
        /// </summary>
        /// <param name="uv">The Ultraviolet context in which to enlist the panel.</param>
        private void CreateUltravioletWindow(UltravioletContext uv)
        {
            Contract.Require(uv, "uv");

            if (this.uv != null)
                throw new InvalidOperationException(WindowsFormsStrings.PanelAlreadyEnlisted);
            
            OnCreatingUltravioletWindow(EventArgs.Empty);

            this.uv = uv;

            this.uvWindow = uv.GetPlatform().Windows.CreateFromNativePointer(this.Handle);
            this.uvWindow.Drawing += uvWindow_Drawing;
            
            OnCreatedUltravioletWindow(EventArgs.Empty);
        }
        /// <summary>
        /// Initializes a new instance of the OpenGLUltravioletGraphics class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="configuration">The Ultraviolet Framework configuration settings for the current context.</param>
        public unsafe OpenGLUltravioletGraphics(UltravioletContext uv, UltravioletConfiguration configuration) : base(uv)
        {
            var glGraphicsConfiguration = configuration.GraphicsConfiguration as OpenGLGraphicsConfiguration;

            if (glGraphicsConfiguration == null)
            {
                throw new InvalidOperationException(OpenGLStrings.InvalidGraphicsConfiguration);
            }

            this.OpenGLEnvironment = uv.GetFactoryMethod <OpenGLEnvironmentFactory>()(uv);

            InitOpenGLVersion(glGraphicsConfiguration, out var versionRequested, out var versionRequired, out var isGLES);
            InitOpenGLEnvironment(glGraphicsConfiguration, isGLES);

            uv.GetPlatform().InitializePrimaryWindow(configuration);

            if (this.context == IntPtr.Zero && configuration.Debug)
            {
                this.context = TryCreateOpenGLContext(uv, OpenGLEnvironment, versionRequested, versionRequired, true, false) ?? IntPtr.Zero;
            }

            if (this.context == IntPtr.Zero)
            {
                this.context = TryCreateOpenGLContext(uv, OpenGLEnvironment, versionRequested, versionRequired, false, true) ?? IntPtr.Zero;
            }

            if (!OpenGLEnvironment.SetSwapInterval(1) && uv.Platform != UltravioletPlatform.iOS)
            {
                OpenGLEnvironment.ThrowPlatformErrorException();
            }

            if (gl.Initialized)
            {
                gl.Uninitialize();
            }

            gl.Initialize(new OpenGLInitializer(OpenGLEnvironment));

            if (!gl.IsVersionAtLeast(versionRequested ?? versionRequired))
            {
                throw new InvalidOperationException(OpenGLStrings.DoesNotMeetMinimumVersionRequirement.Format(gl.MajorVersion, gl.MinorVersion, versionRequested.Major, versionRequested.Minor));
            }

            OpenGLState.ResetCache();

            if (!VerifyCapabilities())
            {
                throw new NotSupportedException(OpenGLStrings.UnsupportedGraphicsDevice);
            }

            if (configuration.Debug && configuration.DebugCallback != null)
            {
                InitializeDebugOutput(configuration);
            }

            this.Capabilities = new OpenGLGraphicsCapabilities(configuration);

            if (Capabilities.SrgbEncodingEnabled && gl.IsFramebufferSrgbAvailable)
            {
                gl.Enable(gl.GL_FRAMEBUFFER_SRGB);
                gl.ThrowIfError();
            }

            this.maxTextureStages            = gl.GetInteger(gl.GL_MAX_TEXTURE_IMAGE_UNITS);
            this.textures                    = new Texture[maxTextureStages];
            this.samplerStates               = new SamplerState[maxTextureStages];
            this.samplerObjects              = Capabilities.SupportsIndependentSamplerState ? new OpenGLSamplerObject[maxTextureStages] : null;
            this.backBufferRenderTargetUsage = glGraphicsConfiguration.BackBufferRenderTargetUsage;

            if (samplerObjects != null)
            {
                for (int i = 0; i < samplerObjects.Length; i++)
                {
                    samplerObjects[i] = new OpenGLSamplerObject(Ultraviolet);
                    samplerObjects[i].Bind((uint)i);
                }
            }

            OpenGLState.VerifyCache();
            ResetDeviceStates();
        }