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