2

I am working with ARM mali 72 on my Android smartphonne.

I would like to use the output buffer fron OpenCL to render it into OpenGL like a texture.

I have no problem with openCL alone nether openGL alone.

I got no cloud to how to use both in the same application.

The goal is to use mY output OpenCL and send it to openGL.

Some peice of code step by step would be very nice.

I can use openCL 2.0 and opengl ES 3.0 on my smartphonne.

************** ADDED THE 30/09/2020 ************

It Look like I need more information on how to manage my problem.

So my configuration is ! I got Java OpenGL ES Application to already develloped. I retreive the camera frame from Camera.OnPreviousFrame then a send it to OpenCL using JNI.

So i would like to Get the EGL display from Java OpenGL ES Send it through JNI and then Compute my openCL kernel send It back to java OpenGL ES.

I know how to retreive data from OpenCL, transform it to bitmap and use SurfaceTexture and GL_TEXTURE_EXTERNAL_OES to display it into openGL ES.

My problem is how to Retreive EGL display from java OpenGL ES. How to send it to C++, this i can manage to find out using JNI. But i do not know how to implement the C++ part using EGL and OpenCL.

The Answer from BenMark is interresting concerning the processing but I am missing some part. It is possible to use my configuration, using java openGL ES or do i nedd to do all the EGL, openGL, openCL code in native ?

Thanks a lot for help me to anderstand the problem and try to find a solution. ;))

hterrolle
  • 49
  • 8

2 Answers2

0

I haven't code a code example but -

Using the EGL API makes interoperability between the GLES and OpenCL APIs easier.

This page provides some tips: https://developer.arm.com/documentation/101574/0400/Using-OpenCL-extensions/Inter-operation-with-EGL/EGL-images

From that page, amongst other things:

  • You'll want the EGL_KHR_image_base extension to share EGL images.
  • In OpenCL you'll want cl_khr_egl_image to use the EGL image, and then you must flush in OpenCL with clFinish or clWaitForEvents to be sure that the image is then ready for use by OpenGL ES.
  • The start and end of the EGL image accesses by OpenCL applications must be signaled by enqueuing clEnqueueAcquireEGLObjectsKHR and clEnqueueReleaseEGLObjectsKHR commands.

I hope that helps get you going.

BenClark
  • 338
  • 2
  • 12
  • this way is to put EGL image inside CL buffer. I need the opposite. CL buffer to GL or EGL image. – hterrolle Sep 24 '20 at 02:03
  • As it says on that page, the role of EGL images is only to serve as a reference to memory allocations made by the low-level APIs. So it preserves the handle and it's passed on to GLES, meaning the CL buffer can be used by GLES once CL has finished with it (& flushed to it to make sure it's stable). The EGL image is essentially just being a pointer to the buffer that both CL & GLES can recognise. – BenClark Sep 25 '20 at 08:23
  • So i i want to process camera image i must send the frame to openGLES texture using GL_TEXTURE_EXTERNAL_OES . than retreive the image in low level API using EGL_KHR_image_base(first ?). than enqueueAcquireGLObjects to get the image. Process the image using OpenCL. than enqueueReleaseGLObjects. and taht all ;)). But how to send the texture from openGLES to low level API EGL ? How to said to EGL which texture to use. I am a little bit confused. I can anderstant the macanisme but to link GPU texture to low level EGL i need GPU memorie adresse or texture pointer ? – hterrolle Sep 25 '20 at 23:58
  • In fact i al using JAVA openGL ES to render. So i need to get the EGL from java and send it to C++ using JNI ? – hterrolle Sep 26 '20 at 11:17
  • That makes it a whole lot trickier if OpenCL is c++ and GLES is java - haven't managed to get a chance to investigate best thing to do there sorry, not familiar with java GLES. – BenClark Oct 01 '20 at 17:01
  • Thanks anyway ;)) But an example in native could be usefull in case i could not find any other possibilities. ;)) – hterrolle Oct 02 '20 at 15:24
0

It was a long anderstanding problem ;))

So the solution are :

It is not possible to Share Context from other thread. So JAVA/OpenCL C++ cannot share data. So depending on GLSL version they is different possibility.

GLES 2.0: need to rewrite SurfaceTexture.cpp to acces (EGL IMAGE) surface form C++ and i even do not know if it is possible due to context nono thread. so Forget it at the moment ;)). But you can still use camera onPrevious to get Data, then send it through JNI to C++ OpenCL, that is what i am doing a this time. Then send back the OpenCL output to the Display View and cath it using Canvas and GL_TEXTURE_EXTERNAL_OES. It works but it is eavy. ;)) And you cannot get nothing from GLSL texture back to C++.

GLSL 3.1: Use Compute shader rather than OpenCL in JAVA. ;)) Have a look at What is the difference between OpenCL and OpenGL's compute shader?

hterrolle
  • 49
  • 8