android-asynctask - 将 openGL 参数传递给 AsyncTask
问题描述
如何正确地将 javax.microedition.khronos.opengles.GL10 作为参数传递给 AsyncTask。这是我尝试过但没有用的代码。如果我直接将参数传递给 SavePNG 方法,它就可以工作。有什么线索吗?谢谢。
这是我的代码:
if (mTakeScreenshot) {
mTakeScreenshot = false;
MyTaskParams params = new MyTaskParams(0, 0, mViewWidth, mViewHeight, gl);
MyTask myTask = new MyTask();
myTask.execute(params);
}
private static class MyTaskParams {
int x;
int y;
int w;
int h;
GL10 gl;
MyTaskParams(int x, int y, int w, int h, GL10 gl) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.gl = gl;
}
}
public class MyTask extends AsyncTask<MyTaskParams, Void, Void> {
@Override
protected Void doInBackground(MyTaskParams... params) {
int x = params[0].x;
int y = params[0].y;
int w = params[0].w;
int h = params[0].h;
GL10 gl = params[0].gl;
SavePNG(0, 0, w, h, gl);
return null;
}
}
解决方案
OpenGL 帧缓冲区操作是单线程的,因此您需要使用回调函数并在必要时调用它,通常在按键或按钮按下回调函数中。
IE
void main()
{
//GL Operations
//GLswapbuffers
//call here or in key / button press callback function
doInBackground(params);
}
protected Void doInBackground(MyTaskParams... params) {
int x = params[0].x;
int y = params[0].y;
int w = params[0].w;
int h = params[0].h;
GL10 gl = params[0].gl;
SavePNG(0, 0, w, h, gl);
}
推荐阅读
- excel - 在自己的子文件夹 vba 中将所有 excel 文件转换为 pdf
- javascript - 是否可以在函数(forEach)中打印一些东西?Vue.Js,JavaScript
- php - 如何以“自然”顺序正确排序数据库中的项目
- css - 根据图像数量更改宽度并在弹性框中响应地调整图像大小
- javascript - 检测 contenteditable div 第一行的向上箭头
- git - 源代码管理资源管理器仅适用于 TFVC 存储库
- java - java如何避免多重继承
- reactjs - Redux - 处理表单错误的正确方法
- ios - iOS 13 的启动画面默认栏样式和 pre 13 的轻量级内容
- python - 如何只打印python中的第一个值