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

Side by Side Diff: src/gpu/effects/GrTextureDomainEffect.cpp

Issue 12547012: Make GrGLEffects use an interface to append their code. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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/effects/GrSimpleTextureEffect.cpp ('k') | src/gpu/gl/GrGLEffectMatrix.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 2012 Google Inc. 2 * Copyright 2012 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 "GrTextureDomainEffect.h" 8 #include "GrTextureDomainEffect.h"
9 #include "GrSimpleTextureEffect.h" 9 #include "GrSimpleTextureEffect.h"
10 #include "GrTBackendEffectFactory.h" 10 #include "GrTBackendEffectFactory.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const TextureSamplerArray& samplers) { 52 const TextureSamplerArray& samplers) {
53 const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffe ct>(stage); 53 const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffe ct>(stage);
54 54
55 const char* coords; 55 const char* coords;
56 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords); 56 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
57 const char* domain; 57 const char* domain;
58 fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 58 fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
59 kVec4f_GrSLType, "TexDom", &domain); 59 kVec4f_GrSLType, "TexDom", &domain);
60 if (GrTextureDomainEffect::kClamp_WrapMode == effect.wrapMode()) { 60 if (GrTextureDomainEffect::kClamp_WrapMode == effect.wrapMode()) {
61 61
62 builder->fFSCode.appendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n ", 62 builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n",
63 coords, domain, domain); 63 coords, domain, domain);
64 64
65 builder->fFSCode.appendf("\t%s = ", outputColor); 65 builder->fsCodeAppendf("\t%s = ", outputColor);
66 builder->appendTextureLookupAndModulate(&builder->fFSCode, 66 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_Sha derType,
67 inputColor, 67 inputColor,
68 samplers[0], 68 samplers[0],
69 "clampCoord"); 69 "clampCoord");
70 builder->fFSCode.append(";\n"); 70 builder->fsCodeAppend(";\n");
71 } else { 71 } else {
72 GrAssert(GrTextureDomainEffect::kDecal_WrapMode == effect.wrapMode()); 72 GrAssert(GrTextureDomainEffect::kDecal_WrapMode == effect.wrapMode());
73 73
74 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { 74 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) {
75 // On the NexusS and GalaxyNexus, the other path (with the 'any' 75 // On the NexusS and GalaxyNexus, the other path (with the 'any'
76 // call) causes the compilation error "Calls to any function that 76 // call) causes the compilation error "Calls to any function that
77 // may require a gradient calculation inside a conditional block 77 // may require a gradient calculation inside a conditional block
78 // may return undefined results". This appears to be an issue with 78 // may return undefined results". This appears to be an issue with
79 // the 'any' call since even the simple "result=black; if (any()) 79 // the 'any' call since even the simple "result=black; if (any())
80 // result=white;" code fails to compile. 80 // result=white;" code fails to compile.
81 builder->fFSCode.appendf("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0); \n"); 81 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n" );
82 builder->fFSCode.appendf("\tvec4 inside = "); 82 builder->fsCodeAppend("\tvec4 inside = ");
83 builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColo r, samplers[0], coords); 83 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment _ShaderType,
84 builder->fFSCode.appendf(";\n"); 84 inputColor,
85 samplers[0],
86 coords);
87 builder->fsCodeAppend(";\n");
85 88
86 builder->fFSCode.appendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", 89 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s .x) - 1.0);\n",
87 coords, domain, domain, domain); 90 coords, domain, domain, domain);
88 builder->fFSCode.appendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", 91 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s .y) - 1.0);\n",
89 coords, domain, domain, domain); 92 coords, domain, domain, domain);
90 builder->fFSCode.appendf("\tfloat blend = step(1.0, max(x, y));\n"); 93 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n");
91 builder->fFSCode.appendf("\t%s = mix(inside, outside, blend);\n", ou tputColor); 94 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outp utColor);
92 } else { 95 } else {
93 builder->fFSCode.append("\tbvec4 outside;\n"); 96 builder->fsCodeAppend("\tbvec4 outside;\n");
94 builder->fFSCode.appendf("\toutside.xy = lessThan(%s, %s.xy);\n", co ords, domain); 97 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coor ds, domain);
95 builder->fFSCode.appendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords, domain); 98 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", c oords, domain);
96 builder->fFSCode.appendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outputColor); 99 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0. 0) : ", outputColor);
97 builder->appendTextureLookupAndModulate(&builder->fFSCode, inputColo r, samplers[0], coords); 100 builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment _ShaderType,
98 builder->fFSCode.append(";\n"); 101 inputColor,
102 samplers[0],
103 coords);
104 builder->fsCodeAppend(";\n");
99 } 105 }
100 } 106 }
101 } 107 }
102 108
103 void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, const GrEf fectStage& stage) { 109 void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, const GrEf fectStage& stage) {
104 const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffe ct>(stage); 110 const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffe ct>(stage);
105 const GrRect& domain = effect.domain(); 111 const GrRect& domain = effect.domain();
106 112
107 float values[4] = { 113 float values[4] = {
108 SkScalarToFloat(domain.left()), 114 SkScalarToFloat(domain.left()),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 GrEffectUnitTest::kAlphaTextureIdx; 220 GrEffectUnitTest::kAlphaTextureIdx;
215 GrRect domain; 221 GrRect domain;
216 domain.fLeft = random->nextUScalar1(); 222 domain.fLeft = random->nextUScalar1();
217 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); 223 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1);
218 domain.fTop = random->nextUScalar1(); 224 domain.fTop = random->nextUScalar1();
219 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); 225 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1);
220 WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode; 226 WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode;
221 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 227 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
222 return GrTextureDomainEffect::Create(textures[texIdx], matrix, domain, wrapM ode); 228 return GrTextureDomainEffect::Create(textures[texIdx], matrix, domain, wrapM ode);
223 } 229 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrSimpleTextureEffect.cpp ('k') | src/gpu/gl/GrGLEffectMatrix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698