Skip to content

Feature/gl texture #208

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

Closed
wants to merge 16 commits into from
20 changes: 20 additions & 0 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func (a *Application) Run() error {
return errors.Errorf("invalid window mode %T", a.config.windowMode)
}

glfw.WindowHint(glfw.ContextVersionMajor, 4) // OR 2
glfw.WindowHint(glfw.ContextVersionMinor, 1)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.width, a.config.windowInitialDimensions.height, "Loading..", monitor, nil)
if err != nil {
return errors.Wrap(err, "creating glfw window")
Expand Down Expand Up @@ -205,6 +210,11 @@ func (a *Application) Run() error {

a.engine.PlatfromMessage = messenger.handlePlatformMessage

texturer := newRegistry(a.engine, a.window)
a.engine.GLExternalTextureFrameCallback = texturer.handleExternalTexture

texturer.init()

// Not very nice, but we can only really fix this when there's a pluggable
// renderer.
defaultTextinputPlugin.keyboardLayout = a.config.keyboardLayout
Expand Down Expand Up @@ -242,6 +252,16 @@ func (a *Application) Run() error {
// platfrom message can be corectly handled by ui.Window.onPlatformMessage.
glfw.WaitEvents()

for _, p := range a.config.plugins {
// Extra init call for plugins that satisfy the PluginTexture interface.
if glfwPlugin, ok := p.(PluginTexture); ok {
err = glfwPlugin.InitPluginTexture(texturer)
if err != nil {
return errors.Wrap(err, "failed to initialize texture plugin"+fmt.Sprintf("%T", p))
}
}
}

a.window.SetKeyCallback(
func(window *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
defaultTextinputPlugin.glfwKeyCallback(window, key, scancode, action, mods)
Expand Down
57 changes: 51 additions & 6 deletions embedder/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ const (
ResultEngineNotRunning Result = -1
)

// FlutterOpenGLTexture corresponds to the C.FlutterOpenGLTexture struct.
type FlutterOpenGLTexture struct {
// Target texture of the active texture unit (example GL_TEXTURE_2D)
Target uint32
// The name of the texture
Name uint32
// The texture format (example GL_RGBA8)
Format uint32
}

// FlutterEngine corresponds to the C.FlutterEngine with his associated callback's method.
type FlutterEngine struct {
// Flutter Engine.
Expand All @@ -65,12 +75,13 @@ type FlutterEngine struct {
index int

// GL callback functions
GLMakeCurrent func() bool
GLClearCurrent func() bool
GLPresent func() bool
GLFboCallback func() int32
GLMakeResourceCurrent func() bool
GLProcResolver func(procName string) unsafe.Pointer
GLMakeCurrent func() bool
GLClearCurrent func() bool
GLPresent func() bool
GLFboCallback func() int32
GLMakeResourceCurrent func() bool
GLProcResolver func(procName string) unsafe.Pointer
GLExternalTextureFrameCallback func(textureID int64, width int, height int) *FlutterOpenGLTexture

// platform message callback function
PlatfromMessage func(message *PlatformMessage)
Expand Down Expand Up @@ -299,6 +310,40 @@ func (flu *FlutterEngine) SendPlatformMessageResponse(
return (Result)(res)
}

// RegisterExternalTexture registers an external texture with a unique identifier.
func (flu *FlutterEngine) RegisterExternalTexture(textureID int64) Result {
flu.sync.Lock()
defer flu.sync.Unlock()
if flu.closed {
return ResultEngineNotRunning
}
res := C.FlutterEngineRegisterExternalTexture(flu.Engine, C.int64_t(textureID))
return (Result)(res)
}

// UnregisterExternalTexture unregisters a previous texture registration.
func (flu *FlutterEngine) UnregisterExternalTexture(textureID int64) Result {
flu.sync.Lock()
defer flu.sync.Unlock()
if flu.closed {
return ResultEngineNotRunning
}
res := C.FlutterEngineUnregisterExternalTexture(flu.Engine, C.int64_t(textureID))
return (Result)(res)
}

// MarkExternalTextureFrameAvailable marks that a new texture frame is
// available for a given texture identifier.
func (flu *FlutterEngine) MarkExternalTextureFrameAvailable(textureID int64) Result {
flu.sync.Lock()
defer flu.sync.Unlock()
if flu.closed {
return ResultEngineNotRunning
}
res := C.FlutterEngineMarkExternalTextureFrameAvailable(flu.Engine, C.int64_t(textureID))
return (Result)(res)
}

// FlutterEngineFlushPendingTasksNow flush tasks on a message loop not
// controlled by the Flutter engine.
//
Expand Down
Loading