| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLSLShaderBuilder_DEFINED | 8 #ifndef GrGLSLShaderBuilder_DEFINED |
| 9 #define GrGLSLShaderBuilder_DEFINED | 9 #define GrGLSLShaderBuilder_DEFINED |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 /** Does the work of appendTextureLookup and modulates the result by modulat
ion. The result is | 53 /** Does the work of appendTextureLookup and modulates the result by modulat
ion. The result is |
| 54 always a vec4. modulation and the swizzle specified by GrGLSLTextureSamp
ler must both be | 54 always a vec4. modulation and the swizzle specified by GrGLSLTextureSamp
ler must both be |
| 55 vec4 or float. If modulation is "" or nullptr it this function acts as t
hough | 55 vec4 or float. If modulation is "" or nullptr it this function acts as t
hough |
| 56 appendTextureLookup were called. */ | 56 appendTextureLookup were called. */ |
| 57 void appendTextureLookupAndModulate(const char* modulation, | 57 void appendTextureLookupAndModulate(const char* modulation, |
| 58 const GrGLSLTextureSampler&, | 58 const GrGLSLTextureSampler&, |
| 59 const char* coordName, | 59 const char* coordName, |
| 60 GrSLType coordType = kVec2f_GrSLType); | 60 GrSLType coordType = kVec2f_GrSLType); |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Adds a #define directive to the top of the shader. |
| 64 */ |
| 65 void define(const char* macro, const char* replacement) { |
| 66 this->definitions().appendf("#define %s %s\n", macro, replacement); |
| 67 } |
| 68 |
| 69 void define(const char* macro, int replacement) { |
| 70 this->definitions().appendf("#define %s %i\n", macro, replacement); |
| 71 } |
| 72 |
| 73 void definef(const char* macro, const char* replacement, ...) { |
| 74 this->definitions().appendf("#define %s ", macro); |
| 75 va_list args; |
| 76 va_start(args, replacement); |
| 77 this->definitions().appendVAList(replacement, args); |
| 78 va_end(args); |
| 79 this->definitions().append("\n"); |
| 80 } |
| 81 |
| 82 /** |
| 63 * Called by GrGLSLProcessors to add code to one of the shaders. | 83 * Called by GrGLSLProcessors to add code to one of the shaders. |
| 64 */ | 84 */ |
| 65 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { | 85 void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) { |
| 66 va_list args; | 86 va_list args; |
| 67 va_start(args, format); | 87 va_start(args, format); |
| 68 this->code().appendVAList(format, args); | 88 this->code().appendVAList(format, args); |
| 69 va_end(args); | 89 va_end(args); |
| 70 } | 90 } |
| 71 | 91 |
| 72 void codeAppend(const char* str) { this->code().append(str); } | 92 void codeAppend(const char* str) { this->code().append(str); } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 165 |
| 146 void nextStage() { | 166 void nextStage() { |
| 147 fShaderStrings.push_back(); | 167 fShaderStrings.push_back(); |
| 148 fCompilerStrings.push_back(this->code().c_str()); | 168 fCompilerStrings.push_back(this->code().c_str()); |
| 149 fCompilerStringLengths.push_back((int)this->code().size()); | 169 fCompilerStringLengths.push_back((int)this->code().size()); |
| 150 fCodeIndex++; | 170 fCodeIndex++; |
| 151 } | 171 } |
| 152 | 172 |
| 153 SkString& versionDecl() { return fShaderStrings[kVersionDecl]; } | 173 SkString& versionDecl() { return fShaderStrings[kVersionDecl]; } |
| 154 SkString& extensions() { return fShaderStrings[kExtensions]; } | 174 SkString& extensions() { return fShaderStrings[kExtensions]; } |
| 175 SkString& definitions() { return fShaderStrings[kDefinitions]; } |
| 155 SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier];
} | 176 SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier];
} |
| 156 SkString& layoutQualifiers() { return fShaderStrings[kLayoutQualifiers]; } | 177 SkString& layoutQualifiers() { return fShaderStrings[kLayoutQualifiers]; } |
| 157 SkString& uniforms() { return fShaderStrings[kUniforms]; } | 178 SkString& uniforms() { return fShaderStrings[kUniforms]; } |
| 158 SkString& inputs() { return fShaderStrings[kInputs]; } | 179 SkString& inputs() { return fShaderStrings[kInputs]; } |
| 159 SkString& outputs() { return fShaderStrings[kOutputs]; } | 180 SkString& outputs() { return fShaderStrings[kOutputs]; } |
| 160 SkString& functions() { return fShaderStrings[kFunctions]; } | 181 SkString& functions() { return fShaderStrings[kFunctions]; } |
| 161 SkString& main() { return fShaderStrings[kMain]; } | 182 SkString& main() { return fShaderStrings[kMain]; } |
| 162 SkString& code() { return fShaderStrings[fCodeIndex]; } | 183 SkString& code() { return fShaderStrings[fCodeIndex]; } |
| 163 | 184 |
| 164 virtual void onFinalize() = 0; | 185 virtual void onFinalize() = 0; |
| 165 | 186 |
| 166 enum { | 187 enum { |
| 167 kVersionDecl, | 188 kVersionDecl, |
| 168 kExtensions, | 189 kExtensions, |
| 190 kDefinitions, |
| 169 kPrecisionQualifier, | 191 kPrecisionQualifier, |
| 170 kLayoutQualifiers, | 192 kLayoutQualifiers, |
| 171 kUniforms, | 193 kUniforms, |
| 172 kInputs, | 194 kInputs, |
| 173 kOutputs, | 195 kOutputs, |
| 174 kFunctions, | 196 kFunctions, |
| 175 kMain, | 197 kMain, |
| 176 kCode, | 198 kCode, |
| 177 }; | 199 }; |
| 178 | 200 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 190 SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1]; | 212 SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1]; |
| 191 int fCodeIndex; | 213 int fCodeIndex; |
| 192 bool fFinalized; | 214 bool fFinalized; |
| 193 | 215 |
| 194 friend class GrGLSLProgramBuilder; | 216 friend class GrGLSLProgramBuilder; |
| 195 friend class GrGLProgramBuilder; | 217 friend class GrGLProgramBuilder; |
| 196 friend class GrGLPathProgramBuilder; // to access fInputs. | 218 friend class GrGLPathProgramBuilder; // to access fInputs. |
| 197 friend class GrVkProgramBuilder; | 219 friend class GrVkProgramBuilder; |
| 198 }; | 220 }; |
| 199 #endif | 221 #endif |
| OLD | NEW |