in Networked Physics/Assets/Oculus/VR/Scripts/OVROverlay.cs [416:498]
private bool PopulateLayer(int mipLevels, bool isHdr, OVRPlugin.Sizei size, int sampleCount, int stage)
{
bool ret = false;
RenderTextureFormat rtFormat = (isHdr) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
for (int eyeId = 0; eyeId < texturesPerStage; ++eyeId)
{
Texture et = layerTextures[eyeId].swapChain[stage];
if (et == null)
continue;
for (int mip = 0; mip < mipLevels; ++mip)
{
int width = size.w >> mip;
if (width < 1) width = 1;
int height = size.h >> mip;
if (height < 1) height = 1;
#if UNITY_2017_1_1 || UNITY_2017_2_OR_NEWER
RenderTextureDescriptor descriptor = new RenderTextureDescriptor(width, height, rtFormat, 0);
descriptor.msaaSamples = sampleCount;
descriptor.useMipMap = true;
descriptor.autoGenerateMips = false;
descriptor.sRGB = false;
var tempRTDst = RenderTexture.GetTemporary(descriptor);
#else
var tempRTDst = RenderTexture.GetTemporary(width, height, 0, rtFormat, RenderTextureReadWrite.Linear, sampleCount);
#endif
if (!tempRTDst.IsCreated())
tempRTDst.Create();
tempRTDst.DiscardContents();
bool dataIsLinear = isHdr || (QualitySettings.activeColorSpace == ColorSpace.Linear);
#if !UNITY_2017_1_OR_NEWER
var rt = textures[eyeId] as RenderTexture;
dataIsLinear |= rt != null && rt.sRGB; //HACK: Unity 5.6 and earlier convert to linear on read from sRGB RenderTexture.
#endif
#if UNITY_ANDROID && !UNITY_EDITOR
dataIsLinear = true; //HACK: Graphics.CopyTexture causes linear->srgb conversion on target write with D3D but not GLES.
#endif
if (currentOverlayShape != OverlayShape.Cubemap && currentOverlayShape != OverlayShape.OffcenterCubemap)
{
tex2DMaterial.SetInt("_linearToSrgb", (!isHdr && dataIsLinear) ? 1 : 0);
//Resolve, decompress, swizzle, etc not handled by simple CopyTexture.
#if !UNITY_ANDROID || UNITY_EDITOR
// The PC compositor uses premultiplied alpha, so multiply it here.
tex2DMaterial.SetInt("_premultiply", 1);
#endif
Graphics.Blit(textures[eyeId], tempRTDst, tex2DMaterial);
Graphics.CopyTexture(tempRTDst, 0, 0, et, 0, mip);
}
#if UNITY_2017_1_OR_NEWER
else // Cubemap
{
for (int face = 0; face < 6; ++face)
{
cubeMaterial.SetInt("_linearToSrgb", (!isHdr && dataIsLinear) ? 1 : 0);
#if !UNITY_ANDROID || UNITY_EDITOR
// The PC compositor uses premultiplied alpha, so multiply it here.
cubeMaterial.SetInt("_premultiply", 1);
#endif
cubeMaterial.SetInt("_face", face);
//Resolve, decompress, swizzle, etc not handled by simple CopyTexture.
Graphics.Blit(textures[eyeId], tempRTDst, cubeMaterial);
Graphics.CopyTexture(tempRTDst, 0, 0, et, face, mip);
}
}
#endif
RenderTexture.ReleaseTemporary(tempRTDst);
ret = true;
}
}
return ret;
}