context.go (3237B)
1 package glfw 2 3 //#include <stdlib.h> 4 //#define GLFW_INCLUDE_NONE 5 //#include "glfw/include/GLFW/glfw3.h" 6 import "C" 7 8 import ( 9 "unsafe" 10 ) 11 12 // MakeContextCurrent makes the context of the window current. 13 // Originally GLFW 3 passes a null pointer to detach the context. 14 // But since we're using receievers, DetachCurrentContext should 15 // be used instead. 16 func (w *Window) MakeContextCurrent() { 17 C.glfwMakeContextCurrent(w.data) 18 panicError() 19 } 20 21 // DetachCurrentContext detaches the current context. 22 func DetachCurrentContext() { 23 C.glfwMakeContextCurrent(nil) 24 panicError() 25 } 26 27 // GetCurrentContext returns the window whose context is current. 28 func GetCurrentContext() *Window { 29 w := C.glfwGetCurrentContext() 30 panicError() 31 if w == nil { 32 return nil 33 } 34 return windows.get(w) 35 } 36 37 // SwapBuffers swaps the front and back buffers of the window. If the 38 // swap interval is greater than zero, the GPU driver waits the specified number 39 // of screen updates before swapping the buffers. 40 func (w *Window) SwapBuffers() { 41 C.glfwSwapBuffers(w.data) 42 panicError() 43 } 44 45 // SwapInterval sets the swap interval for the current context, i.e. the number 46 // of screen updates to wait before swapping the buffers of a window and 47 // returning from SwapBuffers. This is sometimes called 48 // 'vertical synchronization', 'vertical retrace synchronization' or 'vsync'. 49 // 50 // Contexts that support either of the WGL_EXT_swap_control_tear and 51 // GLX_EXT_swap_control_tear extensions also accept negative swap intervals, 52 // which allow the driver to swap even if a frame arrives a little bit late. 53 // You can check for the presence of these extensions using 54 // ExtensionSupported. For more information about swap tearing, 55 // see the extension specifications. 56 // 57 // Some GPU drivers do not honor the requested swap interval, either because of 58 // user settings that override the request or due to bugs in the driver. 59 func SwapInterval(interval int) { 60 C.glfwSwapInterval(C.int(interval)) 61 panicError() 62 } 63 64 // ExtensionSupported reports whether the specified OpenGL or context creation 65 // API extension is supported by the current context. For example, on Windows 66 // both the OpenGL and WGL extension strings are checked. 67 // 68 // As this functions searches one or more extension strings on each call, it is 69 // recommended that you cache its results if it's going to be used frequently. 70 // The extension strings will not change during the lifetime of a context, so 71 // there is no danger in doing this. 72 func ExtensionSupported(extension string) bool { 73 e := C.CString(extension) 74 defer C.free(unsafe.Pointer(e)) 75 ret := glfwbool(C.glfwExtensionSupported(e)) 76 panicError() 77 return ret 78 } 79 80 // GetProcAddress returns the address of the specified OpenGL or OpenGL ES core 81 // or extension function, if it is supported by the current context. 82 // 83 // A context must be current on the calling thread. Calling this function 84 // without a current context will cause a GLFW_NO_CURRENT_CONTEXT error. 85 // 86 // This function is used to provide GL proc resolving capabilities to an 87 // external C library. 88 func GetProcAddress(procname string) unsafe.Pointer { 89 p := C.CString(procname) 90 defer C.free(unsafe.Pointer(p)) 91 ret := unsafe.Pointer(C.glfwGetProcAddress(p)) 92 panicError() 93 return ret 94 }