简体   繁体   English

OpenGL 纹理到 AhardwareBuffer

[英]OpenGL textures into AHardwareBuffer

I came across AHardwareBuffer in Android.我在 Android 中遇到了AHardwareBuffer I wanted to make use of AHardwareBuffer to store textures so that I can use them on different threads where I don't have an OpenGL context.我想使用 AHardwareBuffer 来存储纹理,以便我可以在没有 OpenGL 上下文的不同线程上使用它们。 Currently, I'm doing the following:目前,我正在做以下事情:

  • Generate a texture and bind it to GL_TEXTURE_2D .生成纹理并将其绑定到GL_TEXTURE_2D
  • Create EGLClientBuffer and EGLImageKHR from it. EGLClientBuffer创建EGLClientBufferEGLImageKHR Attach the EGLImage as texture target.附加 EGLImage 作为纹理目标。
  • Generate an FBO and bind it to the texture using glFramebufferTexture2D .生成一个 FBO 并使用glFramebufferTexture2D将其绑定到纹理。
  • To draw the texture (say tex ), I'm rendering it onto the AHardwareBuffer using shaders为了绘制纹理(比如tex ),我使用着色器将它渲染到AHardwareBuffer

However, I wanted away so that I don't need to rerender it onto hardwarebuffer but instead directly store data of the texture onto hardwarebuffer.但是,我想离开,这样我就不需要将它重新渲染到硬件缓冲区,而是直接将纹理数据存储到硬件缓冲区。

I was thinking of using glCopyTexImage2d for doing this.我正在考虑使用glCopyTexImage2d来做这件事。 Is this fine and would it work?这很好吗,它会起作用吗?

Also (a dumb question but I cannot get over it) if I attach my EGLImage which is from the Hardwarebuffer to GL_TEXTURE_2D and define the texture using glTexImage2D, would it not store the data of the texture which is a parameter of glTexImage2D into the hardwarebuffer?同时,(一个愚蠢的问题,但我不能克服它),如果我附上我EGLImage这是从Hardwarebuffer到GL_TEXTURE_2D ,并确定使用glTexImage2D,岂不存储纹理这是一个参数的数据纹理glTexImage2D到hardwarebuffer?

I solved this issue using glSubTexImage2D .我使用glSubTexImage2D解决了这个问题。

First create a opengl texture and bind it to GL_TEXTURE_2D .首先创建一个 opengl 纹理并将其绑定到GL_TEXTURE_2D Then use glEGLImageTargetTexture2DOES to bind texture to EGLImageKHR created from EGLClientBuffer.然后使用glEGLImageTargetTexture2DOES绑定纹理EGLImageKHR从EGLClientBuffer创建。 This is similar to glTexImage2D .这类似于glTexImage2D Any subsequent call to glTexImage2D will break the relationship between the texture and EGLClientBuffer.任何对glTexImage2D后续调用都会破坏纹理和 EGLClientBuffer 之间的关系。

refer: https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt参考: https : //www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt

However glSubTexImage2D preserves the relationship.但是glSubTexImage2D保留了这种关系。 Hence we can load data with this API and store it in AHardwareBuffer .因此,我们可以使用此 API 加载数据并将其存储在AHardwareBuffer

PS: This might me one way and if there are other ways i'll be accepting the answer. PS:这可能是我的一种方式,如果还有其他方式,我会接受答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM