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, GLuint64>; 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 sets gl_Position to attribute a_position, and sets gl_PointSize to 1. 84 ANGLE_UTIL_EXPORT const char *SimpleForPoints(); 85 86 // A shader that passes through attribute a_position, setting it to gl_Position and varying 87 // v_position. 88 ANGLE_UTIL_EXPORT const char *Passthrough(); 89 90 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying 91 // texcoord. 92 ANGLE_UTIL_EXPORT const char *Texture2D(); 93 ANGLE_UTIL_EXPORT const char *Texture2DArray(); 94 95 } // namespace vs 96 97 namespace fs 98 { 99 100 // A shader that renders a simple checker pattern of different colors. X axis and Y axis separate 101 // the different colors. Needs varying v_position. 102 // 103 // - X < 0 && y < 0: Red 104 // - X < 0 && y >= 0: Green 105 // - X >= 0 && y < 0: Blue 106 // - X >= 0 && y >= 0: Yellow 107 ANGLE_UTIL_EXPORT const char *Checkered(); 108 109 // A shader that fills with color taken from uniform named "color". 110 ANGLE_UTIL_EXPORT const char *UniformColor(); 111 112 // A shader that fills with 100% opaque red. 113 ANGLE_UTIL_EXPORT const char *Red(); 114 115 // A shader that fills with 100% opaque green. 116 ANGLE_UTIL_EXPORT const char *Green(); 117 118 // A shader that fills with 100% opaque blue. 119 ANGLE_UTIL_EXPORT const char *Blue(); 120 121 // A shader that samples the texture 122 ANGLE_UTIL_EXPORT const char *Texture2D(); 123 ANGLE_UTIL_EXPORT const char *Texture2DArray(); 124 125 } // namespace fs 126 } // namespace essl1_shaders 127 128 namespace essl3_shaders 129 { 130 131 ANGLE_UTIL_EXPORT const char *PositionAttrib(); 132 ANGLE_UTIL_EXPORT const char *Texture2DUniform(); 133 ANGLE_UTIL_EXPORT const char *LodUniform(); 134 135 namespace vs 136 { 137 138 // A shader that sets gl_Position to zero. 139 ANGLE_UTIL_EXPORT const char *Zero(); 140 141 // A shader that sets gl_Position to attribute a_position. 142 ANGLE_UTIL_EXPORT const char *Simple(); 143 144 // A shader that sets gl_Position to attribute a_position, and sets gl_PointSize to 1. 145 ANGLE_UTIL_EXPORT const char *SimpleForPoints(); 146 147 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying 148 // v_position. 149 ANGLE_UTIL_EXPORT const char *Passthrough(); 150 151 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying 152 // texcoord. 153 ANGLE_UTIL_EXPORT const char *Texture2DLod(); 154 155 } // namespace vs 156 157 namespace fs 158 { 159 160 // A shader that fills with 100% opaque red. 161 ANGLE_UTIL_EXPORT const char *Red(); 162 163 // A shader that fills with 100% opaque green. 164 ANGLE_UTIL_EXPORT const char *Green(); 165 166 // A shader that fills with 100% opaque blue. 167 ANGLE_UTIL_EXPORT const char *Blue(); 168 169 // A shader that samples the texture at a given lod. 170 ANGLE_UTIL_EXPORT const char *Texture2DLod(); 171 172 } // namespace fs 173 } // namespace essl3_shaders 174 175 namespace essl31_shaders 176 { 177 178 ANGLE_UTIL_EXPORT const char *PositionAttrib(); 179 180 namespace vs 181 { 182 183 // A shader that sets gl_Position to zero. 184 ANGLE_UTIL_EXPORT const char *Zero(); 185 186 // A shader that sets gl_Position to attribute a_position. 187 ANGLE_UTIL_EXPORT const char *Simple(); 188 189 // A shader that simply passes through attribute a_position, setting it to gl_Position and varying 190 // v_position. 191 ANGLE_UTIL_EXPORT const char *Passthrough(); 192 193 } // namespace vs 194 195 namespace fs 196 { 197 198 // A shader that fills with 100% opaque red. 199 ANGLE_UTIL_EXPORT const char *Red(); 200 201 // A shader that fills with 100% opaque green. 202 ANGLE_UTIL_EXPORT const char *Green(); 203 204 // A shader that renders a simple gradient of red to green. Needs varying v_position. 205 ANGLE_UTIL_EXPORT const char *RedGreenGradient(); 206 207 } // namespace fs 208 } // namespace essl31_shaders 209 } // namespace angle 210 211 #endif // SAMPLE_UTIL_SHADER_UTILS_H 212