![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
(#1)
|
|
|
Ü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? |
|
|
|
|
(#2)
|
|
|
Moderator
Posts: 3,541
Join Date: 2003.06
Location: usa
|
2009.11.25, 08:46 AM
Did you try glTexSubImage2D?
|
|
|
|
|
(#3)
|
|
|
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.
Author of Chipmunk Physics - A fast and simple rigid body physics library in C. |
|
|
|
|
(#4)
|
||
|
Member
Posts: 147
Join Date: 2009.04
Location: USA
|
2009.11.25, 10:40 AM
Quote:
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) |
|
|
|
|
|
(#5)
|
|
|
Ü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? |
|
|
|
|
(#6)
|
|
|
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. |
|
|
|
|
(#7)
|
|
|
Member
Posts: 1,310
Join Date: 2002.09
Location: Minnesota
|
2009.11.28, 01:06 PM
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.
Author of Chipmunk Physics - A fast and simple rigid body physics library in C. |
|
|
|
|
(#8)
|
|
|
Ü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.
|
|
|
|
|
(#9)
|
|
|
Ü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?
|
|
|
|
|
(#10)
|
||
|
Member
Posts: 147
Join Date: 2009.04
Location: USA
|
2009.12.12, 03:09 AM
Quote:
File a bug , maybe they will include it. |
|
|
|
|
|
(#11)
|
|
|
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. |
|
|
|
|
(#12)
|
|
|
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. |
|
|
|
|
(#13)
|
|
|
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); 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 |
|
|
|
| Thread Tools | |
| Display Modes | |
|
|