From: WonYoung Choi Date: Fri, 12 Oct 2018 03:51:33 +0000 (+0900) Subject: [Tizen] Set GL attributes before creating window (#5) X-Git-Tag: submit/tizen/20181012.035301^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f7ec2b16c6906ce1c26313ac3b3e69d550b3f2f;p=platform%2Fcore%2Fcsapi%2Fopentk.git [Tizen] Set GL attributes before creating window (#5) --- diff --git a/src/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs b/src/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs index 6b7de94d..4968b5e0 100644 --- a/src/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs +++ b/src/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs @@ -77,16 +77,17 @@ namespace OpenTK.Platform.SDL2 if (SdlContext == ContextHandle.Zero) { var error = SDL.GetError(); - Debug.Print("SDL2 failed to create OpenGL context: {0}", error); + Console.Error.WriteLine("SDL2 failed to create OpenGL context: {0}", error); throw new GraphicsContextException(error); } Mode = GetGLAttributes(SdlContext, out flags); } Handle = GraphicsContext.GetCurrentContext(); - Debug.Print("SDL2 created GraphicsContext (handle: {0})", Handle); - Debug.Print(" GraphicsMode: {0}", Mode); - Debug.Print(" GraphicsContextFlags: {0}", flags); + Console.Error.WriteLine("SDL2 created GraphicsContext (handle: {0})", Handle); + Console.Error.WriteLine(" Requested GraphicsMode: {0}", mode); + Console.Error.WriteLine(" Applied GraphicsMode: {0}", Mode); + Console.Error.WriteLine(" GraphicsContextFlags: {0}", flags); } private static GraphicsMode GetGLAttributes(ContextHandle sdlContext, out GraphicsContextFlags context_flags) diff --git a/src/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/src/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index a89e484a..1c3c217f 100644 --- a/src/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/src/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -97,6 +97,7 @@ namespace OpenTK.Platform.SDL2 IntPtr handle; lock (SDL.Sync) { + Console.Error.WriteLine($"Window Bound: [{bounds.Left + x}, {bounds.Top + y}, {width}, {height}]"); handle = SDL.CreateWindow(title, bounds.Left + x, bounds.Top + y, width, height, flags); exists = true; } diff --git a/src/OpenTK/Platform/Tizen/TizenGameApplication.cs b/src/OpenTK/Platform/Tizen/TizenGameApplication.cs index f5aaabb0..b9d0c282 100644 --- a/src/OpenTK/Platform/Tizen/TizenGameApplication.cs +++ b/src/OpenTK/Platform/Tizen/TizenGameApplication.cs @@ -25,6 +25,9 @@ using Tizen.Applications; +using OpenTK.Graphics; +using OpenTK.Platform.SDL2; + namespace OpenTK.Platform.Tizen { /// @@ -112,14 +115,16 @@ namespace OpenTK.Platform.Tizen public void Run(string[] args, double updatesPerSecond, double framesPerSecond) { // Initialize SDL2 - SDL2.SDL.TizenAppInit(args.Length, args); - SDL2.SDL.SetMainReady(); + SDL.TizenAppInit(args.Length, args); + SDL.SetMainReady(); Toolkit.Init(); // Set Internal Event Handlers Backend.AddEventHandler(TizenGameCoreBackend.InternalCreateEventType, () => { - window = new TizenGameWindow(GraphicsMode, DisplayDevice.Default, GLMajor, GLMinor); + // In Tizen SDL Backend, GL Attributes should be set before creating the window. + SetGLAttributes(GraphicsMode, GLMajor, GLMinor); + window = new TizenGameWindow(GraphicsMode, DisplayDevice.Default, Current.ApplicationInfo.ExecutablePath, GLMajor, GLMinor); }); Backend.AddEventHandler(TizenGameCoreBackend.InternalTerminateEventType, () => @@ -152,5 +157,74 @@ namespace OpenTK.Platform.Tizen { window.Exit(); } + + private static void SetGLAttributes(GraphicsMode mode, int major, int minor) + { + SDL.GL.SetAttribute(ContextAttribute.ACCUM_ALPHA_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.ACCUM_RED_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.ACCUM_GREEN_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.ACCUM_BLUE_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.DOUBLEBUFFER, 0); + SDL.GL.SetAttribute(ContextAttribute.ALPHA_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.RED_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.GREEN_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.BLUE_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.DEPTH_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLEBUFFERS, 0); + SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLESAMPLES, 0); + SDL.GL.SetAttribute(ContextAttribute.STENCIL_SIZE, 0); + SDL.GL.SetAttribute(ContextAttribute.STEREO, 0); + + if (mode.AccumulatorFormat.BitsPerPixel > 0) + { + SDL.GL.SetAttribute(ContextAttribute.ACCUM_ALPHA_SIZE, mode.AccumulatorFormat.Alpha); + SDL.GL.SetAttribute(ContextAttribute.ACCUM_RED_SIZE, mode.AccumulatorFormat.Red); + SDL.GL.SetAttribute(ContextAttribute.ACCUM_GREEN_SIZE, mode.AccumulatorFormat.Green); + SDL.GL.SetAttribute(ContextAttribute.ACCUM_BLUE_SIZE, mode.AccumulatorFormat.Blue); + } + + if (mode.Buffers > 0) + { + SDL.GL.SetAttribute(ContextAttribute.DOUBLEBUFFER, mode.Buffers > 1 ? 1 : 0); + } + + if (mode.ColorFormat > 0) + { + SDL.GL.SetAttribute(ContextAttribute.ALPHA_SIZE, mode.ColorFormat.Alpha); + SDL.GL.SetAttribute(ContextAttribute.RED_SIZE, mode.ColorFormat.Red); + SDL.GL.SetAttribute(ContextAttribute.GREEN_SIZE, mode.ColorFormat.Green); + SDL.GL.SetAttribute(ContextAttribute.BLUE_SIZE, mode.ColorFormat.Blue); + } + + if (mode.Depth > 0) + { + SDL.GL.SetAttribute(ContextAttribute.DEPTH_SIZE, mode.Depth); + } + + if (mode.Samples > 0) + { + SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLEBUFFERS, 1); + SDL.GL.SetAttribute(ContextAttribute.MULTISAMPLESAMPLES, mode.Samples); + } + + if (mode.Stencil > 0) + { + SDL.GL.SetAttribute(ContextAttribute.STENCIL_SIZE, 1); + } + + if (mode.Stereo) + { + SDL.GL.SetAttribute(ContextAttribute.STEREO, 1); + } + + if (major > 0) + { + SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MAJOR_VERSION, major); + SDL.GL.SetAttribute(ContextAttribute.CONTEXT_MINOR_VERSION, minor); + } + + SDL.GL.SetAttribute(ContextAttribute.CONTEXT_EGL, 1); + SDL.GL.SetAttribute(ContextAttribute.CONTEXT_PROFILE_MASK, ContextProfileFlags.ES); + } } } diff --git a/src/OpenTK/Platform/Tizen/TizenGameWindow.cs b/src/OpenTK/Platform/Tizen/TizenGameWindow.cs index efaa5b5b..32c1ca35 100755 --- a/src/OpenTK/Platform/Tizen/TizenGameWindow.cs +++ b/src/OpenTK/Platform/Tizen/TizenGameWindow.cs @@ -36,7 +36,12 @@ namespace OpenTK.Platform.Tizen } public TizenGameWindow(GraphicsMode mode, DisplayDevice device, int major, int minor) - : base(device.Width, device.Height, mode, "", GameWindowFlags.FixedWindow, device, major, minor, GraphicsContextFlags.Embedded) + : this(GraphicsMode.Default, DisplayDevice.Default, "", 2, 0) + { + } + + public TizenGameWindow(GraphicsMode mode, DisplayDevice device, string title, int major, int minor) + : base(device.Width, device.Height, mode, title, GameWindowFlags.FixedWindow, device, major, minor, GraphicsContextFlags.Embedded) { SDL2.SDL.SetHint("SDL_IOS_ORIENTATIONS", "Portrait LandscapeLeft LandscapeRight PortraitUpsideDown"); Paused = false;