public override Status StartRun(Texture texture) { Debug.Log("This graph is for testing official examples. You can customize the graph by editing `official_demo_android.txt` (default is `hand_tracking_mobile.pbtxt`)"); sidePacket = new SidePacket(); sidePacket.Emplace("num_hands", new IntPacket(2)); #if UNITY_ANDROID var glTextureName = texture.GetNativeTexturePtr(); var textureWidth = texture.width; var textureHeight = texture.height; GpuBuffer gpuBuffer = null; gpuHelper.RunInGlContext(() => { var glContext = GlContext.GetCurrent(); var glTextureBuffer = new GlTextureBuffer((UInt32)glTextureName, textureWidth, textureHeight, GpuBufferFormat.kBGRA32, OnReleaseDestinationTexture, glContext); gpuBuffer = new GpuBuffer(glTextureBuffer); return(Status.Ok()); }).AssertOk(); outputPacket = new GpuBufferPacket(gpuBuffer); sidePacket.Emplace(destinationBufferName, outputPacket); #endif return(graph.StartRun(sidePacket)); }
public GpuBuffer BuildGpuBuffer(GlContext glContext) { #if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID var glTextureBuffer = new GlTextureBuffer(GetTextureName(), width, height, gpuBufferformat, OnReleaseTextureFrame, glContext); return(new GpuBuffer(glTextureBuffer)); #else throw new NotSupportedException("This method is only supported on Linux or Android"); #endif }
static IntPtr BuildDestination() { var glContext = GlContext.GetCurrent(); var glTextureBuffer = new GlTextureBuffer((UInt32)destinationNativeTexturePtr, destinationWidth, destinationHeight, GpuBufferFormat.kBGRA32, OnReleaseDestinationTexture, glContext); outputPacket = new GpuBufferPacket(new GpuBuffer(glTextureBuffer)); return(Status.Ok().mpPtr); }
public void Dispose() { GlContext.Enable(); FinalImages.Dispose(); Images.Dispose(); GlData.Dispose(); GlContext.Disable(); }
public void TryCreateContext() { int major = 2; int minor = 1; Gl.Initialize(); var deviceContext = DeviceContext.Create(); GlContext glContext = GlContext.TryCreate(deviceContext, major, minor, SharpRetro.LibRetro.retro_hw_context_type.RETRO_HW_CONTEXT_OPENGL, false); Assert.NotNull(glContext); glContext.Dispose(); }
static IntPtr PushInputInGlContext() { try { var glContext = GlContext.GetCurrent(); var glTextureBuffer = new GlTextureBuffer((UInt32)currentTextureName, currentTextureFrame.width, currentTextureFrame.height, currentTextureFrame.gpuBufferformat, currentTextureFrame.OnRelease, glContext); var gpuBuffer = new GpuBuffer(glTextureBuffer); // TODO: ensure the returned status won't be garbage collected prematurely. return(graph.AddPacketToInputStream(inputStream, new GpuBufferPacket(gpuBuffer, currentTimestamp)).mpPtr); } catch (Exception e) { return(Status.FailedPrecondition(e.ToString()).mpPtr); } }
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(); }
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 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 bool SetHWRender(ref retro_hw_render_callback hwRenderCallback) { if (_deviceContext != null) { return(false); } _deviceContext = DeviceContext.Create(); // Try and create an openGl context using the attributes specified in the callback _glContext = GlContext.TryCreate(_deviceContext, (int)hwRenderCallback.version_major, (int)hwRenderCallback.version_minor, (retro_hw_context_type)hwRenderCallback.context_type, hwRenderCallback.debug_context); // Creation might fail if the system doesn't // support the requested attributes if (_glContext == null) { return(false); } // ToDo: Some cores seem to need a separate shared context // but can't get it to work yet... if (_haveSharedContext) { _sharedGlContext = _glContext.CreateSharedContext(); } // Render context that the libretro core will render to, contains a texture buffer and an optional depth/stencil buffer. _libretroContext = new LibretroRenderContext(hwRenderCallback.depth, hwRenderCallback.stencil, hwRenderCallback.bottom_left_origin); // Get the libretro core callbacks _contextResetDlgt = hwRenderCallback.context_reset != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer <retro_hw_context_reset_t>(hwRenderCallback.context_reset) : null; _contextDestroyDlgt = hwRenderCallback.context_destroy != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer <retro_hw_context_reset_t>(hwRenderCallback.context_destroy) : null; // Pass the opengl callbacks back to the core hwRenderCallback.get_proc_address = Marshal.GetFunctionPointerForDelegate(_getProcAddressDelegate); hwRenderCallback.get_current_framebuffer = Marshal.GetFunctionPointerForDelegate(_getCurrentFramebufferDlgt); return(true); }
/// <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_ShouldReturnNull_When_CalledOutOfGlContext() { var glContext = GlContext.GetCurrent(); Assert.Null(glContext); }