在onDrawFrame内调用glDrawArrays致命信号(GLSurfaceView.Renderer,SurfaceTexture.OnFrameAvailableListener) [英] Fatal signal on glDrawArrays within onDrawFrame (GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener)
问题描述
我之后得到一个致命的信号11好几
I am getting a Fatal Signal 11 after quite a few
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
我OnDrawFrame函数中调用。该纹理已经崩溃,我认为这意味着我的顶点和片段着色器正常工作之前正确绘制。
calls within my OnDrawFrame function. The textures are been drawn correctly before the crash, which I believe it means that my vertex and fragment shaders work fine.
我所要做的,就是要融合在一起使用GLSurfaceView.Renderer和SurfaceTexture.OnFrameAvailableListener两个纹理。
What I am trying to do, is to blend two textures together using GLSurfaceView.Renderer and SurfaceTexture.OnFrameAvailableListener.
第一个纹理是现场摄像机preVIEW其表面纹理由它自己的正常工作。第二tetxure仅仅是一个位图图像,这也由它自己的工作正常。但结合他们给人的崩溃。
The first texture is a live camera preview SurfaceTexture which works fine by its own. The second tetxure is just a bitmap image, which also works fine by its own. but combining them gives the crash.
我OnDrawFrame如下:
My OnDrawFrame is as follows:
public void onDrawFrame(GL10 glUnused) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
synchronized(this) {
if (updateSurface) {
mSurface.updateTexImage();
mSurface.getTransformMatrix(mSTMatrix);
updateSurface = false;
}
}
maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
muCRatioHandle = GLES20.glGetUniformLocation(mProgram, "uCRatio");
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textures[0]);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
int t1h = GLES20.glGetUniformLocation ( mProgram, "sTexture1" );
// GLES20.glUniform1i(t1h, textures[0]);
GLES20.glUniform1i(t1h, 1);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textures[1]);
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
int t2h = GLES20.glGetUniformLocation ( mProgram, "sTexture2" );
GLES20.glUniform1i(t2h, 2);
GLES20.glUseProgram(mProgram);
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
mTriangleVertices.position(0);
GLES20.glEnableVertexAttribArray(maPositionHandle);
GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
4*5, mTriangleVertices);
mTriangleVertices.position(3);
GLES20.glEnableVertexAttribArray(maTextureHandle);
GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
4*5, mTriangleVertices);
Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
GLES20.glUniform1f(muCRatioHandle, mCameraRatio);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
GLES20.glDisableVertexAttribArray(maPositionHandle);
GLES20.glDisableVertexAttribArray(maTextureHandle);
// GLES20.glFlush();
}
其中mTriangleVertices是:
where mTriangleVertices is:
mTriangleVertices = ByteBuffer.allocateDirect(mTriangleVerticesData.length
* FLOAT_SIZE_BYTES).order(ByteOrder.nativeOrder()).asFloatBuffer();
mTriangleVertices.put(mTriangleVerticesData).position(0);
和mTriangleVerticesData是:
and mTriangleVerticesData is:
private final float[] mTriangleVerticesData = {
// X, Y, Z, U, V
-1.0f, -1.0f, 0, 0.f, 0.f,
1.0f, -1.0f, 0, 1.f, 0.f,
-1.0f, 1.0f, 0, 0.f, 1.f,
1.0f, 1.0f, 0, 1.f, 1.f,
};
任何提示,链接,甚至code段将是非常美联社preciated!
Any tips, links or even code snippets would be much appreciated!
感谢您提前
推荐答案
不知道这是飞机失事的原因,但你至少分配着色器它太高质感的ID。例如;
Don't know if this is the cause for the crash but you're assigning one too high texture ids for shader at least. For example;
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
int t1h = GLES20.glGetUniformLocation ( mProgram, "sTexture1" );
GLES20.glUniform1i(t1h, 1);
应该读
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
int t1h = GLES20.glGetUniformLocation ( mProgram, "sTexture1" );
GLES20.glUniform1i(t1h, 0);
编辑:嗯,这可能是飞机失事的原因:
Ah, this might be the cause for the crash:
GLES20.glVertexAttribPointer(maTextureHandle, 3, GLES20.GL_FLOAT, false,
4*5, mTriangleVertices);
这应该是
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
4*5, mTriangleVertices);
更可能的,因为你有每个顶点两个纹理值。
More likely since you have two texture values per vertex.
这篇关于在onDrawFrame内调用glDrawArrays致命信号(GLSurfaceView.Renderer,SurfaceTexture.OnFrameAvailableListener)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!