Hello Guest

Troubles using multiple contexts

  • 6 Replies
  • 5230 Views
Troubles using multiple contexts
« on: July 26, 2012, 08:28:43 »
Hello everybody,

I am not developping a game but a small CAD-oriented application. It is a mesh viewer/editor.
I use SWT for the general GUI and indeed LWJGL for interfacing the app with OpenGL.

I can display multiple meshes, each of them if stored in a VBO. When I render them, everything seems to be working correctly.

The comes when I want to use two different GLCanvas, and so two different contexts (one for viewing with a 3D display, translation, zoom and rotaton capabilities, the other, only 2D but with the possibility to orientate the view (front, back, left etc...)). These two contexts are used in two tabs (TabItem in SWT).

When I load my mesh, it is displayed correctly in the first tab (3D) but when I switch to the 2D tab, I get a crash. First I thought it was due to a missuse a VBOs, so for each meshm I generate two VBOs, one for viewing, one for editing. But I have still the same crash.

For now I only display a simple mesh of 4x4 quads. which means 5 nodes per row and column => 25 nodes, and 3 components by node => 75 floats. this is the size of the buffer declared as well. and for the quads, 4x4 = 16 quads, and 4 nodes per quads leads to 64 ints for the size of this buffer. this number is also correct for the buffer size.

So I do not really understand where it is going wrong when I use the two contexts. When I render the view, I call GLContext.setcurrent(mycanvas) and mycanvas.setcurrent().

so I must say that I running a bit out of ideas of where to find my mistake, so I post here since you may help me with this problem.

I used this snippet: http://bingjava.appspot.com/snippet.jsp?id=389 to start using the GLCanvas. now it changed quite a lot : rendering only when needed in a separate method, which call setcontext, setcurrent and so on.

Thank you,

Pierre

Re: Troubles using multiple contexts
« Reply #1 on: July 26, 2012, 13:35:56 »
I think your problem is that different contexts do not share mesh/texture data. So if you are loading the mesh on one canvas, you can't display it on the other canvas without loading it again on that canvas (with current context, of course). To share mesh data you need to use a shared context (see org.lwjgl.opengl.SharedDrawable and related examples).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: Troubles using multiple contexts
« Reply #2 on: July 26, 2012, 16:55:24 »
I'm also thinking about this ... but where can I find some doc on the use of shared drawable ? there's nothing in the wiki and I find google quite silent about it! there are some info on this forum, but still not enough for me to understand how to implement it!

Thanks,

Pierre

Re: Troubles using multiple contexts
« Reply #3 on: July 27, 2012, 13:00:48 »
There is a test in the LWJGL source that should show you how to use it: \src\java\org\lwjgl\test\opengl\multithread
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: Troubles using multiple contexts
« Reply #4 on: August 07, 2012, 21:39:09 »
Hello,

I looked at the example in the doc, and I must say that I am completely lost on the way to share those resources.
I read some post on other forums about creating a context and sharing it over the canvases and then making a canvas current and releasing it after rendering. is it an other way to go ?

Do you have any clear tutoriel of how to implement this kind of thing ?

Thank you,

Pierre

Re: Troubles using multiple contexts
« Reply #5 on: August 10, 2012, 17:36:47 »
A way to get around your issue is to cut off a single canvas into several viewports. I never tried this but it turns out to be the most accessible solution for rendering multple views of the scene. e.g. NEHE tutorial http://nehe.gamedev.net/tutorial/multiple_viewports/20002/
 :D
« Last Edit: August 10, 2012, 17:52:24 by broumbroum »

Re: Troubles using multiple contexts
« Reply #6 on: August 10, 2012, 18:02:10 »
Hi,

I would love to split the viewport ... but I have one canvas per tab ... so only one displayed at a time!