Exemple #1
0
        // Replace the texture, which is 'not used by ATW', to new configured another texture.
        // Create full textures of a queue in once is very heavy loading.  Thus, we replace
        // the texture in a queue one by one.
        private void ReplaceCurrentWithNewTexture()
        {
            Profiler.BeginSample("NewTexture");

            // It will always get an error internally due to our EGL hacking.  Close the callstack dump for speed.
            var origin = Application.GetStackTraceLogType(LogType.Error);

            Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.None);

            // Remove old texture from lists.
            textures.Remove(currentPtr);
            depthes.Remove(currentPtr);
            cfgs.Remove(currentPtr);
            rts.Remove(currentRt);
            ReleaseTexture(currentRt);

            // Create new texture
            T   newRt;
            int newPtr, newDepthPtr;

            newRt = CreateTexture(cfg);
            rts.Add(newRt);

            newPtr      = GetNativePtr(newRt);
            newDepthPtr = GetNativeDepthBufferPtr(newRt);

            textures.Add(newPtr, newRt);
            depthes.Add(newPtr, newDepthPtr);
            cfgs.Add(newPtr, cfg);

            Log.i(TextureManager.TAG, Log.CSB
                  .Append("Rm  rt=").Append(currentPtr).Append(" dp=").Append(currentDepthPtr).Append(" ")
                  .Append("Gen rt=").Append(newPtr).Append(" dp=").Append(newDepthPtr)
                  .ToString());

            // Use "Error" to log OUR hint.  Make sure it be filter with other error logs. don't change it to W or I.
            // The libEGL and Unity error will show because WaveVR change the egl surface for necessary.  Every game using WaveVR Unity plugin will have these logs.
            Log.e(TextureManager.TAG, "If the libEGL and Unity errors appeared above, don't panic or report a bug.  They are safe and will not crash your game.");
            Application.SetStackTraceLogType(LogType.Error, origin);

            if (keyArray.Length != textures.Count)
            {
                keyArray = new Int32[textures.Count];
            }
            textures.Keys.CopyTo(keyArray, 0);

#if UNITY_EDITOR
            if (!Application.isEditor)
#endif
            // The WVR_ReplaceCurrentTextureID will replace the texture which is specified by WVR_GetAvailableTextureID.
            WaveVR_Utils.WVR_ReplaceCurrentTextureID(queue, new IntPtr(newPtr));

            // Assign new to curent
            currentRt       = newRt;
            currentPtr      = newPtr;
            currentDepthPtr = newDepthPtr;

            Profiler.EndSample();
        }