From 80b107c039d0fda5e9813e9dc071ff99a2621da1 Mon Sep 17 00:00:00 2001 From: Anten Skrabec Date: Mon, 21 Jun 2021 13:51:26 -0600 Subject: [PATCH 1/6] add multisampling --- pixelgl/window.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pixelgl/window.go b/pixelgl/window.go index e126041..3d9084d 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -8,6 +8,7 @@ import ( "github.com/faiface/glhf" "github.com/faiface/mainthread" "github.com/faiface/pixel" + "github.com/go-gl/gl/v3.3-core/gl" "github.com/go-gl/glfw/v3.3/glfw" "github.com/pkg/errors" ) @@ -75,6 +76,9 @@ type WindowConfig struct { // Invisible specifies whether the window will be initially hidden. // You can make the window visible later using Window.Show(). Invisible bool + + //SamplesMSAA specifies the level of MSAA to be used. 0 to disable. + SamplesMSAA int } // Window is a window handler. Use this type to manipulate a window (input, drawing, etc.). @@ -100,7 +104,7 @@ type Window struct { typed string } - pressEvents, tempPressEvents [KeyLast + 1]bool + pressEvents, tempPressEvents [KeyLast + 1]bool releaseEvents, tempReleaseEvents [KeyLast + 1]bool prevJoy, currJoy, tempJoy joystickState @@ -127,6 +131,8 @@ func NewWindow(cfg WindowConfig) (*Window, error) { glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) + gl.Enable(gl.MULTISAMPLE) + glfw.WindowHint(glfw.Resizable, bool2int[cfg.Resizable]) glfw.WindowHint(glfw.Decorated, bool2int[!cfg.Undecorated]) glfw.WindowHint(glfw.Floating, bool2int[cfg.AlwaysOnTop]) @@ -134,6 +140,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) { glfw.WindowHint(glfw.TransparentFramebuffer, bool2int[cfg.TransparentFramebuffer]) glfw.WindowHint(glfw.Maximized, bool2int[cfg.Maximized]) glfw.WindowHint(glfw.Visible, bool2int[!cfg.Invisible]) + glfw.WindowHint(glfw.Samples, cfg.SamplesMSAA) if cfg.Position.X != 0 || cfg.Position.Y != 0 { glfw.WindowHint(glfw.Visible, glfw.False) From 7615c055cf00d797a10c8ae1bcc8273f6e5d1a64 Mon Sep 17 00:00:00 2001 From: Anten Skrabec Date: Mon, 21 Jun 2021 14:13:43 -0600 Subject: [PATCH 2/6] move gl.Enable call to inside gl context in window creation --- pixelgl/window.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pixelgl/window.go b/pixelgl/window.go index 3d9084d..121921b 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -131,8 +131,6 @@ func NewWindow(cfg WindowConfig) (*Window, error) { glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) - gl.Enable(gl.MULTISAMPLE) - glfw.WindowHint(glfw.Resizable, bool2int[cfg.Resizable]) glfw.WindowHint(glfw.Decorated, bool2int[!cfg.Undecorated]) glfw.WindowHint(glfw.Floating, bool2int[cfg.AlwaysOnTop]) @@ -170,6 +168,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) { // enter the OpenGL context w.begin() glhf.Init() + gl.Enable(gl.MULTISAMPLE) w.end() return nil From f6e2f3a8d80f9adf8f9c2931e635a3788ad071eb Mon Sep 17 00:00:00 2001 From: Anten Skrabec Date: Sun, 15 Aug 2021 23:31:06 -0600 Subject: [PATCH 3/6] add check for valid msaa values in NewWindow() --- pixelgl/window.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pixelgl/window.go b/pixelgl/window.go index 121921b..d199f49 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -1,6 +1,7 @@ package pixelgl import ( + "fmt" "image" "image/color" "runtime" @@ -123,6 +124,17 @@ func NewWindow(cfg WindowConfig) (*Window, error) { w := &Window{bounds: cfg.Bounds, cursorVisible: true} + flag := false + for _, v := range []int{0, 2, 4, 8, 16} { + if cfg.SamplesMSAA == v { + flag = true + break + } + } + if !flag { + return nil, fmt.Errorf("invalid value '%v' for msaaSamples", cfg.SamplesMSAA) + } + err := mainthread.CallErr(func() error { var err error From 1d936eae7b99f4f14cdac1932f52ec07cbb36ddb Mon Sep 17 00:00:00 2001 From: Anten Skrabec Date: Tue, 17 Aug 2021 23:23:32 -0600 Subject: [PATCH 4/6] add comment about power of two setting for msaa samples --- pixelgl/window.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixelgl/window.go b/pixelgl/window.go index d199f49..dc095b3 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -78,7 +78,7 @@ type WindowConfig struct { // You can make the window visible later using Window.Show(). Invisible bool - //SamplesMSAA specifies the level of MSAA to be used. 0 to disable. + //SamplesMSAA specifies the level of MSAA to be used. Must be a power of 2. 0 to disable. SamplesMSAA int } From 160e665d51019dd9a6fc3bce2dc58e1220bd3523 Mon Sep 17 00:00:00 2001 From: Anten Skrabec Date: Tue, 17 Aug 2021 23:27:19 -0600 Subject: [PATCH 5/6] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7cd01d..c96f255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix SIGSEGV on text.NewAtlas if glyph absent - Use slice for range in Drawer.Dirty(), to improve performance - GLTriangle's fragment shader is used when rendered by the Canvas. +- Add MSAA support ## [v0.10.0] 2020-08-22 - Add AnchorPos struct and functions From f079cc25fe047a1b91e6d336a32022cb08740125 Mon Sep 17 00:00:00 2001 From: Allen Ray Date: Tue, 31 Aug 2021 08:35:57 -0400 Subject: [PATCH 6/6] Update window.go --- pixelgl/window.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixelgl/window.go b/pixelgl/window.go index dc095b3..060a5cc 100644 --- a/pixelgl/window.go +++ b/pixelgl/window.go @@ -78,7 +78,7 @@ type WindowConfig struct { // You can make the window visible later using Window.Show(). Invisible bool - //SamplesMSAA specifies the level of MSAA to be used. Must be a power of 2. 0 to disable. + //SamplesMSAA specifies the level of MSAA to be used. Must be one of 0, 2, 4, 8, 16. 0 to disable. SamplesMSAA int }