Skip to content
Discussion options

You must be logged in to vote

replaceImageByName 放在异步线程调用不会导致 OpenGL 上下文丢失,可以放心使用。原因如下:

  1. replaceImageByName 是纯 CPU 操作:它内部只是替换 shared_ptr 引用、创建 CPU 侧的 ImageReplacement 对象,完全没有 gl* 调用。真正的 GPU 操作发生在 flush() 时,由渲染线程在持有 GL 上下文的情况下执行。
  2. 线程安全有保障:replaceImageByName 和 flush() 共享同一个 rootLocker 互斥锁(std::shared_ptrstd::mutex),不会出现并发竞争。
  3. Android Demo 实测验证:在 demo 的后台线程中调用 replaceImageByName,替换后回到 UI 线程 flush(),画面正常渲染,GL 上下文不受影响。

需要注意的是,PAGImage 如果是通过 FromTexture 创建的,需要在持有 GL 上下文的线程上创建;建议异步替换场景下使用 FromPath / FromBytes / FromBitmap 来创建 PAGImage。

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CodeJhF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants