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