| 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 GrGLFragmentShaderBuilder_DEFINED | 8 #ifndef GrGLFragmentShaderBuilder_DEFINED |
| 9 #define GrGLFragmentShaderBuilder_DEFINED | 9 #define GrGLFragmentShaderBuilder_DEFINED |
| 10 | 10 |
| 11 #include "GrGLShaderBuilder.h" | 11 #include "GrGLShaderBuilder.h" |
| 12 | 12 |
| 13 #include "gl/GrGLTypes.h" |
| 13 #include "glsl/GrGLSLProcessorTypes.h" | 14 #include "glsl/GrGLSLProcessorTypes.h" |
| 14 | 15 |
| 16 class GrRenderTarget; |
| 15 class GrGLVarying; | 17 class GrGLVarying; |
| 16 | 18 |
| 17 /* | 19 /* |
| 18 * This base class encapsulates the functionality which the GP uses to build fra
gment shaders | 20 * This base class encapsulates the functionality which the GP uses to build fra
gment shaders |
| 19 */ | 21 */ |
| 20 class GrGLFragmentBuilder : public GrGLShaderBuilder { | 22 class GrGLFragmentBuilder : public GrGLShaderBuilder { |
| 21 public: | 23 public: |
| 22 GrGLFragmentBuilder(GrGLProgramBuilder* program) | 24 GrGLFragmentBuilder(GrGLProgramBuilder* program) |
| 23 : INHERITED(program) { | 25 : INHERITED(program) { |
| 24 fSubstageIndices.push_back(0); | 26 fSubstageIndices.push_back(0); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if these equations are supported. */ | 106 if these equations are supported. */ |
| 105 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; | 107 virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0; |
| 106 | 108 |
| 107 private: | 109 private: |
| 108 typedef GrGLFragmentBuilder INHERITED; | 110 typedef GrGLFragmentBuilder INHERITED; |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 // TODO rename to Fragment Builder | 113 // TODO rename to Fragment Builder |
| 112 class GrGLFragmentShaderBuilder : public GrGLXPFragmentBuilder { | 114 class GrGLFragmentShaderBuilder : public GrGLXPFragmentBuilder { |
| 113 public: | 115 public: |
| 114 typedef uint8_t DstReadKey; | |
| 115 typedef uint8_t FragPosKey; | 116 typedef uint8_t FragPosKey; |
| 116 | 117 |
| 117 /** Returns a key for adding code to read the dst texture color in service o
f effects that | |
| 118 require reading the dst. It must not return 0 because 0 indicates that t
here is no dst | |
| 119 texture at all (in which case this function should not be called). */ | |
| 120 static DstReadKey KeyForDstRead(const GrTexture* dsttexture, const GrGLCaps&
); | |
| 121 | |
| 122 /** Returns a key for reading the fragment location. This should only be cal
led if there is an | 118 /** Returns a key for reading the fragment location. This should only be cal
led if there is an |
| 123 effect that will requires the fragment position. If the fragment position
is not required, | 119 effect that will requires the fragment position. If the fragment position
is not required, |
| 124 the key is 0. */ | 120 the key is 0. */ |
| 125 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst, const Gr
GLCaps&); | 121 static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst); |
| 126 | 122 |
| 127 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, uint8_t fragPosKey); | 123 GrGLFragmentShaderBuilder(GrGLProgramBuilder* program, uint8_t fragPosKey); |
| 128 | 124 |
| 129 // true public interface, defined explicitly in the abstract interfaces abov
e | 125 // true public interface, defined explicitly in the abstract interfaces abov
e |
| 130 bool enableFeature(GLSLFeature) override; | 126 bool enableFeature(GLSLFeature) override; |
| 131 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords
, | 127 virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords
, |
| 132 int index) override; | 128 int index) override; |
| 133 const char* fragmentPosition() override; | 129 const char* fragmentPosition() override; |
| 134 const char* dstColor() override; | 130 const char* dstColor() override; |
| 135 | 131 |
| 136 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; | 132 void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override; |
| 137 | 133 |
| 138 private: | 134 private: |
| 139 // Private public interface, used by GrGLProgramBuilder to build a fragment
shader | 135 // Private public interface, used by GrGLProgramBuilder to build a fragment
shader |
| 140 void enableCustomOutput(); | 136 void enableCustomOutput(); |
| 141 void enableSecondaryOutput(); | 137 void enableSecondaryOutput(); |
| 142 const char* getPrimaryColorOutputName() const; | 138 const char* getPrimaryColorOutputName() const; |
| 143 const char* getSecondaryColorOutputName() const; | 139 const char* getSecondaryColorOutputName() const; |
| 144 bool compileAndAttachShaders(GrGLuint programId, SkTDArray<GrGLuint>* shader
Ids); | |
| 145 void bindFragmentShaderLocations(GrGLuint programID); | 140 void bindFragmentShaderLocations(GrGLuint programID); |
| 146 | 141 |
| 147 // As GLProcessors emit code, there are some conditions we need to verify.
We use the below | 142 // As GLProcessors emit code, there are some conditions we need to verify.
We use the below |
| 148 // state to track this. The reset call is called per processor emitted. | 143 // state to track this. The reset call is called per processor emitted. |
| 149 bool hasReadDstColor() const { return fHasReadDstColor; } | 144 bool hasReadDstColor() const { return fHasReadDstColor; } |
| 150 bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; } | 145 bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; } |
| 151 void reset() { | 146 void reset() { |
| 152 fHasReadDstColor = false; | 147 fHasReadDstColor = false; |
| 153 fHasReadFragmentPosition = false; | 148 fHasReadFragmentPosition = false; |
| 154 } | 149 } |
| 155 | 150 |
| 156 /* | 151 /* |
| 157 * An internal call for GrGLProgramBuilder to use to add varyings to the ver
tex shader | 152 * An internal call for GrGLProgramBuilder to use to add varyings to the ver
tex shader |
| 158 */ | 153 */ |
| 159 void addVarying(GrGLVarying*, GrSLPrecision); | 154 void addVarying(GrGLVarying*, GrSLPrecision); |
| 160 | 155 |
| 156 void onFinalize() override; |
| 157 |
| 161 /** | 158 /** |
| 162 * Features that should only be enabled by GrGLFragmentShaderBuilder itself. | 159 * Features that should only be enabled by GrGLFragmentShaderBuilder itself. |
| 163 */ | 160 */ |
| 164 enum GLSLPrivateFeature { | 161 enum GLSLPrivateFeature { |
| 165 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, | 162 kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1, |
| 166 kBlendEquationAdvanced_GLSLPrivateFeature, | 163 kBlendEquationAdvanced_GLSLPrivateFeature, |
| 167 kBlendFuncExtended_GLSLPrivateFeature, | 164 kBlendFuncExtended_GLSLPrivateFeature, |
| 168 kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature | 165 kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature |
| 169 }; | 166 }; |
| 170 | 167 |
| 171 // Interpretation of DstReadKey when generating code | |
| 172 enum { | |
| 173 kNoDstRead_DstReadKey = 0, | |
| 174 kYesDstRead_DstReadKeyBit = 0x1, // Set if we do a dst-copy-read. | |
| 175 kUseAlphaConfig_DstReadKeyBit = 0x2, // Set if dst-copy config is alph
a only. | |
| 176 kTopLeftOrigin_DstReadKeyBit = 0x4, // Set if dst-copy origin is top-
left. | |
| 177 }; | |
| 178 | |
| 179 // Interpretation of FragPosKey when generating code | 168 // Interpretation of FragPosKey when generating code |
| 180 enum { | 169 enum { |
| 181 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. | 170 kNoFragPosRead_FragPosKey = 0, // The fragment positition wil
l not be needed. |
| 182 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. | 171 kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to t
op-left. |
| 183 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. | 172 kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to b
ottom-left. |
| 184 }; | 173 }; |
| 185 | 174 |
| 186 static const char* kDstTextureColorName; | 175 static const char* kDstTextureColorName; |
| 187 | 176 |
| 188 bool fHasCustomColorOutput; | 177 bool fHasCustomColorOutput; |
| 189 bool fHasSecondaryOutput; | 178 bool fHasSecondaryOutput; |
| 190 bool fSetupFragPosition; | 179 bool fSetupFragPosition; |
| 191 bool fTopLeftFragPosRead; | 180 bool fTopLeftFragPosRead; |
| 192 int fCustomColorOutputIndex; | 181 int fCustomColorOutputIndex; |
| 193 | 182 |
| 194 // some state to verify shaders and effects are consistent, this is reset be
tween effects by | 183 // some state to verify shaders and effects are consistent, this is reset be
tween effects by |
| 195 // the program creator | 184 // the program creator |
| 196 bool fHasReadDstColor; | 185 bool fHasReadDstColor; |
| 197 bool fHasReadFragmentPosition; | 186 bool fHasReadFragmentPosition; |
| 198 | 187 |
| 199 friend class GrGLProgramBuilder; | 188 friend class GrGLProgramBuilder; |
| 200 | 189 |
| 201 typedef GrGLXPFragmentBuilder INHERITED; | 190 typedef GrGLXPFragmentBuilder INHERITED; |
| 202 }; | 191 }; |
| 203 | 192 |
| 204 #endif | 193 #endif |
| OLD | NEW |