Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (707)
Games in Android Showcase (206)
games submitted by our members
Games in WIP (781)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ? What is best way to keep context after reinit/reshape ?  (Read 3203 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Devvie

Medals: 2

« Posted 2011-10-06 00:02:17 »

When you reinitialize/reshape a JOGL display I believe the context get destroyed and the init() method has to be called again to restore things. This is bad because I lose things like my display lists or my VBOs or Vertex Arrays and I have to recreate/rebind them, etc.

What is the best way to prevent can I maintain reference to, say a display list, so a reshape doesn't require me to remake it? If I'm resizing my window or revalidating the panel that my GLJPanel resides in then I lose my context and I have to wait and rebuild things - this can be annoying for users.

I read a while ago about "sharing contexts" but I don't know how that works. Any suggestions on what to do?
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #1 - Posted 2011-10-06 00:05:40 »

I had posed this question a while back in:

The answer at the time involved "It was suggested that I essentially build a separate GLContext at the start where I load my textures and models (make it current initially and then release it), then follow this with building the normal GLContext for my scene and then share the initial context data with it in the init() function (i.e. following resizes, etc)." ... has anyone done this?
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #2 - Posted 2011-10-06 00:07:41 »

Sorry for my constant is what rogersgb had suggested...I may need to look at this:

I have the same problem with textures and display lists on a GLJPanel. I store them in hash tables when they are created. If they need re-initialized due to context destruction I just grab them back out of the hash table. That implementation works for a heavyweight canvas as well.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight

Medals: 32

« Reply #3 - Posted 2011-10-06 03:35:01 »

A couple of things:
1. GLCanvas doesn't have this resize problem.  But the problem happens if it's hidden and then shown again. GLJPanel has issues with resize because it uses a pbuffer, which has a fixed size.
2. I have done context sharing and I don't think it is that difficult, especially if you're not worrying about multi-threading (which you shouldn't).  However, if you're game or app is simple enough that it can hold most things in memory, then rogersgb's approach is much simpler and less prone to bugs, although less efficient.  At a small scale, that efficiency won't matter.

Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #4 - Posted 2011-10-06 14:16:13 »

I have to use the GLJPanel because I'm inside a Swing component/frame so the GLCanvas won't help me. I'm not doing anything as taxing as a game, simply I'm drawing a 3D scene with the International Space Station vehicle (loaded from a 3DS file) and other approaching vehicles to show their relative position/attitude. I don't think it has to be on par with game performance, as long as I can get sub-second updates of the scene because my telemetry updates would come down at least at 1sec rate and I can't be waiting for the graphics to still update.

How do you go about the context sharing - I understand the concept in principle but have no idea how to even start that. As for the HashTable approach, I'm not sure how do I use it to use it to deal with more complicated things besides display lists - like the textures or buffers? In either case, at minimum I need to make sure that once I load my textures and buffers that I store them away and only during init() do I bind them - right? There is nothing else like having to recreate buffers (I just can't recall)?

I guess what I'm asking is for some direction on how to do the context sharing and/or hash table approach - is there some good reference I can look at or do you have some sample I can check out? The main reason I need this ability is because the graphics card I use on my development machine is poor and display list updates (and vertex buffer/array updates) for my 3DS models seem to take a long time, and if the user does too much resizing then they will really start to get annoyed at the delay.

Offline gouessej
« Reply #5 - Posted 2011-10-06 14:56:29 »

I have to use the GLJPanel because I'm inside a Swing component/frame so the GLCanvas won't help me.
GLCanvas is enough in most cases even with Swing components except when using internal frames. Otherwise, NEWT is a bit more robust to do that. I have already tested NEWT with AWT components; if you need to use it with Swing, I will test it with Swing too. I think it would be a better solution because your context would not be destroyed even though you hide the GLWindow (NEWT) and you show it anew later. Maybe this would be enough for your needs.

I already had the same problems when I wanted to implement a fullscreen toggle in a commercial application. The user could modify some meshes in windowed mode and I had to keep the context alive when he switched to full screen mode and vice versa.

Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #6 - Posted 2011-10-06 15:02:47 »

I noticed one thing strange in my GLCanvas version that has me additionally focused on the GLJPanel and that was some horrible flickering. I need to test it again but it was the flickering of the canvas itself that just made it too frustrating to use.

Edit: yeah, still have it. When I move my frame the GLCanvas section just flickers until I stop and sometimes it just goes blank (disappears) and I have to click inside the GLCanvas section to get it to come back. It is frustrating as hell.

Edit 2: I saw a post by 'cgull' at that said the following in the quote below...and it seems to be working. I just need to make sure it doesn't break something else.

This is caused by AWT erasing the GLCanvas every time before JOGL repaints it and can be worked around by inserting the following line into your main() method:

System.setProperty("sun.awt.noerasebackground", "true");

While this solves the given problem, side effects are possible in other areas of the application such as visible artifacts when resizing the window. I use this in all my JOGL apps though without any problems.

Edit 3: I need to give up...I really do. Now the noerasebackground is essentially preventing any updates to my scene unless I move my mouse in the view. This is so damn frustrating - have I said that yet?!
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #7 - Posted 2011-10-06 15:28:11 »

So far, the main break I have after fixing the flicker (see above) is that my JMenus appear beneath the GLCanvas - basically a lightweight/heavyweight issue.

I saw that this kind of issue seemed to be fixed with JDK 6.0 update 12 and above...but I have update 23 and I still see it. This is the quote I found Maybe I need to try JDK 7

As of the JDK 6 Update 12 and JDK 7 build 19 releases, it is now possible to seamlessly mix heavyweight and lightweight components within the same container. The following screen captures show the same three examples, run under the JDK 7 release, with no changes to the code. In each case, it just works.

Edit: GLCanvas is still causing my popup panels (JWindows) to get partially hidden. Too bad this wasn't truly fixed as they say.
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #8 - Posted 2011-10-06 17:35:05 »

Another thing I noticed with GLCanvas has to do with resizing it. I have it part of a top component of a JSplitPane. When I resize the bottom component by moving the divider down the GLCanvas grows bigger but then it prevents me from shrinking it back. The bigger it gets the bigger it stays and won't let me make it smaller? Any idea why?

Edit: Seems like others have had the same issue and this is due to the heavyweight of GLCanvas you see why I chose GLJPanel.   Grin

Edit 2: It seems I need to do more searching...hehe. Here is the solution,18457..

Basically I added this setMinimumSize() on the panel that contained my GLCanvas:
// We need to create a Dimension object for the JPanel (containing the GLCanvas) minimum 
// size to fix a GLCanvas resize bug. The GLCanvas normally won't recieve resize events
// that shrink a JPanel controled by a JSplitPane.
setMinimumSize(new Dimension());    

Thank God for JOGL developers that came before me. Smiley
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Galdo (207 views)
2017-01-12 13:44:09

Archive (375 views)
2017-01-02 05:31:41

0AndrewShepherd0 (834 views)
2016-12-16 03:58:39

0AndrewShepherd0 (770 views)
2016-12-15 21:50:57

Lunch (907 views)
2016-12-06 16:01:40

ral0r2 (1135 views)
2016-11-23 16:08:26

ClaasJG (1238 views)
2016-11-10 17:36:32

CoffeeChemist (1285 views)
2016-11-05 00:46:53

jay4842 (1368 views)
2016-11-01 19:04:52

theagentd (1198 views)
2016-10-24 17:51:53
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!