1

いくつかの単純なシェーダーを実行していて、ランダムに発生するエラーが発生しました。シーンのレンダリングを開始すると、メッシュが余分なベクトルでレンダリングされることがあります。アクティビティを強制終了してから同じアクティビティを開くと、レンダリングされないことがあります。余分なベクトル。

私の推測では、アクティビティを強制終了しても、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);

問題を確認するためのスクリーンショットを次に示します。

また、電話でアプリを実行したときに撮ったビデオへのリンクもあります。

4

1 に答える 1

2

だから...私はそれが私がやっていた本当にばかげたことだったという問題を見つけました、

//on this line I was sending length, where length was
//the length of the vertices for the triangle it was "9" (x,y,z for each vertex)
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, length);
//I had to divide that by the number of components for each vertex
//so when the vertex only has position attributes (x,y,z) is divided by 3
//when you have more i.e. normals it will be divided by 6 (x,y,z, normalX, normalY, normalZ)
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, length/mVertexAttributes.vertexNumComponents);

これが他の人の役に立つことを願っています。

于 2012-03-29T05:10:03.117 に答える