Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  [SOLVED] Overlay best practises  (Read 1425 times)
0 Members and 1 Guest are viewing this topic.
Offline Mike

JGO Wizard


Medals: 84
Projects: 1
Exp: 6 years


Java guru wanabee


« Posted 2011-02-09 20:44:45 »

Hi all,

I'm creating a semi transparent 2D overlay that needs to update quickly (moving windows and so on) and it worked fine until I tried it at FullHD resolution (putting fullscreen in my game for fun). Some comments would be great because I'm all out of ideas.

What I currently do is:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
If an interface component has moved
    Clear a buffered image the same size as the window (using fillrect, so slow!)
    Draw the interface components onto the buffered image
    Tell the OpenGL thread that the overlay has changed

The OpenGL thread then picks up the buffered image and makes it into a texture (binding the already existing texture but calling glTexImage2D again)

Every loop (no matter if the texture has changed or not)
    The OpenGL thread marks parts of the texture to be drawn (where there is a component)
    Moves over to a 2D viewpoint
    Draws triangles of each marked part using the texture created


The last part (what happens every loop) is really fast no matter the resolution, but the first two parts are really really slow when I'm handling a texture of 2048*2048, which I guess makes sense... it works really great up to 1024*512 though.

What is the best practice around this and how have other people solved it? Handle one BufferedImage/texture per element/window (they are mostly quite small and quite static, the problem is the movement which would be solved then as that's only the triangles moving)? Update the texture using glTexSubImage2D?

Kind regards,
Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2011-02-10 02:33:38 »

Definitely use glTexSubImage2D.  Smart drivers might be able to reuse the same texture memory when making a new image, but who knows?  Also, glTexSubImage2D can be used to transfer only the parts of the BufferedImage that have changed, if you have an easy way of tracking that.

I would also recommend not updating the texture when the window overlay moves.  If you think of all the components placed with respect to the corner of the overlay, then they aren't moving so you don't need to change how they are drawn.

Offline Mike

JGO Wizard


Medals: 84
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #2 - Posted 2011-02-10 19:58:20 »

Definitely use glTexSubImage2D.  Smart drivers might be able to reuse the same texture memory when making a new image, but who knows?  Also, glTexSubImage2D can be used to transfer only the parts of the BufferedImage that have changed, if you have an easy way of tracking that.

I can quite easily figure out what parts changed so that is an option instead of splitting the overlay up into several textures.

I would also recommend not updating the texture when the window overlay moves.  If you think of all the components placed with respect to the corner of the overlay, then they aren't moving so you don't need to change how they are drawn.

Well, I have lots of windows rendered to the overlay and they can be dragged around by the user so I can't make them static with respect to the corner of the overlay.

I'll look into creating several textures instead of one huge one with lots of transparent pixels, update it with glTexSubImage2D and see what happens with the performance Smiley

Kind regards,
Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mike

JGO Wizard


Medals: 84
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #3 - Posted 2011-02-11 21:01:51 »

Creating one texture per overlay element and updating the textures with glTexSubImage2D made a huge difference, no more performance problems for me, thanks! Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!