いくつかの単純なシェーダーを実行していて、ランダムに発生するエラーが発生しました。シーンのレンダリングを開始すると、メッシュが余分なベクトルでレンダリングされることがあります。アクティビティを強制終了してから同じアクティビティを開くと、レンダリングされないことがあります。余分なベクトル。
私の推測では、アクティビティを強制終了しても、GPUのメモリは完全には消去されません。さらに奇妙なことに、これらの余分なポリゴンは、シェーダーロジックを使用してレンダリングされることもあれば、ランダムな正方形で埋められているかのようにレンダリングされることもあります。
頭がおかしくなったので、objを読んだところから、頂点属性を設定したところまで、すべてのコードを確認しました。これを以前に見たことがある場合は、お知らせください。ところで、私はandroid2.1でモトローラマイルストーンを使用しています。
これは、単純な三角形を作成して頂点の属性を設定する場所に関連するコードです。
//This is where I create the mesh
mMesh = new Mesh();
mMesh.setVertices(new float[]{-0.5f, 0f, 0.5f,
0.5f, 0f, -0.5f,
-0.5f, 0f, -0.5f});
ArrayList<VertexAttribute> attributes = new ArrayList<VertexAttribute>();
attributes.add(new VertexAttribute(Usage.Position, 3, ProgramShader.POSITION_ATTRIBUTE));
VertexAttributes vertexAttributes = new VertexAttributes(attributes.toArray(new VertexAttribute[attributes.size()]));
mMesh.setVertexAttributes(vertexAttributes);
...
...
.......
//This is where I send the mesh to opengl
for(VertexAttribute attr :mVertexAttributes.getAttributes().values()){
mVertexBuffer.position(attr.offset);
int handler = shader.getHandler(attr.alias);
if(handler != -1){
try{
GLES20.glVertexAttribPointer(handler, attr.numComponents, GLES20.GL_FLOAT, false, mVertexAttributes.vertexSize, mVertexBuffer);
GLES20.glEnableVertexAttribArray(handler);
}catch (RuntimeException e) {
Log.d("CG", attr.alias);
throw e;
}
}
}
//(length = 3 for a triangle)
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, length);
問題を確認するためのスクリーンショットを次に示します。
また、電話でアプリを実行したときに撮ったビデオへのリンクもあります。