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 (568)
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  
  When to unbind textures in OpenGL?  (Read 2755 times)
0 Members and 1 Guest are viewing this topic.
Offline Bombadil

Senior Member





« Posted 2004-10-12 04:46:21 »

Hi. This is the Java 3d subforum, not the Java3d one, isn't it? :-)  So the place to ask questions about OpenGL and Java, too? :-)

For a 2d game in OpenGL (yeah it's 3d in 2d view) I've loads of textures to bind during game play. Many graphics appear on screen for some time and then disappear. Some of them re-appear some time later, some won't come again.
Currently I've got some usage counter per texture. When a sprite uses one, the texture is bound and the usage counter incs. When a sprites disapears forever, its texture's usage counter decs and when it's zero the texture is unbound.
While this works, it's fussily. Also, when new sprites appear and use the same texture an old disappeared sprite used to use, I've to rebind the texture. Since they're being compressed on the fly this is an overhead which I'd like to avoid.

However, maybe this isn't necessary at all. That's the question. Would it be sufficient to unbind all textures just at the end of the level? And let the OpenGL driver do the rest? With rest I mean: when new textures are being bound, old ones which doesn't fit into the gfx card are moved to the PC's RAM anyway, isn't it?
Any experiences?

How do high level 3d APIs using OpenGL solve this issue? When, for example, a user loads many 3d models which tons of textures and all of those models could appear in the scene graph? When do they bind the textures, and when unbind?


PS: With "bind" I mean something like this:
gl.glGenTextures(...) to get a new texture ID
then
gl.glBindTexture(GL.GL_TEXTURE_2D, texture's ID);

With "unbind" I mean this:
gl.glDeleteTextures(texture's ID)
Online princec

JGO Kernel


Medals: 392
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-10-12 07:48:04 »

I keep everything bound and let the page file handle it Wink Cheeky but effective.

I've been experimenting with the garbage collector automatically unbinding textures for me when my GLTexture objects are collected.

Cas Smiley

Offline Bombadil

Senior Member





« Reply #2 - Posted 2004-10-12 07:55:45 »

Quote
I keep everything bound and let the page file handle it ;) Cheeky but effective.

Thanks for your answer. If the smart Alienflux creator does handle it this way, I'll do so, too. :-)

With "keep bound" you mean during the entire game or for one level?

Does keeping also mean you can "delete" (=null) your BufferedImages (or whatever type you load texture files into from disc) once you've bound the BufferedImages to Ogl's texture (and got an Ogl tex ID) ?
Because currently I keep those BufferedImage in my Java app and they're doubled on the gfx card (and even copied again in case the Ogl driver pages them out...)

Quote

I've been experimenting with the garbage collector automatically unbinding textures for me when my GLTexture objects are collected.

Sounds nice: has it been worth the effort? And also: how do you get notified when the GC kicks your texture?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online princec

JGO Kernel


Medals: 392
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2004-10-12 12:17:38 »

Entire game.

As soon as you've loaded your image into GL with glTexImage2D, forget about it! GL makes a copy of the image and manages it from then on. You no longer need it.

The garbage collection idea is much more complicated than it sounds. You can't use a finalizer because it's a) unreliable and b) occurs in the wrong thread so you've got to figure out some way of using reference queues. I say you, coz I haven't quite got it right yet Wink

Cas Smiley

Offline Bombadil

Senior Member





« Reply #4 - Posted 2004-10-13 05:16:15 »

Quote
Entire game.

As soon as you've loaded your image into GL with glTexImage2D, forget about it! GL makes a copy of the image and manages it from then on. You no longer need it.

Now this is news I love to hear!

Quote
The garbage collection idea is much more complicated than it sounds. You can't use a finalizer because it's a) unreliable and b) occurs in the wrong thread so you've got to figure out some way of using reference queues. I say you, coz I haven't quite got it right yet ;)

Yes sounds ... complicated. I'll stick to the simple(r) things. ;)
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.

Riven (9 views)
2014-10-02 14:36:20

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

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

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

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

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

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

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

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

UprightPath (53 views)
2014-09-20 20:14:06
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!