Beispiel #1
0
    private bool CreateLayerTextures(bool useMipmaps, OVRPlugin.Sizei size, bool isHdr)
    {
        if (isExternalSurface)
        {
            if (externalSurfaceObject == System.IntPtr.Zero)
            {
                externalSurfaceObject = OVRPlugin.GetLayerAndroidSurfaceObject(layerId);
                if (externalSurfaceObject != System.IntPtr.Zero)
                {
                    Debug.LogFormat("GetLayerAndroidSurfaceObject returns {0}", externalSurfaceObject);
                    if (externalSurfaceObjectCreated != null)
                    {
                        externalSurfaceObjectCreated();
                    }
                }
            }
            return(false);
        }

        bool needsCopy = false;

        if (stageCount <= 0)
        {
            return(false);
        }

        // For newer SDKs, blit directly to the surface that will be used in compositing.

        if (layerTextures == null)
        {
            layerTextures = new LayerTexture[texturesPerStage];
        }

        for (int eyeId = 0; eyeId < texturesPerStage; ++eyeId)
        {
            if (layerTextures[eyeId].swapChain == null)
            {
                layerTextures[eyeId].swapChain = new Texture[stageCount];
            }

            if (layerTextures[eyeId].swapChainPtr == null)
            {
                layerTextures[eyeId].swapChainPtr = new IntPtr[stageCount];
            }

            for (int stage = 0; stage < stageCount; ++stage)
            {
                Texture sc    = layerTextures[eyeId].swapChain[stage];
                IntPtr  scPtr = layerTextures[eyeId].swapChainPtr[stage];

                if (sc != null && scPtr != IntPtr.Zero && size.w == sc.width && size.h == sc.height)
                {
                    continue;
                }

                if (scPtr == IntPtr.Zero)
                {
                    scPtr = OVRPlugin.GetLayerTexture(layerId, stage, (OVRPlugin.Eye)eyeId);
                }

                if (scPtr == IntPtr.Zero)
                {
                    continue;
                }

                var txFormat = (isHdr) ? TextureFormat.RGBAHalf : TextureFormat.RGBA32;

                if (currentOverlayShape != OverlayShape.Cubemap && currentOverlayShape != OverlayShape.OffcenterCubemap)
                {
                    sc = Texture2D.CreateExternalTexture(size.w, size.h, txFormat, useMipmaps, true, scPtr);
                }
#if UNITY_2017_1_OR_NEWER
                else
                {
                    sc = Cubemap.CreateExternalTexture(size.w, txFormat, useMipmaps, scPtr);
                }
#endif

                layerTextures[eyeId].swapChain[stage]    = sc;
                layerTextures[eyeId].swapChainPtr[stage] = scPtr;

                needsCopy = true;
            }
        }

        return(needsCopy);
    }