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 |
11 | 11 |
12 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
13 #include "GrGLContext.h" | 13 #include "GrGLContext.h" |
14 #include "GrGLCoordTransform.h" | |
15 #include "GrGLProgramDesc.h" | 14 #include "GrGLProgramDesc.h" |
16 #include "GrGLShaderBuilder.h" | 15 #include "GrGLShaderBuilder.h" |
17 #include "GrGLSL.h" | 16 #include "GrGLSL.h" |
18 #include "GrGLTexture.h" | 17 #include "GrGLTexture.h" |
19 #include "GrGLUniformManager.h" | 18 #include "GrGLUniformManager.h" |
20 | 19 |
21 #include "SkString.h" | 20 #include "SkString.h" |
22 #include "SkXfermode.h" | 21 #include "SkXfermode.h" |
23 | 22 |
24 class GrBinHashKeyBuilder; | 23 class GrBinHashKeyBuilder; |
25 class GrGLEffect; | 24 class GrGLEffect; |
| 25 class GrGLProgramEffects; |
26 class GrGLShaderBuilder; | 26 class GrGLShaderBuilder; |
27 | 27 |
28 /** | 28 /** |
29 * This class manages a GPU program and records per-program information. | 29 * This class manages a GPU program and records per-program information. |
30 * We can specify the attribute locations so that they are constant | 30 * We can specify the attribute locations so that they are constant |
31 * across our shaders. But the driver determines the uniform locations | 31 * across our shaders. But the driver determines the uniform locations |
32 * at link time. We don't need to remember the sampler uniform location | 32 * at link time. We don't need to remember the sampler uniform location |
33 * because we will bind a texture slot to it and never change it | 33 * because we will bind a texture slot to it and never change it |
34 * Uniforms are program-local so we can't rely on fHWState to hold the | 34 * Uniforms are program-local so we can't rely on fHWState to hold the |
35 * previous uniform state after a program change. | 35 * previous uniform state after a program change. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // We use the render target height to provide a y-down frag coord when s
pecifying | 142 // We use the render target height to provide a y-down frag coord when s
pecifying |
143 // origin_upper_left is not supported. | 143 // origin_upper_left is not supported. |
144 UniformHandle fRTHeightUni; | 144 UniformHandle fRTHeightUni; |
145 | 145 |
146 // Uniforms for computing texture coords to do the dst-copy lookup | 146 // Uniforms for computing texture coords to do the dst-copy lookup |
147 UniformHandle fDstCopyTopLeftUni; | 147 UniformHandle fDstCopyTopLeftUni; |
148 UniformHandle fDstCopyScaleUni; | 148 UniformHandle fDstCopyScaleUni; |
149 UniformHandle fDstCopySamplerUni; | 149 UniformHandle fDstCopySamplerUni; |
150 }; | 150 }; |
151 | 151 |
152 typedef SkSTArray<4, GrGLCoordTransform, false> CoordTransformSArray; | |
153 typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray; | |
154 typedef SkSTArray<4, int, true> TextureUnitSArray; | |
155 | |
156 struct EffectAndSamplers { | |
157 EffectAndSamplers() : fGLEffect(NULL) {} | |
158 ~EffectAndSamplers() { delete fGLEffect; } | |
159 GrGLEffect* fGLEffect; | |
160 CoordTransformSArray fCoordTransforms; | |
161 SamplerUniSArray fSamplerUnis; // sampler uni handles for effect's
GrTextureAccess | |
162 TextureUnitSArray fTextureUnits; // texture unit used for each entry
of fSamplerUnis | |
163 }; | |
164 | |
165 GrGLProgram(GrGpuGL* gpu, | 152 GrGLProgram(GrGpuGL* gpu, |
166 const GrGLProgramDesc& desc, | 153 const GrGLProgramDesc& desc, |
167 const GrEffectStage* colorStages[], | 154 const GrEffectStage* colorStages[], |
168 const GrEffectStage* coverageStages[]); | 155 const GrEffectStage* coverageStages[]); |
169 | 156 |
170 bool succeeded() const { return 0 != fProgramID; } | 157 bool succeeded() const { return 0 != fProgramID; } |
171 | 158 |
172 /** | 159 /** |
173 * This is the heavy initialization routine for building a GLProgram. colorS
tages and | 160 * This is the heavy initialization routine for building a GLProgram. colorS
tages and |
174 * coverageStages correspond to the output of GrGLProgramDesc::Build(). | 161 * coverageStages correspond to the output of GrGLProgramDesc::Build(). |
175 */ | 162 */ |
176 bool genProgram(const GrEffectStage* colorStages[], const GrEffectStage* cov
erageStages[]); | 163 bool genProgram(const GrEffectStage* colorStages[], const GrEffectStage* cov
erageStages[]); |
177 | 164 |
178 // Sets the texture units for samplers | 165 // Sets the texture units for samplers |
179 void initSamplerUniforms(); | 166 void initSamplerUniforms(); |
180 void initEffectSamplerUniforms(EffectAndSamplers* effect, int* texUnitIdx); | |
181 | |
182 // Helper for setData(). | |
183 void setEffectData(const GrEffectStage& stage, EffectAndSamplers& effect); | |
184 | 167 |
185 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not | 168 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not |
186 // per-vertex colors. | 169 // per-vertex colors. |
187 void setColor(const GrDrawState&, GrColor color, SharedGLState*); | 170 void setColor(const GrDrawState&, GrColor color, SharedGLState*); |
188 | 171 |
189 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not | 172 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not |
190 // per-vertex coverages. | 173 // per-vertex coverages. |
191 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); | 174 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); |
192 | 175 |
193 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | 176 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform |
194 void setMatrixAndRenderTargetHeight(const GrDrawState&); | 177 void setMatrixAndRenderTargetHeight(const GrDrawState&); |
195 | 178 |
196 // GL program ID | 179 // GL program ID |
197 GrGLuint fProgramID; | 180 GrGLuint fProgramID; |
198 | 181 |
199 // these reflect the current values of uniforms (GL uniform values travel wi
th program) | 182 // these reflect the current values of uniforms (GL uniform values travel wi
th program) |
200 MatrixState fMatrixState; | 183 MatrixState fMatrixState; |
201 GrColor fColor; | 184 GrColor fColor; |
202 GrColor fCoverage; | 185 GrColor fCoverage; |
203 GrColor fColorFilterColor; | 186 GrColor fColorFilterColor; |
204 int fDstCopyTexUnit; | 187 int fDstCopyTexUnit; |
205 | 188 |
206 SkTArray<EffectAndSamplers> fColorEffects; | 189 SkAutoTDelete<GrGLProgramEffects> fColorEffects; |
207 SkTArray<EffectAndSamplers> fCoverageEffects; | 190 SkAutoTDelete<GrGLProgramEffects> fCoverageEffects; |
208 | 191 |
209 GrGLProgramDesc fDesc; | 192 GrGLProgramDesc fDesc; |
210 GrGpuGL* fGpu; | 193 GrGpuGL* fGpu; |
211 | 194 |
212 GrGLUniformManager fUniformManager; | 195 GrGLUniformManager fUniformManager; |
213 UniformHandles fUniformHandles; | 196 UniformHandles fUniformHandles; |
214 | 197 |
215 typedef SkRefCnt INHERITED; | 198 typedef SkRefCnt INHERITED; |
216 }; | 199 }; |
217 | 200 |
218 #endif | 201 #endif |
OLD | NEW |