1
1
package pixelgl
2
2
3
3
import (
4
+ "fmt"
4
5
"image"
5
6
"image/color"
6
7
"runtime"
7
8
8
9
"github.com/faiface/glhf"
9
10
"github.com/faiface/mainthread"
10
11
"github.com/faiface/pixel"
12
+ "github.com/go-gl/gl/v3.3-core/gl"
11
13
"github.com/go-gl/glfw/v3.3/glfw"
12
14
"github.com/pkg/errors"
13
15
)
@@ -75,6 +77,9 @@ type WindowConfig struct {
75
77
// Invisible specifies whether the window will be initially hidden.
76
78
// You can make the window visible later using Window.Show().
77
79
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
78
83
}
79
84
80
85
// 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) {
119
124
120
125
w := & Window {bounds : cfg .Bounds , cursorVisible : true }
121
126
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
+
122
138
err := mainthread .CallErr (func () error {
123
139
var err error
124
140
@@ -134,6 +150,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
134
150
glfw .WindowHint (glfw .TransparentFramebuffer , bool2int [cfg .TransparentFramebuffer ])
135
151
glfw .WindowHint (glfw .Maximized , bool2int [cfg .Maximized ])
136
152
glfw .WindowHint (glfw .Visible , bool2int [! cfg .Invisible ])
153
+ glfw .WindowHint (glfw .Samples , cfg .SamplesMSAA )
137
154
138
155
if cfg .Position .X != 0 || cfg .Position .Y != 0 {
139
156
glfw .WindowHint (glfw .Visible , glfw .False )
@@ -163,6 +180,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
163
180
// enter the OpenGL context
164
181
w .begin ()
165
182
glhf .Init ()
183
+ gl .Enable (gl .MULTISAMPLE )
166
184
w .end ()
167
185
168
186
return nil
0 commit comments