我目前正在尝试将 Android WebView 内容渲染为可在使用 JNI 和 NDK 的 C++ 应用程序中使用的纹理。我不明白为什么它不能按我的预期工作。
我在网上阅读了很多文档,以下是我现在所拥有的:
C++ 方面:
// Create the texture
uint texture;
glGenTextures(1, &texture);
// Bind the texture with the proper external texture target
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
// Create the EGLImage object that maps the GraphicBuffer
int usage = GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_READ_OFTEN | GraphicBuffer::USAGE_SW_WRITE_OFTEN;
auto gralloc = new GraphicBuffer(width, height, PIXEL_FORMAT_RGBA_8888, usage);
EGLClientBuffer clientBuffer = (EGLClientBuffer) gralloc->getNativeBuffer();
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGLint attrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
auto eglImage = eglCreateImageKHR(display, …Run Code Online (Sandbox Code Playgroud)