rsFileA3D.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #ifndef ANDROID_RS_FILE_A3D_H
  17. #define ANDROID_RS_FILE_A3D_H
  18. #include "rsMesh.h"
  19. #include "rsStream.h"
  20. #include <stdio.h>
  21. #include <vector>
  22. #define A3D_MAGIC_KEY "Android3D_ff"
  23. // ---------------------------------------------------------------------------
  24. namespace android {
  25. class Asset;
  26. namespace renderscript {
  27. class FileA3D : public ObjectBase {
  28. public:
  29. explicit FileA3D(Context *rsc);
  30. ~FileA3D();
  31. uint32_t mMajorVersion;
  32. uint32_t mMinorVersion;
  33. uint64_t mIndexOffset;
  34. uint64_t mStringTableOffset;
  35. bool mUse64BitOffsets;
  36. class A3DIndexEntry {
  37. const char *mObjectName;
  38. RsA3DClassID mType;
  39. uint64_t mOffset;
  40. uint64_t mLength;
  41. ObjectBase *mRsObj;
  42. public:
  43. friend class FileA3D;
  44. const char *getObjectName() const {
  45. return mObjectName;
  46. }
  47. RsA3DClassID getType() const {
  48. return mType;
  49. }
  50. ~A3DIndexEntry();
  51. };
  52. bool load(FILE *f);
  53. bool load(Asset *asset);
  54. bool load(const void *data, size_t length);
  55. size_t getNumIndexEntries() const;
  56. const A3DIndexEntry* getIndexEntry(size_t index) const;
  57. ObjectBase *initializeFromEntry(size_t index);
  58. void appendToFile(Context *rsc, ObjectBase *obj);
  59. bool writeFile(const char *filename);
  60. // Currently files do not get serialized,
  61. // but we need to inherit from ObjectBase for ref tracking
  62. virtual void serialize(Context *rsc, OStream *stream) const {
  63. }
  64. virtual RsA3DClassID getClassId() const {
  65. return RS_A3D_CLASS_ID_UNKNOWN;
  66. }
  67. protected:
  68. void parseHeader(IStream *headerStream);
  69. const uint8_t * mData;
  70. void * mAlloc;
  71. uint64_t mDataSize;
  72. OStream *mWriteStream;
  73. std::vector<A3DIndexEntry*> mWriteIndex;
  74. IStream *mReadStream;
  75. std::vector<A3DIndexEntry*> mIndex;
  76. };
  77. } // namespace renderscript
  78. } // namespace android
  79. #endif //ANDROID_RS_FILE_A3D_H