Attention: iDevGames forum has a new home at http://www.idevgames.com/forums.
Please update your bookmarks and linkage.
This forum has been locked and will be available for archival purposes only.
iDevGames - Mac, iPhone, iPad & iPod Game Developers Forum  


iPhone, iPad & iPod Game Development Game programming topics devoted to the Apple iPhone, iPad & iPod.

 
 
Thread Tools Display Modes
Old
  (#1)
Malarkey
Über Member
 
Posts: 370
Join Date: 2004.06
Location: Behind the Orange Curtain
Question on how to change the image data of a texture on a continual basis - 2009.11.25, 02:20 AM

Okay, so I've done a few searches of the forum but can't quite seem to find the right answer for what I'm trying to do so please forgive me if this has been brought up before.

Anyway, I'm using the Texture2D class to convert raw pixel data into something I can show on the screen. However, this raw pixel data is constantly changing so in order to update the image on the screen, I'm continually releasing the old Texture2D object and creating a new one. This strikes me a terribly inefficient. So my question then is it possible to create a texture once and continually update it from this buffer of pixel data? Is this what FBOs and rendering to a texture are for?


The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
   
Old
  (#2)
AnotherJake
Moderator
 
Posts: 3,541
Join Date: 2003.06
Location: usa
2009.11.25, 08:46 AM

Did you try glTexSubImage2D?
   
Old
  (#3)
Skorche
Member
 
Posts: 1,310
Join Date: 2002.09
Location: Minnesota
2009.11.25, 09:19 AM

Also, you should be aware that on the iPhone you should avoid changing a texture in the middle of your rendering code. The iPhone doesn't have a stream renderer, so it has to make a copy of your texture internally when you modify if you've already used it for rendering something. The documentation isn't really clear what the rules are for determining if it needs to do this or not, so it might just do it every time regardless.


Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
   
Old
  (#4)
warmi
Member
 
Posts: 147
Join Date: 2009.04
Location: USA
2009.11.25, 10:40 AM

Quote:
Originally Posted by Malarkey View Post
Okay, so I've done a few searches of the forum but can't quite seem to find the right answer for what I'm trying to do so please forgive me if this has been brought up before.

Anyway, I'm using the Texture2D class to convert raw pixel data into something I can show on the screen. However, this raw pixel data is constantly changing so in order to update the image on the screen, I'm continually releasing the old Texture2D object and creating a new one. This strikes me a terribly inefficient. So my question then is it possible to create a texture once and continually update it from this buffer of pixel data? Is this what FBOs and rendering to a texture are for?
Rendering to FBO will be much faster but it will only work for textures which are modified using OpenGL ES itself ..in other words you cannot use it to create textures out of some external binary data.

Also the biggest hit when uploading textures comes from the fact that the driver needs to "swizzle" whatever texture data you are submitting into its own internal format and , as far as I know, there is no way to avoid this step without Img Tech own custom extension, which is current not supported on the iphone ( the swizzling part happens not when you are creating the texture but when it is being accessed by the driver during rendering)
   
Old
  (#5)
Malarkey
Über Member
 
Posts: 370
Join Date: 2004.06
Location: Behind the Orange Curtain
2009.11.27, 09:33 PM

Thanks for the replies, everyone. I figured glTexSubImage2D would be the way that I want to go but I wanted to make sure that I wasn't overlooking some other technique that I could use.

Skorche: You mention not changing the texture in the middle of my rendering code. Can you elaborate on that? What exactly would be the middle of my rendering code? I have a function that gets called on a timer that makes some OpenGL calls (glClear, glMatrixMode, glLoadIdentity, etc.) before finally calling swapBuffers in the EAGLView. In the middle of that function, I'm making a call to glTexSubImage2D to update the texture. Is that a bad idea then?


The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
   
Old
  (#6)
arekkusu
Member
 
Posts: 1,334
Join Date: 2002.10
Location: Sunnyvale, CA
2009.11.27, 09:52 PM

If you use a texture, then modify it, then use it again before swapBuffers, the renderer will need to keep both copies. This can become quite expensive if you keep modifying the texture in a single frame.

See the description of Tile Based Deferred Rendering for an overview.
   
Old
  (#7)
Skorche
Member
 
Posts: 1,310
Join Date: 2002.09
Location: Minnesota
2009.11.28, 01:06 PM

Quote:
Originally Posted by arekkusu View Post
If you use a texture, then modify it, then use it again before swapBuffers, the renderer will need to keep both copies. This can become quite expensive if you keep modifying the texture in a single frame.
Ok, so it does track if it's been used or not and needs a second copy. Good to know. It was never quite clear on that. I remember reading the documentation and thinking the way it was worded left it open to be implemented to always make a copy of the texture.


Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
   
Old
  (#8)
Malarkey
Über Member
 
Posts: 370
Join Date: 2004.06
Location: Behind the Orange Curtain
2009.11.28, 12:23 PM

Ah, okay, got it. That's what I figured but I don't do much OpenGL programming. Again, thanks for the help everyone.


The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
   
Old
  (#9)
Malarkey
Über Member
 
Posts: 370
Join Date: 2004.06
Location: Behind the Orange Curtain
2009.12.11, 03:24 PM

Okay, so I tried using glTexSubImage2D and performance is just terrible on the device. I actually get a better framerate just submitting the whole power of 2 memory buffer again using glTexImage2D. Is glTexSubImage2D really that expensive or am I just doing something horribly wrong?


The brains and fingers behind Malarkey Software (plus caretaker of the world's two brattiest felines).
   
Old
  (#10)
warmi
Member
 
Posts: 147
Join Date: 2009.04
Location: USA
2009.12.12, 03:09 AM

Quote:
Originally Posted by Malarkey View Post
Okay, so I tried using glTexSubImage2D and performance is just terrible on the device. I actually get a better framerate just submitting the whole power of 2 memory buffer again using glTexImage2D. Is glTexSubImage2D really that expensive or am I just doing something horribly wrong?
What you need is an extension called GL_IMG_texture_stream but unfortunately, it is either not exposed or not implemented on the iPhone ( it is available on other devices ).

File a bug , maybe they will include it.
   
Old
  (#11)
arekkusu
Member
 
Posts: 1,334
Join Date: 2002.10
Location: Sunnyvale, CA
2009.12.11, 04:14 PM

It's expensive. There really isn't a high performance path for this on the iPhone.

You'll get the best upload performance with compressed PVRTC textures, since they have the smallest footprint.
   
Old
  (#12)
Frogblast
Member
 
Posts: 78
Join Date: 2006.08
Location: US
2009.12.12, 02:58 PM

In the short term, your best bet is to TexSubImage into the entire texture level, and to double or triple buffer the texture: ie, when you are done with an image, throw the texture into a queue, and only TexSubImage the whole level after 2 frames or so. This will ensure that the GPU is really done with any operations on that texture.

For the future, please do file bug reports, especially with sample code to demonstrate exactly the case you would like to be faster.
   
Old
  (#13)
godexsoft
Member
 
Posts: 80
Join Date: 2008.11
Location: St.Petersburg, Russia
2010.01.21, 05:32 AM

Hey,

For best performance I had to use FBO which is attached to a texture:

Code:
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, m_unName, 0);
What you will get is simply a framebuffer which you will use just as if it was your backbuffer but the rendered stuff will go into the tuxture attached to the FBO.
In my game I have a generic Quad class which uses this.. for example I generate a static label out of my bitmap fonts engine.

HTH,
Alex


TapMania - iPhone StepMania // Human knowledge belongs to the world!
   
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com
DevServe Network: iDevApps | uDevGames | iDevGames