Fwd: reparenting a GtkDrawingArea with OpenGL

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Fwd: reparenting a GtkDrawingArea with OpenGL

by Jeff Eberl :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Date: Mon, 18 May 2009 23:10:32 -0400


From: Braden McDaniel braden@...>

Subject: Re: [GtkGLExt] reparenting a GtkDrawingArea with OpenGL

To: gtkglext-list@...

Message-ID:

Content-Type: text/plain



On Fri, 2009-05-15 at 14:40 -0600, Jeff Eberl wrote:



I have  a window with two GtkDrawingArea's.  One is a map and one is a

picture, I'm trying to swap the two windows with the click of a

button.  Surrounding each drawing is a bunch of buttons and things.



This is how I reparent them:



gtk_widget_ref(map_widget);

gtk_widget_ref(pic_widget);



gtk_container_remove(left_

container, map_widget);

gtk_container_remove(right_container, pic_widget);



gtk_container_add(left_container, pic_widget);

gtk_container_add(right_container, map_widget);



gtk_widget_unref(map_widget);

gtk_widget_unref(pic_widget);



The buttons, the boxes, and everything in the widgets swaps out, but

the next time I try to draw in either of them, the

gdk_gl_drawable_gl_begin fails:



GdkGKExt-CRITICAL **: gdk_gl_window_impl_x11_make_context_current:

assertion 'GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext)' failed



So, that's a bummer.  I didn't write the code I'm using to instantiate

the widgets, or draw the pic/map.  I'm wondering if maybe the problem

is that the "realize" event gets called twice, but all the gdk setup

stuff is actually in a different method, one that doesn't get called

twice.  The realize callback doesn't really have anything in it.



Hm... Is it getting unrealized? If that happens, and it isn't getting

realized again, that may explain the behavior you're observing.



To debug this, you'd need to track the lifetime of the GdkGLDrawable

that's supposed to be handed off to gdk_gl_drawable_begin; obviously

it's invalid by the time it's getting there.  A stack trace should give

you some starting points for places to put breakpoints.



--

Braden McDaniel braden@...>


After a lot of print statements, and some new callbacks, I've discovered
half of the problem.

I was keeping the gtkContext* around, and it's been invalidated.  So a
simple call to gtk_widget_get_gl_context fixed that.

I connected to the realize and unrealize signals, and the remove calls
unrealize, and the add calls realize.  But there is another problem, the
glLists  and glTextures seem to be getting invalidated.  Looking at the
gears code, it looks like the realize creates a new list (glGenList) but
there's no where that the list gets deleted.  Does this mean the gears
app is leaking video resources?  Or is it getting cleaned up somewhere?
For now, I'm going to delete all lists and textures in the unrealize
event, and create them again in the realize event.  I'm hoping this is
overkill, and someone knows how to fix, or revalidate the lists/textures
without completely reallocating them.

Jeff

_______________________________________________
gtkglext-list mailing list
gtkglext-list@...
http://mail.gnome.org/mailman/listinfo/gtkglext-list

Re: Fwd: reparenting a GtkDrawingArea with OpenGL

by Braden McDaniel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 5/20/09 2:43 PM, Jeff Eberl wrote:

> After a lot of print statements, and some new callbacks, I've discovered
> half of the problem.
>
> I was keeping the gtkContext* around, and it's been invalidated. So a
> simple call to gtk_widget_get_gl_context fixed that.
>
> I connected to the realize and unrealize signals, and the remove calls
> unrealize, and the add calls realize. But there is another problem, the
> glLists and glTextures seem to be getting invalidated. Looking at the
> gears code, it looks like the realize creates a new list (glGenList) but
> there's no where that the list gets deleted. Does this mean the gears
> app is leaking video resources? Or is it getting cleaned up somewhere?

Technically, yes. But I think that the video driver will clean up any
resources associated with the context when the context goes away.

> For now, I'm going to delete all lists and textures in the unrealize
> event, and create them again in the realize event. I'm hoping this is
> overkill, and someone knows how to fix, or revalidate the lists/textures
> without completely reallocating them.

I think deleting them yourself is the safe, responsible thing to
do--kind of like freeing memory in a C program.  Sure, most modern
operating systems will reacquire the memory when the process ends; but
even in programs that aren't expected to be long running it's considered
good practice to release resources when you're done with them.

I do not think there's any way to "revalidate" these resources.  But are
you really going to be swapping these widgets around so much that the
cost of reallocation is likely to be onerous?

--
Braden McDaniel                      e-mail: <braden@...>
<http://endoframe.com>               Jabber: <braden@...>
_______________________________________________
gtkglext-list mailing list
gtkglext-list@...
http://mail.gnome.org/mailman/listinfo/gtkglext-list