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

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

Issue 25474006: Move VertexBuilder to a GrGLFullShaderBuilder subclass (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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; 17 class GrGLProgramEffectsBuilder;
18 class GrGLVertexProgramEffectsBuilder;
18 class GrGLShaderBuilder; 19 class GrGLShaderBuilder;
20 class GrGLFullShaderBuilder;
19 21
20 /** 22 /**
21 * 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
22 * 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
23 * state and shader uniforms. 25 * state and shader uniforms.
24 */ 26 */
25 class GrGLProgramEffects { 27 class GrGLProgramEffects {
26 public: 28 public:
27 typedef GrBackendEffectFactory::EffectKey EffectKey; 29 typedef GrBackendEffectFactory::EffectKey EffectKey;
28 typedef GrGLUniformManager::UniformHandle UniformHandle; 30 typedef GrGLUniformManager::UniformHandle UniformHandle;
29 31
30 /** 32 /**
31 * These methods generate different portions of an effect's final key. 33 * These methods generate different portions of an effect's final key.
32 */ 34 */
33 static EffectKey GenAttribKey(const GrDrawEffect&); 35 static EffectKey GenAttribKey(const GrDrawEffect&);
34 static EffectKey GenTransformKey(const GrDrawEffect&); 36 static EffectKey GenTransformKey(const GrDrawEffect&);
35 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&); 37 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
36 38
37 ~GrGLProgramEffects(); 39 virtual ~GrGLProgramEffects();
38 40
39 /** 41 /**
40 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ es the next 42 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writ es the next
41 * available unit to *texUnitIdx when it returns. 43 * available unit to *texUnitIdx when it returns.
42 */ 44 */
43 void initSamplers(const GrGLUniformManager&, int* texUnitIdx); 45 void initSamplers(const GrGLUniformManager&, int* texUnitIdx);
44 46
45 /** 47 /**
46 * Calls setData() on each effect, and sets their transformation matrices an d texture bindings. 48 * Calls setData() on each effect, and sets their transformation matrices an d texture bindings.
47 */ 49 */
48 void setData(GrGpuGL*, 50 virtual void setData(GrGpuGL*,
49 const GrGLUniformManager&, 51 const GrGLUniformManager&,
50 const GrEffectStage* effectStages[]); 52 const GrEffectStage* effectStages[]) = 0;
51 53
52 /** 54 /**
53 * 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.
54 */ 56 */
55 class TransformedCoords { 57 class TransformedCoords {
56 public: 58 public:
57 TransformedCoords(const char* name, GrSLType type) 59 TransformedCoords(const char* name, GrSLType type)
58 : fName(name), fType(type) { 60 : fName(name), fType(type) {
59 } 61 }
60 62
(...skipping 26 matching lines...) Expand all
87 const char* swizzle() const { return fSwizzle; } 89 const char* swizzle() const { return fSwizzle; }
88 90
89 private: 91 private:
90 UniformHandle fSamplerUniform; 92 UniformHandle fSamplerUniform;
91 uint32_t fConfigComponentMask; 93 uint32_t fConfigComponentMask;
92 char fSwizzle[5]; 94 char fSwizzle[5];
93 }; 95 };
94 96
95 typedef SkTArray<TextureSampler> TextureSamplerArray; 97 typedef SkTArray<TextureSampler> TextureSamplerArray;
96 98
97 private: 99 protected:
98 friend class GrGLProgramEffectsBuilder; 100 friend class GrGLProgramEffectsBuilder;
99 101
100 GrGLProgramEffects(int reserveCount, bool explicitLocalCoords) 102 GrGLProgramEffects(int reserveCount)
101 : fGLEffects(reserveCount) 103 : fGLEffects(reserveCount)
104 , fSamplers(reserveCount) {
105 }
106
107 /**
108 * Helper for setData(). Binds all the textures for an effect.
109 */
110 void bindTextures(GrGpuGL*, const GrEffectRef&, int effectIdx);
111
112 struct Sampler {
113 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {})
114 UniformHandle fUniform;
115 int fTextureUnit;
116 };
117
118 SkTArray<GrGLEffect*> fGLEffects;
119 SkTArray<SkSTArray<4, Sampler, true> > fSamplers;
120 };
121
122 /**
123 * This is a GrGLProgramEffects implementation that does coord transforms with t he vertex shader.
124 */
125 class GrGLVertexProgramEffects : public GrGLProgramEffects {
126 public:
127 virtual void setData(GrGpuGL*,
128 const GrGLUniformManager&,
129 const GrEffectStage* effectStages[]) SK_OVERRIDE;
130
131 private:
132 friend class GrGLVertexProgramEffectsBuilder;
133
134 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords)
135 : INHERITED(reserveCount)
102 , fTransforms(reserveCount) 136 , fTransforms(reserveCount)
103 , fSamplers(reserveCount)
104 , fHasExplicitLocalCoords(explicitLocalCoords) { 137 , fHasExplicitLocalCoords(explicitLocalCoords) {
105 } 138 }
106 139
107 /** 140 /**
108 * Helper for setData(). Sets all the transform matrices for an effect. 141 * Helper for setData(). Sets all the transform matrices for an effect.
109 */ 142 */
110 void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int ef fectIdx); 143 void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int ef fectIdx);
111 144
112 /**
113 * Helper for setData(). Binds all the textures for an effect.
114 */
115 void bindTextures(GrGpuGL*, const GrEffectRef&, int effectIdx);
116
117 struct Transform { 145 struct Transform {
118 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); } 146 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); }
119 UniformHandle fHandle; 147 UniformHandle fHandle;
120 GrSLType fType; 148 GrSLType fType;
121 SkMatrix fCurrentValue; 149 SkMatrix fCurrentValue;
122 }; 150 };
123 151
124 struct Sampler { 152 SkTArray<SkSTArray<2, Transform, true> > fTransforms;
125 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {}) 153 bool fHasExplicitLocalCoords;
126 UniformHandle fUniform;
127 int fTextureUnit;
128 };
129 154
130 SkTArray<GrGLEffect*> fGLEffects; 155 typedef GrGLProgramEffects INHERITED;
131 SkTArray<SkSTArray<2, Transform, true> > fTransforms;
132 SkTArray<SkSTArray<4, Sampler, true> > fSamplers;
133 bool fHasExplicitLocalCoords;
134 }; 156 };
135 157
136 //////////////////////////////////////////////////////////////////////////////// 158 ////////////////////////////////////////////////////////////////////////////////
137 159
138 /** 160 /**
139 * This class is used to construct a GrGLProgramEffects. 161 * This is an abstract base class for constructing different types of GrGLProgra mEffects objects.
140 */ 162 */
141 class GrGLProgramEffectsBuilder { 163 class GrGLProgramEffectsBuilder {
142 public: 164 public:
143 GrGLProgramEffectsBuilder(GrGLShaderBuilder* builder, int reserveCount);
144
145 /** 165 /**
146 * Emits the effect's shader code, and stores the necessary uniforms interna lly. 166 * Emits the effect's shader code, and stores the necessary uniforms interna lly.
147 */ 167 */
148 void emitEffect(const GrEffectStage&, 168 virtual void emitEffect(const GrEffectStage&,
149 GrGLProgramEffects::EffectKey, 169 GrGLProgramEffects::EffectKey,
150 const char* outColor, 170 const char* outColor,
151 const char* inColor, 171 const char* inColor,
152 int stageIndex); 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 */
188 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
189 public:
190 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount);
191
192 virtual void emitEffect(const GrEffectStage&,
193 GrGLProgramEffects::EffectKey,
194 const char* outColor,
195 const char* inColor,
196 int stageIndex) SK_OVERRIDE;
153 197
154 /** 198 /**
155 * Finalizes the building process and returns the effect array. After this c all, the builder 199 * Finalizes the building process and returns the effect array. After this c all, the builder
156 * becomes invalid. 200 * becomes invalid.
157 */ 201 */
158 GrGLProgramEffects* finish() { return fProgramEffects.detach(); } 202 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
159 203
160 private: 204 private:
161 /** 205 /**
162 * Helper for emitEffect(). Emits any attributes an effect might have. 206 * Helper for emitEffect(). Emits any attributes an effect might have.
163 */ 207 */
164 void emitAttributes(const GrEffectStage&); 208 void emitAttributes(const GrEffectStage&);
165 209
166 /** 210 /**
167 * Helper for emitEffect(). Emits code to implement an effect's coord transf orms in the VS. 211 * Helper for emitEffect(). Emits code to implement an effect's coord transf orms in the VS.
168 * Varyings are added as an outputs of the VS and inputs to the FS. The vary ings may be either a 212 * Varyings are added as an outputs of the VS and inputs to the FS. The vary ings may be either a
169 * vec2f or vec3f depending upon whether perspective interpolation is requir ed or not. The names 213 * vec2f or vec3f depending upon whether perspective interpolation is requir ed or not. The names
170 * of the varyings in the VS and FS as well their types are appended to the 214 * of the varyings in the VS and FS as well their types are appended to the
171 * TransformedCoordsArray* object, which is in turn passed to the effect's e mitCode() function. 215 * TransformedCoordsArray* object, which is in turn passed to the effect's e mitCode() function.
172 */ 216 */
173 void emitTransforms(const GrEffectRef&, 217 void emitTransforms(const GrEffectRef&,
174 GrGLProgramEffects::EffectKey, 218 GrGLProgramEffects::EffectKey,
175 GrGLProgramEffects::TransformedCoordsArray*); 219 GrGLProgramEffects::TransformedCoordsArray*);
176 220
177 /** 221 GrGLFullShaderBuilder* fBuilder;
178 * Helper for emitEffect(). Emits uniforms for an effect's texture accesses. The uniform info 222 SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects;
179 * as well as texture access parameters are appended to the TextureSamplerAr ray* object, which
180 * is in turn passed to the effect's emitCode() function.
181 */
182 void emitSamplers(const GrEffectRef&,
183 GrGLProgramEffects::TextureSamplerArray*);
184 223
185 GrGLShaderBuilder* fBuilder; 224 typedef GrGLProgramEffectsBuilder INHERITED;
186 SkAutoTDelete<GrGLProgramEffects> fProgramEffects;
187 }; 225 };
188 226
189 #endif 227 #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