Jump to content

  • Log In with Google      Sign In   
  • Create Account


What is the fastes way to load textures in opengl ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
22 replies to this topic

#21 Katie   Members   -  Reputation: 1282

Like
1Likes
Like

Posted 17 August 2011 - 05:39 AM

Instead of using an actual image format (such as TGA) which supports BGRA format, why not ship your images as plain image files already in that format. You don't need all the headers, you just need four bytes per pixel.

Lay them all out in a big block of ram, save that to disk, gzip it. When you come time to load it, you're only loading one file -- you hoof it into one giant block of ram (only 1 allocation, only 1 directory walk). Ungzipping a file is pretty easy on loading it. In addition your compression should be even better; larger files generally compress better than a set of smaller files because the compression can find more similarities to reduce.

Instead of generating the mipmaps on load every time, generate them on first run and save them out to disk. Again, do this one big block if possible. On load, pull it in, rattle down it transmitting the mipmap levels individually.


If you're on an OS which supports mapping the files, you don't need to load them or do an actual memory allocation. Map the file into your address space, provide suitable "linear access" hints to your buffer caching system so it will do read-aheads, start accessing the memory and away you go. The OS will try and load pages ahead of your accesses in the background; you don't have to wait for the "read()" call to complete. The effect of this is that you can already be generating and uploading mipmaps for texture 1 while the disk IO channels are still loading texture 20.


Instead of asking the GLU library to generate your mipmaps, you could build them yourself by using rendering of the fullsize image to pixel buffer objects and copies internal to the card to make them. That way the mipmap data doesn't have to transit the host-GPU bus.

Sponsor:

#22 L. Spiro   Crossbones+   -  Reputation: 12231

Like
0Likes
Like

Posted 18 August 2011 - 08:27 AM


But I am using ::glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE );

The SGI version of this token has been deprecated for eons. For OpenGL 2 and before, use the standard GL_GENERATE_MIPMAP token in its place.

For OpenGL 3+, use the glGenerateMipmap(GLenum target) function instead.

I don’t actually use SGIS (I use GL_GENERATE_MIPMAP). I just added that just in case the original poster is trying to maintain heavy backwards compatibility as I once did in the past.


Also I strongly suspect that the original poster’s bottleneck is indeed mipmaps.
Yes, they can be generated offline, but I have found so little slowdown with GL_GENERATE_MIPMAP that I don’t believe it is necessary, and it can save you disk space.
I recommend that he test his speed using GL_GENERATE_MIPMAP and then decide if he wants to trade mipmap quality for larger files on disk.


L. Spiro
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#23 swiftcoder   Senior Moderators   -  Reputation: 9587

Like
0Likes
Like

Posted 18 August 2011 - 09:00 AM

Yes, they can be generated offline, but I have found so little slowdown with GL_GENERATE_MIPMAP that I don’t believe it is necessary, and it can save you disk space.
I recommend that he test his speed using GL_GENERATE_MIPMAP and then decide if he wants to trade mipmap quality for larger files on disk.


Yes, I would agree.

And if GL_GENERATE_MIPMAP isn't high enough quality (although it usually is), you can always use an FBO + pixel shader, to manually generate the mipmap chain directly on the GPU.

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS