2015-01-05 1 views
0

내 안드로이드 응용 프로그램에서 압축 텍스처를 사용하려고합니다. 텍스처를로드하는 데 문제가 있습니다. 텍스처가 오브젝트의 오른쪽에 "컷오프"된 것처럼 보입니다.ATI 압축 텍스처 읽기 문제

텍스처를 압축하는 데 ATI의 "TheCompressonator"를 사용하고 있습니다. 테스트 용으로 Nexus 5를 사용하고 있습니다.

문제가 "계산 된"크기의 텍스처 인 것으로 의심되지만이 압축 형식의 refenreces/specification을 찾을 수 없습니다.

누구든지이 파일 형식을 올바르게 읽는 방법을 알고 있습니까?

Nexus 5, blowfish right side is cut off 여기

그것을보고해야 다음은 Samsung tab 2, this is how blowfish should look

(그에 대한 이미지가 누락 된 검은 물체의 질감 상관 없어)하는 방법이다 : 여기

는 넥서스에서 스크린 샷입니다 내 코드 스 니펫.

final int[] textureObjectIds = new int[1]; 

glGenTextures(1, textureObjectIds, 0); 

if(textureObjectIds[0] == 0){ 
    logTextureHelper(Log.WARN, "Could not generate a new OpenGL texture object"); 
    return 0; 
} 

final InputStream bitmap = context.getResources().openRawResource(resourceId); 
byte[] buffer; 
ByteBuffer bf; 

try { 
    buffer = new byte[bitmap.available()]; 
    bitmap.read(buffer); 

    int offset = 0; // 64 bit = header, 15 bit = metadata 
    bf = ByteBuffer.wrap(buffer, offset, buffer.length-offset); 
    bf.order(ByteOrder.LITTLE_ENDIAN); 

    int height = bf.getInt(16); 
    int width = bf.getInt(12); 


    int size = ((height + 3)/4) * ((width + 3)/4) * 16; 
    Log.d("TextureHelper","Buffer size: "+width+" "+height+" "+size); 

    glBindTexture(GL_TEXTURE_2D, textureObjectIds[0]); 

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); 
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); 
    glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); 
    glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); 


    GLES20.glCompressedTexImage2D(GL_TEXTURE_2D, 0,ATC_RGBA_EXPLICIT_ALPHA_AMD, width, height, 0, size, bf); 
    Log.d("TextureHelper","Buffer size: "+bf.capacity()+" : "+buffer.length+" error:"+GLES20.glGetError()); 

    glBindTexture(GL_TEXTURE_2D, 0); //unbind texture 

} catch (IOException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 

return textureObjectIds[0]; 

편집 : 솔루션

buffer = new byte[bitmap.available()]; 
      bitmap.read(buffer); 

      int offset = 128; // 64 bit = header, 15 bit = metadata 
      bf = ByteBuffer.wrap(buffer, offset, buffer.length-offset); 
      bf.order(ByteOrder.LITTLE_ENDIAN); 

      int height = bf.getInt(16); 
      int width = bf.getInt(12); 


      int size = ((height + 3)/4) * ((width + 3)/4) * 16; 
      Log.d("TextureHelper","Buffer size: "+width+" "+height+" "+size); 


      bf.compact();///////SOLUTION! 
      bf.position(0); 


      glBindTexture(GL_TEXTURE_2D, textureObjectIds[0]); 

      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); 
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); 
      glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); 
      glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); 


      GLES20.glCompressedTexImage2D(GL_TEXTURE_2D, 0,ATC_RGBA_EXPLICIT_ALPHA_AMD, width, height, 0, size, bf); 
      Log.d("TextureHelper","Buffer size: "+bf.capacity()+" : "+buffer.length+" error:"+GLES20.glGetError()); 

      glBindTexture(GL_TEXTURE_2D, 0); //unbind texture 

참고 : 당신은 당신이 단지 위치 (128) 오프셋 (offset)를 가지는 경우, 0 위치에 데이터를하는 것이 잘못된 포인터 예외가 발생합니다 필요합니다.

답변

1

크기 계산이 정확하지만 이미지 데이터로 헤더를 업로드하고 있습니다. 후에 너비와 높이를 머리글에서 추출한 다음 머리글을 건너 뛰고 이미지 데이터를 가리 키기 위해 바이트 버퍼를 적절한 크기만큼 오프셋합니다.

이렇게 할 수있는 방법이 몇 가지 있지만이 예제는 두 번째 바이트 버퍼를 제거하기 위해 최적화 할 수 있습니다. 또한 어떤 텍스쳐 포맷을 사용하고 있는지 잘 모르겠다. 헤더는 124 바이트라고 가정하자.

// assumption that buffer[] is the fully loaded contents of the file 
byte[] buffer = ... // load entire file from input stream 

// read the header 
ByteBuffer bfHeader = ByteBuffer.wrap(buffer); 
bfHeader.order(ByteOrder.LITTLE_ENDIAN); 

int height = bfHeader.getInt(16); 
int width = bfHeader.getInt(12); 

// offset to image data 
int headerSize = 124; // (replace with correct header size) 
ByteBuffer bfData = ByteBuffer.wrap(buffer, headerSize, buffer.length-headerSize); 
bfData.order(ByteOrder.LITTLE_ENDIAN); 

// load image data 
int size = ((height + 3)/4) * ((width + 3)/4) * 16; 
glBindTexture(GL_TEXTURE_2D, textureObjectIds[0]); 
GLES20.glCompressedTexImage2D(GL_TEXTURE_2D, 0,ATC_RGBA_EXPLICIT_ALPHA_AMD, width, height, 0, size, bfData);