Skip to content

Add support for external OpenGL textures #102

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
pchampio opened this issue Apr 1, 2019 · 13 comments · Fixed by #219
Closed

Add support for external OpenGL textures #102

pchampio opened this issue Apr 1, 2019 · 13 comments · Fixed by #219
Labels
embedder Issue concerns the embedder package engine Depends on support form the Flutter Engine enhancement New feature or request GLFW

Comments

@pchampio
Copy link
Member

pchampio commented Apr 1, 2019

The flutter engine ABI supports external OpenGL textures allowing the embedder to draw to OpenGL directly. engine#7087

It's needed to implement the VideoPlayer.

@pchampio pchampio added the embedder Issue concerns the embedder package label Apr 1, 2019
@ghost
Copy link

ghost commented Apr 3, 2019

Will also be useful for doing 3D graphics and webrtc.

@cloudwebrtc
Copy link

cloudwebrtc commented Apr 22, 2019

@Drakirus @gedw99
I have done a texture patch on flutter/engine based on GLFW, it seems to work very well, but I don't know how to port to go-flutter, here is my Texture rendering code, maybe it will help you.
https://github.com/cloudwebrtc/flutter-engine/blob/texture_for_glfw/shell/platform/glfw/external_texture_gl.cc

@pchampio

This comment has been minimized.

@cloudwebrtc

This comment has been minimized.

This was referenced Apr 29, 2019
@pchampio pchampio added enhancement New feature or request GLFW engine Depends on support form the Flutter Engine labels Jul 1, 2019
@pchampio
Copy link
Member Author

pchampio commented Jul 15, 2019

Hi @cloudwebrtc I'm seeing progress on flutter/engine about the textureAPI 👍.
I'm trying to implement the textureAPI for go-flutter based your CPP code.

While implementing the API, I hit a wall.

My understanding was that you register a texture using: FlutterEngineRegisterExternalTexture, then mark a new frame with FlutterDesktopMarkExternalTextureFrameAvailable. At some point, in between or after those calls, the flutter-engine calls you back using the gl_external_texture_frame_callback. My issue is that gl_external_texture_frame_callback NEVER gets called.
Am my missing something?
Here is my progress on the implementation: commit

@cloudwebrtc
Copy link

cloudwebrtc commented Jul 22, 2019

@Drakirus Sorry to reply so late, I see you in the code RegisterExternalTexture(textureId: 400), and after a while MarkExternalTextureFrameAvailable(textureId: 600), this place textureId should be a fixed value of int64_t when registering once, for example: textureId = 0, when your The plugin generates a new video frame, only need to execute MarkExternalTextureFrameAvailable(texture: 0), then the flutter engine will call GLExternalTextureFrameCallback(texture: 0, ...).

frameI := int64(0)
for !a.window.ShouldClose() {
    frameI++
    glfw.WaitEventsTimeout(0.016) // timeout to get 60fps-ish iterations			
    if frameI == 400 {
        print("REGISTER: ")
        print(a.engine.RegisterExternalTexture(frameI))
    }
    if frameI == 600 {
        print("New Frame: ")
        print(a.engine.MarkExternalTextureFrameAvailable(frameI))
    }

change to:

frameI := int64(0)
textureId := int64(0)
print(a.engine.RegisterExternalTexture(textureId))
for !a.window.ShouldClose() {
    frameI++
    glfw.WaitEventsTimeout(0.016) // timeout to get 60fps-ish iterations			
    print("New Frame: ")
    print(a.engine.MarkExternalTextureFrameAvailable(textureId))

@pchampio
Copy link
Member Author

@cloudwebrtc Thanks for your reply!
The testing code that I pushed was wrong, I've updated it: commit.

I'm still facing the same issue: gl_external_texture_frame_callback never gets called. 😞

I've updated the code to use a bare C handler code, OnAcquireExternalTexture never get called.

The terminal output looks great:

[....]
Texture: register result: true
go-flutter: no handler found for channel flutter/isolate
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
Texture: New Frame result: true
go-flutter: closing application

@cloudwebrtc
Copy link

cloudwebrtc commented Jul 22, 2019

@Drakirus Your changes are correct, just add Texture(textureId: 1) to flutter lib/main.dart.

            child: Container(
              color: Colors.lightBlueAccent,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Texture(textureId: 1),
                  Text('You have pointed at this box this many times:'),
                  Text(
                    '$_enterCounter Entries\n$_exitCounter Exits',
                    style: Theme.of(context).textTheme.display1,
                  ),
                  Text(
                    'The cursor is here: (${x.toStringAsFixed(2)}, ${y.toStringAsFixed(2)})',
                  ),
                ],
              ),
            ),

I tested it under linux, OnAcquireExternalTexture is called.

[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
=== OnAcquireExternalTexture: 1
Unknown pixel config 0x0
[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
=== OnAcquireExternalTexture: 1
Unknown pixel config 0x0
[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
=== OnAcquireExternalTexture: 1
Unknown pixel config 0x0
[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
=== OnAcquireExternalTexture: 1
Unknown pixel config 0x0
[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
=== OnAcquireExternalTexture: 1
Unknown pixel config 0x0
[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
Texture: New Frame result: true
=== OnAcquireExternalTexture: 1
Unknown pixel config 0x0
[ERROR:flutter/shell/platform/embedder/embedder.cc(578)] Could not create external texture.
go-flutter: closing application

@pchampio
Copy link
Member Author

Texture(textureId: 1) that what I was missing, Thanks!!

@pchampio
Copy link
Member Author

pchampio commented Jul 23, 2019

Making progress:
2019-07-24_00-30

A demo is available at: https://github.com/go-flutter-desktop/examples/tree/feature/gl_texture/texture_tutorial, use hover run -b '@beta' to try it out.

@cloudwebrtc everything was implemented thanks to you, big thanks!

@cloudwebrtc
Copy link

Wow, that's awesome.

@pchampio
Copy link
Member Author

2019-07-25_17-11
Updated the demo. Added an very simple videoplayer

@pchampio pchampio mentioned this issue Aug 2, 2019
@pchampio
Copy link
Member Author

pchampio commented Sep 3, 2019

fix taged in tag: v0.29.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedder Issue concerns the embedder package engine Depends on support form the Flutter Engine enhancement New feature or request GLFW
Development

Successfully merging a pull request may close this issue.

2 participants