Skip to content

Commit f3ccad5

Browse files
committed
feat: select the OpenGL version to use.
wraps the go-gl/gl lib in a internal package with build constrains to let the user choose which go-gl/gl version he desire. support 3.3(default) and none. When the build tag is set to none, no dependency to go-gl/gl is required, but texture plugins will not be supported.
1 parent 9f81046 commit f3ccad5

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

application.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (a *Application) Run() error {
208208
return true
209209
}
210210
a.engine.GLProcResolver = func(procName string) unsafe.Pointer {
211-
return opengl.GetProcAddress(procName)
211+
return glfw.GetProcAddress(procName)
212212
}
213213
a.engine.GLExternalTextureFrameCallback = texturer.handleExternalTexture
214214

internal/opengl/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// building go-flutter.
66
// default is v3.3
77
//
8-
// Golang build constraints are used to do the version selection.
8+
// Golang build constraints are used for version selection.
99
package opengl

internal/opengl/version.go renamed to internal/opengl/opengl.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
// The default version of OpenGL used by go-flutter.
1+
// +build !openglnone
2+
23
package opengl
34

5+
// The default version (3.3) of OpenGL used by go-flutter.
6+
// If you want to support other version, copy/pase this file, change the import
7+
// statement, add builds constraints and open a PR.
8+
49
import (
510
"unsafe"
611

@@ -9,8 +14,10 @@ import (
914
)
1015

1116
// const exposed to go-flutter
12-
const TEXTURE_2D = gl.TEXTURE_2D
13-
const RGBA8 = gl.RGBA8
17+
const (
18+
TEXTURE2D = gl.TEXTURE_2D
19+
RGBA8 = gl.RGBA8
20+
)
1421

1522
// Init opengl
1623
func Init() error {
@@ -67,11 +74,4 @@ func GLFWWindowHint() {
6774
glfw.WindowHint(glfw.ContextVersionMinor, 3)
6875
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
6976
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
70-
71-
}
72-
73-
// GetProcAddress returns the address of the specified OpenGL or OpenGL ES core
74-
// or extension function, if it is supported by the current context.
75-
func GetProcAddress(namea string) unsafe.Pointer {
76-
return gl.GlowGetProcAddress(namea)
7777
}

internal/opengl/opengl_none.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// +build openglnone
2+
3+
package opengl
4+
5+
// Don't link go-flutter against OpenGL, less-dependency at the cost of not
6+
// supporting external texture (eg: video_plugin)
7+
//
8+
// compile go-flutter with: hover build|run --opengl=none
9+
10+
import (
11+
"unsafe"
12+
)
13+
14+
// const exposed to go-flutter
15+
const (
16+
TEXTURE2D = 0
17+
RGBA8 = 0
18+
)
19+
20+
// Init opengl
21+
func Init() error { return nil }
22+
23+
// DeleteTextures deletes named textures
24+
func DeleteTextures(n int32, textures *uint32) {}
25+
26+
// CreateTexture creates a texture for go-flutter uses
27+
func CreateTexture(texture *uint32) {}
28+
29+
// BindTexture binds a named texture to a texturing target
30+
func BindTexture(texture uint32) {}
31+
32+
// Ptr takes a slice or pointer (to a singular scalar value or the first
33+
// element of an array or slice) and returns its GL-compatible address.
34+
func Ptr(data interface{}) unsafe.Pointer { return nil }
35+
36+
// TexImage2D specifies a two-dimensional texture image
37+
func TexImage2D(width, height int32, pixels unsafe.Pointer) {
38+
panic("go-flutter: go-flutter wasn't compiled with support for external texture plugin.")
39+
}
40+
41+
// GLFWWindowHint sets hints for the next call to CreateWindow.
42+
func GLFWWindowHint() {}

texture-registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (t *TextureRegistry) handleExternalTexture(textureID int64,
130130
)
131131

132132
return &embedder.FlutterOpenGLTexture{
133-
Target: opengl.TEXTURE_2D,
133+
Target: opengl.TEXTURE2D,
134134
Name: registration.texture,
135135
Format: opengl.RGBA8,
136136
}

0 commit comments

Comments
 (0)