Example #1
0
        public Cubemap GetReflectionCubemap(IntPtr sessionHandle, IntPtr lightEstimateHandle)
        {
            // Cubemap.CreateExternalTexture only exists in Unity 2017 above.
#if UNITY_2017_2_OR_NEWER
            int           textureId  = 0;
            int           size       = 0;
            bool          usingGLES3 = SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3;
            TextureFormat format     = usingGLES3 ? TextureFormat.RGBAHalf : TextureFormat.RGBA32;

            if (!m_PluginInitialized)
            {
                ExternApi.ARCoreRenderingUtils_SetGLESContext(usingGLES3);
                m_PluginInitialized = true;
            }

            ExternApi.ARCoreRenderingUtils_GetCubemapTexture(ref textureId, ref size);
            if (textureId != 0)
            {
                if (m_HDRCubemap == null || textureId != m_CubemaptextureId)
                {
                    m_HDRCubemap = Cubemap.CreateExternalTexture(size, format, true,
                                                                 new IntPtr(textureId));
                }
            }

            long timestamp = GetTimestamp(sessionHandle, lightEstimateHandle);
            if (m_CubemapTimestamp != timestamp)
            {
                ExternApi.ARCoreRenderingUtils_SetARCoreLightEstimation(sessionHandle,
                                                                        lightEstimateHandle);
                m_CubemapTimestamp = timestamp;
            }

            // Issue plugin event to update cubemap texture.
            GL.IssuePluginEvent(ExternApi.ARCoreRenderingUtils_GetRenderEventFunc(), 1);

            return(m_HDRCubemap);
#else
            return(null);
#endif
        }