Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Some questions related to gl contexts and threads  (Read 1857 times)
0 Members and 1 Guest are viewing this topic.
Offline zingbat

Senior Member




Java games rock!


« Posted 2009-09-20 02:06:13 »

The jogl user guide says that the AWT thread is the one that has the opengl context current. Does this means it's ok to call gl methods from inside awt listeners?

Using jogl active rendering method similar to what is described in the Killer Game Programming book
http://fivedots.coe.psu.ac.th/~ad/jg2/ch15/index.html

suppose we want to use a different thread than AWT. If i understand correctly the rule is one drawable can have many contexts but one context per thread has to be associated to exactly one drawable. Also we have to make the context in each thread current before rendering one step and release it after. Is this correct?

What happens if we start messing with BufferStrategy in a canvas that is being used for opengl rendering? Just curious.
 
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2009-09-20 15:47:37 »

Although the AWT thread gets the context by default, it's not always current.  JOGL only makes the context current when it's calling the GLEventListener methods; so it's not okay to call gl methods from a KeyListener or MouseListener, etc.

As far as it goes for other threads, it sounds like you have the right rules.  Keep in mind that JOGL by default forces everything onto the AWT thread internally, so you'll have to call Threading.disableSingleThreading() to correctly get different threads to work.

I don't exactly know what would happen with a BufferStrategy, but I believe a GLCanvas is double-buffered already because of opengl and I'm pretty sure the BS is unnecessary or could cause problems.

Offline zingbat

Senior Member




Java games rock!


« Reply #2 - Posted 2009-09-20 21:52:15 »

Thanks. That puts some light on this subject.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rsantina

Junior Member





« Reply #3 - Posted 2009-09-23 06:31:13 »

Keep in mind that JOGL by default forces everything onto the AWT thread internally

If you have a canvas that should always be looping and alot of gui around it. This forcing will make the gui slow (as for the application as a whole).

Can Jogl run on another thread? There was someting called worker thread in jogl 1.x but that was very buggy?
Offline lhkbob

JGO Knight


Medals: 32



« Reply #4 - Posted 2009-09-23 13:49:27 »

It's possible to run it on another thread, but the worker thread was buggy.  Although a GLCanvas will work reasonable well off of another thread, I've scene graphical glitches on Macs before.  Also if the swing components are overlayed with the GLCanvas, I'd recommend keeping it single threaded.

Here's a possible solution:
1. Use the new Newt windowing for your primary GL window - it won't contain any UI stuff
2. Complex swing stuff can be in separate AWT windows around it

This setup would work best for an editor or utility and not a game.  IMO a game should not be using swing components but instead use very simple widgets integrated with opengl (this should improve the consistency of the game's LAF).

Offline rsantina

Junior Member





« Reply #5 - Posted 2009-09-23 14:08:06 »

Im working on an application where the 3d scene is part of it showing the CAD model and all encapsulated in a jide layout. Having it a separate window wont do the trick for us!
Offline zingbat

Senior Member




Java games rock!


« Reply #6 - Posted 2009-09-24 23:06:46 »

Quote
As far as it goes for other threads, it sounds like you have the right rules.  Keep in mind that JOGL by default forces everything onto the AWT thread internally, so you'll have to call Threading.disableSingleThreading() to correctly get different threads to work.

Is this still required if you aren't using a GLCanvas and building the GLDrawable directly?

I'm using the following code to associate a GLDrawable to a Frame. I'm actually surprised this is working.

1  
2  
3  
4  
5  
6  
private static Frame frame;
private static GLCapabilities capabilities;
private static GLDrawable drawable;
private static GLContext context;
private static GL gl;
private static GLU glu;


Part of a makeFrame method called from the main method.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
capabilities = new GLCapabilities();
AWTGraphicsDevice dev = new AWTGraphicsDevice(null);
AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) GLDrawableFactory.getFactory().chooseGraphicsConfiguration(capabilities, null, dev);
     
GraphicsConfiguration config = null;
if (awtConfig != null) config = awtConfig.getGraphicsConfiguration();
     
frame = new Frame(title, config);
     
frame.setSize(PWIDTH,PHEIGHT);
frame.setFocusable(true);
frame.requestFocus();
     
drawable = GLDrawableFactory.getFactory().getGLDrawable(frame, capabilities, null);
context = drawable.createContext(null);

// add listeners to frame
...

frame.setVisible(true);


The main method.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
long period = (long)(1000.0 / DEFAULT_FPS) * 1000000L;
     
makeFrame("CubeGL (Active)", period);
     
while (!frame.isDisplayable()) Thread.yield();
     
drawable.setRealized(true); // can now be rendering into

stats = new FrameStatistics(period);
rot = new Rotator3D();
     
init();  // OpenGL initialization

loop();  // A while loop that calls simulUpdate and renderFrame

// Finalize
stats.printStats();
context.destroy();
System.exit(0);  

Offline rsantina

Junior Member





« Reply #7 - Posted 2009-09-25 07:19:41 »

I didnt know you can have a drawable without a glcanvas  Undecided . Will give it a try.

Thanks.

One question: Does this remove the  drawable repaint from the awt thread?
Offline zingbat

Senior Member




Java games rock!


« Reply #8 - Posted 2009-09-25 10:08:15 »

You can use the setIgnoreRepaint(true) method but this is only a good idea if your window is a standalone window. If you want a GL window integrated with a gui then GLJPanel might be the best option.
Offline rsantina

Junior Member





« Reply #9 - Posted 2009-09-25 12:14:11 »

but isnt glcanvas more performant than gljpanel
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #10 - Posted 2009-09-25 21:49:38 »

Is this still required if you aren't using a GLCanvas and building the GLDrawable directly?

No idea, I've never tried.  It's pretty easy to tell if you debug and watch which thread the rendering is being conducted on.

Offline rsantina

Junior Member





« Reply #11 - Posted 2009-09-28 07:53:57 »

It's pretty easy to tell if you debug and watch which thread the rendering is being conducted on.

It always go to the AWT-EventQueue thread
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (26 views)
2014-09-07 01:12:14

Longarmx (33 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!