/// <summary> /// Convert <paramref name="colors" /> to a packet and send it to the input stream. /// </summary> public Status PushColor32(Color32[] colors, int width, int height) { int timestamp = System.Environment.TickCount & System.Int32.MaxValue; var imageFrame = ImageFrame.FromPixels32(colors, width, height); if (!shouldUseGPU()) { var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet.GetPtr())); } var status = gpuHelper.RunInGlContext(() => { var texture = gpuHelper.CreateSourceTexture(imageFrame); var gpuFrame = texture.GetGpuBufferFrame(); UnsafeNativeMethods.GlFlush(); texture.Release(); return(graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuFrame, timestamp).GetPtr())); }); imageFrame.Dispose(); return(status); }
/// <summary> /// Convert <paramref name="colors" /> to a packet and send it to the input stream. /// </summary> public Status PushInput(PixelData pixelData) { var timestamp = new Timestamp(System.Environment.TickCount & System.Int32.MaxValue); var imageFrame = ImageFrame.FromPixels32(pixelData.Colors, pixelData.Width, pixelData.Height, true); if (!IsGpuEnabled()) { var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet)); } var status = gpuHelper.RunInGlContext(() => { var texture = gpuHelper.CreateSourceTexture(imageFrame); var gpuFrame = texture.GetGpuBufferFrame(); Gl.Flush(); texture.Release(); return(graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuFrame, timestamp))); }); imageFrame.Dispose(); return(status); }
public void RunInGlContext_ShouldReturnOk_When_FunctionReturnsOk() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); var status = glCalculatorHelper.RunInGlContext(() => { return(Status.Ok()); }); Assert.True(status.ok); } }
public void RunInGlContext_ShouldReturnInternal_When_FunctionReturnsInternal() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); var status = glCalculatorHelper.RunInGlContext(() => { return(Status.Build(Status.StatusCode.Internal, "error")); }); Assert.AreEqual(status.code, Status.StatusCode.Internal); } }
public void RunInGlContext_ShouldReturnInternal_When_FunctionThrows() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); var status = glCalculatorHelper.RunInGlContext((GlCalculatorHelper.GlFunction)(() => { throw new Exception("Function Throws"); })); Assert.AreEqual(Status.StatusCode.Internal, status.Code()); } }
public void RunInGlContext_ShouldReturnFailedPreCondition_When_FunctionThrows() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var status = glCalculatorHelper.RunInGlContext(() => { throw new InvalidProgramException(); }); Assert.AreEqual(status.code, Status.StatusCode.FailedPrecondition); }
/// <summary> /// Convert <paramref name="colors" /> to a packet and send it to the input stream. /// </summary> public Status PushInput(TextureFrame textureFrame) { var timestamp = new Timestamp(System.Environment.TickCount & System.Int32.MaxValue); ImageFrame imageFrame = null; if (!IsGpuEnabled()) { imageFrame = new ImageFrame( ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray()); textureFrame.Release(); var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet)); } #if UNITY_ANDROID var glTextureName = textureFrame.GetNativeTexturePtr(); return(gpuHelper.RunInGlContext(() => { var glContext = GlContext.GetCurrent(); var glTextureBuffer = new GlTextureBuffer((UInt32)glTextureName, textureFrame.width, textureFrame.height, textureFrame.gpuBufferformat, textureFrame.OnRelease, glContext); var gpuBuffer = new GpuBuffer(glTextureBuffer); return graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, timestamp)); })); #else imageFrame = new ImageFrame( ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray()); textureFrame.Release(); return(gpuHelper.RunInGlContext(() => { var texture = gpuHelper.CreateSourceTexture(imageFrame); var gpuBuffer = texture.GetGpuBufferFrame(); Gl.Flush(); texture.Release(); return graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, timestamp)); })); #endif }
public void GetCurrent_ShouldReturnCurrentContext_When_CalledInGlContext() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); glCalculatorHelper.RunInGlContext(() => { var glContext = GlContext.GetCurrent(); Assert.NotNull(glContext); Assert.True(glContext.IsCurrent()); return(Status.Ok()); }).AssertOk(); }
public void CreateSourceTexture_ShouldFail_When_ImageFrameFormatIsInvalid() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var imageFrame = new ImageFrame(ImageFormat.Format.SBGRA, 32, 24); var status = glCalculatorHelper.RunInGlContext(() => { var texture = glCalculatorHelper.CreateSourceTexture(imageFrame); texture.Dispose(); return(Status.Ok()); }); Assert.AreEqual(status.code, Status.StatusCode.FailedPrecondition); }
private GlContext GetGlContext() { GlContext glContext = null; var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); glCalculatorHelper.RunInGlContext(() => { glContext = GlContext.GetCurrent(); return(Status.Ok()); }).AssertOk(); return(glContext); }
void ExpectSetSurfaceOk(IntPtr surface) { var eglSurfaceHolder = new EglSurfaceHolder(); var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var status = glCalculatorHelper.RunInGlContext(() => { var glContext = GlContext.GetCurrent(); eglSurfaceHolder.SetSurface(surface, glContext); return(Status.Ok()); }); Assert.True(status.ok); }
public void CreateDestinationTexture_ShouldReturnGlTexture_When_GpuBufferFormatIsValid() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var status = glCalculatorHelper.RunInGlContext(() => { var glTexture = glCalculatorHelper.CreateDestinationTexture(32, 24, GpuBufferFormat.kBGRA32); Assert.AreEqual(glTexture.width, 32); Assert.AreEqual(glTexture.height, 24); return(Status.Ok()); }); Assert.True(status.ok); }
public void GetCurrent_ShouldReturnCurrentContext_When_CalledInGlContext() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); glCalculatorHelper.RunInGlContext(() => { using (var glContext = GlContext.GetCurrent()) { Assert.NotNull(glContext); Assert.True(glContext.IsCurrent()); } }).AssertOk(); } }
public void CreateDestinationTexture_ShouldReturnGlTexture_When_GpuBufferFormatIsValid() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); var status = glCalculatorHelper.RunInGlContext(() => { var glTexture = glCalculatorHelper.CreateDestinationTexture(32, 24, GpuBufferFormat.kBGRA32); Assert.AreEqual(32, glTexture.width); Assert.AreEqual(24, glTexture.height); }); Assert.True(status.Ok()); } }
public void CreateSourceTexture_ShouldReturnGlTexture_When_CalledWithImageFrame() { var glCalculatorHelper = new GlCalculatorHelper(); glCalculatorHelper.InitializeForTest(GpuResources.Create().ConsumeValueOrDie()); var imageFrame = new ImageFrame(ImageFormat.Format.SRGBA, 32, 24); var status = glCalculatorHelper.RunInGlContext(() => { var texture = glCalculatorHelper.CreateSourceTexture(imageFrame); Assert.AreEqual(texture.width, 32); Assert.AreEqual(texture.height, 24); texture.Dispose(); return(Status.Ok()); }); Assert.True(status.ok); }
public Status PushInput(TextureFrame textureFrame) { var timestamp = new Timestamp(System.Environment.TickCount & System.Int32.MaxValue); #if !UNITY_ANDROID var imageFrame = new ImageFrame( ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray()); textureFrame.Release(); var packet = new ImageFramePacket(imageFrame, timestamp); return(graph.AddPacketToInputStream(inputStream, packet)); #else lock (frameLock) { currentTimestamp = timestamp; currentTextureFrame = textureFrame; currentTextureName = textureFrame.GetNativeTexturePtr(); return(gpuHelper.RunInGlContext(PushInputInGlContext)); } #endif }
public void CreateSourceTexture_ShouldFail_When_ImageFrameFormatIsInvalid() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); using (var imageFrame = new ImageFrame(ImageFormat.Types.Format.Sbgra, 32, 24)) { var status = glCalculatorHelper.RunInGlContext(() => { using (var texture = glCalculatorHelper.CreateSourceTexture(imageFrame)) { texture.Release(); } }); Assert.AreEqual(Status.StatusCode.FailedPrecondition, status.Code()); status.Dispose(); } } }
public void CreateSourceTexture_ShouldReturnGlTexture_When_CalledWithImageFrame() { using (var glCalculatorHelper = new GlCalculatorHelper()) { glCalculatorHelper.InitializeForTest(GpuResources.Create().Value()); using (var imageFrame = new ImageFrame(ImageFormat.Types.Format.Srgba, 32, 24)) { var status = glCalculatorHelper.RunInGlContext(() => { var texture = glCalculatorHelper.CreateSourceTexture(imageFrame); Assert.AreEqual(32, texture.width); Assert.AreEqual(24, texture.height); texture.Dispose(); }); Assert.True(status.Ok()); status.Dispose(); } } }
public virtual Status PushInput(TextureFrame textureFrame) { currentTimestamp = GetCurrentTimestamp(); #if UNITY_ANDROID && !UNITY_EDITOR if (IsGpuEnabled()) { lock (frameLock) { currentTextureFrame = textureFrame; currentTextureName = textureFrame.GetNativeTexturePtr(); return(gpuHelper.RunInGlContext(PushInputInGlContext)); } } #endif var imageFrame = new ImageFrame( ImageFormat.Format.SRGBA, textureFrame.width, textureFrame.height, 4 * textureFrame.width, textureFrame.GetRawNativeByteArray()); textureFrame.Release(); var packet = new ImageFramePacket(imageFrame, currentTimestamp); return(graph.AddPacketToInputStream(inputStream, packet)); }