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 SkRefCnt { | 36 class GrGLProgram : public SkRefCnt { |
37 public: | 37 public: |
38 SK_DECLARE_INST_COUNT(GrGLProgram) | 38 SK_DECLARE_INST_COUNT(GrGLProgram) |
39 | 39 |
| 40 typedef GrGLShaderBuilder::BuiltinUniformHandles BuiltinUniformHandles; |
| 41 |
40 static GrGLProgram* Create(GrGpuGL* gpu, | 42 static GrGLProgram* Create(GrGpuGL* gpu, |
41 const GrGLProgramDesc& desc, | 43 const GrGLProgramDesc& desc, |
42 const GrEffectStage* colorStages[], | 44 const GrEffectStage* colorStages[], |
43 const GrEffectStage* coverageStages[]); | 45 const GrEffectStage* coverageStages[]); |
44 | 46 |
45 virtual ~GrGLProgram(); | 47 virtual ~GrGLProgram(); |
46 | 48 |
47 /** | 49 /** |
48 * Call to abandon GL objects owned by this program. | 50 * Call to abandon GL objects owned by this program. |
49 */ | 51 */ |
50 void abandon(); | 52 void abandon(); |
51 | 53 |
52 /** | 54 /** |
53 * The shader may modify the blend coefficients. Params are in/out. | 55 * The shader may modify the blend coefficients. Params are in/out. |
54 */ | 56 */ |
55 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const; | 57 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const; |
56 | 58 |
57 const GrGLProgramDesc& getDesc() { return fDesc; } | 59 const GrGLProgramDesc& getDesc() { return fDesc; } |
58 | 60 |
59 /** | 61 /** |
60 * Gets the GL program ID for this program. | 62 * Gets the GL program ID for this program. |
61 */ | 63 */ |
62 GrGLuint programID() const { return fBuilderOutput.fProgramID; } | 64 GrGLuint programID() const { return fProgramID; } |
63 | 65 |
64 bool hasVertexShader() const { return fBuilderOutput.fHasVertexShader; } | 66 bool hasVertexShader() const { return fHasVertexShader; } |
65 | 67 |
66 /** | 68 /** |
67 * Some GL state that is relevant to programs is not stored per-program. In
particular color | 69 * Some GL state that is relevant to programs is not stored per-program. In
particular color |
68 * and coverage attributes can be global state. This struct is read and upda
ted by | 70 * and coverage attributes can be global state. This struct is read and upda
ted by |
69 * GrGLProgram::setColor and GrGLProgram::setCoverage to allow us to avoid s
etting this state | 71 * GrGLProgram::setColor and GrGLProgram::setCoverage to allow us to avoid s
etting this state |
70 * redundantly. | 72 * redundantly. |
71 */ | 73 */ |
72 struct SharedGLState { | 74 struct SharedGLState { |
73 GrColor fConstAttribColor; | 75 GrColor fConstAttribColor; |
74 int fConstAttribColorIndex; | 76 int fConstAttribColorIndex; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 const GrEffectStage* colorStages[], | 160 const GrEffectStage* colorStages[], |
159 const GrEffectStage* coverageStages[], | 161 const GrEffectStage* coverageStages[], |
160 const GrDeviceCoordTexture* dstCopy, // can be NULL | 162 const GrDeviceCoordTexture* dstCopy, // can be NULL |
161 SharedGLState*); | 163 SharedGLState*); |
162 | 164 |
163 private: | 165 private: |
164 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 166 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
165 | 167 |
166 GrGLProgram(GrGpuGL*, | 168 GrGLProgram(GrGpuGL*, |
167 const GrGLProgramDesc&, | 169 const GrGLProgramDesc&, |
168 GrGLProgramDataManager*, | 170 const GrGLShaderBuilder&); |
169 const GrGLShaderBuilder::GenProgramOutput&); | |
170 | 171 |
171 // Sets the texture units for samplers. | 172 // Sets the texture units for samplers. |
172 void initSamplerUniforms(); | 173 void initSamplerUniforms(); |
173 | 174 |
174 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not | 175 // Helper for setData(). Makes GL calls to specify the initial color when th
ere is not |
175 // per-vertex colors. | 176 // per-vertex colors. |
176 void setColor(const GrDrawState&, GrColor color, SharedGLState*); | 177 void setColor(const GrDrawState&, GrColor color, SharedGLState*); |
177 | 178 |
178 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not | 179 // Helper for setData(). Makes GL calls to specify the initial coverage when
there is not |
179 // per-vertex coverages. | 180 // per-vertex coverages. |
180 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); | 181 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); |
181 | 182 |
182 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | 183 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform |
183 void setMatrixAndRenderTargetHeight(const GrDrawState&); | 184 void setMatrixAndRenderTargetHeight(const GrDrawState&); |
184 | 185 |
185 // these reflect the current values of uniforms (GL uniform values travel wi
th program) | 186 // these reflect the current values of uniforms (GL uniform values travel wi
th program) |
186 MatrixState fMatrixState; | 187 MatrixState fMatrixState; |
187 GrColor fColor; | 188 GrColor fColor; |
188 GrColor fCoverage; | 189 GrColor fCoverage; |
189 int fDstCopyTexUnit; | 190 int fDstCopyTexUnit; |
190 | 191 |
191 GrGLShaderBuilder::GenProgramOutput fBuilderOutput; | 192 BuiltinUniformHandles fBuiltinUniformHandles; |
| 193 SkAutoTUnref<GrGLProgramEffects> fColorEffects; |
| 194 SkAutoTUnref<GrGLProgramEffects> fCoverageEffects; |
| 195 GrGLuint fProgramID; |
| 196 bool fHasVertexShader; |
| 197 int fTexCoordSetCnt; |
192 | 198 |
193 GrGLProgramDesc fDesc; | 199 GrGLProgramDesc fDesc; |
194 GrGpuGL* fGpu; | 200 GrGpuGL* fGpu; |
195 | 201 |
196 SkAutoTUnref<GrGLProgramDataManager> fProgramDataManager; | 202 GrGLProgramDataManager fProgramDataManager; |
197 | 203 |
198 typedef SkRefCnt INHERITED; | 204 typedef SkRefCnt INHERITED; |
199 }; | 205 }; |
200 | 206 |
201 #endif | 207 #endif |
OLD | NEW |