您当前的位置: 首页 >  unity

鱼儿-1226

暂无认证

  • 2浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

通过openGL纹理在Unity中获取摄像机图像

鱼儿-1226 发布时间:2020-08-19 10:43:21 ,浏览量:2

主要代码如下 :

IEnumerator Start()

    {         Image_left = new Texture2D(m_videoWidth, m_videoHeight, TextureFormat.ARGB32, false);     //在Unity中创建2D纹理         Image_left.filterMode = FilterMode.Point;                                                                                       //设置参数         Image_left.Apply();         GetComponent().material.SetTexture("_mainTex", Image_left);         GetComponent().material.SetFloat("_tex_start", 0.0f);         GetComponent().material.SetFloat("_tex_end", 1.0f);         GetComponent().material.SetFloat("_tex_offset", 0.0f);         NativeLib.SetCamTex(Image_left.GetNativeTexturePtr());   //自定义的一个dll插件Nativelib,功能是将Image_left的纹理指针传递到openGL中               yield return StartCoroutine("CallPluginAtEndOfFrames");          }     private IEnumerator CallPluginAtEndOfFrames()     {         while (true)         {             // Wait until all frame rendering is done             yield return new WaitForEndOfFrame();             GL.IssuePluginEvent(1);     //重点!!!绘图线程将隐式调用插件DLL中的UnityRenderEvent         }

    }

 

/***************************nativelib***********************/

static void* m_TexturePointer ;

void _DLLExport SetCamTex(void* texturePtr){

    m_TexturePointer = texturePtr;

}

 

void _DLLExport UnityRenderEvent(int eventID){

    glDisable(GL_CULL_FACE);

    ...//这里是openGL的东西,随便你设置了

    DoRending();   //自定义的渲染函数

}

 

void DoRending(){

    GLuint glTex = (GLuint)(size_t)(m_TexturePointer);//获取纹理指针,下面都是openGL的那一套

    glBindTexture(GL_TEXTURE_2D,glTex);

    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_Tex.data);

}

关注
打赏
1604459285
查看更多评论
立即登录/注册

微信扫码登录

0.0380s