Пример #1
0
        public TexturePool(TextureConfig cfg, int size, bool isLeft)
        {
            isReleased = false;

            // Editor doesn't need the texture queue.
            if (Application.isEditor)
            {
                size = 1;
            }

            this.isLeft = isLeft;
            this.size   = size;
            for (int i = 0; i < size; i++)
            {
                currentRt              = new RenderTexture(cfg.w, cfg.h, cfg.depth, cfg.format, RenderTextureReadWrite.Default);
                currentRt.useMipMap    = cfg.useMipMap;
                currentRt.wrapMode     = cfg.wrapMode;
                currentRt.filterMode   = cfg.filterMode;
                currentRt.anisoLevel   = cfg.anisoLevel;
                currentRt.antiAliasing = cfg.antiAliasing;
                currentRt.Create();
                currentPtr = currentRt.GetNativeTexturePtr();

                textures.Add(currentPtr, currentRt);
            }
#if UNITY_EDITOR
            if (Application.isEditor)
            {
                return;
            }
#endif
            var array = new IntPtr[textures.Count];
            textures.Keys.CopyTo(array, 0);
            queue = WaveVR_Utils.WVR_StoreRenderTextures(array, size, isLeft);
        }
        public TexturePool(TextureConfig cfg, int size, WVR_Eye eye) : base(eye)
        {
            using (var ee = Log.ee("WVR_TexMngr", "TexturePool+", "TexturePool-"))
            {
                isReleased = false;

#if UNITY_EDITOR
                // Editor doesn't need the texture queue.
                size = 1;
#endif

                this.isLeft = isLeft;
                this.size   = size;
                for (int i = 0; i < size; i++)
                {
                    currentRt       = CreateTexture(cfg);
                    currentPtr      = GetNativePtr(currentRt);
                    currentDepthPtr = GetNativeDepthBufferPtr(currentRt);

                    textures.Add(currentPtr, currentRt);
                    depthes.Add(currentPtr, currentDepthPtr);

                    Log.d("WVR_TexMngr", "Gen rt" + currentPtr + " dp" + currentDepthPtr);
                }
                keyArray = new IntPtr[textures.Count];
                textures.Keys.CopyTo(keyArray, 0);

#if UNITY_EDITOR
                if (!Application.isEditor)
#endif
                queue = WaveVR_Utils.WVR_StoreRenderTextures(keyArray, size, isBoth || isLeft);
            }
        }
Пример #3
0
        public TexturePool(TextureConfig cfg, int size, WVR_Eye eye) : base(eye)
        {
#if !UNITY_STANDALONE
            this.cfg = cfg;
            using (var ee = Log.ee(TextureManager.TAG, "TexturePool+", "TexturePool-"))
            {
                isReleased = false;

#if UNITY_EDITOR
                // Editor doesn't need the texture queue.
                size = 1;
#endif

                this.isLeft = isLeft;
                this.size   = size;

                // 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);

                for (int i = 0; i < size; i++)
                {
                    rts.Add(CreateTexture(cfg));
                }

                // Call GetNativePtr once after all texture are created.  Try not to block render thread too long.
                for (int i = 0; i < size; i++)
                {
                    T rt = rts[i];
                    currentPtr      = GetNativePtr(rt);
                    currentDepthPtr = GetNativeDepthBufferPtr(rt);

                    textures.Add(currentPtr, rt);
                    depthes.Add(currentPtr, currentDepthPtr);
                    cfgs.Add(currentPtr, cfg);

                    Log.i(TextureManager.TAG, "Gen rt" + currentPtr + " dp" + currentDepthPtr);
                }

                Log.e(TextureManager.TAG, "Don't worry about the libEGL and Unity error showing above.  They are safe and will not crash your game.");
                Application.SetStackTraceLogType(LogType.Error, origin);

                keyArray = new Int32[textures.Count];
                textures.Keys.CopyTo(keyArray, 0);

#if UNITY_EDITOR && UNITY_ANDROID
                if (!Application.isEditor)
#endif
                if (eye == WVR_Eye.WVR_Eye_Both)
                {
                    queue = WaveVR_Utils.WVR_StoreRenderTextures(keyArray, size, isBoth || isLeft, WVR_TextureTarget.WVR_TextureTarget_2D_ARRAY);
                }
                else
                {
                    queue = WaveVR_Utils.WVR_StoreRenderTextures(keyArray, size, isBoth || isLeft, WVR_TextureTarget.WVR_TextureTarget_2D);
                }
            }
#endif
        }
        // 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 of a queue one by one.
        private void ReplaceCurrentWithNewTexture()
        {
            Profiler.BeginSample("NewTexture");

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

#if UNITY_EDITOR
            if (!Application.isEditor)
#endif
            if (queue != IntPtr.Zero)
            {
                Interop.WVR_ReleaseTextureQueue(queue);
            }

            // Create new texture
            T      newRt;
            int    newPtr, newDepthPtr;
            IntPtr newQueue = IntPtr.Zero;
            {
                // 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);

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

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

                // 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);

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

                Log.i(TextureManager.TAG, Log.CSB.Append("Gen rt").Append(newPtr).Append(" dp").Append(newDepthPtr).ToString());
            }

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

#if UNITY_EDITOR
            if (!Application.isEditor)
#endif
            newQueue = WaveVR_Utils.WVR_StoreRenderTextures(keyArray, size, isBoth || isLeft, isBoth ? WVR_TextureTarget.WVR_TextureTarget_2D_ARRAY : WVR_TextureTarget.WVR_TextureTarget_2D);

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

            Profiler.EndSample();
        }