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

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

Issue 25846002: Use vertexless shaders when NVpr is available (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix mac build Created 7 years, 2 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 | « src/gpu/gl/GrGLProgramDesc.h ('k') | src/gpu/gl/GrGLProgramEffects.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 2013 Google Inc. 2 * Copyright 2013 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 #ifndef GrGLProgramEffects_DEFINED 8 #ifndef GrGLProgramEffects_DEFINED
9 #define GrGLProgramEffects_DEFINED 9 #define GrGLProgramEffects_DEFINED
10 10
11 #include "GrBackendEffectFactory.h" 11 #include "GrBackendEffectFactory.h"
12 #include "GrTexture.h" 12 #include "GrTexture.h"
13 #include "GrTextureAccess.h" 13 #include "GrTextureAccess.h"
14 #include "GrGLUniformManager.h" 14 #include "GrGLUniformManager.h"
15 15
16 class GrEffectStage; 16 class GrEffectStage;
17 class GrGLProgramEffectsBuilder;
18 class GrGLVertexProgramEffectsBuilder; 17 class GrGLVertexProgramEffectsBuilder;
19 class GrGLShaderBuilder; 18 class GrGLShaderBuilder;
20 class GrGLFullShaderBuilder; 19 class GrGLFullShaderBuilder;
20 class GrGLFragmentOnlyShaderBuilder;
21 21
22 /** 22 /**
23 * This class encapsulates an array of GrGLEffects and their supporting data (co ord transforms 23 * This class encapsulates an array of GrGLEffects and their supporting data (co ord transforms
24 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag e the necessary GL 24 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manag e the necessary GL
25 * state and shader uniforms. 25 * state and shader uniforms.
26 */ 26 */
27 class GrGLProgramEffects { 27 class GrGLProgramEffects {
28 public: 28 public:
29 typedef GrBackendEffectFactory::EffectKey EffectKey; 29 typedef GrBackendEffectFactory::EffectKey EffectKey;
30 typedef GrGLUniformManager::UniformHandle UniformHandle; 30 typedef GrGLUniformManager::UniformHandle UniformHandle;
(...skipping 18 matching lines...) Expand all
49 */ 49 */
50 virtual void setData(GrGpuGL*, 50 virtual void setData(GrGpuGL*,
51 const GrGLUniformManager&, 51 const GrGLUniformManager&,
52 const GrEffectStage* effectStages[]) = 0; 52 const GrEffectStage* effectStages[]) = 0;
53 53
54 /** 54 /**
55 * Passed to GrGLEffects so they can add transformed coordinates to their sh ader code. 55 * Passed to GrGLEffects so they can add transformed coordinates to their sh ader code.
56 */ 56 */
57 class TransformedCoords { 57 class TransformedCoords {
58 public: 58 public:
59 TransformedCoords(const char* name, GrSLType type) 59 TransformedCoords(const SkString& name, GrSLType type)
60 : fName(name), fType(type) { 60 : fName(name), fType(type) {
61 } 61 }
62 62
63 const char* c_str() const { return fName.c_str(); } 63 const char* c_str() const { return fName.c_str(); }
64 GrSLType type() const { return fType; } 64 GrSLType type() const { return fType; }
65 const SkString& getName() const { return fName; } 65 const SkString& getName() const { return fName; }
66 66
67 private: 67 private:
68 SkString fName; 68 SkString fName;
69 GrSLType fType; 69 GrSLType fType;
(...skipping 20 matching lines...) Expand all
90 90
91 private: 91 private:
92 UniformHandle fSamplerUniform; 92 UniformHandle fSamplerUniform;
93 uint32_t fConfigComponentMask; 93 uint32_t fConfigComponentMask;
94 char fSwizzle[5]; 94 char fSwizzle[5];
95 }; 95 };
96 96
97 typedef SkTArray<TextureSampler> TextureSamplerArray; 97 typedef SkTArray<TextureSampler> TextureSamplerArray;
98 98
99 protected: 99 protected:
100 friend class GrGLProgramEffectsBuilder;
101
102 GrGLProgramEffects(int reserveCount) 100 GrGLProgramEffects(int reserveCount)
103 : fGLEffects(reserveCount) 101 : fGLEffects(reserveCount)
104 , fSamplers(reserveCount) { 102 , fSamplers(reserveCount) {
105 } 103 }
106 104
107 /** 105 /**
106 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's t exture accesses and
107 * appends the necessary data to the TextureSamplerArray* object so effects can add texture
108 * lookups to their code. This method is only meant to be called during the construction phase.
109 */
110 void emitSamplers(GrGLShaderBuilder*, const GrEffectRef&, TextureSamplerArra y*);
111
112 /**
108 * Helper for setData(). Binds all the textures for an effect. 113 * Helper for setData(). Binds all the textures for an effect.
109 */ 114 */
110 void bindTextures(GrGpuGL*, const GrEffectRef&, int effectIdx); 115 void bindTextures(GrGpuGL*, const GrEffectRef&, int effectIdx);
111 116
112 struct Sampler { 117 struct Sampler {
113 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) 118 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {})
114 UniformHandle fUniform; 119 UniformHandle fUniform;
115 int fTextureUnit; 120 int fTextureUnit;
116 }; 121 };
117 122
118 SkTArray<GrGLEffect*> fGLEffects; 123 SkTArray<GrGLEffect*> fGLEffects;
119 SkTArray<SkSTArray<4, Sampler, true> > fSamplers; 124 SkTArray<SkSTArray<4, Sampler, true> > fSamplers;
120 }; 125 };
121 126
122 /** 127 /**
128 * This is an abstract base class for constructing different types of GrGLProgra mEffects objects.
129 */
130 class GrGLProgramEffectsBuilder {
131 public:
132 /**
133 * Emits the effect's shader code, and stores the necessary uniforms interna lly.
134 */
135 virtual void emitEffect(const GrEffectStage&,
136 GrGLProgramEffects::EffectKey,
137 const char* outColor,
138 const char* inColor,
139 int stageIndex) = 0;
140 };
141
142 ////////////////////////////////////////////////////////////////////////////////
143
144 /**
123 * This is a GrGLProgramEffects implementation that does coord transforms with t he vertex shader. 145 * This is a GrGLProgramEffects implementation that does coord transforms with t he vertex shader.
124 */ 146 */
125 class GrGLVertexProgramEffects : public GrGLProgramEffects { 147 class GrGLVertexProgramEffects : public GrGLProgramEffects {
126 public: 148 public:
127 virtual void setData(GrGpuGL*, 149 virtual void setData(GrGpuGL*,
128 const GrGLUniformManager&, 150 const GrGLUniformManager&,
129 const GrEffectStage* effectStages[]) SK_OVERRIDE; 151 const GrEffectStage* effectStages[]) SK_OVERRIDE;
130 152
131 private: 153 private:
132 friend class GrGLVertexProgramEffectsBuilder; 154 friend class GrGLVertexProgramEffectsBuilder;
133 155
134 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords) 156 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords)
135 : INHERITED(reserveCount) 157 : INHERITED(reserveCount)
136 , fTransforms(reserveCount) 158 , fTransforms(reserveCount)
137 , fHasExplicitLocalCoords(explicitLocalCoords) { 159 , fHasExplicitLocalCoords(explicitLocalCoords) {
138 } 160 }
139 161
140 /** 162 /**
163 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called
164 * during the construction phase.
165 */
166 void emitEffect(GrGLFullShaderBuilder*,
167 const GrEffectStage&,
168 GrGLProgramEffects::EffectKey,
169 const char* outColor,
170 const char* inColor,
171 int stageIndex);
172
173 /**
174 * Helper for emitEffect(). Emits any attributes an effect may have.
175 */
176 void emitAttributes(GrGLFullShaderBuilder*, const GrEffectStage&);
177
178 /**
179 * Helper for emitEffect(). Emits code to implement an effect's coord transf orms in the VS.
180 * Varyings are added as an outputs of the VS and inputs to the FS. The vary ings may be either a
181 * vec2f or vec3f depending upon whether perspective interpolation is requir ed or not. The names
182 * of the varyings in the VS and FS as well their types are appended to the
183 * TransformedCoordsArray* object, which is in turn passed to the effect's e mitCode() function.
184 */
185 void emitTransforms(GrGLFullShaderBuilder*,
186 const GrEffectRef&,
187 EffectKey,
188 TransformedCoordsArray*);
189
190 /**
141 * Helper for setData(). Sets all the transform matrices for an effect. 191 * Helper for setData(). Sets all the transform matrices for an effect.
142 */ 192 */
143 void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int ef fectIdx); 193 void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int ef fectIdx);
144 194
145 struct Transform { 195 struct Transform {
146 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } 196 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); }
147 UniformHandle fHandle; 197 UniformHandle fHandle;
148 GrSLType fType; 198 GrSLType fType;
149 SkMatrix fCurrentValue; 199 SkMatrix fCurrentValue;
150 }; 200 };
151 201
152 SkTArray<SkSTArray<2, Transform, true> > fTransforms; 202 SkTArray<SkSTArray<2, Transform, true> > fTransforms;
153 bool fHasExplicitLocalCoords; 203 bool fHasExplicitLocalCoords;
154 204
155 typedef GrGLProgramEffects INHERITED; 205 typedef GrGLProgramEffects INHERITED;
156 }; 206 };
157 207
158 ////////////////////////////////////////////////////////////////////////////////
159
160 /** 208 /**
161 * This is an abstract base class for constructing different types of GrGLProgra mEffects objects. 209 * This class is used to construct a GrGLVertexProgramEffects* object.
162 */
163 class GrGLProgramEffectsBuilder {
164 public:
165 /**
166 * Emits the effect's shader code, and stores the necessary uniforms interna lly.
167 */
168 virtual void emitEffect(const GrEffectStage&,
169 GrGLProgramEffects::EffectKey,
170 const char* outColor,
171 const char* inColor,
172 int stageIndex) = 0;
173
174 protected:
175 /**
176 * Helper for emitEffect(). Emits uniforms for an effect's texture accesses and appends the
177 * necessary data to the TextureSamplerArray* object so effects can add text ure lookups.
178 */
179 static void emitSamplers(GrGLShaderBuilder*,
180 GrGLProgramEffects*,
181 const GrEffectRef&,
182 GrGLProgramEffects::TextureSamplerArray*);
183 };
184
185 /**
186 * This class is used to construct a GrGLVertexProgramEffects object.
187 */ 210 */
188 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder { 211 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
189 public: 212 public:
190 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount); 213 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount);
191 214
192 virtual void emitEffect(const GrEffectStage&, 215 virtual void emitEffect(const GrEffectStage&,
193 GrGLProgramEffects::EffectKey, 216 GrGLProgramEffects::EffectKey,
217 const char* outColor,
218 const char* inColor,
219 int stageIndex) SK_OVERRIDE;
220
221 /**
222 * Finalizes the building process and returns the effect array. After this c all, the builder
223 * becomes invalid.
224 */
225 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
226
227 private:
228 GrGLFullShaderBuilder* fBuilder;
229 SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects;
230
231 typedef GrGLProgramEffectsBuilder INHERITED;
232 };
233
234 ////////////////////////////////////////////////////////////////////////////////
235
236 /**
237 * This is a GrGLProgramEffects implementation that does coord transforms with t he the built-in GL
238 * TexGen functionality.
239 */
240 class GrGLTexGenProgramEffects : public GrGLProgramEffects {
241 public:
242 virtual void setData(GrGpuGL*,
243 const GrGLUniformManager&,
244 const GrEffectStage* effectStages[]) SK_OVERRIDE;
245
246 private:
247 friend class GrGLTexGenProgramEffectsBuilder;
248
249 GrGLTexGenProgramEffects(int reserveCount)
250 : INHERITED(reserveCount)
251 , fTransforms(reserveCount) {
252 }
253
254 /**
255 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called
256 * during the construction phase.
257 */
258 void emitEffect(GrGLFragmentOnlyShaderBuilder*,
259 const GrEffectStage&,
260 GrGLProgramEffects::EffectKey,
261 const char* outColor,
262 const char* inColor,
263 int stageIndex);
264
265 /**
266 * Helper for emitEffect(). Allocates texture units from the builder for eac h transform in an
267 * effect. The transforms all use adjacent texture units. They either use tw o or three of the
268 * coordinates at a given texture unit, depending on if they need perspectiv e interpolation.
269 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[ 0])') as well as the
270 * types are appended to the TransformedCoordsArray* object, which is in tur n passed to the
271 * effect's emitCode() function.
272 */
273 void setupTexGen(GrGLFragmentOnlyShaderBuilder*,
274 const GrEffectRef&,
275 EffectKey,
276 TransformedCoordsArray*);
277
278 /**
279 * Helper for setData(). Sets the TexGen state for each transform in an effe ct.
280 */
281 void setTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx);
282
283 struct Transforms {
284 Transforms(EffectKey transformKey, int texCoordIndex)
285 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {}
286 EffectKey fTransformKey;
287 int fTexCoordIndex;
288 };
289
290 SkTArray<Transforms> fTransforms;
291
292 typedef GrGLProgramEffects INHERITED;
293 };
294
295 /**
296 * This class is used to construct a GrGLTexGenProgramEffects* object.
297 */
298 class GrGLTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
299 public:
300 GrGLTexGenProgramEffectsBuilder(GrGLFragmentOnlyShaderBuilder*, int reserveC ount);
301
302 virtual void emitEffect(const GrEffectStage&,
303 GrGLProgramEffects::EffectKey,
194 const char* outColor, 304 const char* outColor,
195 const char* inColor, 305 const char* inColor,
196 int stageIndex) SK_OVERRIDE; 306 int stageIndex) SK_OVERRIDE;
197 307
198 /** 308 /**
199 * Finalizes the building process and returns the effect array. After this c all, the builder 309 * Finalizes the building process and returns the effect array. After this c all, the builder
200 * becomes invalid. 310 * becomes invalid.
201 */ 311 */
202 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } 312 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
203 313
204 private: 314 private:
205 /** 315 GrGLFragmentOnlyShaderBuilder* fBuilder;
206 * Helper for emitEffect(). Emits any attributes an effect might have. 316 SkAutoTDelete<GrGLTexGenProgramEffects> fProgramEffects;
207 */
208 void emitAttributes(const GrEffectStage&);
209
210 /**
211 * Helper for emitEffect(). Emits code to implement an effect's coord transf orms in the VS.
212 * Varyings are added as an outputs of the VS and inputs to the FS. The vary ings may be either a
213 * vec2f or vec3f depending upon whether perspective interpolation is requir ed or not. The names
214 * of the varyings in the VS and FS as well their types are appended to the
215 * TransformedCoordsArray* object, which is in turn passed to the effect's e mitCode() function.
216 */
217 void emitTransforms(const GrEffectRef&,
218 GrGLProgramEffects::EffectKey,
219 GrGLProgramEffects::TransformedCoordsArray*);
220
221 GrGLFullShaderBuilder* fBuilder;
222 SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects;
223 317
224 typedef GrGLProgramEffectsBuilder INHERITED; 318 typedef GrGLProgramEffectsBuilder INHERITED;
225 }; 319 };
226 320
227 #endif 321 #endif
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLProgramDesc.h ('k') | src/gpu/gl/GrGLProgramEffects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698