Search Unity

Android OES Texture Support

Discussion in 'General Graphics' started by AndrewRH, Oct 18, 2016.

  1. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Hi,

    Recently for Android I've had to use the GLSL feature of shaderlab. While I'm very grateful that this feature exists, it does seem to be quite neglected...

    The reason I have to use GLSL is because we make video plugins for Unity (AVPro Video) and on Android we require a special type of sampler which doesn't work with CG/HLSL:
    uniform samplerExternalOES _MainTex;

    Previously we would blit this special "OES" native texture to a standard GL_TEXTURE_2D, but for 4K playback this extra overhead can be the difference between the device overheating or not..

    I pass these textures back to Unity (via Texture2D.CreateExternalTexture()), but since it doesn't know about them we have to do all rendering through a GLSL shader that has this sampler set up This works great, but there are a few issues that I've encountered with this workflow:

    1) BUG - If I have 2 meshes, each using a different material with a different OES video texture bound, both meshes will either get just one of the texture applied, or they will flicker. Seems like Unity isn't able to keep track of material states correctly when using these textures with GLSL shaders?

    2) Unity 5.4.1 and 5.4.2 has started to log an error in the Android console when I call CreateExternalTexture() using this texture:
    Unity : OPENGL NATIVE PLUG-IN ERROR: GL_INVALID_OPERATION: Operation illegal in current state. Something must have changed here, such as it's trying to set a texture property state, but I think these OES texture don't allow changing of wrap/filter mode, so this could be the cause of the error. Either way it shows that Unity isn't testing for these special texture types and handles them correctly recently which is a bit worrying for me if I intend to use this feature in the future.

    3) The GLSL shader that we write in Unity doesn't get compiled in the Editor, so finding bugs in it is very tough. We have deploy to Android and watch the console to see if the shader errors or not. This is painful, but even worse usually the error reporting is basically zero in Android so it's just trial and error to fix. The shader compiler is also very sensitive and even sometimes having comments in the wrong places can break it. Even differences compared to the normal shaderlab shaders, such as I can use #if MYFEATURE works fine, but in GLSL that breaks the build and I instead have to use #if defined(MYFEATURE).
    It would be great if Unity could compile GLSL shaders in the Editor, or even better, if we could add GLSL snippets into existing CG/HLSL shaders so that these custom GLES specific lines can be added.

    For Android this OES texture feature is very very useful for video playback. I'm not sure if anyone else is really using it much, so I want to make sure that this is a feature Unity is aware of and doesn't forget about :)

    Thanks for listening :)
     
  2. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Did you make java plugin? Using GLSurfaceView.Renderer to try?
     
  3. AndrewRH

    AndrewRH

    Joined:
    Jan 24, 2012
    Posts:
    2,806
    Yes the plugin is a mixture of Java and C++. We're using the SurfaceTexture class.
     
  4. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
  5. PeterGeneral

    PeterGeneral

    Joined:
    Jun 5, 2015
    Posts:
    14