Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  [OT] Component.repaint() & stutter  (Read 814 times)
0 Members and 1 Guest are viewing this topic.
Offline mabraham

Junior Member





« Posted 2006-03-27 20:40:37 »

Apologies if this is somewhat off-topic but...

I'm developing an app which uses a GLCanvas to render some scene.  The user has certain tools they can use to draw some kind of shapes (this is all relatively basic 2-D btw).  These tools are done via mouse listeners on the canvas, and there's some pretty computation expensive code that creates these shapes (mask shapes they are, and they are rendered as textured quads btw).  Once a shape has been created or modified in the listener, it calls repaint() on the canvas to update the view.  OK so the problem I have is that while creating a new shape in the listener code takes around 10..15ms (rendering the scene itself takes about the same, depending on no of objects), view updates aren't smooth at all, and in fact the faster I drag the mouse around the worse it gets, to the point where I get virtually no view updates at all!

So why is this off-topic?  Because... it appears that repaint events are batched together and enter the event queue at low priority.  My guess is that the mouse events are flooding the queue so that none the repaint events makes it.  This has nothing to do with JOGL but I found no better place to post this, and I'm hoping someone will be able to help!

Possible solutions I've thought of so far:
  • Whenever a view parameter changes, call GLCanvas.display() directly, instead of replying on the repaint mechanism.  This is problematic with the way the app is designed.  There's so many listeners watching various different view properties that I cannot guarantee that only one of them will trigger display().  It would be very inefficient (and slow) if I get multiple updates upon a single change to one view property.
  • Move the computation from the listener code into a separate worker thread which, once the computation is finished, will invoke repaint() or display() even.  This may well work for an isolated test case, but will make the design very complex and error prone.
  • Use a JComponent instead of a canvas.  I'm not joking; obviously I don't see how that would be compatible with JOGL but: I have attached a non-GL test case that shows the difference in repaint mechanism between heavyweights and lightweights.  I'm wondering if I could employ a Swing RepaintManager maybe Huh  I dunno...
Offline Ken Russell

JGO Coder




Java games rock!


« Reply #1 - Posted 2006-03-27 21:58:38 »

Very interesting problem.

Under the circumstances I would suggest you build your own repainting mechanism on top of the display() method. Start a worker thread whose only job it is to wait for "repaint" requests on a particular GLAutoDrawable and call display() on it. If you make the requests asynchronous from when they are actually performed this will have the effect of batching them up as necessary. Here's a modified version of your test case doing this for the pure Java case; doing something similar for JOGL should actually be easier, since the RepaintHandler would deal only with GLAutoDrawables rather than having to interact with the EventQueue and do something different for the lightweight and heavyweight cases.

I'd also recommend you post your test case on the Swing and AWT board on javadesktop.org. It's surprising the behavior is so different between the two (and portably different, too -- I see the difference on Solaris/SPARC as well).
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.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (38 views)
2014-08-08 02:01:56
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!