Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
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 1071 times)
0 Members and 1 Guest are viewing this topic.
Offline Mickelukas

JGO Ninja


Medals: 39
Projects: 2


Java guru wanabee


« Posted 2011-02-09 21: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

Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2011-02-10 03: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 Mickelukas

JGO Ninja


Medals: 39
Projects: 2


Java guru wanabee


« Reply #2 - Posted 2011-02-10 20: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

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Mickelukas

JGO Ninja


Medals: 39
Projects: 2


Java guru wanabee


« Reply #3 - Posted 2011-02-11 22: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

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (125 views)
2013-05-17 21:29:12

alaslipknot (133 views)
2013-05-16 21:24:48

gouessej (163 views)
2013-05-16 00:53:38

gouessej (155 views)
2013-05-16 00:17:58

theagentd (168 views)
2013-05-15 15:01:13

theagentd (153 views)
2013-05-15 15:00:54

StreetDoggy (197 views)
2013-05-14 15:56:26

kutucuk (221 views)
2013-05-12 17:10:36

kutucuk (220 views)
2013-05-12 15:36:09

UnluckyDevil (224 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.109 seconds with 21 queries.