This commit is contained in:
faiface 2016-11-23 23:25:45 +01:00
parent eb316e5126
commit 4480f61a0a
4 changed files with 30 additions and 8 deletions

View File

@ -17,6 +17,9 @@ type Shader struct {
//
// Note that vertexShader and fragmentShader parameters must contain the source code, they're not filenames.
func NewShader(parent BeginEnder, vertexShader, fragmentShader string) (*Shader, error) {
parent.Begin()
defer parent.End()
shader := &Shader{
parent: parent,
}

View File

@ -14,6 +14,9 @@ type Texture struct {
// NewTexture creates a new texture with the specified width and height.
// The pixels must be a sequence of RGBA values.
func NewTexture(parent BeginEnder, width, height int, pixels []uint8) (*Texture, error) {
parent.Begin()
defer parent.End()
texture := &Texture{parent: parent}
err := DoGLErr(func() {
gl.GenTextures(1, &texture.tex)

View File

@ -100,6 +100,9 @@ type VertexArray struct {
// NewVertexArray creates a new vertex array and wraps another BeginEnder around it.
func NewVertexArray(parent BeginEnder, format VertexFormat, mode VertexDrawMode, usage VertexUsage, data []float64) (*VertexArray, error) {
parent.Begin()
defer parent.End()
va := &VertexArray{
parent: parent,
format: format,

View File

@ -2,6 +2,7 @@ package pixel
import (
"github.com/faiface/pixel/pixelgl"
"github.com/go-gl/gl/v3.3-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/pkg/errors"
)
@ -59,26 +60,38 @@ func NewWindow(config WindowConfig) (*Window, error) {
return w, nil
}
func (w *Window) Update() {
func (w *Window) Clear(r, g, b, a float64) {
w.Begin()
pixelgl.Do(func() {
gl.ClearColor(float32(r), float32(g), float32(b), float32(a))
gl.Clear(gl.COLOR_BUFFER_BIT)
})
w.End()
}
func (w *Window) Update() {
w.Begin()
pixelgl.Do(func() {
w.Begin()
if w.config.VSync {
glfw.SwapInterval(1)
}
w.window.SwapBuffers()
glfw.PollEvents()
w.End()
})
w.End()
}
var currentWindow *Window = nil
func (w *Window) Begin() {
if currentWindow != w {
w.window.MakeContextCurrent()
pixelgl.Init()
currentWindow = w
}
pixelgl.Do(func() {
if currentWindow != w {
w.window.MakeContextCurrent()
pixelgl.Init()
currentWindow = w
}
})
}
func (w *Window) End() {