Opengl 创建 FBO- 致命信号 11 错误
Opengl Create FBO- fatal signal 11 error
在我的 android 游戏中,我想在 FBO 中渲染我的场景并附加一个纹理,稍后使用该纹理,但是当我使用 glGenFramebuffers
时我得到这个错误:
07-30 06:17:27.839: A/libc(1338): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xd0 in tid 1353 (GLThread 157)
如果需要,这里是我的代码:
createTexture
函数:
public int CreateTexture(int w, int h){
int[] textureId = new int[1];
int i;
i = GLES20.glGetError();
GLES20.glGenTextures(1, textureId,0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[0]);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, w, h, 0, GLES20.GL_RGBA, GLES20.GL_FLOAT, null);
ijad kon vali ba hichi poresh nakon hanooz
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
if(i!=0){
Log.d("ERROR", "ERROR Happend"+i+"");
return i;
}
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
return textureId[0];
}
和onDrawFrame
:
public synchronized void onDrawFrame(GL10 gl) {
if(first){
int renderTexture;
renderTexture = CreateTexture(128,128 );
GLES20.glGenFramebuffers(1, FBO,0);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture, 0);
first = false;
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FBO[0]);
// Some 'global' settings.
//gl.glEnableClientState(GLES20.GL_VERTEX_ATTRIB_ARRAY_ENABLED);
gl.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GLES20.GL_FLOAT, 0, mBufVertices);
// Enable color array.
gl.glEnableClientState(GLES10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GLES20.GL_FLOAT, 0, mBufColors);
//inja khasiate transparent ro faAl mikonim ke betoonim too CurlPage be kaaghaz alpha bedim
gl.glEnable(GLES20.GL_BLEND);
gl.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
gl.glDisable(GLES10.GL_LIGHTING);
gl.glDisable(GLES20.GL_TEXTURE_2D);
gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mVerticesCountFront);
int backStartIdx = Math.max(0, mVerticesCountFront - 2);
//Log.d("mVerticesCountFront", ""+mVerticesCountFront+"");
int backCount = mVerticesCountFront + mVerticesCountBack - backStartIdx;
// Draw back facing blank vertices.
//gl.glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, backStartIdx, backCount);
// Disable textures and color array.
gl.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GLES10.GL_COLOR_ARRAY);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
gl.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
}
知道为什么我会收到这样的错误吗?
首先,每次 onDrawFrame() 时,您都会创建一个新的纹理和一个新的 FBO,每次您的应用程序想要绘制一个框架时,它都会分配更多的内存,这将以灾难告终。
您需要在开始渲染之前一次性创建纹理和 FBO,类似于 initFrameBuffer(GL10 gl) 并保持生成的 FBO 整数。
然后
public synchronized void onDrawFrame(GL10 gl) {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FBO[0]);
.... Draw calls.
}
在我的 android 游戏中,我想在 FBO 中渲染我的场景并附加一个纹理,稍后使用该纹理,但是当我使用 glGenFramebuffers
时我得到这个错误:
07-30 06:17:27.839: A/libc(1338): Fatal signal 11 (SIGSEGV), code 1, fault addr 0xd0 in tid 1353 (GLThread 157)
如果需要,这里是我的代码:
createTexture
函数:
public int CreateTexture(int w, int h){
int[] textureId = new int[1];
int i;
i = GLES20.glGetError();
GLES20.glGenTextures(1, textureId,0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[0]);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, w, h, 0, GLES20.GL_RGBA, GLES20.GL_FLOAT, null);
ijad kon vali ba hichi poresh nakon hanooz
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
if(i!=0){
Log.d("ERROR", "ERROR Happend"+i+"");
return i;
}
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
return textureId[0];
}
和onDrawFrame
:
public synchronized void onDrawFrame(GL10 gl) {
if(first){
int renderTexture;
renderTexture = CreateTexture(128,128 );
GLES20.glGenFramebuffers(1, FBO,0);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture, 0);
first = false;
}
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FBO[0]);
// Some 'global' settings.
//gl.glEnableClientState(GLES20.GL_VERTEX_ATTRIB_ARRAY_ENABLED);
gl.glEnableClientState(GLES10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GLES20.GL_FLOAT, 0, mBufVertices);
// Enable color array.
gl.glEnableClientState(GLES10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GLES20.GL_FLOAT, 0, mBufColors);
//inja khasiate transparent ro faAl mikonim ke betoonim too CurlPage be kaaghaz alpha bedim
gl.glEnable(GLES20.GL_BLEND);
gl.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
gl.glDisable(GLES10.GL_LIGHTING);
gl.glDisable(GLES20.GL_TEXTURE_2D);
gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mVerticesCountFront);
int backStartIdx = Math.max(0, mVerticesCountFront - 2);
//Log.d("mVerticesCountFront", ""+mVerticesCountFront+"");
int backCount = mVerticesCountFront + mVerticesCountBack - backStartIdx;
// Draw back facing blank vertices.
//gl.glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
gl.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, backStartIdx, backCount);
// Disable textures and color array.
gl.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GLES10.GL_COLOR_ARRAY);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
gl.glDisableClientState(GLES10.GL_VERTEX_ARRAY);
}
知道为什么我会收到这样的错误吗?
首先,每次 onDrawFrame() 时,您都会创建一个新的纹理和一个新的 FBO,每次您的应用程序想要绘制一个框架时,它都会分配更多的内存,这将以灾难告终。
您需要在开始渲染之前一次性创建纹理和 FBO,类似于 initFrameBuffer(GL10 gl) 并保持生成的 FBO 整数。
然后
public synchronized void onDrawFrame(GL10 gl) {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FBO[0]);
.... Draw calls.
}