嗨,我正在开发一个安卓应用程序,我正处于测试阶段,我正在不同的设备上试用它。我在nexus 7上开发了该应用程序。
当我在 arm mali gpu 设备上运行它时,渲染的 textrue 开始疯狂地闪烁/滞后。如果我将点大小设置为 1,我在生成的纹理中使用 GLES20.GL_POINTS早期渲染的纹理。
知道是什么原因造成的吗?
private void setupRenderToTexture() {
fb = new int[1];
depthRb = new int[1];
renderTex = new int[2];
// generate
GLES20.glGenFramebuffers(1, fb, 0);
GLES20.glGenRenderbuffers(1, depthRb, 0);
GLES20.glGenTextures(1, renderTex, 0);
// create render buffer and bind 16-bit depth buffer
GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRb[0]);
GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, texW, texH);
}
这是我渲染到文本的方法:
private void createSmokeTexture() {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb[0]);
GLES20.glClearColor(0.48f, 0.48f, 0.48f, 0.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTex[0], 0);
GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRb[0]);
//background counts
renderscriptSmokeStep_involke();
GLES20.glUseProgram(mProgramSmoke);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramSmoke, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramSmoke, "u_Move");
mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramSmoke, "u_Texture");
smokeParticleSizeUniformHandle = GLES20.glGetUniformLocation(mProgramSmoke, "u_PointSize");
maximumDensityHandler = GLES20.glGetUniformLocation(mProgramSmoke, "u_MaximumDensity");
cellDensityHandle = GLES20.glGetAttribLocation(mProgramSmoke, "a_Age");
smokeStartPositionHandle = GLES20.glGetAttribLocation(mProgramSmoke, "a_Position");
Matrix.setIdentityM(mMoveMatrix, 0);
Matrix.translateM(mMoveMatrix, 0, positionX, positionY, 0);
Matrix.multiplyMM(mMoveMatrix, 0, Render.mModelMatrix, 0, mMoveMatrix, 0);
GLES20.glUniform1f(smokeParticleSizeUniformHandle, PARTICLE_SIZE);
GLES20.glUniform1f(maximumDensityHandler, MAXIMUM_DENSITY);
GLES20.glUniform1i(mTextureUniformHandle, 0);
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMoveMatrix, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, Render.m2dProjectionMatrix, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, particlePosBuffer);
GLES20.glEnableVertexAttribArray(smokeStartPositionHandle);
GLES20.glVertexAttribPointer(smokeStartPositionHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glEnableVertexAttribArray(cellDensityHandle);
GLES20.glVertexAttribPointer(cellDensityHandle, 1, GLES20.GL_FLOAT, false, 0, cellDensity);
// Draw the point.
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, NUM_PARTICLES);
}
这在绘制时被调用:
public void draw(){
createSmokeTexture();
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
setTexture(renderTex[0]);
drawSmokeToScreen();
}
阿斯达斯
private void setTexture(int texture) {
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, texW, texH, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
}
然后我把它画到屏幕上
private void drawSmokeToScreen() {
GLES20.glUseProgram(mProgramHandle);
mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Move");
positionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
textureHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, Render.mModelMatrix, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, Render.m2dProjectionMatrix, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, fullDrawSurfice.getPositionDataIndex());
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glVertexAttribPointer(positionHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, fullDrawSurfice.getTextureDataIndex());
GLES20.glEnableVertexAttribArray(textureHandle);
GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 0, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
}