Forums - Shader multi-texturing producing garbage (unless calling glGenTextures each frame)

9 posts / 0 new
Last post
Shader multi-texturing producing garbage (unless calling glGenTextures each frame)
Gideon_P.
Join Date: 3 Apr 11
Posts: 5
Posted: Sun, 2012-01-22 06:22

Hi,

I'm trying to do video frames rendering on Android devices using native OpenGL ES 2.
Input video frames are in YUV format - so I'm creating a texture per component  (Y => TEXTURE0,  U => TEXTURE1, V => TEXTURE2)
U & V textures are quarter the size of the Y texture. (width/2, height/2)

I'm then using a fragment shader to convert Y,U,V texels into a single RGB color per texel.
This works ok for the first frame.

But when trying to update the texture pixels - only the Y texture is mapped correctly.
The U & V textures produce garbage
(It looks like Adreno thinks U, V textures are the same size as the Y texture, so it reads the texture with an incorrect stride)

I encountered this on HTC Incredible S, Desire S, Flyer, Nexus 1 (all running Gingerbread).
The same code works flawlessley on non-Adreno devices (PowerVR, Mali, Tegra) 

Is there a fix/workaround for this issue?

Thanks

 

 

  • Up0
  • Down0
Mark_Feldman Moderator
Join Date: 4 Jan 12
Posts: 58
Posted: Wed, 2012-02-22 16:30

Could you share your shader code and render-to-texture code?  There are several flavors of YUV formats - could you also share how the YUV frames are aquired?

thanks..

  • Up0
  • Down0
Gideon_P.
Join Date: 3 Apr 11
Posts: 5
Posted: Thu, 2012-02-23 01:04

Hi,

The YUV pixel buffer is in 420P format.
The first frame renders OK (this is right after generating/setting the textures) 
But in the following frames - only the Y texture is rendered correclty, the U & V textures are rendered with what seems like the wrong stride (this is after updating the textures with glTexSubImage2D)

Shader code: http://pastebin.com/ZSzU1KWh

Rendering code: http://pastebin.com/ZwiW3zKi

Thanks in advance.

 

 

  • Up0
  • Down0
Gideon_P.
Join Date: 3 Apr 11
Posts: 5
Posted: Sun, 2012-03-18 10:29

Hi, thanks for your reply.

Changing precision didn't solve the issue. 

Yes, the raw pixel buffer is in 420P format (http://en.wikipedia.org/wiki/File:Yuv420.svg)
If I call the "Setup Textures" code, each frame - the rendering is ok (but much slower, of course):

http://i39.tinypic.com/intqbr.png 

But if I just update the textures each frame - the Y channel looks ok, but U & V are messed up:

http://i43.tinypic.com/el1pfp.png

Any idea?

Thanks in advance.

 

  • Up0
  • Down0
Mark_Feldman Moderator
Join Date: 4 Jan 12
Posts: 58
Posted: Mon, 2012-03-19 15:29

Can you determine if you need to regenerate (glGenTextures) the textures every frame? Can the glGenTextures call be called once?

  • Up0
  • Down0
Gideon_P.
Join Date: 3 Apr 11
Posts: 5
Posted: Tue, 2012-03-20 01:05

That's the problem, if I do not call glGenTextures() - I get the garbled frame.
It only works correctly when regenerating the textures every frame.

  • Up0
  • Down0
Mark_Feldman Moderator
Join Date: 4 Jan 12
Posts: 58
Posted: Tue, 2012-03-20 07:37

You might want to verify that the same thread which creates the textures is also used when updating them.

 

Also you might want to investigate using Surface Textures for handling streaming textures, thought I'm not sure if your compression format is supported.

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

http://developer.android.com/reference/android/graphics/SurfaceTexture.html 

  • Up0
  • Down0
Gideon_P.
Join Date: 3 Apr 11
Posts: 5
Posted: Thu, 2012-03-22 08:07

Thanks.

I've verified that all the texture code runs on the same thread (GLThread managed by GLSurfaceView)
And I cannot use Surface Textures as they are not supported before API Level 11 (Honeycomb).

I noticed, though, that if I setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY) and sleep(100) between calls to requestRender() - Then it renderes correclty (???)

So it seems there may be some timing/synchronization issue? 

I was under the impression that - when onDrawFrame(GL10 gl) completes - I can call requestRender() again (like RENDERMODE_CONTINUOUSLY)?
Isn't rendering supposed to be synchronized on the GLThread? How doI know when it is "safe" to requestRender again? 

Thanks in advance

  • Up0
  • Down0
Mark_Feldman Moderator
Join Date: 4 Jan 12
Posts: 58
Posted: Wed, 2012-04-11 09:11

Take a look again at the description for requestRender()

http://developer.android.com/reference/android/opengl/GLSurfaceView.html...()

 

1) The mode must to be set to RENDERMODE_WHEN_DIRTY (not continuously)

2) Seems to be able to be called on any thread...

 

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.