无法在Android上使用本机插件(opengl ES3 API)读取Unity WebcamTexture像素

我正在尝试在本地c ++插件中克隆WebCamTexture.GetPixels32函数以执行图像处理任务,因此我可以使用某些c ++库修改图像缓冲区。

我创建了一个本机插件界面,作为Unity提供的此示例:

https://github.com/Unity-Technologies/NativeRenderingPlugin

我使用opengl ES 3作为Android的api,使用opengl Core作为编辑器。

我对OnRenderEvent函数的实现很简单,只需函数调用即可复制WebCamTexture的像素

static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
{
    // Unknown / unsupported graphics device type? Do nothing
    if (s_CurrentAPI == NULL)
        return;

    CopyTexturePixels();
    nbreOfCpy++;

}

这就是我试图复制纹理像素的方式

static void CopyTexturePixels()
{
    void* textureHandle = g_TextureHandle;
    int width = g_TextureWidth;
    int height = g_TextureHeight;

    if (!textureHandle)
        textureCopy = -1;



    GLuint gltex = (GLuint)(size_t)(textureHandle);
    glBindTexture(GL_TEXTURE_2D, gltex);

    GLuint framebuffer;
    glGenFramebuffers(1, &framebuffer);
    glBindFramebuffer(GL_FRAMEBUFFER, (GLuint)framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gltex, 0);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, glBuffer);


    if ( glGetError() == GL_NO_ERROR )
        textureCopy = 1;
    else
        textureCopy = 0;
}

我添加了两个变量nbreOfCpy和textureCopy,以确保确实调用了这两个函数。

此代码可在编辑器中完美运行(我使用的是Windows 10),但对于Android,由opengl glBuffer读取的图像始终提供相同的缓冲区,并且根本不会更新。

有什么帮助吗?