flipping textures

gidday, how are yous dealing with loading textures in the most optimal fashion WRT image flipping.
ie with some image formats the data is stored with the origin at the bottom, and with others the data starts at the top of the image.

at the moment im loading the whole image in and then flipping the rows myself, is it perhaps better/faster loading in the image a row at a time?

also is there some method to automatically flip the image in gl (ild expect it to be in the imagestore but i see nothing)

cheers zed

t = 1.0 - t

if u mean changing the texture coordinates, then thats untidy for obvious reasons.

Actually, to speed up the loading … we reverse the picture by itself. As you can imagine, it works well …


Great idea.

I don’t know but glPixelStore is probably the place to look. I think it would be GL_UNPACK_SKIP_PIXELS or GL_UNPACK_SKIP_ROWS.
Maybe you pass glTexImage a pointer to the last row, and call glPixelStore(GL_UNPACK_SKIP_ROWS, -2)

I’ve never tried this. Even if it works, I doubt it would be fast.

Originally posted by SeskaPeel:
[b]Actually, to speed up the loading … we reverse the picture by itself. As you can imagine, it works well …

Do you mean, “we reverse the picture ourselves”? So presumably you mean you flip certain picture formats in photoshop and save them out flipped?
I’m pretty sure zed would simply not use a flipped format if he had the opportunity to flip it in photoshop! He probably doesn’t have control over what images are fed into his engine, and in what format…in which case, seskapeel, your suggestion is pointless.
Personally, I sometimes reverse the texture coordinates in the texture matrix…every texture in my system has an associated texture matrix, even if it’s identity most of the time. I sometimes use this texture matrix to deal with non-pow2 textures as well.
But, it may be simpler if you just write a little function to flip the image data itself after loading…saves confusion later on.

Dear knackered, what you describe is what we do. We had control over the textures, zed never said he did or he did not.
Your suggestion is as pointless as mine, as you considered he didn’t.


Ok peel, don’t take offense - I didn’t mean ‘pointless’ in the sense that you suggesting it was pointless…you shouldn’t be so quick to take things the wrong way, you’ll give yourself a stroke, no matter how much garlic you consume.
With resources that I have control over (ie. in non-tool like apps) I tend to load them in whatever format they arrive from the artist in, process them (flip,swizzle or whatever on the CPU) then save them out as compressed (lossy or lossless) binary in my own format for subsequent quick loading. I cache them in a cache directory, and check incoming modified dates against cache modified dates to determine if the binary cache version needs updating.
I would imagine everyone else does this also.

I would imagine everyone else does this also.
Nope, sounds pretty competent but it’s not appropriate for a lot of applications.

Dear knackered, don’t worry, you didn’t offend me.

Some time ago, we used a system of additional file along with the texture (MyTexture.jpg + MyTexture.cfg). Each time a texture was to be loaded, we checked to see if there was a matching .cfg file along.
This cfg included filtering, anisotropy, optional flip operations that could already be made, and compression options).

We moved to a better system, and I think we’ll fall back to the good old cfg sooner or later.

I don’t like garlic,

glPixelStore(GL_UNPACK_SKIP_ROWS, -2)
i dont believe u can use negative numbers ill give it a try though

I would imagine everyone else does this also.

 W   :) 

flipping the texture in a paint program does work but it means depending on the image format, some text is gonna be upside down on the screen not to mention it being a PITA to do manually

flipping the texture coords also works but what happens when a different image is loaded for that model, youre buggered unless u also store extra info somewhere else eg with the model saying that its texture corrdinates are flipped

the best method is to get the right orientation straight away when youre loading the texture, this way u can forget about it.

ill time both flipping methods tonight to see which is faster, ill let yous know.

looks like i was majorly wrong with my supposition of C being quicker than B, now i think about it, it actually it makes sense anyways,
times include the actual creation of the gl texture

A/ time of unflipped texture
B/ flipped with multiple file reads ie read in line then go onto next line
C/ single file read and then flipped

uncompressed targa


A/ 0.045648 sec
B/ 0.048494
C/ 0.086399


A/ 0.002204
B/ 0.002319
C/ 0.003613

so the cost of flipping textures is pretty minimal