From 1761211ba10580fc095987290fe651f16abc887f Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Thu, 19 Oct 2023 09:37:01 +0300 Subject: [PATCH] [example] Update linux texture --- .../embedder_texture/linux/CMakeLists.txt | 9 +-- .../linux/embedder_texture_plugin.cc | 65 ++++++------------- 2 files changed, 21 insertions(+), 53 deletions(-) diff --git a/packages/embedder_texture/linux/CMakeLists.txt b/packages/embedder_texture/linux/CMakeLists.txt index 980b84a..433c4b0 100644 --- a/packages/embedder_texture/linux/CMakeLists.txt +++ b/packages/embedder_texture/linux/CMakeLists.txt @@ -21,11 +21,4 @@ target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) -target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) - -# sudo apt-get install libglew-dev -target_link_libraries(${PLUGIN_NAME} PUBLIC - EGL - GLEW - GL -) +target_link_libraries(${PLUGIN_NAME} PUBLIC GL) diff --git a/packages/embedder_texture/linux/embedder_texture_plugin.cc b/packages/embedder_texture/linux/embedder_texture_plugin.cc index fc79fcf..f130565 100644 --- a/packages/embedder_texture/linux/embedder_texture_plugin.cc +++ b/packages/embedder_texture/linux/embedder_texture_plugin.cc @@ -3,15 +3,7 @@ #include #include -#include -#include -#include -#include -#include - -#include -#include -#include +#include #include "embedder_texture_plugin_private.h" @@ -30,8 +22,6 @@ struct _LinuxOpenglPlugin FlTexture *texture = nullptr; FlTextureRegistrar *texture_registrar = nullptr; - GdkGLContext *context = nullptr; - GdkWindow *window = nullptr; FlMyTextureGL *myTexture = nullptr; FlView *fl_view = nullptr; }; @@ -64,23 +54,6 @@ static void embedder_texture_plugin_handle_method_call( fl_method_call_respond(method_call, response, nullptr); } -void set_color(LinuxOpenglPlugin *self) -{ - gdk_gl_context_make_current(self->context); - - static GLfloat pixels[] = - { - 1, 0, 0, - 0, 1, 0, - 0, 0, 1, - 1, 1, 1 - }; - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, pixels); - - fl_texture_registrar_mark_texture_frame_available(self->texture_registrar, self->texture); -} - FlMethodResponse *create( LinuxOpenglPlugin *self, FlMethodCall *method_call) @@ -102,23 +75,33 @@ FlMethodResponse *create( if (self->width != 0 && self->height != 0) { - self->window = gtk_widget_get_parent_window(GTK_WIDGET(self->fl_view)); - self->context = gdk_window_create_gl_context(self->window, &error); - - gdk_gl_context_make_current(self->context); - + static GLfloat pixels[] = + { + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + 1, 1, 1 + }; + + // create in open gl glGenTextures(1, &self->texture_id); glBindTexture(GL_TEXTURE_2D, self->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); - // drawing on the texture - set_color(self); - + // create self->myTexture = fl_my_texture_gl_new(GL_TEXTURE_2D, self->texture_id, self->width, self->height); self->texture = FL_TEXTURE(self->myTexture); + // reg fl_texture_registrar_register_texture(self->texture_registrar, self->texture); - gdk_gl_context_clear_current(); + // draw + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_FLOAT, pixels); + + // send id g_autoptr(FlValue) result = fl_value_new_int(reinterpret_cast(self->texture)); return FL_METHOD_RESPONSE(fl_method_success_response_new(result)); } @@ -186,13 +169,5 @@ void embedder_texture_plugin_register_with_registrar(FlPluginRegistrar *registra g_object_ref(plugin), g_object_unref); - GLenum err = glewInit(); - if (GLEW_OK != err) - { - printf("%s", "Error!"); - printf("%s", glewGetErrorString(err)); - return; - } - g_object_unref(plugin); }