Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411488 Posts in 69377 Topics- by 58433 Members - Latest Member: Bohdan_Zoshchenko

April 29, 2024, 03:04:19 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)[deleted]
Pages: [1]
Print
Author Topic: [deleted]  (Read 1858 times)
bluej774
Guest
« on: January 28, 2010, 02:02:17 AM »

[deleted]
« Last Edit: May 25, 2021, 06:18:49 PM by bluej774 » Logged
Saint
Level 3
***



View Profile WWW
« Reply #1 on: January 28, 2010, 02:37:23 AM »

Yes.

First, bind the texture as usual with glBindTexture, then...

Code:
glGetTexLevelParameteriv(GL_TEXTURE_2D,[Mipmap level, likely 0 in your case],GL_TEXTURE_WIDTH,[Pointer to GLint that will receive the result]);

... Or use GL_TEXTURE_HEIGHT to find the height. Read up more on this function in the GL documentation;
http://www.opengl.org/sdk/docs/man/
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #2 on: January 28, 2010, 08:11:12 AM »

It probably makes more sense for you to store that information manually together with the texture ID somewhere.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
mewse
Level 6
*



View Profile WWW
« Reply #3 on: January 29, 2010, 03:48:39 AM »

Here's another question.  Can textures pile up in the background and max out memory?

Yes.  If you keep creating textures and don't ever glDeleteTextures them, then eventually you'll fill up memory on the video card, and OpenGL will start swapping them in and out to the video card as they're used.  This can be a big performance problem, and OpenGL won't tell you if that's happening.  So you want to be a little careful with what and how many textures you're asking OpenGL to use.


The reason I ask is that I've written a Sprite class.  Naturally, I've written a destructor that uses the glDeleteTextures call to delete the texture being referenced in that sprite class.  But then I realized that the texture the Sprite object references can also be referenced by another variable.  So if a Sprite object is destroyed and the texture goes with it, but then another reference to that texture is used for something, it'll cause problems.  So, what's the recommended solution?  Should I not destroy textures in the Sprite class at the risk of texture buildup?  Or is there a better solution I'm not thinking of?

The correct thing to do is to have your game be aware of the textures it's asked OpenGL to use.  If a texture is used for lots of sprites, your game should only ask OpenGL to create it once, and then share that texture ID amongst all the sprites.  You should then tell OpenGL to destroy the texture only once no sprites are referencing the texture any more, and you don't expect to need the texture again.  (That is, it's worth keeping projectile textures around, even if no sprites are currently drawing with them, because you'll probably need them again soon.  No point destroying them and then immediately re-creating them a frame or two later, after all!)

Personally, I wrap the OpenGL texture ID in a "Texture" class, on which I also store a "reference count"; the number of objects referencing that texture.  As I create objects which use the texture, I increment the reference count, and as I destroy them, I decrement the reference count.  If the reference count is greater than zero, I know that something is still using that texture.  Or if it drops to zero, then I know that nothing's using it any more and it can safely be removed from OpenGL.  And if the reference count drops below zero, then I know I have a bug in my code.  Wink
Logged
Ivan
Owl Country
Level 10
*


alright, let's see what we can see


View Profile
« Reply #4 on: January 29, 2010, 09:21:43 AM »

Another way of dealing with that is writing a simple resource manager that will load every texture you're going to use into video memory, and then your sprites or whatever will just request the instance by the filename.
Logged

http://polycode.org/ - Free, cross-platform, open-source engine.
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic