Ejemplo n.º 1
0
        private static void ParseUndistortedPtrData()
        {
            Marshal.Copy(DataInfoUndistorted[(int)SeeThroughDataMask.FRAME_SEQ].ptr, RawUndistortedFrameIndex, 0, RawUndistortedFrameIndex.Length);
            Marshal.Copy(DataInfoUndistorted[(int)SeeThroughDataMask.TIME_STP].ptr, RawUndistortedTimeIndex, 0, RawUndistortedTimeIndex.Length);
            Marshal.Copy(DataInfoUndistorted[(int)SeeThroughDataMask.POSE_LEFT].ptr, RawUndistortedPoseLeft, 0, RawUndistortedPoseLeft.Length);
            Marshal.Copy(DataInfoUndistorted[(int)SeeThroughDataMask.POSE_RIGHT].ptr, RawUndistortedPoseRight, 0, RawUndistortedPoseRight.Length);

            for (int i = 0; i < 4; i++)
            {
                UndistortedPoseLeft.SetColumn(i, new Vector4(RawUndistortedPoseLeft[i * 4 + 0], RawUndistortedPoseLeft[i * 4 + 1],
                                                             RawUndistortedPoseLeft[i * 4 + 2], RawUndistortedPoseLeft[i * 4 + 3]));
                UndistortedPoseRight.SetColumn(i, new Vector4(RawUndistortedPoseRight[i * 4 + 0], RawUndistortedPoseRight[i * 4 + 1],
                                                              RawUndistortedPoseRight[i * 4 + 2], RawUndistortedPoseRight[i * 4 + 3]));
            }
        }
Ejemplo n.º 2
0
        private static void ParseUndistortedPtrData()
        {
            // Parse the textures.
            // Prepare to receive GPU shared textures.
            // Get data according to whether the non-4k or the 4k see through is in use.
            uint receivedBufferIndex;

            System.IntPtr receivedPointerToSharedHandleLeft;
            System.IntPtr receivedPointerToSharedHandleRight;
            GetFrameGpuTextureRelatedData(SeeThrough.SRWork_SeeThrough.b4KImageReady, out receivedBufferIndex,
                                          out receivedPointerToSharedHandleLeft, out receivedPointerToSharedHandleRight);

            if (SRWorkModule_API.SetShareHandle(receivedPointerToSharedHandleLeft, receivedPointerToSharedHandleRight, receivedBufferIndex,
                                                SeeThrough.SRWork_SeeThrough.b4KImageReady) && !SetTextureFromHandleReady)
            {
                //Use render event to create D3D11ShaderResourceView 0:Non4K 1:4K
                GL.IssuePluginEvent(SRWorkModule_API.GetRenderEventFunc(), SeeThrough.SRWork_SeeThrough.b4KImageReady ? 1 : 0);

                IntPtr ShaderResourceViewLeft  = IntPtr.Zero;
                IntPtr ShaderResourceViewRight = IntPtr.Zero;
                bool   SetTexture = true;

                for (int i = 0; i < RingBufferSize; i++)
                {
                    SetTexture &= SRWorkModule_API.GetShaderResourceView(i, SeeThrough.SRWork_SeeThrough.b4KImageReady, ref ShaderResourceViewLeft, ref ShaderResourceViewRight);

                    if (!SetTexture)
                    {
                        break;
                    }

                    if (UndistortedTextureDataBuffer[i].Initialized)
                    {
                        continue;
                    }

                    UndistortedTextureDataBuffer[i].Left        = Texture2D.CreateExternalTexture(UndistortedImageWidth, UndistortedImageHeight, TextureFormat.RGBA32, false, false, ShaderResourceViewLeft);
                    UndistortedTextureDataBuffer[i].Right       = Texture2D.CreateExternalTexture(UndistortedImageWidth, UndistortedImageHeight, TextureFormat.RGBA32, false, false, ShaderResourceViewRight);
                    UndistortedTextureDataBuffer[i].Initialized = true;
                }

                SetTextureFromHandleReady = SetTexture;
            }

            // Todo : It will be release when call Release().
            if (SetTextureFromHandleReady)
            {
                TextureUndistortedDisplayLeft  = UndistortedTextureDataBuffer[(int)receivedBufferIndex].Left;
                TextureUndistortedDisplayRight = UndistortedTextureDataBuffer[(int)receivedBufferIndex].Right;
            }

            // Parse the pose.
            if (SeeThrough.SRWork_SeeThrough.b4KImageReady)
            {
                RawUndistortedFrameIndex[0] = SeeThrough.SRWork_SeeThrough.see_through_4k_data_.output4k_frameSeq;
                RawUndistortedTimeIndex[0]  = SeeThrough.SRWork_SeeThrough.see_through_4k_data_.output4k_timeStp;
                Marshal.Copy(SeeThrough.SRWork_SeeThrough.see_through_4k_data_.output4k_pose_left, RawUndistortedPoseLeft, 0, RawUndistortedPoseLeft.Length);
                Marshal.Copy(SeeThrough.SRWork_SeeThrough.see_through_4k_data_.output4k_pose_right, RawUndistortedPoseRight, 0, RawUndistortedPoseRight.Length);
            }
            else
            {
                RawUndistortedFrameIndex[0] = SeeThrough.SRWork_SeeThrough.see_through_data_.frame_Seq;
                RawUndistortedTimeIndex[0]  = SeeThrough.SRWork_SeeThrough.see_through_data_.time_Stp;
                Marshal.Copy(SeeThrough.SRWork_SeeThrough.see_through_data_.pose_left, RawUndistortedPoseLeft, 0, RawUndistortedPoseLeft.Length);
                Marshal.Copy(SeeThrough.SRWork_SeeThrough.see_through_data_.pose_right, RawUndistortedPoseRight, 0, RawUndistortedPoseRight.Length);
            }

            for (int i = 0; i < 4; i++)
            {
                UndistortedPoseLeft.SetColumn(i, new Vector4(RawUndistortedPoseLeft[i * 4 + 0], RawUndistortedPoseLeft[i * 4 + 1],
                                                             RawUndistortedPoseLeft[i * 4 + 2], RawUndistortedPoseLeft[i * 4 + 3]));
                UndistortedPoseRight.SetColumn(i, new Vector4(RawUndistortedPoseRight[i * 4 + 0], RawUndistortedPoseRight[i * 4 + 1],
                                                              RawUndistortedPoseRight[i * 4 + 2], RawUndistortedPoseRight[i * 4 + 3]));
            }
        }