Skip to content

Commit

Permalink
Merge pull request #285 from cebarks/msaa
Browse files Browse the repository at this point in the history
Add Multisample Anti-aliasing support
  • Loading branch information
dusk125 authored Aug 31, 2021
2 parents 9e8e09f + f079cc2 commit b61f150
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions pixelgl/window.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package pixelgl

import (
"fmt"
"image"
"image/color"
"runtime"

"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"
)
Expand Down Expand Up @@ -75,6 +77,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. Must be one of 0, 2, 4, 8, 16. 0 to disable.
SamplesMSAA int
}

// Window is a window handler. Use this type to manipulate a window (input, drawing, etc.).
Expand Down Expand Up @@ -119,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

Expand All @@ -134,6 +150,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)
Expand Down Expand Up @@ -163,6 +180,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
// enter the OpenGL context
w.begin()
glhf.Init()
gl.Enable(gl.MULTISAMPLE)
w.end()

return nil
Expand Down

0 comments on commit b61f150

Please sign in to comment.