Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: src/gpu/gl/GrGLProgram.h

Issue 16180006: separate arrays for color and coverage effects. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add helper function Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/gpu/gl/GrGLProgram.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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,
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
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,
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[]);
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 void initEffectSamplerUniforms(EffectAndSamplers* effect, int* texUnitIdx);
186
187 bool compileShaders(const GrGLShaderBuilder& builder);
188
189 const char* adjustInColor(const SkString& inColor) const;
190
191 // Helper for setData().
192 void setEffectData(GrGpuGL* gpu, const GrEffectStage& stage, const EffectAnd Samplers& effect);
193
194 // Helper for setData(). Makes GL calls to specify the initial color when th ere is not
195 // per-vertex colors.
196 void setColor(const GrDrawState&, GrColor color, SharedGLState*);
197
198 // Helper for setData(). Makes GL calls to specify the initial coverage when there is not
199 // per-vertex coverages.
200 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*);
201
202 // Helper for setData() that sets the view matrix and loads the render targe t height uniform
203 void setMatrixAndRenderTargetHeight(const GrDrawState&);
204
198 // GL IDs 205 // GL IDs
199 GrGLuint fVShaderID; 206 GrGLuint fVShaderID;
200 GrGLuint fGShaderID; 207 GrGLuint fGShaderID;
201 GrGLuint fFShaderID; 208 GrGLuint fFShaderID;
202 GrGLuint fProgramID; 209 GrGLuint fProgramID;
203 210
204 // these reflect the current values of uniforms (GL uniform values travel wi th program) 211 // these reflect the current values of uniforms (GL uniform values travel wi th program)
205 MatrixState fMatrixState; 212 MatrixState fMatrixState;
206 GrColor fColor; 213 GrColor fColor;
207 GrColor fCoverage; 214 GrColor fCoverage;
208 GrColor fColorFilterColor; 215 GrColor fColorFilterColor;
209 int fDstCopyTexUnit; 216 int fDstCopyTexUnit;
210 217
211 SkTArray<EffectAndSamplers> fEffectStates; 218 SkTArray<EffectAndSamplers> fColorEffects;
219 SkTArray<EffectAndSamplers> fCoverageEffects;
212 220
213 GrGLProgramDesc fDesc; 221 GrGLProgramDesc fDesc;
214 const GrGLContext& fContext; 222 const GrGLContext& fContext;
215 223
216 GrGLUniformManager fUniformManager; 224 GrGLUniformManager fUniformManager;
217 UniformHandles fUniformHandles; 225 UniformHandles fUniformHandles;
218 226
219 typedef GrRefCnt INHERITED; 227 typedef GrRefCnt INHERITED;
220 }; 228 };
221 229
222 #endif 230 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/gl/GrGLProgram.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698