1 // Copyright 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifdef USE_ANGLE_SHADER_PARSER
16 #pragma once
17 
18 #include <functional>
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include <GLES2/gl2.h>
24 
25 
26 #include "ShaderTranslator.h"
27 
28 namespace ANGLEShaderParser {
29 
30 // Convenient to query those
31 extern ST_BuiltInResources kResources;
32 
33 // For performing link-time validation of shader programs.
34 struct ShaderLinkInfo {
35     int esslVersion;
36     std::vector<ST_ShaderVariable> uniforms;
37     std::vector<ST_ShaderVariable> varyings;
38     std::vector<ST_ShaderVariable> attributes;
39     std::vector<ST_ShaderVariable> outputVars;
40     std::vector<ST_InterfaceBlock> interfaceBlocks;
41     std::map<std::string, std::string> nameMap;
42     std::map<std::string, std::string> nameMapReverse;
43 
44     ShaderLinkInfo();
45     ShaderLinkInfo(const ShaderLinkInfo& other);
46     ShaderLinkInfo& operator=(const ShaderLinkInfo& other);
47     ShaderLinkInfo(ShaderLinkInfo&& other);
48     ShaderLinkInfo& operator=(ShaderLinkInfo&& other);
49     ~ShaderLinkInfo();
50 
51 protected:
52     void copyFromOther(const ShaderLinkInfo& other);
53     void clear();
54 };
55 
56 using BuiltinResourcesEditCallback = std::function<void(ST_BuiltInResources&)>;
57 
58 bool globalInitialize(
59     bool isGles2Gles,
60     BuiltinResourcesEditCallback callback);
61 
62 bool translate(bool hostUsesCoreProfile,
63                const char* src, GLenum shaderType,
64                std::string* outInfolog, std::string* outObjCode,
65                ShaderLinkInfo* outShaderLinkInfo);
66 
67 } // namespace ANGLEShaderParser
68 
69 #endif
70