Skip to content

Commit

Permalink
Add support for GLFW 3.3 (#256)
Browse files Browse the repository at this point in the history
GLFW tag 3.3-stable @ glfw/glfw@e4e9581

* Fix C Include & address GLFW v3.3 removals
* Glfw moved away from posix_tls.c to posix_thread.c (this reflects that they now contain more than TLS)
* Glfw moved away from win32_tls.c to win32_thread.c (same as above)
* Glfw removed wayland-.*-unstable-v1-client-protocol.c
* Glfw added wl_platform.h
* Glfw removed GLFW_USE_RETINA, _GLFW_USE_CHDIR and _GLFW_USE_MENUBAR compile-time macros
* Glfw removed support for MIR
* Address deprecations of glfw 3.3
* Glfw deprecate glfwSetCharModsCallback
* Glfw deprecate the window parameter of glfwGetClipboardString and
  glfwSetClipboardString, NULL can be used as the window argument
* Add glfw.SetClipboardString(string) and glfw.GetClipboardString()
  function (no Window type required)
* Use casting and clang-format c code
* Use casting instead of callback in C helpers (same as #219)
* Update travis
* Fix Darwin build tag

Fixes: #245, #255, #240, #230, #170
  • Loading branch information
pchampio authored and pwaller committed Nov 24, 2019
1 parent e6da0ac commit e5ec435
Show file tree
Hide file tree
Showing 107 changed files with 81,406 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ matrix:
install:
- # Do nothing. This is needed to prevent default install action "go get -t -v ./..." from happening here (we want it to happen inside script step).
script:
- go get -t -v ./v3.2/...
- go get -t -v ./v3.3/...
- diff -u <(echo -n) <(gofmt -d -s .)
- go tool vet .
- go test -v -race ./v3.2/...
- go test -v -race ./v3.3/...
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Please keep the list sorted.

Champion Pierre
Coşku Baş
Dmitri Shuralyov
Geert-Johan Riemer
Expand Down
77 changes: 71 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GLFW 3.2 for Go [![Build Status](https://travis-ci.org/go-gl/glfw.svg?branch=master)](https://travis-ci.org/go-gl/glfw) [![GoDoc](https://godoc.org/github.com/go-gl/glfw/v3.2/glfw?status.svg)](https://godoc.org/github.com/go-gl/glfw/v3.2/glfw)
# GLFW 3.3 for Go [![Build Status](https://travis-ci.org/go-gl/glfw.svg?branch=master)](https://travis-ci.org/go-gl/glfw) [![GoDoc](https://godoc.org/github.com/go-gl/glfw/v3.3/glfw?status.svg)](https://godoc.org/github.com/go-gl/glfw/v3.3/glfw)

## Installation

Expand All @@ -10,7 +10,7 @@
* Go 1.4+ is required on Windows (otherwise you must use MinGW v4.8.1 exactly, see [Go issue 8811](https://github.com/golang/go/issues/8811)).

```
go get -u github.com/go-gl/glfw/v3.2/glfw
go get -u github.com/go-gl/glfw/v3.3/glfw
```

### OpenGL ES
Expand All @@ -19,7 +19,7 @@ If your target system only provides an OpenGL ES implementation (true for some A
You do this by defining the appropriate build tags, e.g.

```
go get -u -tags=gles2 github.com/go-gl/glfw/v3.2/glfw
go get -u -tags=gles2 github.com/go-gl/glfw/v3.3/glfw
```

Supported tags are `gles1`, `gles2`, `gles3` and `vulkan`.
Expand All @@ -32,7 +32,7 @@ package main

import (
"runtime"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/go-gl/glfw/v3.3/glfw"
)

func init() {
Expand Down Expand Up @@ -65,10 +65,74 @@ func main() {

## Changelog

* Easy `go get` installation. GLFW source code is now included in-repo and compiled in so you don't have to build GLFW on your own and distribute shared libraries. The revision of GLFW C library used is listed in [GLFW_C_REVISION.txt](https://github.com/go-gl/glfw/blob/master/v3.2/glfw/GLFW_C_REVISION.txt) file.
* The error callback is now set internally. Functions return an error with corresponding code and description (do a type assertion to glfw3.Error for accessing the variables) if the error is recoverable. If not a panic will occur.
### GLFW 3.3 Specific Changes
- Joystick functions now uses receivers instead of passing the joystick ID as argument.
- Vulkan methods are intentionally not implemented. `Window.Handle` can be used to create a Vulkan surface via the [this](https://github.com/vulkan-go/vulkan) package.

* Renamed `Window.GLFWWindow` to `Window.Handle`
* Added function `Window.SetAttrib`.
* Added function `Window.RequestAttention`.
* Added function `Window.GetContentScale`.
* Added function `Window.GetOpacity`.
* Added function `Window.SetOpacity`.
* Added function `Window.SetMaximizeCallback`.
* Added function `Window.SetContentScaleCallback`.
* Added function `Monitor.GetWorkarea`.
* Added function `Monitor.GetContentScale`.
* Added function `Monitor.SetUserPointer`.
* Added function `Monitor.GetUserPointer`.
* Added function `InitHint`.
* Added function `RawMouseMotionSupported`
* Added function `GetKeyScancode`.
* Added function `WindowHintString`.
* Added function `GetClipboardString`.
* Added function `SetClipboardString`.
* Added function `Joystick.GetHats`.
* Added function `Joystick.IsGamepad`.
* Added function `Joystick.GetGUID`.
* Added function `Joystick.GetGamepadName`.
* Added function `Joystick.GetGamepadState`.
* Added function `Joystick.SetUserPointer`.
* Added function `Joystick.GetUserPointer`.
* Added function `UpdateGamepadMappings`.
* Added function `SetX11SelectionString`.
* Added function `GetX11SelectionString`.
* Added gamepad button IDs.
* Added gamepad axis IDs.
* Added joystick hat state IDs.
* Added ModifierKey `ModCapsLock`.
* Added ModifierKey `ModNumLock`
* Added InputMode `LockKeyMods`.
* Added InputMode `RawMouseMotion`.
* Added hint `Hovered`.
* Added hint `CenterCursor`.
* Added hint `TransparentFramebuffer`.
* Added hint `FocusOnShow`.
* Added hint `ScaleToMonitor`.
* Added hint `JoystickHatButtons`.
* Added hint `CocoaChdirResources`.
* Added hint `CocoaMenubar`.
* Added hint `TransparentFramebuffer`.
* Added hint value `OSMesaContextAPI`.
* Added hint value `CocoaGraphicsSwitching`.
* Added hint value `CocoaRetinaFramebuffer`.
* Added string hint value `CocoaFrameNAME`.
* Added string hint value `X11ClassName`.
* Added string hint value `X11InstanceName`.
* `MonitorEvent` renamed to `PeripheralEvent` for reuse with joystick events.
* `Joystick.GetButtons` Returns `[]Action` instead of `[]byte`.
* `SetMonitorCallback` Returns `MonitorCallback`.
* `Focus` No longer returns an error.
* `Iconify` No longer returns an error.
* `Maximize` No longer returns an error.
* `Restore` No longer returns an error.
* `GetClipboardString` No longer returns an error.


### GLFW 3.2 Specfic Changes
- Easy `go get` installation. GLFW source code is now included in-repo and compiled in so you don't have to build GLFW on your own and distribute shared libraries. The revision of GLFW C library used is listed in [GLFW_C_REVISION.txt](https://github.com/go-gl/glfw/blob/master/v3.3/glfw/GLFW_C_REVISION.txt) file.
- The error callback is now set internally. Functions return an error with corresponding code and description (do a type assertion to glfw3.Error for accessing the variables) if the error is recoverable. If not a panic will occur.

* Added function `Window.SetSizeLimits`.
* Added function `Window.SetAspectRatio`.
* Added function `Window.SetMonitor`.
Expand All @@ -86,6 +150,7 @@ func main() {
* Added hint `NativeContextAPI`.
* Added hint `EGLContextAPI`.


### GLFW 3.1 Specfic Changes
* Added type `Cursor`.
* Added function `Window.SetDropCallback`.
Expand Down
1 change: 1 addition & 0 deletions v3.3/glfw/GLFW_C_REVISION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e4e9581557826bd522158ab9159859e20e10700e
49 changes: 49 additions & 0 deletions v3.3/glfw/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package glfw

/*
// Windows Build Tags
// ----------------
// GLFW Options:
#cgo windows CFLAGS: -D_GLFW_WIN32 -Iglfw/deps/mingw
// Linker Options:
#cgo windows LDFLAGS: -lopengl32 -lgdi32
// Darwin Build Tags
// ----------------
// GLFW Options:
#cgo darwin CFLAGS: -D_GLFW_COCOA -Wno-deprecated-declarations
// Linker Options:
#cgo darwin LDFLAGS: -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
// Linux Build Tags
// ----------------
// GLFW Options:
#cgo linux,!wayland CFLAGS: -D_GLFW_X11 -D_GNU_SOURCE
#cgo linux,wayland CFLAGS: -D_GLFW_WAYLAND -D_GNU_SOURCE
// Linker Options:
#cgo linux,!gles1,!gles2,!gles3,!vulkan LDFLAGS: -lGL
#cgo linux,gles1 LDFLAGS: -lGLESv1
#cgo linux,gles2 LDFLAGS: -lGLESv2
#cgo linux,gles3 LDFLAGS: -lGLESv3
#cgo linux,vulkan LDFLAGS: -lvulkan
#cgo linux,!wayland LDFLAGS: -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -lm -lXinerama -ldl -lrt
#cgo linux,wayland LDFLAGS: -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon -lm -ldl -lrt
// FreeBSD Build Tags
// ----------------
// GLFW Options:
#cgo freebsd pkg-config: glfw3
#cgo freebsd CFLAGS: -D_GLFW_HAS_DLOPEN
#cgo freebsd,!wayland CFLAGS: -D_GLFW_X11 -D_GLFW_HAS_GLXGETPROCADDRESSARB
#cgo freebsd,wayland CFLAGS: -D_GLFW_WAYLAND
// Linker Options:
#cgo freebsd,!wayland LDFLAGS: -lm -lGL -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -lXinerama
#cgo freebsd,wayland LDFLAGS: -lm -lGL -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
*/
import "C"
12 changes: 12 additions & 0 deletions v3.3/glfw/c_glfw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package glfw

/*
#include "glfw/src/context.c"
#include "glfw/src/init.c"
#include "glfw/src/input.c"
#include "glfw/src/monitor.c"
#include "glfw/src/vulkan.c"
#include "glfw/src/window.c"
#include "glfw/src/osmesa_context.c"
*/
import "C"
14 changes: 14 additions & 0 deletions v3.3/glfw/c_glfw_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package glfw

/*
#cgo CFLAGS: -x objective-c
#include "glfw/src/cocoa_init.m"
#include "glfw/src/cocoa_joystick.m"
#include "glfw/src/cocoa_monitor.m"
#include "glfw/src/cocoa_window.m"
#include "glfw/src/cocoa_time.c"
#include "glfw/src/posix_thread.c"
#include "glfw/src/nsgl_context.m"
#include "glfw/src/egl_context.c"
*/
import "C"
24 changes: 24 additions & 0 deletions v3.3/glfw/c_glfw_linbsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// +build linux freebsd

package glfw

/*
#ifdef _GLFW_WAYLAND
#include "glfw/src/wl_init.c"
#include "glfw/src/wl_monitor.c"
#include "glfw/src/wl_window.c"
#include "glfw/src/wl_platform.h"
#endif
#ifdef _GLFW_X11
#include "glfw/src/x11_init.c"
#include "glfw/src/x11_monitor.c"
#include "glfw/src/x11_window.c"
#include "glfw/src/glx_context.c"
#endif
#include "glfw/src/linux_joystick.c"
#include "glfw/src/posix_time.c"
#include "glfw/src/posix_thread.c"
#include "glfw/src/xkb_unicode.c"
#include "glfw/src/egl_context.c"
*/
import "C"
13 changes: 13 additions & 0 deletions v3.3/glfw/c_glfw_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package glfw

/*
#include "glfw/src/win32_init.c"
#include "glfw/src/win32_joystick.c"
#include "glfw/src/win32_monitor.c"
#include "glfw/src/win32_time.c"
#include "glfw/src/win32_thread.c"
#include "glfw/src/win32_window.c"
#include "glfw/src/wgl_context.c"
#include "glfw/src/egl_context.c"
*/
import "C"
94 changes: 94 additions & 0 deletions v3.3/glfw/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package glfw

//#include <stdlib.h>
//#define GLFW_INCLUDE_NONE
//#include "glfw/include/GLFW/glfw3.h"
import "C"

import (
"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)
panicError()
}

// DetachCurrentContext detaches the current context.
func DetachCurrentContext() {
C.glfwMakeContextCurrent(nil)
panicError()
}

// GetCurrentContext returns the window whose context is current.
func GetCurrentContext() *Window {
w := C.glfwGetCurrentContext()
panicError()
if w == nil {
return nil
}
return windows.get(w)
}

// 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)
panicError()
}

// 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))
panicError()
}

// ExtensionSupported reports 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))
ret := glfwbool(C.glfwExtensionSupported(e))
panicError()
return ret
}

// GetProcAddress returns the address of the specified OpenGL or OpenGL ES core
// or extension function, if it is supported by the current context.
//
// A context must be current on the calling thread. Calling this function
// without a current context will cause a GLFW_NO_CURRENT_CONTEXT error.
//
// This function is used to provide GL proc resolving capabilities to an
// external C library.
func GetProcAddress(procname string) unsafe.Pointer {
p := C.CString(procname)
defer C.free(unsafe.Pointer(p))
ret := unsafe.Pointer(C.glfwGetProcAddress(p))
panicError()
return ret
}
3 changes: 3 additions & 0 deletions v3.3/glfw/error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "_cgo_export.h"

void glfwSetErrorCallbackCB() { glfwSetErrorCallback((GLFWerrorfun)goErrorCB); }
Loading

0 comments on commit e5ec435

Please sign in to comment.