[Tizen] Set GL attributes before creating window (#5) accepted/tizen/unified/20181012.083459 submit/tizen/20181012.035301
authorWonYoung Choi <wy80.choi@samsung.com>
Fri, 12 Oct 2018 03:51:33 +0000 (12:51 +0900)
committerGitHub <noreply@github.com>
Fri, 12 Oct 2018 03:51:33 +0000 (12:51 +0900)
src/OpenTK/Platform/SDL2/Sdl2GraphicsContext.cs
src/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs
src/OpenTK/Platform/Tizen/TizenGameApplication.cs
src/OpenTK/Platform/Tizen/TizenGameWindow.cs

index 6b7de94..4968b5e 100644 (file)
@@ -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)
index a89e484..1c3c217 100644 (file)
@@ -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;
                 }
index f5aaabb..b9d0c28 100644 (file)
@@ -25,6 +25,9 @@
 
 using Tizen.Applications;
 
+using OpenTK.Graphics;
+using OpenTK.Platform.SDL2;
+
 namespace OpenTK.Platform.Tizen
 {
     /// <summary>
@@ -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);
+        }
     }
 }
index efaa5b5..32c1ca3 100755 (executable)
@@ -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;