如何在android ndk中使用GraphicBuffer [英] How to use GraphicBuffer in android ndk

查看:21
本文介绍了如何在android ndk中使用GraphicBuffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 如何提高 android 中的 opengl es 显示性能 .我试图构建使用带有 ndk-r9d 的 GraphicBuffer 的代码.但它是说 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......

提前谢谢..

推荐答案

这几天我也在研究这个问题.

I am working on this problem these days, too.

许多博客表示需要一份 Android 源代码副本才能与您的项目链接.我相信在运行时从 libui.so 中获取函数会更优雅,这就是 Aleksandar Stojiljkovic 提到的替代方法".

Many blogs said a copy of Android source code is needed to link along with your project. I believe it's more elegant to get function from libui.so in runtime, which is the "alternative approach" mentioned by Aleksandar Stojiljkovic.

我已经编写了一个简单的库来做到这一点.这里就是它.

I have written a simple library to do that. Here is it.

这篇关于如何在android ndk中使用GraphicBuffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆