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