| OLD | NEW |
| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 GrCoordSet get_source_coords(EffectKey transformKey, int transformIdx) { | 82 GrCoordSet get_source_coords(EffectKey transformKey, int transformIdx) { |
| 83 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord
s_Flag ? | 83 return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoord
s_Flag ? |
| 84 kPosition_GrCoordSet : | 84 kPosition_GrCoordSet : |
| 85 kLocal_GrCoordSet; | 85 kLocal_GrCoordSet; |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. | 89 * Retrieves the final matrix that a transform needs to apply to its source coor
ds. |
| 90 */ | 90 */ |
| 91 SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx)
{ | 91 SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx)
{ |
| 92 const GrCoordTransform& coordTransform = (*drawEffect.effect())->coordTransf
orm(transformIdx); | 92 const GrCoordTransform& coordTransform = drawEffect.effect()->coordTransform
(transformIdx); |
| 93 SkMatrix combined; | 93 SkMatrix combined; |
| 94 if (kLocal_GrCoordSet == coordTransform.sourceCoords() && | 94 if (kLocal_GrCoordSet == coordTransform.sourceCoords() && |
| 95 !drawEffect.programHasExplicitLocalCoords()) { | 95 !drawEffect.programHasExplicitLocalCoords()) { |
| 96 combined.setConcat(coordTransform.getMatrix(), drawEffect.getCoordChange
Matrix()); | 96 combined.setConcat(coordTransform.getMatrix(), drawEffect.getCoordChange
Matrix()); |
| 97 } else { | 97 } else { |
| 98 combined = coordTransform.getMatrix(); | 98 combined = coordTransform.getMatrix(); |
| 99 } | 99 } |
| 100 if (coordTransform.reverseY()) { | 100 if (coordTransform.reverseY()) { |
| 101 // combined.postScale(1,-1); | 101 // combined.postScale(1,-1); |
| 102 // combined.postTranslate(0,1); | 102 // combined.postTranslate(0,1); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 for (int a = 0; a < numAttributes; ++a) { | 122 for (int a = 0; a < numAttributes; ++a) { |
| 123 EffectKey value = attributeIndices[a] << 3 * a; | 123 EffectKey value = attributeIndices[a] << 3 * a; |
| 124 SkASSERT(0 == (value & key)); // keys for each attribute ought not to ov
erlap | 124 SkASSERT(0 == (value & key)); // keys for each attribute ought not to ov
erlap |
| 125 key |= value; | 125 key |= value; |
| 126 } | 126 } |
| 127 return key; | 127 return key; |
| 128 } | 128 } |
| 129 | 129 |
| 130 EffectKey GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) { | 130 EffectKey GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) { |
| 131 EffectKey totalKey = 0; | 131 EffectKey totalKey = 0; |
| 132 int numTransforms = (*drawEffect.effect())->numTransforms(); | 132 int numTransforms = drawEffect.effect()->numTransforms(); |
| 133 for (int t = 0; t < numTransforms; ++t) { | 133 for (int t = 0; t < numTransforms; ++t) { |
| 134 EffectKey key = 0; | 134 EffectKey key = 0; |
| 135 const GrCoordTransform& coordTransform = (*drawEffect.effect())->coordTr
ansform(t); | 135 const GrCoordTransform& coordTransform = drawEffect.effect()->coordTrans
form(t); |
| 136 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); | 136 SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType(); |
| 137 SkMatrix::TypeMask type1; | 137 SkMatrix::TypeMask type1; |
| 138 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { | 138 if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 139 type1 = drawEffect.getCoordChangeMatrix().getType(); | 139 type1 = drawEffect.getCoordChangeMatrix().getType(); |
| 140 } else { | 140 } else { |
| 141 if (drawEffect.programHasExplicitLocalCoords()) { | 141 if (drawEffect.programHasExplicitLocalCoords()) { |
| 142 // We only make the key indicate that device coords are referenc
ed when the local coords | 142 // We only make the key indicate that device coords are referenc
ed when the local coords |
| 143 // are not actually determined by positions. Otherwise the local
coords var and position | 143 // are not actually determined by positions. Otherwise the local
coords var and position |
| 144 // var are identical. | 144 // var are identical. |
| 145 key |= kPositionCoords_Flag; | 145 key |= kPositionCoords_Flag; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 156 } | 156 } |
| 157 key <<= kTransformKeyBits * t; | 157 key <<= kTransformKeyBits * t; |
| 158 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to
overlap | 158 SkASSERT(0 == (totalKey & key)); // keys for each transform ought not to
overlap |
| 159 totalKey |= key; | 159 totalKey |= key; |
| 160 } | 160 } |
| 161 return totalKey; | 161 return totalKey; |
| 162 } | 162 } |
| 163 | 163 |
| 164 EffectKey GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, cons
t GrGLCaps& caps) { | 164 EffectKey GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, cons
t GrGLCaps& caps) { |
| 165 EffectKey key = 0; | 165 EffectKey key = 0; |
| 166 int numTextures = (*drawEffect.effect())->numTextures(); | 166 int numTextures = drawEffect.effect()->numTextures(); |
| 167 for (int t = 0; t < numTextures; ++t) { | 167 for (int t = 0; t < numTextures; ++t) { |
| 168 const GrTextureAccess& access = (*drawEffect.effect())->textureAccess(t)
; | 168 const GrTextureAccess& access = drawEffect.effect()->textureAccess(t); |
| 169 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText
ure()->config()); | 169 uint32_t configComponentMask = GrPixelConfigComponentMask(access.getText
ure()->config()); |
| 170 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s
wizzleMask())) { | 170 if (swizzle_requires_alpha_remapping(caps, configComponentMask, access.s
wizzleMask())) { |
| 171 key |= 1 << t; | 171 key |= 1 << t; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 return key; | 174 return key; |
| 175 } | 175 } |
| 176 | 176 |
| 177 GrGLProgramEffects::~GrGLProgramEffects() { | 177 GrGLProgramEffects::~GrGLProgramEffects() { |
| 178 int numEffects = fGLEffects.count(); | 178 int numEffects = fGLEffects.count(); |
| 179 for (int e = 0; e < numEffects; ++e) { | 179 for (int e = 0; e < numEffects; ++e) { |
| 180 SkDELETE(fGLEffects[e]); | 180 SkDELETE(fGLEffects[e]); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 void GrGLProgramEffects::emitSamplers(GrGLShaderBuilder* builder, | 184 void GrGLProgramEffects::emitSamplers(GrGLShaderBuilder* builder, |
| 185 const GrEffectRef& effect, | 185 const GrEffect* effect, |
| 186 TextureSamplerArray* outSamplers) { | 186 TextureSamplerArray* outSamplers) { |
| 187 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); | 187 SkTArray<Sampler, true>& samplers = fSamplers.push_back(); |
| 188 int numTextures = effect->numTextures(); | 188 int numTextures = effect->numTextures(); |
| 189 samplers.push_back_n(numTextures); | 189 samplers.push_back_n(numTextures); |
| 190 SkString name; | 190 SkString name; |
| 191 for (int t = 0; t < numTextures; ++t) { | 191 for (int t = 0; t < numTextures; ++t) { |
| 192 name.printf("Sampler%d", t); | 192 name.printf("Sampler%d", t); |
| 193 samplers[t].fUniform = builder->addUniform(GrGLShaderBuilder::kFragment_
Visibility, | 193 samplers[t].fUniform = builder->addUniform(GrGLShaderBuilder::kFragment_
Visibility, |
| 194 kSampler2D_GrSLType, | 194 kSampler2D_GrSLType, |
| 195 name.c_str()); | 195 name.c_str()); |
| 196 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, | 196 SkNEW_APPEND_TO_TARRAY(outSamplers, TextureSampler, |
| 197 (samplers[t].fUniform, effect->textureAccess(t)))
; | 197 (samplers[t].fUniform, effect->textureAccess(t)))
; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 void GrGLProgramEffects::initSamplers(const GrGLUniformManager& uniformManager,
int* texUnitIdx) { | 201 void GrGLProgramEffects::initSamplers(const GrGLUniformManager& uniformManager,
int* texUnitIdx) { |
| 202 int numEffects = fGLEffects.count(); | 202 int numEffects = fGLEffects.count(); |
| 203 SkASSERT(numEffects == fSamplers.count()); | 203 SkASSERT(numEffects == fSamplers.count()); |
| 204 for (int e = 0; e < numEffects; ++e) { | 204 for (int e = 0; e < numEffects; ++e) { |
| 205 SkTArray<Sampler, true>& samplers = fSamplers[e]; | 205 SkTArray<Sampler, true>& samplers = fSamplers[e]; |
| 206 int numSamplers = samplers.count(); | 206 int numSamplers = samplers.count(); |
| 207 for (int s = 0; s < numSamplers; ++s) { | 207 for (int s = 0; s < numSamplers; ++s) { |
| 208 SkASSERT(samplers[s].fUniform.isValid()); | 208 SkASSERT(samplers[s].fUniform.isValid()); |
| 209 uniformManager.setSampler(samplers[s].fUniform, *texUnitIdx); | 209 uniformManager.setSampler(samplers[s].fUniform, *texUnitIdx); |
| 210 samplers[s].fTextureUnit = (*texUnitIdx)++; | 210 samplers[s].fTextureUnit = (*texUnitIdx)++; |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffectRef& effect, i
nt effectIdx) { | 215 void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect* effect, int
effectIdx) { |
| 216 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; | 216 const SkTArray<Sampler, true>& samplers = fSamplers[effectIdx]; |
| 217 int numSamplers = samplers.count(); | 217 int numSamplers = samplers.count(); |
| 218 SkASSERT(numSamplers == effect->numTextures()); | 218 SkASSERT(numSamplers == effect->numTextures()); |
| 219 for (int s = 0; s < numSamplers; ++s) { | 219 for (int s = 0; s < numSamplers; ++s) { |
| 220 SkASSERT(samplers[s].fTextureUnit >= 0); | 220 SkASSERT(samplers[s].fTextureUnit >= 0); |
| 221 const GrTextureAccess& textureAccess = effect->textureAccess(s); | 221 const GrTextureAccess& textureAccess = effect->textureAccess(s); |
| 222 gpu->bindTexture(samplers[s].fTextureUnit, | 222 gpu->bindTexture(samplers[s].fTextureUnit, |
| 223 textureAccess.getParams(), | 223 textureAccess.getParams(), |
| 224 static_cast<GrGLTexture*>(textureAccess.getTexture())); | 224 static_cast<GrGLTexture*>(textureAccess.getTexture())); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 //////////////////////////////////////////////////////////////////////////////// | 228 //////////////////////////////////////////////////////////////////////////////// |
| 229 | 229 |
| 230 void GrGLVertexProgramEffects::emitEffect(GrGLFullShaderBuilder* builder, | 230 void GrGLVertexProgramEffects::emitEffect(GrGLFullShaderBuilder* builder, |
| 231 const GrEffectStage& stage, | 231 const GrEffectStage& stage, |
| 232 EffectKey key, | 232 EffectKey key, |
| 233 const char* outColor, | 233 const char* outColor, |
| 234 const char* inColor, | 234 const char* inColor, |
| 235 int stageIndex) { | 235 int stageIndex) { |
| 236 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords); | 236 GrDrawEffect drawEffect(stage, fHasExplicitLocalCoords); |
| 237 const GrEffectRef& effect = *stage.getEffect(); | 237 const GrEffect* effect = stage.getEffect(); |
| 238 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 238 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); |
| 239 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | 239 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); |
| 240 | 240 |
| 241 this->emitAttributes(builder, stage); | 241 this->emitAttributes(builder, stage); |
| 242 this->emitTransforms(builder, effect, key, &coords); | 242 this->emitTransforms(builder, effect, key, &coords); |
| 243 this->emitSamplers(builder, effect, &samplers); | 243 this->emitSamplers(builder, effect, &samplers); |
| 244 | 244 |
| 245 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 245 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); |
| 246 fGLEffects.push_back(glEffect); | 246 fGLEffects.push_back(glEffect); |
| 247 | 247 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 264 | 264 |
| 265 void GrGLVertexProgramEffects::emitAttributes(GrGLFullShaderBuilder* builder, | 265 void GrGLVertexProgramEffects::emitAttributes(GrGLFullShaderBuilder* builder, |
| 266 const GrEffectStage& stage) { | 266 const GrEffectStage& stage) { |
| 267 int numAttributes = stage.getVertexAttribIndexCount(); | 267 int numAttributes = stage.getVertexAttribIndexCount(); |
| 268 const int* attributeIndices = stage.getVertexAttribIndices(); | 268 const int* attributeIndices = stage.getVertexAttribIndices(); |
| 269 for (int a = 0; a < numAttributes; ++a) { | 269 for (int a = 0; a < numAttributes; ++a) { |
| 270 // TODO: Make addAttribute mangle the name. | 270 // TODO: Make addAttribute mangle the name. |
| 271 SkString attributeName("aAttr"); | 271 SkString attributeName("aAttr"); |
| 272 attributeName.appendS32(attributeIndices[a]); | 272 attributeName.appendS32(attributeIndices[a]); |
| 273 builder->addEffectAttribute(attributeIndices[a], | 273 builder->addEffectAttribute(attributeIndices[a], |
| 274 (*stage.getEffect())->vertexAttribType(a), | 274 stage.getEffect()->vertexAttribType(a), |
| 275 attributeName); | 275 attributeName); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, | 279 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, |
| 280 const GrEffectRef& effect, | 280 const GrEffect* effect, |
| 281 EffectKey effectKey, | 281 EffectKey effectKey, |
| 282 TransformedCoordsArray* outCoords)
{ | 282 TransformedCoordsArray* outCoords)
{ |
| 283 SkTArray<Transform, true>& transforms = fTransforms.push_back(); | 283 SkTArray<Transform, true>& transforms = fTransforms.push_back(); |
| 284 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); | 284 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); |
| 285 int numTransforms = effect->numTransforms(); | 285 int numTransforms = effect->numTransforms(); |
| 286 transforms.push_back_n(numTransforms); | 286 transforms.push_back_n(numTransforms); |
| 287 for (int t = 0; t < numTransforms; t++) { | 287 for (int t = 0; t < numTransforms; t++) { |
| 288 GrSLType varyingType = kVoid_GrSLType; | 288 GrSLType varyingType = kVoid_GrSLType; |
| 289 const char* uniName; | 289 const char* uniName; |
| 290 switch (get_matrix_type(totalKey, t)) { | 290 switch (get_matrix_type(totalKey, t)) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 341 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
| 342 const GrGLUniformManager& uniformManager, | 342 const GrGLUniformManager& uniformManager, |
| 343 const GrEffectStage* effectStages[]) { | 343 const GrEffectStage* effectStages[]) { |
| 344 int numEffects = fGLEffects.count(); | 344 int numEffects = fGLEffects.count(); |
| 345 SkASSERT(numEffects == fTransforms.count()); | 345 SkASSERT(numEffects == fTransforms.count()); |
| 346 SkASSERT(numEffects == fSamplers.count()); | 346 SkASSERT(numEffects == fSamplers.count()); |
| 347 for (int e = 0; e < numEffects; ++e) { | 347 for (int e = 0; e < numEffects; ++e) { |
| 348 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); | 348 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); |
| 349 fGLEffects[e]->setData(uniformManager, drawEffect); | 349 fGLEffects[e]->setData(uniformManager, drawEffect); |
| 350 this->setTransformData(uniformManager, drawEffect, e); | 350 this->setTransformData(uniformManager, drawEffect, e); |
| 351 this->bindTextures(gpu, *drawEffect.effect(), e); | 351 this->bindTextures(gpu, drawEffect.effect(), e); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 void GrGLVertexProgramEffects::setTransformData(const GrGLUniformManager& unifor
mManager, | 355 void GrGLVertexProgramEffects::setTransformData(const GrGLUniformManager& unifor
mManager, |
| 356 const GrDrawEffect& drawEffect, | 356 const GrDrawEffect& drawEffect, |
| 357 int effectIdx) { | 357 int effectIdx) { |
| 358 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; | 358 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; |
| 359 int numTransforms = transforms.count(); | 359 int numTransforms = transforms.count(); |
| 360 SkASSERT(numTransforms == (*drawEffect.effect())->numTransforms()); | 360 SkASSERT(numTransforms == drawEffect.effect()->numTransforms()); |
| 361 for (int t = 0; t < numTransforms; ++t) { | 361 for (int t = 0; t < numTransforms; ++t) { |
| 362 SkASSERT(transforms[t].fHandle.isValid()); | 362 SkASSERT(transforms[t].fHandle.isValid()); |
| 363 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); | 363 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); |
| 364 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 364 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
| 365 uniformManager.setSkMatrix(transforms[t].fHandle, matrix); | 365 uniformManager.setSkMatrix(transforms[t].fHandle, matrix); |
| 366 transforms[t].fCurrentValue = matrix; | 366 transforms[t].fCurrentValue = matrix; |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 | 370 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 386 | 386 |
| 387 //////////////////////////////////////////////////////////////////////////////// | 387 //////////////////////////////////////////////////////////////////////////////// |
| 388 | 388 |
| 389 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyShaderBuilder* bui
lder, | 389 void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyShaderBuilder* bui
lder, |
| 390 const GrEffectStage& stage, | 390 const GrEffectStage& stage, |
| 391 EffectKey key, | 391 EffectKey key, |
| 392 const char* outColor, | 392 const char* outColor, |
| 393 const char* inColor, | 393 const char* inColor, |
| 394 int stageIndex) { | 394 int stageIndex) { |
| 395 GrDrawEffect drawEffect(stage, false); | 395 GrDrawEffect drawEffect(stage, false); |
| 396 const GrEffectRef& effect = *stage.getEffect(); | 396 const GrEffect* effect = stage.getEffect(); |
| 397 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); | 397 SkSTArray<2, TransformedCoords> coords(effect->numTransforms()); |
| 398 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); | 398 SkSTArray<4, TextureSampler> samplers(effect->numTextures()); |
| 399 | 399 |
| 400 SkASSERT(0 == stage.getVertexAttribIndexCount()); | 400 SkASSERT(0 == stage.getVertexAttribIndexCount()); |
| 401 this->setupPathTexGen(builder, effect, key, &coords); | 401 this->setupPathTexGen(builder, effect, key, &coords); |
| 402 this->emitSamplers(builder, effect, &samplers); | 402 this->emitSamplers(builder, effect, &samplers); |
| 403 | 403 |
| 404 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); | 404 GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect); |
| 405 fGLEffects.push_back(glEffect); | 405 fGLEffects.push_back(glEffect); |
| 406 | 406 |
| 407 // Enclose custom code in a block to avoid namespace conflicts | 407 // Enclose custom code in a block to avoid namespace conflicts |
| 408 SkString openBrace; | 408 SkString openBrace; |
| 409 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); | 409 openBrace.printf("\t{ // Stage %d: %s\n", stageIndex, glEffect->name()); |
| 410 builder->fsCodeAppend(openBrace.c_str()); | 410 builder->fsCodeAppend(openBrace.c_str()); |
| 411 | 411 |
| 412 SkASSERT(!glEffect->isVertexEffect()); | 412 SkASSERT(!glEffect->isVertexEffect()); |
| 413 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp
lers); | 413 glEffect->emitCode(builder, drawEffect, key, outColor, inColor, coords, samp
lers); |
| 414 | 414 |
| 415 builder->fsCodeAppend("\t}\n"); | 415 builder->fsCodeAppend("\t}\n"); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyShaderBuilder
* builder, | 418 void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyShaderBuilder
* builder, |
| 419 const GrEffectRef& effect, | 419 const GrEffect* effect, |
| 420 EffectKey effectKey, | 420 EffectKey effectKey, |
| 421 TransformedCoordsArray* outCoords) { | 421 TransformedCoordsArray* outCoords) { |
| 422 int numTransforms = effect->numTransforms(); | 422 int numTransforms = effect->numTransforms(); |
| 423 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); | 423 EffectKey totalKey = GrBackendEffectFactory::GetTransformKey(effectKey); |
| 424 int texCoordIndex = builder->addTexCoordSets(numTransforms); | 424 int texCoordIndex = builder->addTexCoordSets(numTransforms); |
| 425 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); | 425 SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex)); |
| 426 SkString name; | 426 SkString name; |
| 427 for (int t = 0; t < numTransforms; ++t) { | 427 for (int t = 0; t < numTransforms; ++t) { |
| 428 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? | 428 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? |
| 429 kVec3f_GrSLType : | 429 kVec3f_GrSLType : |
| 430 kVec2f_GrSLType; | 430 kVec2f_GrSLType; |
| 431 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); | 431 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex
++); |
| 432 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); | 432 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, | 436 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, |
| 437 const GrGLUniformManager& uniformManager, | 437 const GrGLUniformManager& uniformManager, |
| 438 const GrEffectStage* effectStages[]) { | 438 const GrEffectStage* effectStages[]) { |
| 439 int numEffects = fGLEffects.count(); | 439 int numEffects = fGLEffects.count(); |
| 440 SkASSERT(numEffects == fTransforms.count()); | 440 SkASSERT(numEffects == fTransforms.count()); |
| 441 SkASSERT(numEffects == fSamplers.count()); | 441 SkASSERT(numEffects == fSamplers.count()); |
| 442 for (int e = 0; e < numEffects; ++e) { | 442 for (int e = 0; e < numEffects; ++e) { |
| 443 GrDrawEffect drawEffect(*effectStages[e], false); | 443 GrDrawEffect drawEffect(*effectStages[e], false); |
| 444 fGLEffects[e]->setData(uniformManager, drawEffect); | 444 fGLEffects[e]->setData(uniformManager, drawEffect); |
| 445 this->setPathTexGenState(gpu, drawEffect, e); | 445 this->setPathTexGenState(gpu, drawEffect, e); |
| 446 this->bindTextures(gpu, *drawEffect.effect(), e); | 446 this->bindTextures(gpu, drawEffect.effect(), e); |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 | 449 |
| 450 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, | 450 void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu, |
| 451 const GrDrawEffect& drawEffect, | 451 const GrDrawEffect& drawEffect, |
| 452 int effectIdx) { | 452 int effectIdx) { |
| 453 EffectKey totalKey = fTransforms[effectIdx].fTransformKey; | 453 EffectKey totalKey = fTransforms[effectIdx].fTransformKey; |
| 454 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; | 454 int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex; |
| 455 int numTransforms = (*drawEffect.effect())->numTransforms(); | 455 int numTransforms = drawEffect.effect()->numTransforms(); |
| 456 for (int t = 0; t < numTransforms; ++t) { | 456 for (int t = 0; t < numTransforms; ++t) { |
| 457 switch (get_matrix_type(totalKey, t)) { | 457 switch (get_matrix_type(totalKey, t)) { |
| 458 case kNoPersp_MatrixType: { | 458 case kNoPersp_MatrixType: { |
| 459 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | 459 const SkMatrix& transform = get_transform_matrix(drawEffect, t); |
| 460 gpu->enablePathTexGen(texCoordIndex++, | 460 gpu->enablePathTexGen(texCoordIndex++, |
| 461 GrGpuGL::kST_PathTexGenComponents, | 461 GrGpuGL::kST_PathTexGenComponents, |
| 462 transform); | 462 transform); |
| 463 break; | 463 break; |
| 464 } | 464 } |
| 465 case kGeneral_MatrixType: { | 465 case kGeneral_MatrixType: { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 483 } | 483 } |
| 484 | 484 |
| 485 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 485 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
| 486 GrGLProgramEffects::EffectK
ey key, | 486 GrGLProgramEffects::EffectK
ey key, |
| 487 const char* outColor, | 487 const char* outColor, |
| 488 const char* inColor, | 488 const char* inColor, |
| 489 int stageIndex) { | 489 int stageIndex) { |
| 490 SkASSERT(NULL != fProgramEffects.get()); | 490 SkASSERT(NULL != fProgramEffects.get()); |
| 491 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn
dex); | 491 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn
dex); |
| 492 } | 492 } |
| OLD | NEW |