forked from go-gl/glfw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
73 lines (63 loc) · 2.49 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package glfw3
//#include <stdlib.h>
//#include <GLFW/glfw3.h>
import "C"
import (
"errors"
"unsafe"
)
//MakeContextCurrent makes the context of the window current.
//Originally GLFW 3 passes a null pointer to detach the context.
//But since we're using receievers, DetachCurrentContext should
//be used instead.
func (w *Window) MakeContextCurrent() {
C.glfwMakeContextCurrent(w.data)
}
//DetachCurrentContext detaches the current context.
func DetachCurrentContext() {
C.glfwMakeContextCurrent(nil)
}
//GetCurrentContext returns the window whose context is current.
func GetCurrentContext() (*Window, error) {
w := C.glfwGetCurrentContext()
if w == nil {
return nil, errors.New("Current context is not set.")
}
return &Window{w}, nil
}
//SwapBuffers swaps the front and back buffers of the window. If the
//swap interval is greater than zero, the GPU driver waits the specified number
//of screen updates before swapping the buffers.
func (w *Window) SwapBuffers() {
C.glfwSwapBuffers(w.data)
}
//SwapInterval sets the swap interval for the current context, i.e. the number
//of screen updates to wait before swapping the buffers of a window and
//returning from SwapBuffers. This is sometimes called
//'vertical synchronization', 'vertical retrace synchronization' or 'vsync'.
//
//Contexts that support either of the WGL_EXT_swap_control_tear and
//GLX_EXT_swap_control_tear extensions also accept negative swap intervals,
//which allow the driver to swap even if a frame arrives a little bit late.
//You can check for the presence of these extensions using
//ExtensionSupported. For more information about swap tearing,
//see the extension specifications.
//
//Some GPU drivers do not honor the requested swap interval, either because of
//user settings that override the request or due to bugs in the driver.
func SwapInterval(interval int) {
C.glfwSwapInterval(C.int(interval))
}
//ExtensionSupported returns whether the specified OpenGL or context creation
//API extension is supported by the current context. For example, on Windows
//both the OpenGL and WGL extension strings are checked.
//
//As this functions searches one or more extension strings on each call, it is
//recommended that you cache its results if it's going to be used frequently.
//The extension strings will not change during the lifetime of a context, so
//there is no danger in doing this.
func ExtensionSupported(extension string) bool {
e := C.CString(extension)
defer C.free(unsafe.Pointer(e))
return glfwbool(C.glfwExtensionSupported(e))
}