-
-
Notifications
You must be signed in to change notification settings - Fork 172
Custom GL Texture with gl_external_texture_frame_callback #320
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
Comments
If I remember correctly, the |
Thanks, I got it working in the meantime. The The code for in the
Also, it is important to register the Texture to the Flutter Engine:
To push a new texture to the Flutter Engine (This results in the callback being called):
|
You can also use: struct texture *texture = texture_new(texture_registry);
texture_push_frame(
texture,
&(const struct gl_texture_frame) {
.target = GL_TEXTURE_2D,
...
},
on_texture_destroy,
texture_userdata
); Which doesn't call |
@ardera static struct texture* color_texture = NULL;
static uint8_t* pixels = NULL;
static void color_frame_destroy(const struct texture_frame *frame, void *userdata){
(void) frame;
(void)(userdata);
printf("frame_destroy\n");
}
static int on_create(struct platch_obj *object, FlutterPlatformMessageResponseHandle *response_handle) {
struct std_value *args;
args = &object->std_arg;
if (color_texture != NULL){
return platch_respond_error_std(response_handle, "gl_error","Texture already created.",NULL);
}
if (args == NULL ) {
return platch_respond_illegal_arg_std(response_handle, "Expected `arg` to be a int array with two elements.");
}
if (!STDVALUE_IS_LIST(*args)|| args->size != 2){
return platch_respond_illegal_arg_std(response_handle, "Expected `arg` to be a int array with two elements.");
}
if (!STDVALUE_IS_INT(args->list[0]) || !STDVALUE_IS_INT(args->list[1])) {
return platch_respond_illegal_arg_std(response_handle, "Expected `arg` to be a int array with two elements.");
}
GLsizei width = (GLsizei)(STDVALUE_AS_INT(args->list[0]));
GLsizei height = (GLsizei)(STDVALUE_AS_INT(args->list[1]));
color_texture = flutterpi_create_texture(flutterpi);
if (color_texture == NULL) {
return platch_respond_error_std(response_handle, "gl_error","Failed to create texture.",NULL);
}
GLuint gl_texture_id;
pixels = malloc(width * height * 4);
for (int32_t i = 0; i < width * height; i++) {
pixels[i*4] = 255;
pixels[i*4+1] = 0;
pixels[i*4+2] = 0;
pixels[i*4+3] = 255;
}
glGenTextures(1, &gl_texture_id);
glBindTexture(GL_TEXTURE_2D, gl_texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8_OES, width, height, 0, GL_RGBA8_OES, GL_UNSIGNED_BYTE, pixels);
struct texture_frame frame = {
.gl = {
.target = GL_TEXTURE_2D,
.name = gl_texture_id,
.format = GL_RGBA8_OES,
.width = 0,
.height = 0,
},
.destroy = color_frame_destroy,
.userdata = pixels,
};
// Push the frame to the texture.
texture_push_frame(color_texture, &frame);
struct std_value result = {
.type = kStdInt64,
.int64_value = texture_get_id(color_texture),
};
int ok = platch_respond_success_std(
response_handle,
&result
);
return ok;
} |
Hi
Not sure if GitHub issues are the right place for this question.
I'm trying to implement a custom Texture into flutter-pi.
First, I have tried the described setup from this issue entry #312 (comment) to integrate Gstreamer with a custom Texture. Unfortunately, I encountered issues with switching between camera and video playback. I guess this is some kind of issue in the Gstreamer abstraction while enabling and disabling streams.
Thus, my next step was trying to render a texture directly without the Gstreamer abstraction and texture registry.
My approach was to disable the texture registry code in
on_gl_external_texture_frame_callback
and add my custom code to return a "fixed" texture.My expection with this code is to get a texture with random noise/pixels. But I just get a black texture/widget with a few red dots in the top left corner.
Is my approach wrong, or should something like this work? I know that this is no final solution, as I also need a way to tell the flutter engine when a new frame is available. But as per my understanding this should work to get at least a first initial frame.
The printf statements are fired a few times on startup. So Flutter definitely has polled the texture.
I have also tried to experiment with
GL_TEXTURE_EXTERNAL_OES
andGL_TEXTURE_2D
.When binding the texture with
GL_TEXTURE_2D
I get the following error from the engine:[ERROR:flutter/shell/platform/embedder/embedder_external_texture_gl.cc(98)] Could not create external texture->
My code looks like this:
The text was updated successfully, but these errors were encountered: