Skip to content

Commit b61f150

Browse files
authored
Merge pull request #285 from cebarks/msaa
Add Multisample Anti-aliasing support
2 parents 9e8e09f + f079cc2 commit b61f150

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Fix SIGSEGV on text.NewAtlas if glyph absent
1111
- Use slice for range in Drawer.Dirty(), to improve performance
1212
- GLTriangle's fragment shader is used when rendered by the Canvas.
13+
- Add MSAA support
1314

1415
## [v0.10.0] 2020-08-22
1516
- Add AnchorPos struct and functions

pixelgl/window.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package pixelgl
22

33
import (
4+
"fmt"
45
"image"
56
"image/color"
67
"runtime"
78

89
"github.com/faiface/glhf"
910
"github.com/faiface/mainthread"
1011
"github.com/faiface/pixel"
12+
"github.com/go-gl/gl/v3.3-core/gl"
1113
"github.com/go-gl/glfw/v3.3/glfw"
1214
"github.com/pkg/errors"
1315
)
@@ -75,6 +77,9 @@ type WindowConfig struct {
7577
// Invisible specifies whether the window will be initially hidden.
7678
// You can make the window visible later using Window.Show().
7779
Invisible bool
80+
81+
//SamplesMSAA specifies the level of MSAA to be used. Must be one of 0, 2, 4, 8, 16. 0 to disable.
82+
SamplesMSAA int
7883
}
7984

8085
// Window is a window handler. Use this type to manipulate a window (input, drawing, etc.).
@@ -119,6 +124,17 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
119124

120125
w := &Window{bounds: cfg.Bounds, cursorVisible: true}
121126

127+
flag := false
128+
for _, v := range []int{0, 2, 4, 8, 16} {
129+
if cfg.SamplesMSAA == v {
130+
flag = true
131+
break
132+
}
133+
}
134+
if !flag {
135+
return nil, fmt.Errorf("invalid value '%v' for msaaSamples", cfg.SamplesMSAA)
136+
}
137+
122138
err := mainthread.CallErr(func() error {
123139
var err error
124140

@@ -134,6 +150,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
134150
glfw.WindowHint(glfw.TransparentFramebuffer, bool2int[cfg.TransparentFramebuffer])
135151
glfw.WindowHint(glfw.Maximized, bool2int[cfg.Maximized])
136152
glfw.WindowHint(glfw.Visible, bool2int[!cfg.Invisible])
153+
glfw.WindowHint(glfw.Samples, cfg.SamplesMSAA)
137154

138155
if cfg.Position.X != 0 || cfg.Position.Y != 0 {
139156
glfw.WindowHint(glfw.Visible, glfw.False)
@@ -163,6 +180,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
163180
// enter the OpenGL context
164181
w.begin()
165182
glhf.Init()
183+
gl.Enable(gl.MULTISAMPLE)
166184
w.end()
167185

168186
return nil

0 commit comments

Comments
 (0)