public unsafe bool Update(EasyAR.Buffer buffer) { if (Texture != null) { Texture.SetData(0, 0, 0, textureWidth, textureHeight, (byte *)buffer.data().ToPointer() + textureOffset); return(true); } return(false); }
/// <summary> /// Detects new output frames and updates the camera, then passes the output frame through an event to update the foreground /// </summary> /// <param name="timeStep"></param> protected override void OnUpdate(float timeStep) { if (paused) { return; } Optional <OutputFrame> optionalOframe = OutputFrameBuffer.peek(); if (optionalOframe.OnSome) { OutputFrame oframe = optionalOframe.Some; Optional <InputFrame> optionalIframe = oframe.inputFrame(); if (optionalIframe.OnSome) { InputFrame iframe = optionalIframe.Some; CameraParameters cameraParameters = iframe.cameraParameters(); if (cameraParameters != null) { Image image = iframe.image(); float aspectRatio = (float)(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Height); int rotation = 0; switch (DeviceDisplay.MainDisplayInfo.Rotation) { case DisplayRotation.Rotation90: rotation = 90; break; case DisplayRotation.Rotation180: rotation = 180; break; case DisplayRotation.Rotation270: rotation = 270; break; } if (iframe.index() != previousInputFrameIndex) { Matrix44F ip = cameraParameters.imageProjection(aspectRatio, rotation, true, false); Matrix4 iprj = ip.ToUrhoMatrix(); bgCamera.SetProjection(iprj); EasyAR.Buffer buffer = image.buffer(); try { backgroundUpdater.UpdateTexture(Application, image.format(), image.width(), image.height(), buffer); } finally { buffer.Dispose(); } previousInputFrameIndex = iframe.index(); } ARFrameUpdated?.Invoke(oframe, cameraParameters, aspectRatio, rotation); image.Dispose(); cameraParameters.Dispose(); } iframe.Dispose(); } oframe.Dispose(); } base.OnUpdate(timeStep); }
public bool UpdateTexture(Application application, PixelFormat format, int width, int height, EasyAR.Buffer buffer) { if (this.initializedFormat != format || this.initializedWidth != width || this.initializedHeight != height) { if (this.initializedFormat == PixelFormat.Unknown) { if (!InitTextures(application, format, width, height)) { return(false); } } else { return(false); } } bgTexture.Update(buffer); uvTexture.Update(buffer); vTexture.Update(buffer); return(true); }