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