現在、3Dビューアを実装しています。これは基本的に、ユーザーが自分のSDカードにあるすべての画像のサブセットをレンダリングします。私が思うだろう最も一致する製品はCoolirisのようになります:Android OpenGLテクスチャ:オンザフライでの作成と削除
これは単に、新しいタイルが画面に入って、新しい画像を表示し、それぞれ示す異なる画像、画面上のNタイルのスクロールボードを示しています。
私の問題のために:私はプログラムをうまく動作させ、クワッドをレンダリングしています。クワッドがスクリーンから出ると、それはリサイクル/リリースされます。そして、新しいクワッドは、スクリーンに入る前にタイルボードに追加され続けます。
何百もの画像が存在する可能性があるため、テクスチャを即座に作成して削除する必要があります(メモリが不足しないように)。私が持っている問題は、テクスチャを削除した後、新しく作成されたテクスチャは、現在使用中の他のテクスチャのIDを取得するように見えるということです。
私のレンダリングループは次のようになります。
TileBoard {
Image[] allImages;
Tile[] board;
}
Tile {
Image image;
}
Image {
String path;
int textureId;
int referenceCount;
}
テクスチャ作成コード:
void render(GL10 gl) {
0. Move the camera
// Tile board maintenance
1. Remove tiles out of screen
2. Add new tiles which are about to enter screen
// Texture handling
3. glDeleteTextures on all unused textures followed by glFlush
4. For newly used images
- Create corresponding Bitmap
- Create the OpenGL texture, followed by glFlush
- Release the Bitmap
// Rendering
5. Render the tile (using a textured quad)
}
は、データの編成方法の良いアイデアを与えるために、ここでのクラスの概要は、
protected void loadSingleTexture(GL10 gl, long objectId, Bitmap bmp) {
int[] textures = new int[1];
gl.glGenTextures(1, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
gl.glFlush();
if (bmp != null) bmp.recycle();
if (listener != null) listener.onTextureLoaded(gl, objectId, textures[0]);
}
テクスチャ削除コード:
// pendingTextureUnloads is a Set<Integer>
if (pendingTextureUnloads.size() > 0) {
int[] textureIds = new int[pendingTextureUnloads.size()];
int i = 0;
Iterator<Integer> it = pendingTextureUnloads.iterator();
while (it.hasNext()) {
textureIds[i] = it.next();
}
gl.glDeleteTextures(textureIds.length, textureIds, 0);
gl.glFlush();
}
どこでもglGetErrorを呼び出そうとしましたか? – Tim