| 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 GrGLShaderBuilder_DEFINED | 8 #ifndef GrGLShaderBuilder_DEFINED |
| 9 #define GrGLShaderBuilder_DEFINED | 9 #define GrGLShaderBuilder_DEFINED |
| 10 | 10 |
| 11 #include "SkTArray.h" | 11 #include "SkTArray.h" |
| 12 #include "gl/GrGLFragmentProcessor.h" | 12 #include "gl/GrGLFragmentProcessor.h" |
| 13 #include "gl/GrGLProgramDesc.h" | 13 #include "gl/GrGLProgramDesc.h" |
| 14 #include "gl/GrGLProgramDataManager.h" | 14 #include "gl/GrGLProgramDataManager.h" |
| 15 #include "gl/GrGLTypes.h" | 15 #include "gl/GrGLTypes.h" |
| 16 | 16 |
| 17 #include <stdarg.h> | 17 #include <stdarg.h> |
| 18 | 18 |
| 19 class GrGLCaps; | 19 class GrGLCaps; |
| 20 class GrGLContextInfo; | 20 class GrGLContextInfo; |
| 21 class GrGLProgramBuilder; | 21 class GrGLProgramBuilder; |
| 22 class GrGLSLTextureSampler; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 base class for all shaders builders | 25 base class for all shaders builders |
| 25 */ | 26 */ |
| 26 class GrGLShaderBuilder { | 27 class GrGLShaderBuilder { |
| 27 public: | 28 public: |
| 28 typedef GrGLProcessor::TransformedCoordsArray TransformedCoordsArray; | |
| 29 typedef GrGLProcessor::TextureSampler TextureSampler; | |
| 30 | |
| 31 GrGLShaderBuilder(GrGLProgramBuilder* program); | 29 GrGLShaderBuilder(GrGLProgramBuilder* program); |
| 32 | 30 |
| 33 void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); } | 31 void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); } |
| 34 void addOutput(const GrGLSLShaderVar& output) { fOutputs.push_back(output);
} | 32 void addOutput(const GrGLSLShaderVar& output) { fOutputs.push_back(output);
} |
| 35 | 33 |
| 36 /* | 34 /* |
| 37 * We put texture lookups in the base class because it is TECHNICALLY possib
le to do texture | 35 * We put texture lookups in the base class because it is TECHNICALLY possib
le to do texture |
| 38 * lookups in any kind of shader. However, for the time being using these c
alls on non-fragment | 36 * lookups in any kind of shader. However, for the time being using these c
alls on non-fragment |
| 39 * shaders will result in a shader compilation error as texture sampler unif
orms are only | 37 * shaders will result in a shader compilation error as texture sampler unif
orms are only |
| 40 * visible to the fragment shader. It would not be hard to change this beha
vior, if someone | 38 * visible to the fragment shader. It would not be hard to change this beha
vior, if someone |
| 41 * actually wants to do texture lookups in a non-fragment shader | 39 * actually wants to do texture lookups in a non-fragment shader |
| 42 * | 40 * |
| 43 * TODO if append texture lookup is used on a non-fragment shader, sampler u
niforms should be | 41 * TODO if append texture lookup is used on a non-fragment shader, sampler u
niforms should be |
| 44 * made visible to that shaders | 42 * made visible to that shaders |
| 45 */ | 43 */ |
| 46 /** Appends a 2D texture sample with projection if necessary. coordType must
either be Vec2f or | 44 /** Appends a 2D texture sample with projection if necessary. coordType must
either be Vec2f or |
| 47 Vec3f. The latter is interpreted as projective texture coords. The vec l
ength and swizzle | 45 Vec3f. The latter is interpreted as projective texture coords. The vec l
ength and swizzle |
| 48 order of the result depends on the GrTextureAccess associated with the T
extureSampler. */ | 46 order of the result depends on the GrTextureAccess associated with the G
rGLSLTextureSampler. |
| 47 */ |
| 49 void appendTextureLookup(SkString* out, | 48 void appendTextureLookup(SkString* out, |
| 50 const TextureSampler&, | 49 const GrGLSLTextureSampler&, |
| 51 const char* coordName, | 50 const char* coordName, |
| 52 GrSLType coordType = kVec2f_GrSLType) const; | 51 GrSLType coordType = kVec2f_GrSLType) const; |
| 53 | 52 |
| 54 /** Version of above that appends the result to the fragment shader code ins
tead.*/ | 53 /** Version of above that appends the result to the fragment shader code ins
tead.*/ |
| 55 void appendTextureLookup(const TextureSampler&, | 54 void appendTextureLookup(const GrGLSLTextureSampler&, |
| 56 const char* coordName, | 55 const char* coordName, |
| 57 GrSLType coordType = kVec2f_GrSLType); | 56 GrSLType coordType = kVec2f_GrSLType); |
| 58 | 57 |
| 59 | 58 |
| 60 /** Does the work of appendTextureLookup and modulates the result by modulat
ion. The result is | 59 /** Does the work of appendTextureLookup and modulates the result by modulat
ion. The result is |
| 61 always a vec4. modulation and the swizzle specified by TextureSampler mu
st both be vec4 or | 60 always a vec4. modulation and the swizzle specified by GrGLSLTextureSamp
ler must both be |
| 62 float. If modulation is "" or nullptr it this function acts as though ap
pendTextureLookup were | 61 vec4 or float. If modulation is "" or nullptr it this function acts as t
hough |
| 63 called. */ | 62 appendTextureLookup were called. */ |
| 64 void appendTextureLookupAndModulate(const char* modulation, | 63 void appendTextureLookupAndModulate(const char* modulation, |
| 65 const TextureSampler&, | 64 const GrGLSLTextureSampler&, |
| 66 const char* coordName, | 65 const char* coordName, |
| 67 GrSLType coordType = kVec2f_GrSLType); | 66 GrSLType coordType = kVec2f_GrSLType); |
| 68 | 67 |
| 69 /** If texture swizzling is available using tex parameters then it is prefer
red over mangling | 68 /** If texture swizzling is available using tex parameters then it is prefer
red over mangling |
| 70 the generated shader code. This potentially allows greater reuse of cach
ed shaders. */ | 69 the generated shader code. This potentially allows greater reuse of cach
ed shaders. */ |
| 71 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCa
ps& caps); | 70 static const GrGLenum* GetTexParamSwizzle(GrPixelConfig config, const GrGLCa
ps& caps); |
| 72 | 71 |
| 73 /** | 72 /** |
| 74 * Called by GrGLProcessors to add code to one of the shaders. | 73 * Called by GrGLProcessors to add code to one of the shaders. |
| 75 */ | 74 */ |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 VarArray fOutputs; | 200 VarArray fOutputs; |
| 202 uint32_t fFeaturesAddedMask; | 201 uint32_t fFeaturesAddedMask; |
| 203 SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1]; | 202 SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1]; |
| 204 int fCodeIndex; | 203 int fCodeIndex; |
| 205 bool fFinalized; | 204 bool fFinalized; |
| 206 | 205 |
| 207 friend class GrGLProgramBuilder; | 206 friend class GrGLProgramBuilder; |
| 208 friend class GrGLPathProgramBuilder; // to access fInputs. | 207 friend class GrGLPathProgramBuilder; // to access fInputs. |
| 209 }; | 208 }; |
| 210 #endif | 209 #endif |
| OLD | NEW |