• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef SAMPLE_UTIL_SHADER_UTILS_H
8 #define SAMPLE_UTIL_SHADER_UTILS_H
9 
10 #include <functional>
11 #include <map>
12 #include <string>
13 #include <vector>
14 
15 #include "common/angleutils.h"
16 #include "util/util_export.h"
17 #include "util/util_gl.h"
18 
19 ANGLE_UTIL_EXPORT GLuint CheckLinkStatusAndReturnProgram(GLuint program, bool outputErrorMessages);
20 ANGLE_UTIL_EXPORT GLuint GetProgramShader(GLuint program, GLint requestedType);
21 ANGLE_UTIL_EXPORT GLuint CompileShader(GLenum type, const char *source);
22 ANGLE_UTIL_EXPORT GLuint CompileShaderFromFile(GLenum type, const std::string &sourcePath);
23 
24 ANGLE_UTIL_EXPORT GLuint
25 CompileProgramWithTransformFeedback(const char *vsSource,
26                                     const char *fsSource,
27                                     const std::vector<std::string> &transformFeedbackVaryings,
28                                     GLenum bufferMode);
29 
30 ANGLE_UTIL_EXPORT GLuint CompileProgram(const char *vsSource, const char *fsSource);
31 
32 ANGLE_UTIL_EXPORT GLuint CompileProgram(const char *vsSource,
33                                         const char *fsSource,
34                                         const std::function<void(GLuint)> &preLinkCallback);
35 
36 ANGLE_UTIL_EXPORT GLuint CompileProgramWithGS(const char *vsSource,
37                                               const char *gsSource,
38                                               const char *fsSource);
39 ANGLE_UTIL_EXPORT GLuint CompileProgramWithTESS(const char *vsSource,
40                                                 const char *tcsSource,
41                                                 const char *tesSource,
42                                                 const char *fsSource);
43 ANGLE_UTIL_EXPORT GLuint CompileProgramFromFiles(const std::string &vsPath,
44                                                  const std::string &fsPath);
45 ANGLE_UTIL_EXPORT GLuint CompileComputeProgram(const char *csSource,
46                                                bool outputErrorMessages = true);
47 ANGLE_UTIL_EXPORT bool LinkAttachedProgram(GLuint program);
48 
49 ANGLE_UTIL_EXPORT GLuint LoadBinaryProgramOES(const std::vector<uint8_t> &binary,
50                                               GLenum binaryFormat);
51 ANGLE_UTIL_EXPORT GLuint LoadBinaryProgramES3(const std::vector<uint8_t> &binary,
52                                               GLenum binaryFormat);
53 
54 ANGLE_UTIL_EXPORT void EnableDebugCallback(GLDEBUGPROC callbackChain, const void *userParam);
55 
56 using CounterNameToIndexMap = std::map<std::string, GLuint>;
57 using CounterNameToValueMap = std::map<std::string, GLuint>;
58 
59 ANGLE_UTIL_EXPORT CounterNameToIndexMap BuildCounterNameToIndexMap();
60 ANGLE_UTIL_EXPORT angle::VulkanPerfCounters GetPerfCounters(const CounterNameToIndexMap &indexMap);
61 ANGLE_UTIL_EXPORT CounterNameToValueMap BuildCounterNameToValueMap();
62 ANGLE_UTIL_EXPORT std::vector<angle::PerfMonitorTriplet> GetPerfMonitorTriplets();
63 
64 namespace angle
65 {
66 
67 namespace essl1_shaders
68 {
69 
70 ANGLE_UTIL_EXPORT const char *PositionAttrib();
71 ANGLE_UTIL_EXPORT const char *ColorUniform();
72 ANGLE_UTIL_EXPORT const char *Texture2DUniform();
73 
74 namespace vs
75 {
76 
77 // A shader that sets gl_Position to zero.
78 ANGLE_UTIL_EXPORT const char *Zero();
79 
80 // A shader that sets gl_Position to attribute a_position.
81 ANGLE_UTIL_EXPORT const char *Simple();
82 
83 // A shader that passes through attribute a_position, setting it to gl_Position and varying
84 // v_position.
85 ANGLE_UTIL_EXPORT const char *Passthrough();
86 
87 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying
88 // texcoord.
89 ANGLE_UTIL_EXPORT const char *Texture2D();
90 
91 }  // namespace vs
92 
93 namespace fs
94 {
95 
96 // A shader that renders a simple checker pattern of different colors. X axis and Y axis separate
97 // the different colors. Needs varying v_position.
98 //
99 // - X < 0 && y < 0: Red
100 // - X < 0 && y >= 0: Green
101 // - X >= 0 && y < 0: Blue
102 // - X >= 0 && y >= 0: Yellow
103 ANGLE_UTIL_EXPORT const char *Checkered();
104 
105 // A shader that fills with color taken from uniform named "color".
106 ANGLE_UTIL_EXPORT const char *UniformColor();
107 
108 // A shader that fills with 100% opaque red.
109 ANGLE_UTIL_EXPORT const char *Red();
110 
111 // A shader that fills with 100% opaque green.
112 ANGLE_UTIL_EXPORT const char *Green();
113 
114 // A shader that fills with 100% opaque blue.
115 ANGLE_UTIL_EXPORT const char *Blue();
116 
117 // A shader that samples the texture
118 ANGLE_UTIL_EXPORT const char *Texture2D();
119 
120 }  // namespace fs
121 }  // namespace essl1_shaders
122 
123 namespace essl3_shaders
124 {
125 
126 ANGLE_UTIL_EXPORT const char *PositionAttrib();
127 ANGLE_UTIL_EXPORT const char *Texture2DUniform();
128 ANGLE_UTIL_EXPORT const char *LodUniform();
129 
130 namespace vs
131 {
132 
133 // A shader that sets gl_Position to zero.
134 ANGLE_UTIL_EXPORT const char *Zero();
135 
136 // A shader that sets gl_Position to attribute a_position.
137 ANGLE_UTIL_EXPORT const char *Simple();
138 
139 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying
140 // v_position.
141 ANGLE_UTIL_EXPORT const char *Passthrough();
142 
143 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying
144 // texcoord.
145 ANGLE_UTIL_EXPORT const char *Texture2DLod();
146 
147 }  // namespace vs
148 
149 namespace fs
150 {
151 
152 // A shader that fills with 100% opaque red.
153 ANGLE_UTIL_EXPORT const char *Red();
154 
155 // A shader that fills with 100% opaque green.
156 ANGLE_UTIL_EXPORT const char *Green();
157 
158 // A shader that fills with 100% opaque blue.
159 ANGLE_UTIL_EXPORT const char *Blue();
160 
161 // A shader that samples the texture at a given lod.
162 ANGLE_UTIL_EXPORT const char *Texture2DLod();
163 
164 }  // namespace fs
165 }  // namespace essl3_shaders
166 
167 namespace essl31_shaders
168 {
169 
170 ANGLE_UTIL_EXPORT const char *PositionAttrib();
171 
172 namespace vs
173 {
174 
175 // A shader that sets gl_Position to zero.
176 ANGLE_UTIL_EXPORT const char *Zero();
177 
178 // A shader that sets gl_Position to attribute a_position.
179 ANGLE_UTIL_EXPORT const char *Simple();
180 
181 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying
182 // v_position.
183 ANGLE_UTIL_EXPORT const char *Passthrough();
184 
185 }  // namespace vs
186 
187 namespace fs
188 {
189 
190 // A shader that fills with 100% opaque red.
191 ANGLE_UTIL_EXPORT const char *Red();
192 
193 // A shader that fills with 100% opaque green.
194 ANGLE_UTIL_EXPORT const char *Green();
195 
196 // A shader that renders a simple gradient of red to green. Needs varying v_position.
197 ANGLE_UTIL_EXPORT const char *RedGreenGradient();
198 
199 }  // namespace fs
200 }  // namespace essl31_shaders
201 }  // namespace angle
202 
203 #endif  // SAMPLE_UTIL_SHADER_UTILS_H
204