Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 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 | |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 20 | #include "rsMesh.h" |
| 21 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 22 | #include "rsStream.h" |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 23 | #include <stdio.h> |
| 24 | |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 25 | #define A3D_MAGIC_KEY "Android3D_ff" |
| 26 | |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 27 | // --------------------------------------------------------------------------- |
| 28 | namespace android { |
Jason Sams | a6ab26a | 2012-03-28 17:44:21 -0700 | [diff] [blame] | 29 | class Asset; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 30 | |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 31 | namespace renderscript { |
| 32 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 33 | class FileA3D : public ObjectBase { |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 34 | public: |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 35 | FileA3D(Context *rsc); |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 36 | ~FileA3D(); |
| 37 | |
| 38 | uint32_t mMajorVersion; |
| 39 | uint32_t mMinorVersion; |
| 40 | uint64_t mIndexOffset; |
| 41 | uint64_t mStringTableOffset; |
| 42 | bool mUse64BitOffsets; |
| 43 | |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 44 | class A3DIndexEntry { |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 45 | const char *mObjectName; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 46 | RsA3DClassID mType; |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 47 | uint64_t mOffset; |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 48 | uint64_t mLength; |
| 49 | ObjectBase *mRsObj; |
| 50 | public: |
| 51 | friend class FileA3D; |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 52 | const char *getObjectName() const { |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 53 | return mObjectName; |
| 54 | } |
| 55 | RsA3DClassID getType() const { |
| 56 | return mType; |
| 57 | } |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 58 | |
| 59 | ~A3DIndexEntry(); |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 62 | bool load(FILE *f); |
Alex Sakhartchouk | 5224a27 | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 63 | bool load(Asset *asset); |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 64 | bool load(const void *data, size_t length); |
| 65 | |
| 66 | size_t getNumIndexEntries() const; |
| 67 | const A3DIndexEntry* getIndexEntry(size_t index) const; |
| 68 | ObjectBase *initializeFromEntry(size_t index); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 69 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 70 | void appendToFile(Context *rsc, ObjectBase *obj); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 71 | bool writeFile(const char *filename); |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 72 | |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 73 | // Currently files do not get serialized, |
| 74 | // but we need to inherit from ObjectBase for ref tracking |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 75 | virtual void serialize(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 76 | } |
| 77 | virtual RsA3DClassID getClassId() const { |
| 78 | return RS_A3D_CLASS_ID_UNKNOWN; |
| 79 | } |
| 80 | |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 81 | protected: |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 82 | |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 83 | void parseHeader(IStream *headerStream); |
| 84 | |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 85 | const uint8_t * mData; |
| 86 | void * mAlloc; |
| 87 | uint64_t mDataSize; |
Alex Sakhartchouk | 5224a27 | 2011-01-07 11:12:08 -0800 | [diff] [blame] | 88 | Asset *mAsset; |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 89 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 90 | OStream *mWriteStream; |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 91 | std::vector<A3DIndexEntry*> mWriteIndex; |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 92 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 93 | IStream *mReadStream; |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 94 | std::vector<A3DIndexEntry*> mIndex; |
Jason Sams | a5597fc | 2009-07-08 18:01:53 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | |
| 98 | } |
| 99 | } |
| 100 | #endif //ANDROID_RS_FILE_A3D_H |