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 19 matching lines...) Expand all Loading... |
30 * across our shaders. But the driver determines the uniform locations | 30 * across our shaders. But the driver determines the uniform locations |
31 * at link time. We don't need to remember the sampler uniform location | 31 * at link time. We don't need to remember the sampler uniform location |
32 * because we will bind a texture slot to it and never change it | 32 * because we will bind a texture slot to it and never change it |
33 * Uniforms are program-local so we can't rely on fHWState to hold the | 33 * Uniforms are program-local so we can't rely on fHWState to hold the |
34 * previous uniform state after a program change. | 34 * previous uniform state after a program change. |
35 */ | 35 */ |
36 class GrGLProgram : public GrRefCnt { | 36 class GrGLProgram : public GrRefCnt { |
37 public: | 37 public: |
38 SK_DECLARE_INST_COUNT(GrGLProgram) | 38 SK_DECLARE_INST_COUNT(GrGLProgram) |
39 | 39 |
40 static GrGLProgram* Create(const GrGLContext& gl, | 40 static GrGLProgram* Create(GrGpuGL* gpu, |
41 const GrGLProgramDesc& desc, | 41 const GrGLProgramDesc& desc, |
42 const GrEffectStage* colorStages[], | 42 const GrEffectStage* colorStages[], |
43 const GrEffectStage* coverageStages[]); | 43 const GrEffectStage* coverageStages[]); |
44 | 44 |
45 virtual ~GrGLProgram(); | 45 virtual ~GrGLProgram(); |
46 | 46 |
47 /** | 47 /** |
48 * Call to abandon GL objects owned by this program. | 48 * Call to abandon GL objects owned by this program. |
49 */ | 49 */ |
50 void abandon(); | 50 void abandon(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 fRenderTargetOrigin = (GrSurfaceOrigin) -1; | 101 fRenderTargetOrigin = (GrSurfaceOrigin) -1; |
102 } | 102 } |
103 }; | 103 }; |
104 | 104 |
105 /** | 105 /** |
106 * This function uploads uniforms and calls each GrGLEffect's setData. It is
called before a | 106 * This function uploads uniforms and calls each GrGLEffect's setData. It is
called before a |
107 * draw occurs using the program after the program has already been bound. I
t also uses the | 107 * draw occurs using the program after the program has already been bound. I
t also uses the |
108 * GrGpuGL object to bind the textures required by the GrGLEffects. The colo
r and coverage | 108 * GrGpuGL object to bind the textures required by the GrGLEffects. The colo
r and coverage |
109 * stages come from GrGLProgramDesc::Build(). | 109 * stages come from GrGLProgramDesc::Build(). |
110 */ | 110 */ |
111 void setData(GrGpuGL*, | 111 void setData(GrDrawState::BlendOptFlags, |
112 GrDrawState::BlendOptFlags, | |
113 const GrEffectStage* colorStages[], | 112 const GrEffectStage* colorStages[], |
114 const GrEffectStage* coverageStages[], | 113 const GrEffectStage* coverageStages[], |
115 const GrDeviceCoordTexture* dstCopy, // can be NULL | 114 const GrDeviceCoordTexture* dstCopy, // can be NULL |
116 SharedGLState*); | 115 SharedGLState*); |
117 | 116 |
118 private: | 117 private: |
119 typedef GrGLUniformManager::UniformHandle UniformHandle; | 118 typedef GrGLUniformManager::UniformHandle UniformHandle; |
120 | 119 |
121 // handles for uniforms (aside from per-effect samplers) | 120 // handles for uniforms (aside from per-effect samplers) |
122 struct UniformHandles { | 121 struct UniformHandles { |
(...skipping 16 matching lines...) Expand all Loading... |
139 typedef SkSTArray<4, int, true> TextureUnitSArray; | 138 typedef SkSTArray<4, int, true> TextureUnitSArray; |
140 | 139 |
141 struct EffectAndSamplers { | 140 struct EffectAndSamplers { |
142 EffectAndSamplers() : fGLEffect(NULL) {} | 141 EffectAndSamplers() : fGLEffect(NULL) {} |
143 ~EffectAndSamplers() { delete fGLEffect; } | 142 ~EffectAndSamplers() { delete fGLEffect; } |
144 GrGLEffect* fGLEffect; | 143 GrGLEffect* fGLEffect; |
145 SamplerUniSArray fSamplerUnis; // sampler uni handles for effect's G
rTextureAccess | 144 SamplerUniSArray fSamplerUnis; // sampler uni handles for effect's G
rTextureAccess |
146 TextureUnitSArray fTextureUnits; // texture unit used for each entry o
f fSamplerUnis | 145 TextureUnitSArray fTextureUnits; // texture unit used for each entry o
f fSamplerUnis |
147 }; | 146 }; |
148 | 147 |
149 GrGLProgram(const GrGLContext& gl, | 148 GrGLProgram(GrGpuGL* gpu, |
150 const GrGLProgramDesc& desc, | 149 const GrGLProgramDesc& desc, |
151 const GrEffectStage* colorStages[], | 150 const GrEffectStage* colorStages[], |
152 const GrEffectStage* coverageStages[]); | 151 const GrEffectStage* coverageStages[]); |
153 | 152 |
154 bool succeeded() const { return 0 != fProgramID; } | 153 bool succeeded() const { return 0 != fProgramID; } |
155 | 154 |
156 /** | 155 /** |
157 * This is the heavy initialization routine for building a GLProgram. colorS
tages and | 156 * This is the heavy initialization routine for building a GLProgram. colorS
tages and |
158 * coverageStages correspond to the output of GrGLProgramDesc::Build(). | 157 * coverageStages correspond to the output of GrGLProgramDesc::Build(). |
159 */ | 158 */ |
(...skipping 12 matching lines...) Expand all Loading... |
172 | 171 |
173 // Sets the texture units for samplers | 172 // Sets the texture units for samplers |
174 void initSamplerUniforms(); | 173 void initSamplerUniforms(); |
175 void initEffectSamplerUniforms(EffectAndSamplers* effect, int* texUnitIdx); | 174 void initEffectSamplerUniforms(EffectAndSamplers* effect, int* texUnitIdx); |
176 | 175 |
177 bool compileShaders(const GrGLShaderBuilder& builder); | 176 bool compileShaders(const GrGLShaderBuilder& builder); |
178 | 177 |
179 const char* adjustInColor(const SkString& inColor) const; | 178 const char* adjustInColor(const SkString& inColor) const; |
180 | 179 |
181 // Helper for setData(). | 180 // Helper for setData(). |
182 void setEffectData(GrGpuGL* gpu, const GrEffectStage& stage, const EffectAnd
Samplers& effect); | 181 void setEffectData(const GrEffectStage& stage, const EffectAndSamplers& effe
ct); |
183 | 182 |
184 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not | 183 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not |
185 // per-vertex colors. | 184 // per-vertex colors. |
186 void setColor(const GrDrawState&, GrColor color, SharedGLState*); | 185 void setColor(const GrDrawState&, GrColor color, SharedGLState*); |
187 | 186 |
188 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not | 187 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not |
189 // per-vertex coverages. | 188 // per-vertex coverages. |
190 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); | 189 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); |
191 | 190 |
192 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | 191 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform |
193 void setMatrixAndRenderTargetHeight(const GrDrawState&); | 192 void setMatrixAndRenderTargetHeight(const GrDrawState&); |
194 | 193 |
195 // GL IDs | 194 // GL IDs |
196 GrGLuint fVShaderID; | 195 GrGLuint fVShaderID; |
197 GrGLuint fGShaderID; | 196 GrGLuint fGShaderID; |
198 GrGLuint fFShaderID; | 197 GrGLuint fFShaderID; |
199 GrGLuint fProgramID; | 198 GrGLuint fProgramID; |
200 | 199 |
201 // these reflect the current values of uniforms (GL uniform values travel wi
th program) | 200 // these reflect the current values of uniforms (GL uniform values travel wi
th program) |
202 MatrixState fMatrixState; | 201 MatrixState fMatrixState; |
203 GrColor fColor; | 202 GrColor fColor; |
204 GrColor fCoverage; | 203 GrColor fCoverage; |
205 GrColor fColorFilterColor; | 204 GrColor fColorFilterColor; |
206 int fDstCopyTexUnit; | 205 int fDstCopyTexUnit; |
207 | 206 |
208 SkTArray<EffectAndSamplers> fColorEffects; | 207 SkTArray<EffectAndSamplers> fColorEffects; |
209 SkTArray<EffectAndSamplers> fCoverageEffects; | 208 SkTArray<EffectAndSamplers> fCoverageEffects; |
210 | 209 |
211 GrGLProgramDesc fDesc; | 210 GrGLProgramDesc fDesc; |
212 const GrGLContext& fContext; | 211 GrGpuGL* fGpu; |
213 | 212 |
214 GrGLUniformManager fUniformManager; | 213 GrGLUniformManager fUniformManager; |
215 UniformHandles fUniformHandles; | 214 UniformHandles fUniformHandles; |
216 | 215 |
217 typedef GrRefCnt INHERITED; | 216 typedef GrRefCnt INHERITED; |
218 }; | 217 }; |
219 | 218 |
220 #endif | 219 #endif |
OLD | NEW |