왜 텍스처가 너무 많은 공간을 차지합니까? 내 응용 프로그램의 램 사용을보고 내 휴대 전화에서 작업 관리자를 사용하는 경우는 말한다Android : OpenGL 텍스처가 너무 커서 이유를 알아낼 수 없습니다
Used heap dump 1.8 MB
Number of objects 49,447
Number of classes 2,257
Number of class loaders 4
Number of GC roots 8,551
Format hprof
JVM version
Time 1:08:15 AM GMT+02:00
Date Oct 2, 2011
Identifier size 32-bit
그러나 : 많이 OpenGL을 사용
내 애플, 운전 중에 다음과 같은 힙 통계 *를 생산 내 애플 리케이션은 44.42 메가 바이트를 사용합니다. 힙 크기 사용과 램 사용 사이에 어떤 관계가 있습니까? 나는 42MB의 많은 것들이 내 열린 GL 텍스처라고 생각하지만, 왜 디스크에 모든 파일들이 합쳐져서 24MB를 차지하기 때문에 그들이 왜 그렇게 많은 공간을 차지하는지 알 수 없다. 시각). 그리고 텍스쳐를로드하기 전에 비트 맵의 크기를 조절하여 많은 것들을 더 작게 만들 수도 있습니다. 또한 동적으로 일부 텍스처를 만들지 만 사용 후에는 텍스처를 파괴합니다.
내가 OpenGL을 1.0과 안드로이드 2.2을 사용하고, 나는 텍스처를로드하는 데 사용하는 전형적인 코드는 다음과 같습니다
public int load_texture(int res_id){
if(mBitmapOpts==null){
mBitmapOpts = new BitmapFactory.Options();
mBitmapOpts.inScaled = false;
}
mBtoLoad = BitmapFactory.decodeResource(MyApplicationObject.getContext().getResources(),res_id, mBitmapOpts);
assert mBtoLoad != null;
return GraphicsOperations.set_gl_texture(mBtoLoad);
}
:
내가 비트 맵을로드하는 데 사용
static int set_gl_texture(Bitmap bitmap){
bitmap = Bitmap.createScaledBitmap(bitmap, 256, 256, true);
// generate one texture pointer
mGL.glGenTextures(1, mTextures, 0);
mGL.glBindTexture(GL10.GL_TEXTURE_2D, mTextures[0]); // A bound texture is
// an active texture
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0,GL10.GL_RGBA, bitmap, 0);
// create nearest filtered texture
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR); // This is where the scaling algorithms are
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR); // This is where the scaling algorithms are
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
mGL.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_CLAMP_TO_EDGE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
Log.v("GLSurfaceView", "Loading Texture Finished, Error Codes:"+mGL.glGetError());
return mTextures[0];
}
코드는 다음과 같습니다
* 매트를 사용하여 hprof 파일을 분석하면 같은 데이터가 eclipse ddms에서 생성됩니다.
메모리가 압축 해제 후 해제됩니다. – fazo
OpenGL 컨텍스트에 푸시 된 후 데이터가 여전히 메모리에 있습니다. 하지만 비트 맵 자체와 같은 데이터는 아닙니다. glTexImage2D를 사용하기 전후에 네이티브 메모리 사용량을 출력하여 테스트 할 수 있습니다. – David