Skip to content

Commit 782d85a

Browse files
committed
Texture support (#217)
1 parent e75d3ab commit 782d85a

9 files changed

+450
-139
lines changed

application.go

+20
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (a *Application) Run() error {
100100
return errors.Errorf("invalid window mode %T", a.config.windowMode)
101101
}
102102

103+
glfw.WindowHint(glfw.ContextVersionMajor, 4)
104+
glfw.WindowHint(glfw.ContextVersionMinor, 1)
105+
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
106+
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
107+
103108
if a.config.windowInitialLocations.xpos != 0 {
104109
// To create the window at a specific position, make it initially invisible
105110
// using the Visible window hint, set its position and then show it.
@@ -217,6 +222,11 @@ func (a *Application) Run() error {
217222

218223
a.engine.PlatfromMessage = messenger.handlePlatformMessage
219224

225+
texturer := newRegistry(a.engine, a.window)
226+
a.engine.GLExternalTextureFrameCallback = texturer.handleExternalTexture
227+
228+
texturer.init()
229+
220230
// Not very nice, but we can only really fix this when there's a pluggable
221231
// renderer.
222232
defaultTextinputPlugin.keyboardLayout = a.config.keyboardLayout
@@ -254,6 +264,16 @@ func (a *Application) Run() error {
254264
// platfrom message can be corectly handled by ui.Window.onPlatformMessage.
255265
glfw.WaitEvents()
256266

267+
for _, p := range a.config.plugins {
268+
// Extra init call for plugins that satisfy the PluginTexture interface.
269+
if glfwPlugin, ok := p.(PluginTexture); ok {
270+
err = glfwPlugin.InitPluginTexture(texturer)
271+
if err != nil {
272+
return errors.Wrap(err, "failed to initialize texture plugin"+fmt.Sprintf("%T", p))
273+
}
274+
}
275+
}
276+
257277
a.window.SetKeyCallback(
258278
func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
259279
defaultTextinputPlugin.glfwKeyCallback(window, key, scancode, action, mods)

embedder/embedder.go

+51-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ const (
5353
ResultEngineNotRunning Result = -1
5454
)
5555

56+
// FlutterOpenGLTexture corresponds to the C.FlutterOpenGLTexture struct.
57+
type FlutterOpenGLTexture struct {
58+
// Target texture of the active texture unit (example GL_TEXTURE_2D)
59+
Target uint32
60+
// The name of the texture
61+
Name uint32
62+
// The texture format (example GL_RGBA8)
63+
Format uint32
64+
}
65+
5666
// FlutterEngine corresponds to the C.FlutterEngine with his associated callback's method.
5767
type FlutterEngine struct {
5868
// Flutter Engine.
@@ -65,12 +75,13 @@ type FlutterEngine struct {
6575
index int
6676

6777
// GL callback functions
68-
GLMakeCurrent func() bool
69-
GLClearCurrent func() bool
70-
GLPresent func() bool
71-
GLFboCallback func() int32
72-
GLMakeResourceCurrent func() bool
73-
GLProcResolver func(procName string) unsafe.Pointer
78+
GLMakeCurrent func() bool
79+
GLClearCurrent func() bool
80+
GLPresent func() bool
81+
GLFboCallback func() int32
82+
GLMakeResourceCurrent func() bool
83+
GLProcResolver func(procName string) unsafe.Pointer
84+
GLExternalTextureFrameCallback func(textureID int64, width int, height int) *FlutterOpenGLTexture
7485

7586
// platform message callback function
7687
PlatfromMessage func(message *PlatformMessage)
@@ -299,6 +310,40 @@ func (flu *FlutterEngine) SendPlatformMessageResponse(
299310
return (Result)(res)
300311
}
301312

313+
// RegisterExternalTexture registers an external texture with a unique identifier.
314+
func (flu *FlutterEngine) RegisterExternalTexture(textureID int64) Result {
315+
flu.sync.Lock()
316+
defer flu.sync.Unlock()
317+
if flu.closed {
318+
return ResultEngineNotRunning
319+
}
320+
res := C.FlutterEngineRegisterExternalTexture(flu.Engine, C.int64_t(textureID))
321+
return (Result)(res)
322+
}
323+
324+
// UnregisterExternalTexture unregisters a previous texture registration.
325+
func (flu *FlutterEngine) UnregisterExternalTexture(textureID int64) Result {
326+
flu.sync.Lock()
327+
defer flu.sync.Unlock()
328+
if flu.closed {
329+
return ResultEngineNotRunning
330+
}
331+
res := C.FlutterEngineUnregisterExternalTexture(flu.Engine, C.int64_t(textureID))
332+
return (Result)(res)
333+
}
334+
335+
// MarkExternalTextureFrameAvailable marks that a new texture frame is
336+
// available for a given texture identifier.
337+
func (flu *FlutterEngine) MarkExternalTextureFrameAvailable(textureID int64) Result {
338+
flu.sync.Lock()
339+
defer flu.sync.Unlock()
340+
if flu.closed {
341+
return ResultEngineNotRunning
342+
}
343+
res := C.FlutterEngineMarkExternalTextureFrameAvailable(flu.Engine, C.int64_t(textureID))
344+
return (Result)(res)
345+
}
346+
302347
// FlutterEngineFlushPendingTasksNow flush tasks on a message loop not
303348
// controlled by the Flutter engine.
304349
//

0 commit comments

Comments
 (0)