OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #ifndef GrGLProgram_DEFINED | 9 #ifndef GrGLProgram_DEFINED |
10 #define GrGLProgram_DEFINED | 10 #define GrGLProgram_DEFINED |
(...skipping 20 matching lines...) Expand all Loading... | |
31 * because we will bind a texture slot to it and never change it | 31 * because we will bind a texture slot to it and never change it |
32 * Uniforms are program-local so we can't rely on fHWState to hold the | 32 * Uniforms are program-local so we can't rely on fHWState to hold the |
33 * previous uniform state after a program change. | 33 * previous uniform state after a program change. |
34 */ | 34 */ |
35 class GrGLProgram : public GrRefCnt { | 35 class GrGLProgram : public GrRefCnt { |
36 public: | 36 public: |
37 SK_DECLARE_INST_COUNT(GrGLProgram) | 37 SK_DECLARE_INST_COUNT(GrGLProgram) |
38 | 38 |
39 static GrGLProgram* Create(const GrGLContext& gl, | 39 static GrGLProgram* Create(const GrGLContext& gl, |
40 const GrGLProgramDesc& desc, | 40 const GrGLProgramDesc& desc, |
41 const GrEffectStage* stages[]); | 41 const GrEffectStage* colorStages[], |
42 const GrEffectStage* coverageStages[]); | |
42 | 43 |
43 virtual ~GrGLProgram(); | 44 virtual ~GrGLProgram(); |
44 | 45 |
45 /** | 46 /** |
46 * Call to abandon GL objects owned by this program. | 47 * Call to abandon GL objects owned by this program. |
47 */ | 48 */ |
48 void abandon(); | 49 void abandon(); |
49 | 50 |
50 /** | 51 /** |
51 * The shader may modify the blend coefficients. Params are in/out. | 52 * The shader may modify the blend coefficients. Params are in/out. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 fViewMatrix = SkMatrix::InvalidMatrix(); | 97 fViewMatrix = SkMatrix::InvalidMatrix(); |
97 fRenderTargetSize.fWidth = -1; | 98 fRenderTargetSize.fWidth = -1; |
98 fRenderTargetSize.fHeight = -1; | 99 fRenderTargetSize.fHeight = -1; |
99 fRenderTargetOrigin = (GrSurfaceOrigin) -1; | 100 fRenderTargetOrigin = (GrSurfaceOrigin) -1; |
100 } | 101 } |
101 }; | 102 }; |
102 | 103 |
103 /** | 104 /** |
104 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a | 105 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a |
105 * draw occurs using the program after the program has already been bound. I t also uses the | 106 * draw occurs using the program after the program has already been bound. I t also uses the |
106 * GrGpuGL object to bind the textures required by the GrGLEffects. | 107 * GrGpuGL object to bind the textures required by the GrGLEffects. The colo r and coverage |
108 * stages come from GrGLProgramDesc::Build(). | |
107 */ | 109 */ |
108 void setData(GrGpuGL*, | 110 void setData(GrGpuGL*, |
109 GrDrawState::BlendOptFlags, | 111 GrDrawState::BlendOptFlags, |
110 const GrEffectStage* stages[], // output of GrGLProgramDe sc:Build() | 112 const GrEffectStage* colorStages[], |
113 const GrEffectStage* coverageStages[], | |
111 const GrDeviceCoordTexture* dstCopy, // can be NULL | 114 const GrDeviceCoordTexture* dstCopy, // can be NULL |
112 SharedGLState*); | 115 SharedGLState*); |
113 | 116 |
114 private: | 117 private: |
115 GrGLProgram(const GrGLContext& gl, | |
bsalomon
2013/06/06 19:13:02
I moved all the type declarations above the functi
| |
116 const GrGLProgramDesc& desc, | |
117 const GrEffectStage* stages[]); | |
118 | |
119 bool succeeded() const { return 0 != fProgramID; } | |
120 | |
121 /** | |
122 * This is the heavy initialization routine for building a GLProgram. stages is all the enabled | |
123 * color stages followed by all the enabled coverage stages as output by | |
124 * GrGLProgramDesc::Build() | |
125 */ | |
126 bool genProgram(const GrEffectStage* stages[]); | |
127 | |
128 GrSLConstantVec genInputColor(GrGLShaderBuilder* builder, SkString* inColor) ; | |
129 | |
130 GrSLConstantVec genInputCoverage(GrGLShaderBuilder* builder, SkString* inCov erage); | |
131 | |
132 void genGeometryShader(GrGLShaderBuilder* segments) const; | |
133 | |
134 typedef GrGLUniformManager::UniformHandle UniformHandle; | 118 typedef GrGLUniformManager::UniformHandle UniformHandle; |
135 | 119 |
136 // Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program | |
137 bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder, | |
138 bool bindColorOut, | |
139 bool bindDualSrcOut); | |
140 | |
141 // Sets the texture units for samplers | |
142 void initSamplerUniforms(); | |
143 | |
144 bool compileShaders(const GrGLShaderBuilder& builder); | |
145 | |
146 const char* adjustInColor(const SkString& inColor) const; | |
147 | |
148 // Helper for setData(). Makes GL calls to specify the initial color when th ere is not | |
149 // per-vertex colors. | |
150 void setColor(const GrDrawState&, GrColor color, SharedGLState*); | |
151 | |
152 // Helper for setData(). Makes GL calls to specify the initial coverage when there is not | |
153 // per-vertex coverages. | |
154 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); | |
155 | |
156 // Helper for setData() that sets the view matrix and loads the render targe t height uniform | |
157 void setMatrixAndRenderTargetHeight(const GrDrawState&); | |
158 | |
159 // handles for uniforms (aside from per-effect samplers) | 120 // handles for uniforms (aside from per-effect samplers) |
160 struct UniformHandles { | 121 struct UniformHandles { |
161 UniformHandle fViewMatrixUni; | 122 UniformHandle fViewMatrixUni; |
162 UniformHandle fColorUni; | 123 UniformHandle fColorUni; |
163 UniformHandle fCoverageUni; | 124 UniformHandle fCoverageUni; |
164 UniformHandle fColorFilterUni; | 125 UniformHandle fColorFilterUni; |
165 | 126 |
166 // We use the render target height to provide a y-down frag coord when s pecifying | 127 // We use the render target height to provide a y-down frag coord when s pecifying |
167 // origin_upper_left is not supported. | 128 // origin_upper_left is not supported. |
168 UniformHandle fRTHeightUni; | 129 UniformHandle fRTHeightUni; |
(...skipping 19 matching lines...) Expand all Loading... | |
188 typedef SkSTArray<4, int, true> TextureUnitSArray; | 149 typedef SkSTArray<4, int, true> TextureUnitSArray; |
189 | 150 |
190 struct EffectAndSamplers { | 151 struct EffectAndSamplers { |
191 EffectAndSamplers() : fGLEffect(NULL) {} | 152 EffectAndSamplers() : fGLEffect(NULL) {} |
192 ~EffectAndSamplers() { delete fGLEffect; } | 153 ~EffectAndSamplers() { delete fGLEffect; } |
193 GrGLEffect* fGLEffect; | 154 GrGLEffect* fGLEffect; |
194 SamplerUniSArray fSamplerUnis; // sampler uni handles for effect's G rTextureAccess | 155 SamplerUniSArray fSamplerUnis; // sampler uni handles for effect's G rTextureAccess |
195 TextureUnitSArray fTextureUnits; // texture unit used for each entry o f fSamplerUnis | 156 TextureUnitSArray fTextureUnits; // texture unit used for each entry o f fSamplerUnis |
196 }; | 157 }; |
197 | 158 |
159 GrGLProgram(const GrGLContext& gl, | |
bsalomon
2013/06/06 19:13:02
... changed the signature of this function...
| |
160 const GrGLProgramDesc& desc, | |
161 const GrEffectStage* colorStages[], | |
162 const GrEffectStage* coverageStages[]); | |
163 | |
164 bool succeeded() const { return 0 != fProgramID; } | |
165 | |
166 /** | |
167 * This is the heavy initialization routine for building a GLProgram. colorS tages and | |
168 * coverageStages correspond to the output of GrGLProgramDesc::Build(). | |
169 */ | |
170 bool genProgram(const GrEffectStage* colorStages[], const GrEffectStage* cov erageStages[]); | |
bsalomon
2013/06/06 19:13:02
... changed the signature of this function...
| |
171 | |
172 GrSLConstantVec genInputColor(GrGLShaderBuilder* builder, SkString* inColor) ; | |
173 | |
174 GrSLConstantVec genInputCoverage(GrGLShaderBuilder* builder, SkString* inCov erage); | |
175 | |
176 void genGeometryShader(GrGLShaderBuilder* segments) const; | |
177 | |
178 // Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program | |
179 bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder, | |
180 bool bindColorOut, | |
181 bool bindDualSrcOut); | |
182 | |
183 // Sets the texture units for samplers | |
184 void initSamplerUniforms(); | |
185 | |
186 bool compileShaders(const GrGLShaderBuilder& builder); | |
187 | |
188 const char* adjustInColor(const SkString& inColor) const; | |
189 | |
190 // Helper for setData(). | |
bsalomon
2013/06/06 19:13:02
... and added this function.
| |
191 void setEffectData(GrGpuGL* gpu, const GrEffectStage& stage, const EffectAnd Samplers& effect); | |
192 | |
193 // Helper for setData(). Makes GL calls to specify the initial color when th ere is not | |
194 // per-vertex colors. | |
195 void setColor(const GrDrawState&, GrColor color, SharedGLState*); | |
196 | |
197 // Helper for setData(). Makes GL calls to specify the initial coverage when there is not | |
198 // per-vertex coverages. | |
199 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); | |
200 | |
201 // Helper for setData() that sets the view matrix and loads the render targe t height uniform | |
202 void setMatrixAndRenderTargetHeight(const GrDrawState&); | |
203 | |
198 // GL IDs | 204 // GL IDs |
199 GrGLuint fVShaderID; | 205 GrGLuint fVShaderID; |
200 GrGLuint fGShaderID; | 206 GrGLuint fGShaderID; |
201 GrGLuint fFShaderID; | 207 GrGLuint fFShaderID; |
202 GrGLuint fProgramID; | 208 GrGLuint fProgramID; |
203 | 209 |
204 // these reflect the current values of uniforms (GL uniform values travel wi th program) | 210 // these reflect the current values of uniforms (GL uniform values travel wi th program) |
205 MatrixState fMatrixState; | 211 MatrixState fMatrixState; |
206 GrColor fColor; | 212 GrColor fColor; |
207 GrColor fCoverage; | 213 GrColor fCoverage; |
208 GrColor fColorFilterColor; | 214 GrColor fColorFilterColor; |
209 int fDstCopyTexUnit; | 215 int fDstCopyTexUnit; |
210 | 216 |
211 SkTArray<EffectAndSamplers> fEffectStates; | 217 SkTArray<EffectAndSamplers> fColorEffects; |
218 SkTArray<EffectAndSamplers> fCoverageEffects; | |
212 | 219 |
213 GrGLProgramDesc fDesc; | 220 GrGLProgramDesc fDesc; |
214 const GrGLContext& fContext; | 221 const GrGLContext& fContext; |
215 | 222 |
216 GrGLUniformManager fUniformManager; | 223 GrGLUniformManager fUniformManager; |
217 UniformHandles fUniformHandles; | 224 UniformHandles fUniformHandles; |
218 | 225 |
219 typedef GrRefCnt INHERITED; | 226 typedef GrRefCnt INHERITED; |
220 }; | 227 }; |
221 | 228 |
222 #endif | 229 #endif |
OLD | NEW |