Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLFW v3.4 #400

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions scripts/generate-buildable-source-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/env bash

EXEC=$0;

function usage() {
echo "usage: $EXEC <glfw_tag_name>";
exit $1;
}

TAG_NAME=$1;

if [ "x$TAG_NAME" = "x" ]; then
usage 1;
fi

IFS='.' read -a TAG_PARTS <<< "$TAG_NAME"
TAG_DIR="v${TAG_PARTS[0]}.${TAG_PARTS[1]}"
echo TAG_DIR
echo $TAG_DIR

CMD="mktemp -d";
TMP_DIR=$($CMD);
EXIT_CODE=$?;
if [ $EXIT_CODE != 0 ]; then
echo "$EXEC: \"$CMD\" failed to execute. exiting..." > /dev/stderr;
exit 1;
fi

pushd "$TMP_DIR";

git clone --depth 1 --branch "$TAG_NAME" https://github.com/glfw/glfw.git
mkdir glfw/build
cd glfw/build
cmake ..
# TODO don't use this hacky way to generate the wayland protocol headers
make -f src/CMakeFiles/glfw.dir/build.make src/CMakeFiles/glfw.dir/depend # generates required header files in build process
BUILD_DIR=../../glfw-aggregate
mkdir "$BUILD_DIR"
mkdir "$BUILD_DIR/include"
cp src/*.h "$BUILD_DIR/include"

cd ..
BUILD_DIR="./build/$BUILD_DIR"

cp -r src "$BUILD_DIR/src"
cp -r include/* "$BUILD_DIR/include"
cp -r deps "$BUILD_DIR/deps"
cp LICENSE.md "$BUILD_DIR/LICENSE.md"
# TODO generate dummy.go files

popd;
BUILD_DIR="$TMP_DIR/glfw/$BUILD_DIR"

GLFW_DIR="$TAG_DIR/glfw/glfw"
rm -rf "$GLFW_DIR"
mv "$BUILD_DIR" "$GLFW_DIR"

rm -rf "$TMP_DIR";
1 change: 1 addition & 0 deletions v3.4/glfw/GLFW_C_REVISION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dc46d3f8129712e42856c20e99a604a3b08ad581
57 changes: 57 additions & 0 deletions v3.4/glfw/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package glfw

/*
#cgo CFLAGS: -Iglfw/include -D_GNU_SOURCE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So then, _GNU_SOURCE is now globally set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no response to #400 (comment), I'll just mark this as resolved.


// Windows Build Tags
// ----------------
// GLFW Options:
#cgo windows CFLAGS: -D_GLFW_WIN32 -Iglfw/deps/mingw

// Linker Options:
#cgo windows LDFLAGS: -lgdi32

#cgo !gles2,windows LDFLAGS: -lopengl32
#cgo gles2,windows LDFLAGS: -lGLESv2

// Darwin Build Tags
// ----------------
// GLFW Options:
#cgo darwin CFLAGS: -D_GLFW_COCOA -Wno-deprecated-declarations

// Linker Options:
#cgo darwin LDFLAGS: -framework Cocoa -framework IOKit -framework CoreVideo

#cgo !gles2,darwin LDFLAGS: -framework OpenGL
#cgo gles2,darwin LDFLAGS: -lGLESv2

// Linux Build Tags
// ----------------
// GLFW Options:
#cgo linux,!wayland CFLAGS: -D_GLFW_X11
#cgo linux,x11 CFLAGS: -D_GLFW_X11
#cgo linux,wayland CFLAGS: -D_GLFW_WAYLAND
Copy link
Contributor

@metal3d metal3d May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on top, is it OK that _GNU_SOURCE is now globally set?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want it set but I couldn't compile at all without it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no response to #400 (comment), I'll just mark this as resolved.


// 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,x11 LDFLAGS: -lX11 -lXrandr -lXxf86vm -lXi -lXcursor -lm -lXinerama -ldl -lrt
#cgo linux,wayland LDFLAGS: -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon -lm -ldl -lrt

// BSD Build Tags
// ----------------
// GLFW Options:
#cgo freebsd,!wayland netbsd,!wayland openbsd pkg-config: x11 xau xcb xdmcp
#cgo freebsd,wayland netbsd,wayland pkg-config: wayland-client wayland-cursor wayland-egl epoll-shim
#cgo freebsd netbsd openbsd CFLAGS: -D_GLFW_HAS_DLOPEN
#cgo freebsd,!wayland netbsd,!wayland openbsd CFLAGS: -D_GLFW_X11 -D_GLFW_HAS_GLXGETPROCADDRESSARB
#cgo freebsd,wayland netbsd,wayland CFLAGS: -D_GLFW_WAYLAND

// Linker Options:
#cgo freebsd netbsd openbsd LDFLAGS: -lm
*/
import "C"
19 changes: 19 additions & 0 deletions v3.4/glfw/build_cgo_hack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build required
// +build required

package glfw

// This file exists purely to prevent the golang toolchain from stripping
// away the c source directories and files when `go mod vendor` is used
// to populate a `vendor/` directory of a project depending on `go-gl/glfw`.
//
// How it works:
// - every directory which only includes c source files receives a dummy.go file.
// - every directory we want to preserve is included here as a _ import.
// - this file is given a build to exclude it from the regular build.
import (
// Prevent go tooling from stripping out the c source files.
_ "github.com/go-gl/glfw/v3.4/glfw/glfw/deps"
_ "github.com/go-gl/glfw/v3.4/glfw/glfw/include/GLFW"
_ "github.com/go-gl/glfw/v3.4/glfw/glfw/src"
)
17 changes: 17 additions & 0 deletions v3.4/glfw/c_glfw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package glfw

/*
#include "glfw/src/platform.c"
#include "glfw/src/context.c"
#include "glfw/src/null_init.c"
#include "glfw/src/init.c"
#include "glfw/src/input.c"
#include "glfw/src/null_joystick.c"
#include "glfw/src/null_monitor.c"
#include "glfw/src/monitor.c"
#include "glfw/src/vulkan.c"
#include "glfw/src/null_window.c"
#include "glfw/src/window.c"
#include "glfw/src/osmesa_context.c"
*/
import "C"
30 changes: 30 additions & 0 deletions v3.4/glfw/c_glfw_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build freebsd || netbsd || openbsd
// +build freebsd netbsd openbsd

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/wayland-idle-inhibit-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-pointer-constraints-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-relative-pointer-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-viewporter-client-protocol.c"
#include "glfw/src/wayland-xdg-decoration-unstable-v1-client-protocol.c"
#include "glfw/src/wayland-xdg-shell-client-protocol.c"
#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/null_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"
15 changes: 15 additions & 0 deletions v3.4/glfw/c_glfw_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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_module.c"
#include "glfw/src/posix_thread.c"
#include "glfw/src/nsgl_context.m"
#include "glfw/src/egl_context.c"
*/
import "C"
16 changes: 16 additions & 0 deletions v3.4/glfw/c_glfw_lin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build linux
// +build linux

package glfw

/*
#include "glfw/src/glx_context.c"
#include "glfw/src/linux_joystick.c"
#include "glfw/src/posix_module.c"
#include "glfw/src/posix_poll.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"
11 changes: 11 additions & 0 deletions v3.4/glfw/c_glfw_lin_wayland.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build linux && wayland
// +build linux,wayland

package glfw

/*
#include "glfw/src/wl_init.c"
#include "glfw/src/wl_monitor.c"
#include "glfw/src/wl_window.c"
*/
import "C"
11 changes: 11 additions & 0 deletions v3.4/glfw/c_glfw_lin_x11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build (linux && !wayland) || (linux && x11)
// +build linux,!wayland linux,x11

package glfw

/*
#include "glfw/src/x11_window.c"
#include "glfw/src/x11_init.c"
#include "glfw/src/x11_monitor.c"
*/
import "C"
13 changes: 13 additions & 0 deletions v3.4/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.4/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.4/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); }