OpenGL, reading texture memory
I'm normally a DirectX guy but am doing some OpenGL for iPhone.
Can anyone tell me if it's possible to get at the texture memory after you've put it in a texture? For instance, in DirectX, you'd just say Texture->Lock().
By googling, I see that there's glReadPixels, but when I use that it only reads what's on the screen in the frame buffer. Is there a way to point it at a texture? (I've tried binding the texture right before calling, still get the frame buffer).
I'm trying to get access to the alpha data of the texture for picking. I don't want to store a whole seperate chunk of data about it because I don't use the picking that often, so it'd be a terrible waste to use it on every single image...especially when the data is sitting there on the video card. (It doesn't need to be fast, I only do it once).
Thanks in advance!
Standard OpenGL has glGetTexImage, but I don't think there's a way of reading from textures in GL ES. There *may* be something you can pull off with an FBO and ReadPixels, but I wouldn't bet on it.
Well this is a total bummer. Score one for the Microsoft fanboys.
Why do you need to read the texel? Is it for alpha testing (clicking on sprite)?
Originally Posted by Raptisoft
Yeah, it's for alpha testing. Don't want to store the data ahead of time, and don't want to store data for each sprite, since I only use a very limited number for alpha testing. Basically, I don't want to say at load time "I will need the alpha for this" because that would cramp my free for all hippie communist programming style, which is "what a beautiful morning! Today I feel like I that sprite should be pickable." Imagine if I did that and then I had to go back and find the sprite load and say mSprite.mMakeSureThisIsPickable=true. It would take me even longer to finish games than it took me to finish Boonka.
So I want to be able to say at any time, BOOM, this sprite now builds pick information for itself. I like call Sprite.Pick, and if there's no pick information, shazam, it builds it so it's always there from now on forever.
BTW, I spoke too soon... I found a solution that works. Bind the texture as if it were render to texture, then read the framebuffer pixels. So I guess the DirectX fanboys don't get their point after all.
They wouldn't get the point anyway: you can't use DirectX in iPhone :-P.
Beyond that, it is said that OpenGL|ES has a more streamlined API than "desktop" OpenGL where there aren't multiple ways to do the same thing. So if what you describe reads pixels from a texture then this is why glGetTexImage doesn't exist. I haven't used ES myself though, but AFAIK it is one of the goals of the OpenGL redesign (when and if it happens, GL3 failed on that) to be more like ES.