mobfishgmbh / Cardboard-VR-Unity-SDK

Apache License 2.0
56 stars 11 forks source link

ArgumentException when constructing RenderTexture #47

Closed daltonbr closed 4 years ago

daltonbr commented 4 years ago

It's happening in the Editor for Unity 2019.3.15f1 (on Windows / DX11 and OSX / Metal)

Got this Argument Exception in CardboardMainCamera.cs when trying to construct that RenderTexture.

ArgumentException: RenderTextureDesc graphicsFormat must be a supported GraphicsFormat. None is not supported.
Parameter name: desc.graphicsFormat
UnityEngine.RenderTexture.ValidateRenderTextureDesc (UnityEngine.RenderTextureDescriptor desc) (at <e98ed0368295432e8c11e52d6243ee11>:0)
UnityEngine.RenderTexture..ctor (UnityEngine.RenderTextureDescriptor desc) (at <e98ed0368295432e8c11e52d6243ee11>:0)
MobfishCardboard.CardboardMainCamera.SetupRenderTexture () (at Assets/3rdParty/Cardboard/Scripts/Behaviours/CardboardMainCamera.cs:89)

I see that the graphicsFormat is set to None by default, maybe that wasn't a problem in 2018.4. I've tried to set a few other formats in there, but couldn't get it to work.

Thanks for this great initiative!

daltonbr commented 4 years ago

Just got it to work with GraphicsFormat.R8G8B8A8_SRGB Don't know if it's the ideal one, although not crashing anymore.

            eyeRenderTextureDesc = new RenderTextureDescriptor()
            {
                dimension = TextureDimension.Tex2D,
                width = Screen.width / 2,
                height = Screen.height,
                depthBufferBits = 16,
                volumeDepth = 1,
                msaaSamples = 1,
                vrUsage = VRTextureUsage.OneEye,
                graphicsFormat = GraphicsFormat.R8G8B8A8_SRGB
            };

I looped over all supported textures for RenderTextures

        private void TestGraphicsFormat()
        {
            foreach (GraphicsFormat format in (GraphicsFormat[]) Enum.GetValues(typeof(GraphicsFormat)))
            {
                Debug.Log($"[Test Format] {format:G}: {SystemInfo.IsFormatSupported(format, FormatUsage.Render)}");
            }
        }
cai-mobfish commented 4 years ago

In Unity 2018.4, RenderTextureDescriptor doesn't have this property graphicsFormat, however, RenderTexture has a constructor overload with a graphic format parameter.

And in both Unity 2018 and Unity 2019, GraphicsFormat is under experimental namespace.

So there are 2 approches to fix it:

Also, SystemInfo.GetCompatibleFormat is only available in unity 2019.

daltonbr commented 4 years ago

Thanks for the detailed info. I will just add preprocessor directives then!

cai-mobfish commented 4 years ago

Reopen this ticket, i'm going to do it on my side, it would be an issue when using unity 2019.