1 /*
2 * Copyright (C) 2011 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 #pragma once
17 
18 #include <array>
19 #include <vector>
20 
21 // Convenient class used to hold the common context data shared
22 // by both the GLESv1 and GLESv2 decoders. This corresponds to
23 // vertex attribute buffers.
24 class  GLDecoderContextData {
25 public:
26     // List of supported vertex attribute indices, as they appear in
27     // a glVertexAttribPointer() call.
28     enum PointerDataLocation {
29         VERTEX_LOCATION = 0,
30         NORMAL_LOCATION = 1,
31         COLOR_LOCATION = 2,
32         POINTSIZE_LOCATION = 3,
33         TEXCOORD0_LOCATION = 4,
34         TEXCOORD1_LOCATION = 5,
35         TEXCOORD2_LOCATION = 6,
36         TEXCOORD3_LOCATION = 7,
37         TEXCOORD4_LOCATION = 8,
38         TEXCOORD5_LOCATION = 9,
39         TEXCOORD6_LOCATION = 10,
40         TEXCOORD7_LOCATION = 11,
41         MATRIXINDEX_LOCATION = 12,
42         WEIGHT_LOCATION = 13,
43         LAST_LOCATION = 14
44     };
45 
46     // Store |len| bytes from |data| into the buffer associated with
47     // vertex attribute index |loc|.
storePointerData(unsigned int loc,void * data,size_t len)48     void storePointerData(unsigned int loc, void *data, size_t len) {
49         if (loc < mPointerData.size()) {
50             auto& ptrData = mPointerData[loc];
51             ptrData.assign(reinterpret_cast<char*>(data),
52                            reinterpret_cast<char*>(data) + len);
53         } else {
54             // User error, don't do anything here
55         }
56     }
57 
58     // Return pointer to data associated with vertex attribute index |loc|
pointerData(unsigned int loc)59     void* pointerData(unsigned int loc) const {
60         if (loc < mPointerData.size()) {
61             return const_cast<char*>(mPointerData[loc].data());
62         } else {
63             // User error. Return nullptr.
64             return nullptr;
65         }
66     }
67 
68 private:
69     static const int kMaxVertexAttributes = 16;
70 
71     std::array<std::vector<char>, kMaxVertexAttributes> mPointerData = {};
72 };