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); } }
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 }
public void reset() { using (var ee = Log.ee(TAG, "reset")) { #if UNITY_EDITOR poolSize = 3; if (!Application.isEditor) #endif { poolSize = WaveVR_Utils.WVR_GetNumberOfTextures(); } int size = Mathf.Max(Screen.width / 2, Screen.height); uint w = (uint)size; uint h = (uint)size; Interop.WVR_GetRenderTargetSize(ref w, ref h); screenWidth = (int)w; screenHeight = (int)h; float previewRatio = GetPreviewImageRatio(); int scaledWidth = ToMultipleOfTwo((int)(screenWidth * FinalScale * previewRatio)); int scaledHeight = ToMultipleOfTwo((int)(screenHeight * FinalScale * previewRatio)); int antiAliasing = AllowAntiAliasing ? QualitySettings.antiAliasing : 0; if (antiAliasing == 0) { antiAliasing = 1; } Log.d(TAG, "Texture width=" + scaledWidth + " height=" + scaledHeight + " antiAliasing=" + antiAliasing); var cfg = new TextureConfig(); cfg.w = scaledWidth; cfg.h = scaledHeight; cfg.depth = 24; // Only 24 has StencilBuffer. See Unity document. Only 24 can let VR work normally. cfg.format = RenderTextureFormat.ARGB32; cfg.useMipMap = false; cfg.wrapMode = TextureWrapMode.Clamp; cfg.filterMode = FilterMode.Bilinear; cfg.anisoLevel = 1; cfg.antiAliasing = antiAliasing; if (validate()) { ReleaseTexturePools(); } if (IsSinglePass) { both = new TexturePoolRenderTexture2DArray(cfg, poolSize); } else { left = new TexturePoolRenderTexture(cfg, poolSize, WVR_Eye.WVR_Eye_Left); right = new TexturePoolRenderTexture(cfg, poolSize, WVR_Eye.WVR_Eye_Right); } } // reset log.ee }
public void reset() { using (var ee = Log.ee("WVR_TexMngr", "reset")) { #if UNITY_EDITOR poolSize = 3; if (!Application.isEditor) #endif { poolSize = WaveVR_Utils.WVR_GetNumberOfTextures(); } int size = Mathf.Max(Screen.width / 2, Screen.height); uint w = (uint)size; uint h = (uint)size; if (!Application.isEditor) { Interop.WVR_GetRenderTargetSize(ref w, ref h); } int screenWidth = (int)(w); int screenHeight = (int)(h); int antiAliasing = AllowAntiAliasing ? QualitySettings.antiAliasing : 0; if (antiAliasing == 0) { antiAliasing = 1; } Log.d("WVR_TexMngr", "TextureManager: screenWidth=" + screenWidth + " screenHeight=" + screenHeight + " antiAliasing=" + antiAliasing); var cfg = new TextureConfig(); cfg.w = screenWidth; cfg.h = screenHeight; cfg.depth = 24; cfg.format = RenderTextureFormat.ARGB32; cfg.useMipMap = false; cfg.wrapMode = TextureWrapMode.Clamp; cfg.filterMode = FilterMode.Bilinear; cfg.anisoLevel = 1; cfg.antiAliasing = antiAliasing; if (validate()) { ReleaseTexturePools(); } if (IsSinglePass) { both = new TexturePoolRenderTexture2DArray(cfg, poolSize); } else { left = new TexturePoolRenderTexture(cfg, poolSize, WVR_Eye.WVR_Eye_Left); right = new TexturePoolRenderTexture(cfg, poolSize, WVR_Eye.WVR_Eye_Right); } } // reset log.ee }
protected override Texture2DArray CreateTexture(TextureConfig cfg) { var rt = new Texture2DArray(cfg.w, cfg.h, 2, TextureFormat.ARGB32, cfg.useMipMap, false) { wrapMode = cfg.wrapMode, anisoLevel = cfg.anisoLevel, }; return(rt); }
protected override RenderTexture CreateTexture(TextureConfig cfg) { var rt = new RenderTexture(cfg.w, cfg.h, cfg.depth, cfg.format, RenderTextureReadWrite.Default) { useMipMap = cfg.useMipMap, wrapMode = cfg.wrapMode, filterMode = cfg.filterMode, anisoLevel = cfg.anisoLevel, antiAliasing = cfg.antiAliasing, }; rt.Create(); return(rt); }
protected override RenderTexture CreateTexture(TextureConfig cfg) { var rt = new RenderTexture(cfg.w, cfg.h, cfg.depth, cfg.format, RenderTextureReadWrite.Default) { useMipMap = cfg.useMipMap, wrapMode = cfg.wrapMode, filterMode = cfg.filterMode, anisoLevel = cfg.anisoLevel, antiAliasing = cfg.antiAliasing, dimension = TextureDimension.Tex2DArray, volumeDepth = 2, vrUsage = VRTextureUsage.TwoEyes, }; rt.Create(); return(rt); }
public void Resize(float resolutionScale = 1.0f) { resolutionScale = Mathf.Clamp(resolutionScale, 0.1f, 1.0f); // Too similar change will be skipped. But always can reset to 1.0f. if (resolutionScale < 1.0f && Mathf.Abs(this.resolutionScale - resolutionScale) < 0.0001f) { Log.d(TAG, "Skip similar resize change."); return; } this.resolutionScale = resolutionScale; float previewRatio = GetPreviewImageRatio(); int scaledWidth = ToMultipleOfTwo((int)(screenWidth * FinalScale * previewRatio)); int scaledHeight = ToMultipleOfTwo((int)(screenHeight * FinalScale * previewRatio)); Log.d(TAG, Log.CSB.Append("Resized texture width=").Append(scaledWidth).Append(", height=").Append(scaledHeight).ToString()); if (IsSinglePass) { TextureConfig cfg = both.Config; cfg.w = scaledWidth; cfg.h = scaledHeight; both.Config = cfg; } else { TextureConfig cfg = left.Config; cfg.w = scaledWidth; cfg.h = scaledHeight; left.Config = cfg; cfg = right.Config; cfg.w = scaledWidth; cfg.h = scaledHeight; right.Config = cfg; } }
protected abstract T CreateTexture(TextureConfig cfg);
public TexturePoolRenderTexture(TextureConfig cfg, int size, WVR_Eye eye) : base(cfg, size, eye) { }
public TexturePoolRenderTexture2DArray(TextureConfig cfg, int size) : base(cfg, size, WVR_Eye.WVR_Eye_Both) { }