1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_RS_FILE_A3D_H 18 #define ANDROID_RS_FILE_A3D_H 19 20 #include "RenderScript.h" 21 #include "rsFileA3DDecls.h" 22 #include "rsMesh.h" 23 24 #include <utils/String8.h> 25 #include <stdio.h> 26 27 // --------------------------------------------------------------------------- 28 namespace android { 29 namespace renderscript { 30 31 class FileA3D 32 { 33 public: 34 FileA3D(); 35 ~FileA3D(); 36 37 uint32_t mMajorVersion; 38 uint32_t mMinorVersion; 39 uint64_t mIndexOffset; 40 uint64_t mStringTableOffset; 41 bool mUse64BitOffsets; 42 43 struct A3DIndexEntry { 44 String8 mID; 45 A3DChunkType mType; 46 uint64_t mOffset; 47 void * mRsObj; 48 }; 49 50 bool load(Context *rsc, FILE *f); 51 52 protected: 53 class IO 54 { 55 public: 56 IO(const uint8_t *, bool use64); 57 58 float loadF() { 59 mPos = (mPos + 3) & (~3); 60 float tmp = reinterpret_cast<const float *>(&mData[mPos])[0]; 61 mPos += sizeof(float); 62 return tmp; 63 } 64 int32_t loadI32() { 65 mPos = (mPos + 3) & (~3); 66 int32_t tmp = reinterpret_cast<const int32_t *>(&mData[mPos])[0]; 67 mPos += sizeof(int32_t); 68 return tmp; 69 } 70 uint32_t loadU32() { 71 mPos = (mPos + 3) & (~3); 72 uint32_t tmp = reinterpret_cast<const uint32_t *>(&mData[mPos])[0]; 73 mPos += sizeof(uint32_t); 74 return tmp; 75 } 76 uint16_t loadU16() { 77 mPos = (mPos + 1) & (~1); 78 uint16_t tmp = reinterpret_cast<const uint16_t *>(&mData[mPos])[0]; 79 mPos += sizeof(uint16_t); 80 return tmp; 81 } 82 uint8_t loadU8() { 83 uint8_t tmp = reinterpret_cast<const uint8_t *>(&mData[mPos])[0]; 84 mPos += sizeof(uint8_t); 85 return tmp; 86 } 87 uint64_t loadOffset(); 88 void loadString(String8 *s); 89 uint64_t getPos() const {return mPos;} 90 const uint8_t * getPtr() const; 91 protected: 92 const uint8_t * mData; 93 uint64_t mPos; 94 bool mUse64; 95 }; 96 97 98 bool process(Context *rsc); 99 bool processIndex(Context *rsc, A3DIndexEntry *); 100 void processChunk_Mesh(Context *rsc, IO *io, A3DIndexEntry *ie); 101 void processChunk_Primitive(Context *rsc, IO *io, A3DIndexEntry *ie); 102 void processChunk_Verticies(Context *rsc, IO *io, A3DIndexEntry *ie); 103 void processChunk_Element(Context *rsc, IO *io, A3DIndexEntry *ie); 104 void processChunk_ElementSource(Context *rsc, IO *io, A3DIndexEntry *ie); 105 106 const uint8_t * mData; 107 void * mAlloc; 108 uint64_t mDataSize; 109 Context * mRsc; 110 111 Vector<A3DIndexEntry> mIndex; 112 Vector<String8> mStrings; 113 Vector<uint32_t> mStringIndexValues; 114 115 }; 116 117 118 } 119 } 120 #endif //ANDROID_RS_FILE_A3D_H 121 122 123