Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tweaking behavior of "Automatic" graphics api selection in unity 4.6.3 and upcoming 5.0

Discussion in 'iOS and tvOS' started by Alexey, Feb 20, 2015.

  1. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,623
    with addition of metal we now have separate graphics api selector on ios.
    you can both enforce some api, or pick Automatic that tries in that order: metal->gles3->gles2.
    Now, sometimes you need more control, so i will explain how to tweak the fallback order to better suit your needs.
    NB: this involves trampoline code tweaking. We are still thinking about how to do it on editor side, but no promises.
    1. open Classes/UnityAppController+Rendering.mm
    2. search for function static int SelectRenderingAPIImpl()
    in there you will see
    Code (csharp):
    1.  
    2. const bool       iosSupport[]     = {canSupportMetal, _ios70orNewer, true};
    3.  
    this array of bools is THE place that directs the fallback order:
    Code (csharp):
    1.  
    2. for(int i = 0 ; i < 3 && !api ; ++i)
    3. {
    4.    if(iosSupport && UnityIsRenderingAPISupported(unityApiEnum) && checkSupport(checkSupportArg))
    5.      api = unityApiEnum;
    6. }
    7.  
    so what you need is: for things you want to be NOT considered in fallbacks just change bool value to false.
    the order is like this:
    iosSupport[0] = if we should try metal
    iosSupport[1] = if we should try gles3
    iosSupport[2] = if we should try gles2
    so if you want Automatic selection of gles3/gles2 (without metal)
    change
    Code (csharp):
    1.  
    2. const bool       iosSupport[]     = {canSupportMetal, _ios70orNewer, true};
    3.  
    to
    Code (csharp):
    1.  
    2. const bool       iosSupport[]     = {false, _ios70orNewer, true};
    3.  
    NB1: this will tweak ONLY automatic selection: if you pick explicit graphics api in editor it will be handled in UnityIsRenderingAPISupported function, which will return true only for selected api
    NB2: in the example above compiler warning will be generated about canSupportMetal var not used. You can ignore it, or if you feel comfortable with objc, you can just check code of the function and remove var itself
     
    Last edited: Mar 5, 2015
  2. Twistplay

    Twistplay

    Joined:
    Dec 6, 2012
    Posts:
    36
    Thanks for this very useful tip! - I would definitely vote for "Automatic - OpenGLES only" in the editor's drop down list though.
     
  3. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Yes until its confirmed Metal is stable and working correctly.
     
  4. xuanyusong

    xuanyusong

    Joined:
    Apr 10, 2013
    Posts:
    49
    android http://developer.android.com/guide/topics/graphics/opengl.html#manifest

    Code (CSharp):
    1. private static double glVersion = 3.0;
    2.  
    3. private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
    4.  
    5.   private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    6.  
    7.   public EGLContext createContext(
    8.           EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
    9.  
    10.       Log.w(TAG, "creating OpenGL ES " + glVersion + " context");
    11.       int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, (int) glVersion,
    12.               EGL10.EGL_NONE };
    13.       // attempt to create a OpenGL ES 3.0 context
    14.       EGLContext context = egl.eglCreateContext(
    15.               display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
    16.       return context; // returns null if 3.0 is not supported;
    17.   }
    18. }