I have a Renderscript which processes an image that is given in output to an Allocation. I want to use this Allocation as a texture in my OpenGL program but I don't know how to get a texture ID from the Allocation.
On the other hand, I know I could use a graphic Renderscript, but since it has been deprecated, I guess there must be some other way to achieve the same result.
You have phrased the question in terms of transforming an Allocation into a texture, but it's easier to think of creating a texture then granting the Allocation ownership of that texture. This way, you would know the texture ID before passing it to the Allocation. Beware: the Allocation has the power to radically change properties of the texture.
Step by step:
Create a GL texture
Create a SurfaceTexture using its ID
Create an Allocation with usage
Allocation.USAGE_IO_OUTPUT | Allocation.USAGE_SCRIPT
Pass the SurfaceTexture to the Allocation with
setSurface()
Put data in the Allocation
Call
ioSend()
on the Allocation to update the textureRepeat steps 5 and 6 as often as you want to update the texture
I am very far from a GL expert, so step 2 is frankly conjecture. Below is an adaptation of the HelloCompute sample in which I replace
displayout
with a TextureView, which is a View that handily creates a texture and a SurfaceTexture for me. From then on I follow the steps above.Specify USAGE_IO_OUTPUT when you create the Allocation. Assuming you are generating the texture data in a script you would also add USAGE_SCRIPT. You can then call
Allocation.setSurface(theGLSurface)
to link the allocation to a texture. Each time you want to update the texture with the contents of the script you need to call.
Allocation.ioSend()
This will move the data without making extra copies.