gpu,gpu/gl: introduce Backend

A recent change made the OpenGL functions an interface of the functions
required for the implementation of GPU, a renderer for Gio operations.
That allowed for running Gio on external systems where OpenGL is
available.

However, to allow for non-OpenGL flavored backends such as Vulkan,
Metal and Direct3D, this change introduces Backend for the high-level
operations required by GPU. This change also adds a concrete backend
to package gl.

Type Backend is a first cut heavily based on OpenGL. Future changes will add
more backends, where the Backend interface quite possibly will need refinement.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-09 17:03:57 +01:00
parent 9602337b45
commit 3ae5a37c24
16 changed files with 984 additions and 483 deletions
+6 -4
View File
@@ -6,6 +6,8 @@ import (
"fmt"
"runtime"
"strings"
"gioui.org/internal/unsafe"
)
// SRGBFBO implements an intermediate sRGB FBO
@@ -26,7 +28,7 @@ type SRGBFBO struct {
func NewSRGBFBO(f Functions) (*SRGBFBO, error) {
var es3 bool
glVer := f.GetString(VERSION)
ver, err := ParseGLVersion(glVer)
ver, err := parseGLVersion(glVer)
if err != nil {
return nil, err
}
@@ -55,17 +57,17 @@ func NewSRGBFBO(f Functions) (*SRGBFBO, error) {
func (s *SRGBFBO) Blit() {
if !s.blitted {
prog, err := CreateProgram(s.c, blitVSrc, blitFSrc, []string{"pos", "uv"})
prog, err := createProgram(s.c, blitVSrc, blitFSrc, []string{"pos", "uv"})
if err != nil {
panic(err)
}
s.prog = prog
s.c.UseProgram(prog)
s.c.Uniform1i(GetUniformLocation(s.c, prog, "tex"), 0)
s.c.Uniform1i(getUniformLocation(s.c, prog, "tex"), 0)
s.quad = s.c.CreateBuffer()
s.c.BindBuffer(ARRAY_BUFFER, s.quad)
s.c.BufferData(ARRAY_BUFFER,
BytesView([]float32{
unsafe.BytesView([]float32{
-1, +1, 0, 1,
+1, +1, 1, 1,
-1, -1, 0, 0,