리눅스 & 안드로이드2011. 8. 11. 10:11
Google에서 RenderScript 강화 하는듯 하다.
이미 HoneyComb이 릴리즈 되면서 부터 RenderScript도 공식적으로 사용할 수 있게 되어 있다.

그런데 관련된 자료가 많지 않다.
강화 한다고 하면 Google에서 대대적으로 자료를 공개하고 널리널리 전파해야 하는거 아닌가?
Microsoft와는 너무도 다른 행보...

아직 준비가 덜 되었을 수도 있고, 정리가 덜 되었을 수도 있고...
암튼, RenderScript에서 사용할 수 있다는 A3D File Format에 대해 분석 해 본다.
(HoneyComb 소스가 있는것도 아니고, 그렇다고 HoneyComb device가 있는것도 아니고, 그냥 Froyo의 framework source에 있는 파일들로 분석 해 본다. 소가 뒷 걸음질 치다가 쥐를 잡기를 바라며...)


우선 아래 세 개의 파일에서부터 시작 해 보자.

android/frameworks/base/libs/rs/rsFileA3D.h
android/frameworks/base/libs/rs/rsFileA3D.cpp
android/frameworks/base/libs/rs/rsMesh.h




[Phase #1] A3DIndexEntry Vector를 완성하는 단계
 

12 bytes: magic string "Android3D_ff"

4 bytes: major version
4 bytes: minor version
4 bytes: flag
(64bit data type 사용여부, 0 아니면 1)
8 bytes: data size
(실제로는 파일 크기와 동일
flag에따라 4 bytes 또는 8 bytes가 될 수 있음
여기서는 flag 값을 1로 간주하고 8 bytes로 표시)
8 bytes: index offset
8 bytes:  string offset

<12 bytes + index offset> -----> mIndex Vector를 구성
4 bytes: index entry count

A3DIndexEntry
4 bytes:  string index
4 bytes: A3DChunkType

8 bytes: offset
... chunk type에 따라 Phase #2에서 처럼 추가 data가 존재할 수 있을 듯 ...
... 실제 A3D sample file을 구해서 까보지 않는 이상은 두루뭉술하게-_-; ...

...
(index entry count 개수 만큼)
...

A3DIndexEntry
4 bytes:  string index
4 bytes: A3DChunkType

8 bytes: offset
... chunk type에 따라 Phase #2에서 처럼 추가 data가 존재할 수 있을 듯 ...
... 실제 A3D sample file을 구해서 까보지 않는 이상은 두루뭉술하게-_-; ...

<12 bytes + string offset> -----> mStrings Vector를 구성
4 bytes: string entry count
4 bytes: string type (반드시 0)

8 bytes: offset for string entry data
4 bytes: string length N (실제로는 12 bytes + offset for string entry data)
N bytes: string data 

...
(string entry count 개수 만큼)
...

8 bytes: offset for string entry data
4 bytes: string length N (실제로는 12 bytes + offset for string entry data)
N bytes: string data


[참고1] 3 개의 Vector로 구성 됨
* mStrings - Vector of String8
* mStringsIndexValues - Vector of uint32_t
* mIndex - Vector of A3DIndexEntry

[참고2] A3DIndexEntry의 구성
.mID = mStrings[string index]
.mType = A3DChunkType
.mOffset = 8 bytes offset

[참고3] mStringIndexValues Vector는 mStrings Vector와 mIndex를 mapping하는 역할을 한다
mIndex

mStringIndexValues


mStrings
 A3DIndexEntry [0]
0 [0] ------------ [0] string8
A3DIndexEntry  [1] 3 [1] ------------ [1] string8
A3DIndexEntry  [2] 2 [2] ------------ [2] string8
A3DIndexEntry [3] 1 [3] ------------ [3] string8
A3DIndexEntry [4]
5 [4] ------------ [4] string8
A3DIndexEntry [5]
4 [5] ------------ [5] string8
* mStringIndexValues[string index] = mIndex Vector의 index
* 대각선을 그릴 수 없어 색상으로 mapping :-)



[Phase #2] A3DIndexEntry Vector entry 각각을 처리하는 단계

앞서 Phase #1에서 완성 된 mIndex Vector의 각 항목에 대해 index entry count 개수만큼 반복하여 수행된다.

<CHUNK_ELEMENT>
comment 처리가 되어 있어 skip! 앞으로 어떻게 바뀔지 모른다!


<CHUNK_ELEMENT_SOURCE>
4 bytes: index
4 bytes: count
sizeof(float) *
   count bytes: data


<CHUNK_VERTICIES>
4 bytes: allocation count
4 * allocation count bytes: indices of mIndex Vector 


<CHUNK_MESH>
4 bytes: primitives count
4  * primitives count bytes: indices of mIndex Vector


<CHUNK_PRIMITIVE>
4 bytes: index count
4 bytes: index of mIndex Vector for the verticies
2 bytes: restart counts
1 byte: bits (8 / 16 / 32)
1 byte: primitive type


bits * index count bytes: indices for primitive
bits * restart counts bytes: indices for restart ??? (restart counts가 0보다 큰 경우)


Posted by 세월의돌