OpenGL, reading texture memory

Discussion in 'Game Development (Technical)' started by Raptisoft, Feb 22, 2009.

  1. Raptisoft

    Raptisoft
    Expand Collapse
    Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    804
    Likes Received:
    0
    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. Bad Sector

    Bad Sector
    Expand Collapse
    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    3
  3. PoV

    PoV
    Expand Collapse
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
  4. Raptisoft

    Raptisoft
    Expand Collapse
    Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    804
    Likes Received:
    0
    Well this is a total bummer. Score one for the Microsoft fanboys.
     
  5. jcottier

    jcottier
    Expand Collapse
    New Member

    Joined:
    Jul 12, 2006
    Messages:
    1,386
    Likes Received:
    0
    Why do you need to read the texel? Is it for alpha testing (clicking on sprite)?

    JC
     
  6. Raptisoft

    Raptisoft
    Expand Collapse
    Indie Author

    Joined:
    Jul 29, 2004
    Messages:
    804
    Likes Received:
    0
    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. Bad Sector

    Bad Sector
    Expand Collapse
    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    3
    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. PoV

    PoV
    Expand Collapse
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Alright then. Bet lost it seems. Will have to remember that for later. ;)
     

Share This Page