|
|
|
|
|
|
using UnityEngine; |
|
|
|
using System.Collections.Generic; |
|
|
|
#if UNITY_EDITOR
|
|
|
|
using UnityEditor; |
|
|
|
#endif
|
|
|
|
|
|
|
|
public class TextureCache2D : TextureCache |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
private CubemapArray m_Cache; |
|
|
|
|
|
|
|
// alternative panorama path intended for mobile
|
|
|
|
// the member variables below are only in use when m_IsNoCubeArray is true.
|
|
|
|
private bool m_IsNoCubeArray = false; |
|
|
|
// the member variables below are only in use when TextureCache.supportsCubemapArrayTextures is false
|
|
|
|
private Texture2DArray m_CacheNoCubeArray; |
|
|
|
private RenderTexture[] m_StagingRTs; |
|
|
|
private int m_NumPanoMipLevels; |
|
|
|
|
|
|
// alternative panorama path intended for mobile
|
|
|
|
// the member variables below are only in use when m_IsNoCubeArray is true.
|
|
|
|
|
|
|
|
if(m_IsNoCubeArray) |
|
|
|
if(!TextureCache.supportsCubemapArrayTextures) |
|
|
|
TransferToPanoCache(sliceIndex, texture); |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
public override Texture GetTexCache() |
|
|
|
{ |
|
|
|
return m_IsNoCubeArray ? (Texture) m_CacheNoCubeArray : m_Cache; |
|
|
|
return !TextureCache.supportsCubemapArrayTextures ? (Texture) m_CacheNoCubeArray : m_Cache; |
|
|
|
} |
|
|
|
|
|
|
|
public bool AllocTextureArray(int numCubeMaps, int width, TextureFormat format, bool isMipMapped) |
|
|
|
|
|
|
|
|
|
|
if(m_IsNoCubeArray) |
|
|
|
if(!TextureCache.supportsCubemapArrayTextures) |
|
|
|
{ |
|
|
|
if(!m_CubeBlitMaterial) m_CubeBlitMaterial = new Material(Shader.Find("Hidden/CubeToPano")); |
|
|
|
|
|
|
|
|
|
|
// create panorama 2D array. Hardcoding the render target for now when m_IsNoCubeArray is true. No convenient way atm. to
|
|
|
|
// create panorama 2D array. Hardcoding the render target for now. No convenient way atm to
|
|
|
|
// map from TextureFormat to RenderTextureFormat and don't want to deal with sRGB issues for now.
|
|
|
|
m_CacheNoCubeArray = new Texture2DArray(panoWidthTop, panoHeightTop, numCubeMaps, TextureFormat.RGBAHalf, isMipMapped) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
public void Release() |
|
|
|
{ |
|
|
|
if(m_IsNoCubeArray) |
|
|
|
if (m_CacheNoCubeArray) |
|
|
|
{ |
|
|
|
Texture.DestroyImmediate(m_CacheNoCubeArray); |
|
|
|
for(int m=0; m<m_NumPanoMipLevels; m++) |
|
|
|
|
|
|
m_StagingRTs=null; |
|
|
|
if(m_CubeBlitMaterial) Material.DestroyImmediate(m_CubeBlitMaterial); |
|
|
|
} |
|
|
|
else Texture.DestroyImmediate(m_Cache); |
|
|
|
if (m_Cache) |
|
|
|
Texture.DestroyImmediate(m_Cache); |
|
|
|
} |
|
|
|
|
|
|
|
private void TransferToPanoCache(int sliceIndex, Texture texture) |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
public static bool isMobileBuildTarget |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
#if UNITY_EDITOR
|
|
|
|
switch (EditorUserBuildSettings.activeBuildTarget) |
|
|
|
{ |
|
|
|
case BuildTarget.iOS: |
|
|
|
case BuildTarget.Android: |
|
|
|
case BuildTarget.Tizen: |
|
|
|
case BuildTarget.WSAPlayer: |
|
|
|
// Note: We return true on purpose even if Windows Store Apps are running on Desktop.
|
|
|
|
return true; |
|
|
|
default: |
|
|
|
return false; |
|
|
|
} |
|
|
|
#else
|
|
|
|
return Application.isMobilePlatform; |
|
|
|
#endif
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static TextureFormat GetPreferredCompressedTextureFormat |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
var format = TextureFormat.RGBAHalf; |
|
|
|
|
|
|
|
var probeFormat = TextureFormat.BC6H; |
|
|
|
|
|
|
|
// On editor the texture is uncompressed when operating against mobile build targets
|
|
|
|
if (SystemInfo.SupportsTextureFormat(probeFormat) && !TextureCache.isMobileBuildTarget) |
|
|
|
format = probeFormat; |
|
|
|
|
|
|
|
return format; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static bool supportsCubemapArrayTextures |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return (SystemInfo.supportsCubemapArrayTextures && !TextureCache.isMobileBuildTarget); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private struct SSliceEntry |
|
|
|
{ |
|
|
|