GNOME Bugzilla – Bug 779414
GtkBox in a GtkOverlay Above GtkGlArea Flickering
Last modified: 2018-05-02 18:12:22 UTC
I am Using OS : Lubuntu 16.04.2 Renderer: Mesa DRI Intel(R) HD Graphics 530 (Skylake GT2) OpenGL version supported 4.3 (Core Profile) Mesa 12.0.6 Gtk Version 3.18.9 I am using a GtkOverlay Container and adding a GlArea and GtkBox using AddOverlay The GtkBox sometimes (randomly) flickers when it is positioned above the GlArea. i have also seen that a GlArea above another GlArea does not flicker. Help Appreciated
Please attach a minimal, self-contained test case to reproduce the problem with a supported version (3.18 is too old).
/* Sample Code reflecting producing the said behaviour. The Box will flicker randomly. 3.18.9 is the default version provided by Lubuntu 16.04.2 */ #include <iostream> #include <gtkmm/window.h> #include <gtkmm.h> #include<gdkmm.h> #include <gtk/gtk.h> #include <epoxy/gl.h> #include <glib.h> using namespace std; using namespace Gtk; struct TestClass { Gtk::GLArea glArea; const GLchar* vertexSource; const GLchar* fragmentSource ; GLuint gl_vao, gl_buffer, gl_program; GLuint vao,vbo; GLuint shaderProgram; GLuint texture = 0; unsigned char * memmoryBuff; bool on_timeout() { glArea.queue_render(); return true; } void on_realize() { glArea.set_auto_render(true); glArea.set_hexpand(); glArea.set_vexpand(); glArea.set_halign(Gtk::ALIGN_FILL); glArea.set_valign(Gtk::ALIGN_FILL); glArea.make_current(); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); std::cout<<"PreviewOpenGLWidget::on_realize"<<std::endl; const GLubyte* renderer = glGetString(GL_RENDERER); const GLubyte* version = glGetString(GL_VERSION); printf("Renderer: %s\n", renderer); printf("OpenGL version supported %s\n", version); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //////////initialization/////////////////// glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); GLfloat vertices[] = { // Position Color Texcoords -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, // Top-left 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // Top-right 1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, // Bottom-right -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f // Bottom-left }; glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW); GLuint ebo; glGenBuffers(1, &ebo); GLuint elements[] = { 0, 1, 2, 2, 3, 0 }; glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW); // Create and compile the vertex shader GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexShader, 1, &vertexSource, NULL); glCompileShader(vertexShader); // Create and compile the fragment shader GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragmentShader, 1, &fragmentSource, NULL); glCompileShader(fragmentShader); // Link the vertex and fragment shader into a shader program shaderProgram = glCreateProgram(); glAttachShader(shaderProgram, vertexShader); glAttachShader(shaderProgram, fragmentShader); glBindFragDataLocation(shaderProgram, 0, "outColor"); glLinkProgram(shaderProgram); //glUseProgram(shaderProgram); // Specify the layout of the vertex data GLint posAttrib = glGetAttribLocation(shaderProgram, "position"); glEnableVertexAttribArray(posAttrib); glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), 0); GLint colAttrib = glGetAttribLocation(shaderProgram, "color"); glEnableVertexAttribArray(colAttrib); glVertexAttribPointer(colAttrib, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat))); GLint texAttrib = glGetAttribLocation(shaderProgram, "texcoord"); glEnableVertexAttribArray(texAttrib); glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), (void*)(5 * sizeof(GLfloat))); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); 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_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1280, 720, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); } bool on_render(const Glib::RefPtr< Gdk::GLContext >& context) { static unsigned int count = 0; static unsigned char t = 0; unsigned char a = t; for(int i=0 ; i< 1280*720 *3; i++) { memmoryBuff[i] = a++; } glUseProgram(shaderProgram); glBindVertexArray(vao); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1280, 720, GL_RGB, GL_UNSIGNED_BYTE, memmoryBuff); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glBindVertexArray (0); glUseProgram (0); count++; //if((count % 2) == 0) { t++; } return false; } TestClass() { // memmoryBuff = new unsigned char[1280*720*3]; glArea.signal_render().connect(sigc::mem_fun(*this, &TestClass::on_render)); glArea.signal_realize().connect(sigc::mem_fun(*this, &TestClass::on_realize)); Glib::signal_timeout().connect( sigc::mem_fun(*this, &TestClass::on_timeout), 30 ); #define IGNORE_VAR(type, identifier) \ { \ type IGNORED_VARIABLE_abcd = identifier; \ identifier = IGNORED_VARIABLE_abcd; \ } vertexSource = "#version 150 core\n" "in vec2 position;" "in vec3 color;" "in vec2 texcoord;" "out vec3 Color;" "out vec2 Texcoord;" "void main()" "{" " Color = color;" " Texcoord = texcoord;" " gl_Position = vec4(position, 0.0, 1.0);" "}"; fragmentSource = "#version 150 core\n" "in vec3 Color;" "in vec2 Texcoord;" "out vec4 outColor;" "uniform sampler2D tex;" "void main()" "{" " outColor = texture(tex, Texcoord) * vec4(1.0,1.0,1.0, 1.0);" "}"; shaderProgram = 0; } }; int main(int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv,"org.gtkmm.examples.base"); Gtk::Window window; Gtk::Overlay overlay; Gtk::Button mButton; Gtk::Box mBox; TestClass test; window.fullscreen(); mBox.override_background_color(Gdk::RGBA("#aeea96"), Gtk::STATE_FLAG_NORMAL); // test.glArea.override_background_color(Gdk::RGBA("green"), Gtk::STATE_FLAG_NORMAL); mBox.set_size_request(1080,650); mBox.set_halign(Gtk::ALIGN_CENTER); mBox.set_valign(Gtk::ALIGN_CENTER); mButton.set_halign(Gtk::ALIGN_CENTER); mButton.set_valign(Gtk::ALIGN_CENTER); mBox.add(mButton); test.glArea.set_size_request(1280,720); overlay.set_double_buffered(true); mButton.set_size_request(100,100); overlay.set_opacity(.9); overlay.add_overlay(test.glArea); overlay.add_overlay(mBox); window.add(overlay); overlay.reorder_overlay(mBox,1); window.show_all(); return app->run(window); }
Thanks! Attaching as an attachment is welcome. :)
hi Andre, i have compiled GTK 3.22.7 for Lubuntu 16.04.2. i have been unable to reproduce the flickering issue. but i am being bombarded with the following warnings. gtk_widget_size_allocate(): attempt to underallocate gtkmm__GtkOverlay's child gtkmm__GtkOverlay Allocation is 0x0, but minimum required size is 1440x810.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/774.