summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsFileA3D.h
blob: 9ee08ec43f5810f3791e922ce7e277b8896d3fc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_RS_FILE_A3D_H
#define ANDROID_RS_FILE_A3D_H

#include "RenderScript.h"
#include "rsFileA3DDecls.h"
#include "rsMesh.h"

#include <utils/String8.h>
#include <stdio.h>

// ---------------------------------------------------------------------------
namespace android {
namespace renderscript {

class FileA3D
{
public:
    FileA3D();
    ~FileA3D();

    uint32_t mMajorVersion;
    uint32_t mMinorVersion;
    uint64_t mIndexOffset;
    uint64_t mStringTableOffset;
    bool mUse64BitOffsets;

    struct A3DIndexEntry {
        String8 mID;
        A3DChunkType mType;
        uint64_t mOffset;
        void * mRsObj;
    };

    bool load(Context *rsc, FILE *f);

protected:
    class IO
    {
    public:
        IO(const uint8_t *, bool use64);
    
        float loadF() {
            mPos = (mPos + 3) & (~3);
            float tmp = reinterpret_cast<const float *>(&mData[mPos])[0];
            mPos += sizeof(float);
            return tmp;
        }
        int32_t loadI32() {
            mPos = (mPos + 3) & (~3);
            int32_t tmp = reinterpret_cast<const int32_t *>(&mData[mPos])[0];
            mPos += sizeof(int32_t);
            return tmp;
        }
        uint32_t loadU32() {
            mPos = (mPos + 3) & (~3);
            uint32_t tmp = reinterpret_cast<const uint32_t *>(&mData[mPos])[0];
            mPos += sizeof(uint32_t);
            return tmp;
        }
        uint16_t loadU16() {
            mPos = (mPos + 1) & (~1);
            uint16_t tmp = reinterpret_cast<const uint16_t *>(&mData[mPos])[0];
            mPos += sizeof(uint16_t);
            return tmp;
        }
        uint8_t loadU8() {
            uint8_t tmp = reinterpret_cast<const uint8_t *>(&mData[mPos])[0];
            mPos += sizeof(uint8_t);
            return tmp;
        }
        uint64_t loadOffset();
        void loadString(String8 *s);
        uint64_t getPos() const {return mPos;}
        const uint8_t * getPtr() const;
    protected:
        const uint8_t * mData;
        uint64_t mPos;
        bool mUse64;
    };


    bool process(Context *rsc);
    bool processIndex(Context *rsc, A3DIndexEntry *);
    void processChunk_Mesh(Context *rsc, IO *io, A3DIndexEntry *ie);
    void processChunk_Primitive(Context *rsc, IO *io, A3DIndexEntry *ie);
    void processChunk_Verticies(Context *rsc, IO *io, A3DIndexEntry *ie);
    void processChunk_Element(Context *rsc, IO *io, A3DIndexEntry *ie);
    void processChunk_ElementSource(Context *rsc, IO *io, A3DIndexEntry *ie);

    const uint8_t * mData;
    void * mAlloc;
    uint64_t mDataSize;
    Context * mRsc;

    Vector<A3DIndexEntry> mIndex;
    Vector<String8> mStrings;
    Vector<uint32_t> mStringIndexValues;

};


}
}
#endif //ANDROID_RS_FILE_A3D_H