Results 1 to 8 of 8

Thread: OpenGL, reading texture memory

  1. #1
    Senior Member
    Join Date
    Jul 2004
    Posts
    804

    Default OpenGL, reading texture memory

    Hi everyone,
    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!
    --John

  2. #2
    Senior Member
    Join Date
    May 2005
    Location
    Warsaw, Poland
    Posts
    2,733

  3. #3
    Senior Member
    Join Date
    Jul 2004
    Location
    London, Ontario, Canadia
    Posts
    2,132

    Default

    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.

    http://khronos.org/registry/gles/ext...fer_object.txt
    Mike Kasprzak | sykhronics entertainment | Blog | twitter | Ludum Dare
    Smiles + HD (It's on everything™, IGF finalist, won a car) | ??? (2013) | MORE: Book, PuffBOMB, Towlr
    Hey you what's up yo? Kickin' it oldskool style!

  4. #4
    Senior Member
    Join Date
    Jul 2004
    Posts
    804

    Default

    Well this is a total bummer. Score one for the Microsoft fanboys.

  5. #5
    Senior Member
    Join Date
    Jul 2006
    Location
    France
    Posts
    1,388

    Default

    Quote Originally Posted by Raptisoft View Post
    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)?

    JC

  6. #6
    Senior Member
    Join Date
    Jul 2004
    Posts
    804

    Default

    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.

  7. #7
    Senior Member
    Join Date
    May 2005
    Location
    Warsaw, Poland
    Posts
    2,733

    Default

    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.

  8. #8
    Senior Member
    Join Date
    Jul 2004
    Location
    London, Ontario, Canadia
    Posts
    2,132

    Default

    Quote Originally Posted by Raptisoft View Post
    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.
    Alright then. Bet lost it seems. Will have to remember that for later.
    Mike Kasprzak | sykhronics entertainment | Blog | twitter | Ludum Dare
    Smiles + HD (It's on everything™, IGF finalist, won a car) | ??? (2013) | MORE: Book, PuffBOMB, Towlr
    Hey you what's up yo? Kickin' it oldskool style!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •