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

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

Issue 25846002: Use vertexless shaders when NVpr is available (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Oops, make all the tests pass 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
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 #include "GrGLProgramEffects.h" 8 #include "GrGLProgramEffects.h"
9 #include "GrDrawEffect.h" 9 #include "GrDrawEffect.h"
10 #include "gl/GrGLEffect.h" 10 #include "gl/GrGLEffect.h"
(...skipping 19 matching lines...) Expand all
30 30
31 /** 31 /**
32 * The key for an individual coord transform is made up of a matrix type and a b it that 32 * The key for an individual coord transform is made up of a matrix type and a b it that
33 * indicates the source of the input coords. 33 * indicates the source of the input coords.
34 */ 34 */
35 enum { 35 enum {
36 kMatrixTypeKeyBits = 2, 36 kMatrixTypeKeyBits = 2,
37 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1, 37 kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
38 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits), 38 kPositionCoords_Flag = (1 << kMatrixTypeKeyBits),
39 kTransformKeyBits = kMatrixTypeKeyBits + 1, 39 kTransformKeyBits = kMatrixTypeKeyBits + 1,
40 kTransformKeyMask = (1 << kTransformKeyBits) - 1,
41 }; 40 };
42 41
43 namespace { 42 namespace {
44 43
45 /** 44 /**
46 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic h channels are 45 * Do we need to either map r,g,b->a or a->r. configComponentMask indicates whic h channels are
47 * present in the texture's config. swizzleComponentMask indicates the channels present in the 46 * present in the texture's config. swizzleComponentMask indicates the channels present in the
48 * shader swizzle. 47 * shader swizzle.
49 */ 48 */
50 inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps, 49 inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps,
(...skipping 11 matching lines...) Expand all
62 } 61 }
63 if (kRGB_GrColorComponentFlags & swizzleComponentMask) { 62 if (kRGB_GrColorComponentFlags & swizzleComponentMask) {
64 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that 63 // The 'r', 'g', and/or 'b's must be mapped to 'a' according to our semantics that
65 // alpha-only textures smear alpha across all four channels when rea d. 64 // alpha-only textures smear alpha across all four channels when rea d.
66 return true; 65 return true;
67 } 66 }
68 } 67 }
69 return false; 68 return false;
70 } 69 }
71 70
71 /**
72 * Retrieves the matrix type from transformKey for the transform at transformIdx .
73 */
74 MatrixType get_matrix_type(EffectKey transformKey, int transformIdx) {
75 return static_cast<MatrixType>(
76 (transformKey >> (kTransformKeyBits * transformIdx)) & kMatrixTyp eKeyMask);
77 }
78
79 /**
80 * Retrieves the source coords from transformKey for the transform at transformI dx. It may not be
81 * the same coordinate set as the original GrCoordTransform if the position and local coords are
82 * identical for this program.
83 */
84 GrCoordSet get_source_coords(EffectKey transformKey, int transformIdx) {
85 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord s_Flag ?
86 kPosition_GrCoordSet :
87 kLocal_GrCoordSet;
88 }
89
90 /**
91 * Retrieves the final translation that a transform needs to apply to its source coords (and
92 * verifies that a translation is all it needs).
93 */
94 void get_transform_translation(const GrDrawEffect& drawEffect,
95 int transformIdx,
96 GrGLfloat* tx,
97 GrGLfloat* ty) {
98 const GrCoordTransform& coordTransform = (*drawEffect.effect())->coordTransf orm(transformIdx);
99 SkASSERT(!coordTransform.reverseY());
100 const SkMatrix& matrix = coordTransform.getMatrix();
101 if (kLocal_GrCoordSet == coordTransform.sourceCoords() &&
102 !drawEffect.programHasExplicitLocalCoords()) {
103 const SkMatrix& coordChangeMatrix = drawEffect.getCoordChangeMatrix();
104 SkASSERT(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChangeMat rix.getType()));
105 *tx = SkScalarToFloat(matrix[SkMatrix::kMTransX] + coordChangeMatrix[SkM atrix::kMTransX]);
106 *ty = SkScalarToFloat(matrix[SkMatrix::kMTransY] + coordChangeMatrix[SkM atrix::kMTransY]);
107 } else {
108 SkASSERT(SkMatrix::kTranslate_Mask == matrix.getType());
109 *tx = SkScalarToFloat(matrix[SkMatrix::kMTransX]);
110 *ty = SkScalarToFloat(matrix[SkMatrix::kMTransY]);
111 }
112 }
113
114 /**
115 * Retrieves the final matrix that a transform needs to apply to its source coor ds.
116 */
117 SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx) {
118 const GrCoordTransform& coordTransform = (*drawEffect.effect())->coordTransf orm(transformIdx);
119 SkMatrix combined;
120 if (kLocal_GrCoordSet == coordTransform.sourceCoords() &&
121 !drawEffect.programHasExplicitLocalCoords()) {
122 combined.setConcat(coordTransform.getMatrix(), drawEffect.getCoordChange Matrix());
123 } else {
124 combined = coordTransform.getMatrix();
125 }
126 if (coordTransform.reverseY()) {
127 // combined.postScale(1,-1);
128 // combined.postTranslate(0,1);
129 combined.set(SkMatrix::kMSkewY,
130 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]);
131 combined.set(SkMatrix::kMScaleY,
132 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]);
133 combined.set(SkMatrix::kMTransY,
134 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]);
135 }
136 return combined;
137 }
138
72 } 139 }
73 140
74 EffectKey GrGLProgramEffects::GenAttribKey(const GrDrawEffect& drawEffect) { 141 EffectKey GrGLProgramEffects::GenAttribKey(const GrDrawEffect& drawEffect) {
75 EffectKey key = 0; 142 EffectKey key = 0;
76 int numAttributes = drawEffect.getVertexAttribIndexCount(); 143 int numAttributes = drawEffect.getVertexAttribIndexCount();
77 SkASSERT(numAttributes <= 2); 144 SkASSERT(numAttributes <= 2);
78 const int* attributeIndices = drawEffect.getVertexAttribIndices(); 145 const int* attributeIndices = drawEffect.getVertexAttribIndices();
79 for (int a = 0; a < numAttributes; ++a) { 146 for (int a = 0; a < numAttributes; ++a) {
80 EffectKey value = attributeIndices[a] << 3 * a; 147 EffectKey value = attributeIndices[a] << 3 * a;
81 SkASSERT(0 == (value & key)); // keys for each attribute ought not to ov erlap 148 SkASSERT(0 == (value & key)); // keys for each attribute ought not to ov erlap
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 239 }
173 } 240 }
174 241
175 void GrGLVertexProgramEffects::setTransformData(const GrGLUniformManager& unifor mManager, 242 void GrGLVertexProgramEffects::setTransformData(const GrGLUniformManager& unifor mManager,
176 const GrDrawEffect& drawEffect, 243 const GrDrawEffect& drawEffect,
177 int effectIdx) { 244 int effectIdx) {
178 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; 245 SkTArray<Transform, true>& transforms = fTransforms[effectIdx];
179 int numTransforms = transforms.count(); 246 int numTransforms = transforms.count();
180 SkASSERT(numTransforms == (*drawEffect.effect())->numTransforms()); 247 SkASSERT(numTransforms == (*drawEffect.effect())->numTransforms());
181 for (int t = 0; t < numTransforms; ++t) { 248 for (int t = 0; t < numTransforms; ++t) {
182 const GrCoordTransform& coordTransform = (*drawEffect.effect())->coordTr ansform(t);
183 const SkMatrix& matrix = coordTransform.getMatrix();
184 const SkMatrix& coordChangeMatrix = kLocal_GrCoordSet == coordTransform. sourceCoords() ?
185 drawEffect.getCoordChangeMatrix( ) :
186 SkMatrix::I();
187 SkASSERT(transforms[t].fHandle.isValid() != (kVoid_GrSLType == transform s[t].fType)); 249 SkASSERT(transforms[t].fHandle.isValid() != (kVoid_GrSLType == transform s[t].fType));
188 switch (transforms[t].fType) { 250 switch (transforms[t].fType) {
189 case kVoid_GrSLType: 251 case kVoid_GrSLType:
190 SkASSERT(matrix.isIdentity()); 252 SkASSERT(get_transform_matrix(drawEffect, t).isIdentity());
191 SkASSERT(coordChangeMatrix.isIdentity());
192 SkASSERT(!coordTransform.reverseY());
193 return; 253 return;
194 case kVec2f_GrSLType: { 254 case kVec2f_GrSLType: {
195 SkASSERT(SkMatrix::kTranslate_Mask == (matrix.getType() | coordC hangeMatrix.getType())); 255 GrGLfloat tx, ty;
196 SkASSERT(!coordTransform.reverseY()); 256 get_transform_translation(drawEffect, t, &tx, &ty);
197 SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[S kMatrix::kMTransX];
198 SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[S kMatrix::kMTransY];
199 if (transforms[t].fCurrentValue.get(SkMatrix::kMTransX) != tx || 257 if (transforms[t].fCurrentValue.get(SkMatrix::kMTransX) != tx ||
200 transforms[t].fCurrentValue.get(SkMatrix::kMTransY) != ty) { 258 transforms[t].fCurrentValue.get(SkMatrix::kMTransY) != ty) {
201 uniformManager.set2f(transforms[t].fHandle, tx, ty); 259 uniformManager.set2f(transforms[t].fHandle, tx, ty);
202 transforms[t].fCurrentValue.set(SkMatrix::kMTransX, tx); 260 transforms[t].fCurrentValue.set(SkMatrix::kMTransX, tx);
203 transforms[t].fCurrentValue.set(SkMatrix::kMTransY, ty); 261 transforms[t].fCurrentValue.set(SkMatrix::kMTransY, ty);
204 } 262 }
205 break; 263 break;
206 } 264 }
207 case kMat33f_GrSLType: { 265 case kMat33f_GrSLType: {
208 SkMatrix combined; 266 const SkMatrix& matrix = get_transform_matrix(drawEffect, t);
209 combined.setConcat(matrix, coordChangeMatrix); 267 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) {
210 if (coordTransform.reverseY()) { 268 uniformManager.setSkMatrix(transforms[t].fHandle, matrix);
211 // combined.postScale(1,-1); 269 transforms[t].fCurrentValue = matrix;
212 // combined.postTranslate(0,1);
213 combined.set(SkMatrix::kMSkewY,
214 combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkew Y]);
215 combined.set(SkMatrix::kMScaleY,
216 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScal eY]);
217 combined.set(SkMatrix::kMTransY,
218 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTran sY]);
219 }
220 if (!transforms[t].fCurrentValue.cheapEqualTo(combined)) {
221 uniformManager.setSkMatrix(transforms[t].fHandle, combined);
222 transforms[t].fCurrentValue = combined;
223 } 270 }
224 break; 271 break;
225 } 272 }
226 default: 273 default:
227 GrCrash("Unexpected uniform type."); 274 GrCrash("Unexpected uniform type.");
228 } 275 }
229 } 276 }
230 } 277 }
231 278
279 void GrGLTexGenProgramEffects::setData(GrGpuGL* gpu,
280 const GrGLUniformManager& uniformManager,
281 const GrEffectStage* effectStages[]) {
282 int numEffects = fGLEffects.count();
283 SkASSERT(numEffects == fTransformKeys.count());
284 SkASSERT(numEffects == fSamplers.count());
285 int texCoordIdx = fFirstTexCoordIdx;
286 SkASSERT(texCoordIdx >= 0);
287 for (int e = 0; e < numEffects; ++e) {
288 GrDrawEffect drawEffect(*effectStages[e], false);
289 fGLEffects[e]->setData(uniformManager, drawEffect);
290 this->setTexGenState(gpu, drawEffect, &texCoordIdx, e);
291 this->bindTextures(gpu, *drawEffect.effect(), e);
292 }
293 SkASSERT(fNumTexCoordSets == texCoordIdx - fFirstTexCoordIdx);
294 }
295
296 void GrGLTexGenProgramEffects::setTexGenState(GrGpuGL* gpu,
297 const GrDrawEffect& drawEffect,
298 int* texCoordIdx,
299 int effectIdx) {
300 EffectKey transformKey = fTransformKeys[effectIdx];
301 int numTransforms = (*drawEffect.effect())->numTransforms();
302 for (int t = 0; t < numTransforms; ++t) {
303 switch (get_matrix_type(transformKey, t)) {
304 case kIdentity_MatrixType: {
305 SkASSERT(get_transform_matrix(drawEffect, t).isIdentity());
306 GrGLfloat identity[] = {1, 0, 0,
307 0, 1, 0};
308 gpu->enableTexGen((*texCoordIdx)++, GrGpuGL::kST_TexGenComponent s, identity);
309 break;
310 }
311 case kTrans_MatrixType: {
312 GrGLfloat tx, ty;
313 get_transform_translation(drawEffect, t, &tx, &ty);
314 GrGLfloat translate[] = {1, 0, tx,
315 0, 1, ty};
316 gpu->enableTexGen((*texCoordIdx)++, GrGpuGL::kST_TexGenComponent s, translate);
317 break;
318 }
319 case kNoPersp_MatrixType: {
320 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
321 gpu->enableTexGen((*texCoordIdx)++, GrGpuGL::kST_TexGenComponent s, transform);
322 break;
323 }
324 case kGeneral_MatrixType: {
325 const SkMatrix& transform = get_transform_matrix(drawEffect, t);
326 gpu->enableTexGen((*texCoordIdx)++, GrGpuGL::kSTR_TexGenComponen ts, transform);
327 break;
328 }
329 default:
330 GrCrash("Unexpected matrixs type.");
331 }
332 }
333 }
334
232 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffectRef& effect, i nt effectIdx) { 335 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffectRef& effect, i nt effectIdx) {
233 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; 336 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx];
234 int numSamplers = samplers.count(); 337 int numSamplers = samplers.count();
235 SkASSERT(numSamplers == effect->numTextures()); 338 SkASSERT(numSamplers == effect->numTextures());
236 for (int s = 0; s < numSamplers; ++s) { 339 for (int s = 0; s < numSamplers; ++s) {
237 SkASSERT(samplers[s].fTextureUnit >= 0); 340 SkASSERT(samplers[s].fTextureUnit >= 0);
238 const GrTextureAccess& textureAccess = effect->textureAccess(s); 341 const GrTextureAccess& textureAccess = effect->textureAccess(s);
239 gpu->bindTexture(samplers[s].fTextureUnit, 342 gpu->bindTexture(samplers[s].fTextureUnit,
240 textureAccess.getParams(), 343 textureAccess.getParams(),
241 static_cast<GrGLTexture*>(textureAccess.getTexture())); 344 static_cast<GrGLTexture*>(textureAccess.getTexture()));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 (*stage.getEffect())->vertexAttribType(a), 401 (*stage.getEffect())->vertexAttribType(a),
299 attributeName); 402 attributeName);
300 } 403 }
301 } 404 }
302 405
303 void GrGLVertexProgramEffectsBuilder::emitTransforms(const GrEffectRef& effect, 406 void GrGLVertexProgramEffectsBuilder::emitTransforms(const GrEffectRef& effect,
304 EffectKey effectKey, 407 EffectKey effectKey,
305 TransformedCoordsArray* out Coords) { 408 TransformedCoordsArray* out Coords) {
306 typedef GrGLVertexProgramEffects::Transform Transform; 409 typedef GrGLVertexProgramEffects::Transform Transform;
307 SkTArray<Transform, true>& transforms = fProgramEffects->fTransforms.push_ba ck(); 410 SkTArray<Transform, true>& transforms = fProgramEffects->fTransforms.push_ba ck();
308 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); 411 EffectKey transformKey = GrBackendEffectFactory::GetTransformKey(effectKey);
309 int numTransforms = effect->numTransforms(); 412 int numTransforms = effect->numTransforms();
310 transforms.push_back_n(numTransforms); 413 transforms.push_back_n(numTransforms);
311 for (int t = 0; t < numTransforms; t++) { 414 for (int t = 0; t < numTransforms; t++) {
312 EffectKey key = (totalKey >> (kTransformKeyBits * t)) & kTransformKeyMas k;
313 GrSLType varyingType = kVoid_GrSLType; 415 GrSLType varyingType = kVoid_GrSLType;
314 const char* uniName; 416 const char* uniName;
315 switch (key & kMatrixTypeKeyMask) { 417 switch (get_matrix_type(transformKey, t)) {
316 case kIdentity_MatrixType: 418 case kIdentity_MatrixType:
317 transforms[t].fType = kVoid_GrSLType; 419 transforms[t].fType = kVoid_GrSLType;
318 uniName = NULL; 420 uniName = NULL;
319 varyingType = kVec2f_GrSLType; 421 varyingType = kVec2f_GrSLType;
320 break; 422 break;
321 case kTrans_MatrixType: 423 case kTrans_MatrixType:
322 transforms[t].fType = kVec2f_GrSLType; 424 transforms[t].fType = kVec2f_GrSLType;
323 uniName = "StageTranslate"; 425 uniName = "StageTranslate";
324 varyingType = kVec2f_GrSLType; 426 varyingType = kVec2f_GrSLType;
325 break; 427 break;
(...skipping 27 matching lines...) Expand all
353 SkString suffixedVaryingName; 455 SkString suffixedVaryingName;
354 if (0 != t) { 456 if (0 != t) {
355 suffixedVaryingName.append(varyingName); 457 suffixedVaryingName.append(varyingName);
356 suffixedVaryingName.appendf("_%i", t); 458 suffixedVaryingName.appendf("_%i", t);
357 varyingName = suffixedVaryingName.c_str(); 459 varyingName = suffixedVaryingName.c_str();
358 } 460 }
359 const char* vsVaryingName; 461 const char* vsVaryingName;
360 const char* fsVaryingName; 462 const char* fsVaryingName;
361 fBuilder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryin gName); 463 fBuilder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryin gName);
362 464
363 const GrGLShaderVar& coords = (kPositionCoords_Flag & key) ? 465 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( transformKey, t) ?
364 fBuilder->positionAttribute() : 466 fBuilder->positionAttribute() :
365 fBuilder->localCoordsAttribute(); 467 fBuilder->localCoordsAttribute();
366 // varying = matrix * coords (logically) 468 // varying = matrix * coords (logically)
367 switch (transforms[t].fType) { 469 switch (transforms[t].fType) {
368 case kVoid_GrSLType: 470 case kVoid_GrSLType:
369 SkASSERT(kVec2f_GrSLType == varyingType); 471 SkASSERT(kVec2f_GrSLType == varyingType);
370 fBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords.c_ str()); 472 fBuilder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords.c_ str());
371 break; 473 break;
372 case kVec2f_GrSLType: 474 case kVec2f_GrSLType:
373 SkASSERT(kVec2f_GrSLType == varyingType); 475 SkASSERT(kVec2f_GrSLType == varyingType);
374 fBuilder->vsCodeAppendf("\t%s = %s + %s;\n", 476 fBuilder->vsCodeAppendf("\t%s = %s + %s;\n",
375 vsVaryingName, uniName, coords.c_str()); 477 vsVaryingName, uniName, coords.c_str());
376 break; 478 break;
377 case kMat33f_GrSLType: { 479 case kMat33f_GrSLType: {
378 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == va ryingType); 480 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == va ryingType);
379 if (kVec2f_GrSLType == varyingType) { 481 if (kVec2f_GrSLType == varyingType) {
380 fBuilder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", 482 fBuilder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n",
381 vsVaryingName, uniName, coords.c_str ()); 483 vsVaryingName, uniName, coords.c_str ());
382 } else { 484 } else {
383 fBuilder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", 485 fBuilder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n",
384 vsVaryingName, uniName, coords.c_str ()); 486 vsVaryingName, uniName, coords.c_str ());
385 } 487 }
386 break; 488 break;
387 } 489 }
388 default: 490 default:
389 GrCrash("Unexpected uniform type."); 491 GrCrash("Unexpected uniform type.");
390 } 492 }
391 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (fsVaryingName, var yingType)); 493 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords,
494 (SkString(fsVaryingName), varyingType));
392 } 495 }
393 } 496 }
394 497
498 GrGLTexGenProgramEffectsBuilder::GrGLTexGenProgramEffectsBuilder(
499 GrGLFragmentOnlyShaderBuilder* builder,
500 int reserveCount)
501 : fBuilder(builder)
502 , fProgramEffects(SkNEW_ARGS(GrGLTexGenProgramEffects, (reserveCount))) {
503 }
504
505 void GrGLTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
506 EffectKey key,
507 const char* outColor,
508 const char* inColor,
509 int stageIndex) {
510 SkASSERT(NULL != fProgramEffects.get());
511
512 GrDrawEffect drawEffect(stage, false);
513 const GrEffectRef& effect = *stage.getEffect();
514 SkSTArray<2, TransformedCoords> coords(effect->numTransforms());
515 SkSTArray<4, TextureSampler> samplers(effect->numTextures());
516
517 SkASSERT(0 == stage.getVertexAttribIndexCount());
518 this->setupTexGen(effect, key, &coords);
519 INHERITED::emitSamplers(fBuilder, fProgramEffects.get(), effect, &samplers);
520
521 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
522 fProgramEffects->fGLEffects.push_back(glEffect);
523
524 // Enclose custom code in a block to avoid namespace conflicts
525 SkString openBrace;
526 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name());
527 fBuilder->fsCodeAppend(openBrace.c_str());
528
529 SkASSERT(!glEffect->isVertexEffect());
530 glEffect->emitCode(fBuilder, drawEffect, key, outColor, inColor, coords, sam plers);
531
532 fBuilder->fsCodeAppend("\t}\n");
533 }
534
535 void GrGLTexGenProgramEffectsBuilder::setupTexGen(const GrEffectRef& effect,
536 EffectKey effectKey,
537 TransformedCoordsArray* outCoo rds) {
538 int numTransforms = effect->numTransforms();
539 SkDEBUGCODE(fProgramEffects->fNumTexCoordSets += numTransforms;)
540 int texCoordIdx = fBuilder->addTexCoordSets(numTransforms);
541 EffectKey transformKey = GrBackendEffectFactory::GetTransformKey(effectKey);
542 fProgramEffects->fTransformKeys.push_back(transformKey);
543 SkString name;
544 for (int t = 0; t < numTransforms; ++t) {
545 GrSLType type = kGeneral_MatrixType == get_matrix_type(transformKey, t) ?
546 kVec3f_GrSLType :
547 kVec2f_GrSLType;
548 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIdx++ );
549 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type));
550 }
551 }
552
395 void GrGLProgramEffectsBuilder::emitSamplers(GrGLShaderBuilder* builder, 553 void GrGLProgramEffectsBuilder::emitSamplers(GrGLShaderBuilder* builder,
396 GrGLProgramEffects* programEffects, 554 GrGLProgramEffects* programEffects,
397 const GrEffectRef& effect, 555 const GrEffectRef& effect,
398 TextureSamplerArray* outSamplers) { 556 TextureSamplerArray* outSamplers) {
399 typedef GrGLProgramEffects::Sampler Sampler; 557 typedef GrGLProgramEffects::Sampler Sampler;
400 SkTArray<Sampler, true>& samplers = programEffects->fSamplers.push_back(); 558 SkTArray<Sampler, true>& samplers = programEffects->fSamplers.push_back();
401 int numTextures = effect->numTextures(); 559 int numTextures = effect->numTextures();
402 samplers.push_back_n(numTextures); 560 samplers.push_back_n(numTextures);
403 SkString name; 561 SkString name;
404 for (int t = 0; t < numTextures; ++t) { 562 for (int t = 0; t < numTextures; ++t) {
405 name.printf("Sampler%d", t); 563 name.printf("Sampler%d", t);
406 samplers[t].fUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ Visibility, 564 samplers[t].fUniform = builder->addUniform(GrGLShaderBuilder::kFragment_ Visibility,
407 kSampler2D_GrSLType, 565 kSampler2D_GrSLType,
408 name.c_str()); 566 name.c_str());
409 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, 567 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler,
410 (samplers[t].fUniform, effect->textureAccess(t))) ; 568 (samplers[t].fUniform, effect->textureAccess(t))) ;
411 } 569 }
412 } 570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698