如何使用GraphicBuffer在Android的NDK如何使用、GraphicBuffer、NDK、Android

2023-09-06 04:22:38 作者:季末更寂寞、思绪絮乱

我问这个参考回答我的问题在How以提高机器人 OpenGL ES的显示性能。我试图建立code,它使用GraphicBuffer与NDK-r9d。但它说GraphicBuffer未在此范围内声明。为eglCreateImageKHR和glEGLImageTargetTexture2DOES同样的意见。

I am asking this with reference to an answer for my question at How to improve opengl es display performance in android . I was trying to build the code which uses GraphicBuffer with ndk-r9d. but It is saying GraphicBuffer is not declared in this scope. The same comments for eglCreateImageKHR and glEGLImageTargetTexture2DOES.

我添加EGL / eglext.h和GLES2 / gl2ext.h。我试图包括的ui / GraphicBuffer.h但并不服用。是否有添加另一头文件?

I have added EGL/eglext.h and GLES2/gl2ext.h . I tried to include ui/GraphicBuffer.h but it is not taking it. Is there another header file to be added ?

我已经加入,以避免使用glTexSubImage2D的()。

The code given below I have added to avoid use of glTexSubImage2D().

  GraphicBuffer * pGraphicBuffer = new GraphicBuffer(frame_width, frame_height, PIXEL_FORMAT_RGB_565, GraphicBuffer::USAGE_SW_WRITE_OFTEN | GraphicBuffer::USAGE_HW_TEXTURE);

        // Lock the buffer to get a pointer
        unsigned char * pBitmap = NULL;
        pGraphicBuffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,(void **)&pBitmap);

        // Write 2D image to pBitmap
        memcpy(pBitmap, frame_buffer, frame_width * frame_height * 3);

        // Unlock to allow OpenGL ES to use it
        pGraphicBuffer->unlock();

        EGLClientBuffer ClientBufferAddress = pGraphicBuffer->getNativeBuffer();
        EGLint SurfaceType = EGL_NATIVE_BUFFER_ANDROID;

        // Make an EGL Image at the same address of the native client buffer
        EGLDisplay eglDisplayHandle = eglGetDisplay(EGL_DEFAULT_DISPLAY);

        // Create an EGL Image with these attributes
        EGLint eglImageAttributes[] = {EGL_WIDTH, frame_width, EGL_HEIGHT, frame_height, EGL_MATCH_FORMAT_KHR,  EGL_FORMAT_RGB_565_KHR, EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};

        EGLImageKHR eglImageHandle = eglCreateImageKHR(eglDisplayHandle, EGL_NO_CONTEXT, SurfaceType, ClientBufferAddress, eglImageAttributes);

        // Create a texture and bind it to GL_TEXTURE_2D
/*        EGLint TextureHandle;
        glGenTextures(1, &TextureHandle);
        glBindTexture(GL_TEXTURE_2D, TextureHandle);
*/
        // Attach the EGL Image to the same texture
        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, eglImageHandle);

我能做些什么来让它运行......

What can I do to get it run......

在此先感谢。

推荐答案

不幸的是,它被认为是从这里删除,但你可以得到一些答案有: http://community.arm.com/groups/arm-mali-graphics/blog/2013/10/24/eglimage--updating-a-texture-without-copying-memory-under-android

Unfortunately, it got removed from here but you could get some answers there: http://community.arm.com/groups/arm-mali-graphics/blog/2013/10/24/eglimage--updating-a-texture-without-copying-memory-under-android

总之,你需要建立Android平台code和创建库,将包访问GraphicBuffer和所需的API,并建立针对Android的code基地。至于其他的规定,你需要保持图书馆...

In short, you'll need to build Android platform code and create library that would wrap access to GraphicBuffer and required API and build against android code base. As other stated, you'll need to maintain the library...

这是一种替代方法: https://$c$c.google.com/p/chromium/$c$csearch#chromium/src/third_party/deqp/src/framework/platform/android/tcuAndroidInternals.cpp&l=167