Skip to content

Commit

Permalink
Regenerate with KHR header and overloads (#135)
Browse files Browse the repository at this point in the history
* make package module-aware

* regenerate all with KHR include and newest overrides

* use GitHub actions for CI, drop Travis

* change build status link

* fix: add missing comma

* install libgl1-mesa-dev on Ubuntu

* properly calling apt-get; adapt minimum Go version

* add passage about checkptr errors
  • Loading branch information
dertseha authored Apr 26, 2021
1 parent ae072ca commit a3bfa83
Show file tree
Hide file tree
Showing 78 changed files with 16,061 additions and 2,260 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Main
on: [push, pull_request]
jobs:

tests:
name: ${{matrix.go-version}} ${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.9, 1.12, 1.16]
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Install dependencies (linux)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get install libgl1-mesa-dev
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{matrix.go-version}}
- name: Print go version
run: go version
- name: Check out module
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Run tests
run: go test -v -race ./...
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

48 changes: 37 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gl [![Build Status](https://travis-ci.org/go-gl/gl.svg?branch=master)](https://travis-ci.org/go-gl/gl) [![GoDoc](https://godoc.org/github.com/go-gl/gl?status.svg)](https://godoc.org/github.com/go-gl/gl)
# gl [![Build Status](https://github.com/go-gl/gl/actions/workflows/main/badge.svg)](https://github.com/go-gl/gl/actions/workflows/main) [![Go Reference](https://pkg.go.dev/badge/github.com/go-gl/gl.svg)](https://pkg.go.dev/github.com/go-gl/gl)

This repository holds Go bindings to various OpenGL versions. They are auto-generated using [Glow](https://github.com/go-gl/glow).

Expand All @@ -11,8 +11,7 @@ Requirements:
- A cgo compiler (typically gcc).
- On Ubuntu/Debian-based systems, the `libgl1-mesa-dev` package.

Usage
-----
## Usage

Use `go get -u` to download and install the prebuilt packages. The prebuilt packages support OpenGL versions 2.1, 3.1, 3.2, 3.3, 4.1, 4.2, 4.3, 4.4, 4.5, 4.6 across both the core and compatibility profiles and include all extensions. Pick whichever one(s) you need:

Expand All @@ -23,6 +22,8 @@ Use `go get -u` to download and install the prebuilt packages. The prebuilt pack
Once the bindings are installed you can use them with the appropriate import statements.

```Go
package main

import "github.com/go-gl/gl/v3.3-core/gl"

func main() {
Expand All @@ -41,25 +42,50 @@ The `gl` package contains the OpenGL functions and enumeration values for the im

A note about threading and goroutines. The bindings do not expose a mechanism to make an OpenGL context current on a different thread so you must restrict your usage to the thread on which you called `gl.Init()`. To do so you should use [LockOSThread](https://code.google.com/p/go-wiki/wiki/LockOSThread).

Examples
--------
## Examples

Examples illustrating how to use the bindings are available in the [example](https://github.com/go-gl/example) repo. There are examples for [OpenGL 4.1 core](https://github.com/go-gl/example/tree/master/gl41core-cube) and [OpenGL 2.1](https://github.com/go-gl/example/tree/master/gl21-cube).

Function Loading
----------------
## Function Loading

The `procaddr` package contains platform-specific functions for [loading OpenGL functions](https://www.opengl.org/wiki/Load_OpenGL_Functions). Calling `gl.Init()` uses the `auto` subpackage to automatically select an appropriate implementation based on the build environment. If you want to select a specific implementation you can use the `noauto` build tag and the `gl.InitWithProcAddrFunc` initialization function.

Generating
----------
## Go >=1.14 and `checkptr`

In version 1.14 of Go, the race detector added `checkptr` instrumentation. This compilation option ensures that programs follow `unsafe.Pointer` safety rules. See here for details: https://golang.org/doc/go1.14#compiler.

If enabled, there is a high chance that it will cause program termination when calling specific OpenGL functions, with a message like this:

```
fatal error: checkptr: pointer arithmetic computed bad pointer value
```

The reported call stack will point to a function like `gl.VertexAttribPointer()` that receives an `unsafe.Pointer` as parameter.
In case such function requires an "offset" passed in as a pointer (in the low-level API), a different signature needs to be used in order to satisfy the detector.

For this purpose `glow` generates "override" functions which have a different signature, taking `uintptr` instead. These functions have the suffix `WithOffset` (or similar) in their name.
For the previous example, it would be `gl.VertexAttribPointerWithOffset()`.

Not all such functions have an appropriate override! In case you stumble over such an error, and the override is missing, you have the following options:
* Disable the detector by building your program with `-gcflags=all=-d=checkptr=0`
* Report the missing function(s) as [issue for `glow`](https://github.com/go-gl/glow/issues)
* Possibly even create a pull-request for `glow` with the missing override yourself, and re-generate the `gl` bindings.

## Generating

These gl bindings are generated using the [Glow](https://github.com/go-gl/glow) generator. Only developers of this repository need to do this step.

It is required to have `glow` source in the same Go workspace (since relative paths are used) and the `glow` binary should be in your `$PATH`. Doable with `go get -u github.com/go-gl/glow` if your `$GOPATH/bin` is in your `$PATH`.
It is required to have `glow` source in a sibling directory to `go-gl/gl` since relative paths are used for generation (see `generate.go`).
For non-module-aware cases, this means `glow` needs to be in the same Go workspace as `go-gl/gl`.
For module-aware cases, `go-gl/glow` needs to be checked out parallel to `go-gl/gl`.

In either case, the `glow` binary must be in your `$PATH`. Doable with `go get -u github.com/go-gl/glow` if your `$GOPATH/bin` is in your `$PATH`.

Perform generation with the following:

```bash
go generate -tags=gen github.com/go-gl/gl
cd path/to/go-gl/gl
go generate -tags=gen .
```

More information about these bindings can be found in the [Glow repository](https://github.com/go-gl/glow).
Loading

0 comments on commit a3bfa83

Please sign in to comment.