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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 277 } |
278 | 278 |
279 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, | 279 void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder, |
280 const GrEffectRef& effect, | 280 const GrEffectRef& 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 | |
288 SkTArray<FragmentInputTransform, true>* fragmentInputTransforms = NULL; | |
289 if (builder->ctxInfo().caps()->pathRenderingSupport()) { | |
290 fragmentInputTransforms = &fFragmentInputTransforms.push_back(); | |
291 fragmentInputTransforms->push_back_n(numTransforms); | |
292 } | |
293 | |
287 for (int t = 0; t < numTransforms; t++) { | 294 for (int t = 0; t < numTransforms; t++) { |
288 GrSLType varyingType = kVoid_GrSLType; | 295 GrSLType varyingType = kVoid_GrSLType; |
289 const char* uniName; | 296 const char* uniName; |
290 switch (get_matrix_type(totalKey, t)) { | 297 switch (get_matrix_type(totalKey, t)) { |
291 case kNoPersp_MatrixType: | 298 case kNoPersp_MatrixType: |
292 uniName = "StageMatrix"; | 299 uniName = "StageMatrix"; |
293 varyingType = kVec2f_GrSLType; | 300 varyingType = kVec2f_GrSLType; |
294 break; | 301 break; |
295 case kGeneral_MatrixType: | 302 case kGeneral_MatrixType: |
296 uniName = "StageMatrix"; | 303 uniName = "StageMatrix"; |
(...skipping 15 matching lines...) Expand all Loading... | |
312 | 319 |
313 const char* varyingName = "MatrixCoord"; | 320 const char* varyingName = "MatrixCoord"; |
314 SkString suffixedVaryingName; | 321 SkString suffixedVaryingName; |
315 if (0 != t) { | 322 if (0 != t) { |
316 suffixedVaryingName.append(varyingName); | 323 suffixedVaryingName.append(varyingName); |
317 suffixedVaryingName.appendf("_%i", t); | 324 suffixedVaryingName.appendf("_%i", t); |
318 varyingName = suffixedVaryingName.c_str(); | 325 varyingName = suffixedVaryingName.c_str(); |
319 } | 326 } |
320 const char* vsVaryingName; | 327 const char* vsVaryingName; |
321 const char* fsVaryingName; | 328 const char* fsVaryingName; |
322 builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVarying Name); | 329 GrGLUniformManager::FragmentInputHandle fragmentInputHandle = builder->a ddVarying( |
330 varyingType, varyingName, &vsVaryingName, &fsVaryingName); | |
331 | |
332 if (fragmentInputTransforms) { | |
333 (*fragmentInputTransforms)[t].fHandle = fragmentInputHandle; | |
334 (*fragmentInputTransforms)[t].fType = varyingType; | |
335 } | |
323 | 336 |
324 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( totalKey, t) ? | 337 const GrGLShaderVar& coords = kPosition_GrCoordSet == get_source_coords( totalKey, t) ? |
325 builder->positionAttribute() : | 338 builder->positionAttribute() : |
326 builder->localCoordsAttribute(); | 339 builder->localCoordsAttribute(); |
327 // varying = matrix * coords (logically) | 340 // varying = matrix * coords (logically) |
328 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp e); | 341 SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingTyp e); |
329 if (kVec2f_GrSLType == varyingType) { | 342 if (kVec2f_GrSLType == varyingType) { |
330 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", | 343 builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n", |
331 vsVaryingName, uniName, coords.c_str()); | 344 vsVaryingName, uniName, coords.c_str()); |
332 } else { | 345 } else { |
333 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", | 346 builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n", |
334 vsVaryingName, uniName, coords.c_str()); | 347 vsVaryingName, uniName, coords.c_str()); |
335 } | 348 } |
336 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, | 349 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, |
337 (SkString(fsVaryingName), varyingType)); | 350 (SkString(fsVaryingName), varyingType)); |
338 } | 351 } |
339 } | 352 } |
340 | 353 |
341 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, | 354 void GrGLVertexProgramEffects::setData(GrGpuGL* gpu, |
355 GrGpu::DrawType drawType, | |
342 const GrGLUniformManager& uniformManager, | 356 const GrGLUniformManager& uniformManager, |
343 const GrEffectStage* effectStages[]) { | 357 const GrEffectStage* effectStages[]) { |
Kimmo Kinnunen
2014/07/01 13:01:21
So here we would need a context which would point
| |
344 int numEffects = fGLEffects.count(); | 358 int numEffects = fGLEffects.count(); |
345 SkASSERT(numEffects == fTransforms.count()); | 359 SkASSERT(numEffects == fTransforms.count()); |
346 SkASSERT(numEffects == fSamplers.count()); | 360 SkASSERT(numEffects == fSamplers.count()); |
347 for (int e = 0; e < numEffects; ++e) { | 361 for (int e = 0; e < numEffects; ++e) { |
348 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); | 362 GrDrawEffect drawEffect(*effectStages[e], fHasExplicitLocalCoords); |
349 fGLEffects[e]->setData(uniformManager, drawEffect); | 363 fGLEffects[e]->setData(uniformManager, drawEffect); |
350 this->setTransformData(uniformManager, drawEffect, e); | 364 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
365 this->setFragmentInputTransformData(gpu, uniformManager, drawEffect, e); | |
366 } else { | |
367 this->setTransformData(gpu, uniformManager, drawEffect, e); | |
368 } | |
351 this->bindTextures(gpu, *drawEffect.effect(), e); | 369 this->bindTextures(gpu, *drawEffect.effect(), e); |
352 } | 370 } |
353 } | 371 } |
354 | 372 |
355 void GrGLVertexProgramEffects::setTransformData(const GrGLUniformManager& unifor mManager, | 373 void GrGLVertexProgramEffects::setTransformData(GrGpuGL* gpu, |
374 const GrGLUniformManager& unifor mManager, | |
356 const GrDrawEffect& drawEffect, | 375 const GrDrawEffect& drawEffect, |
357 int effectIdx) { | 376 int effectIdx) { |
358 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; | 377 SkTArray<Transform, true>& transforms = fTransforms[effectIdx]; |
359 int numTransforms = transforms.count(); | 378 int numTransforms = transforms.count(); |
360 SkASSERT(numTransforms == (*drawEffect.effect())->numTransforms()); | 379 SkASSERT(numTransforms == (*drawEffect.effect())->numTransforms()); |
361 for (int t = 0; t < numTransforms; ++t) { | 380 for (int t = 0; t < numTransforms; ++t) { |
362 SkASSERT(transforms[t].fHandle.isValid()); | 381 SkASSERT(transforms[t].fHandle.isValid()); |
363 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); | 382 const SkMatrix& matrix = get_transform_matrix(drawEffect, t); |
364 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { | 383 if (!transforms[t].fCurrentValue.cheapEqualTo(matrix)) { |
365 uniformManager.setSkMatrix(transforms[t].fHandle, matrix); | 384 uniformManager.setSkMatrix(transforms[t].fHandle, matrix); |
366 transforms[t].fCurrentValue = matrix; | 385 transforms[t].fCurrentValue = matrix; |
367 } | 386 } |
368 } | 387 } |
369 } | 388 } |
370 | 389 |
390 void GrGLVertexProgramEffects::setFragmentInputTransformData( | |
391 GrGpuGL* gpu, | |
392 const GrGLUniformManager& uniformManager, | |
393 const GrDrawEffect& drawEffect, | |
394 int effectIdx) { | |
395 SkTArray<FragmentInputTransform, true>& transforms = fFragmentInputTransform s[effectIdx]; | |
396 int numTransforms = transforms.count(); | |
397 SkASSERT(numTransforms == (*drawEffect.effect())->numTransforms()); | |
398 for (int t = 0; t < numTransforms; ++t) { | |
399 SkASSERT(transforms[t].fHandle.isValid()); | |
400 const SkMatrix& transform = get_transform_matrix(drawEffect, t); | |
401 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) | |
402 continue; | |
403 transforms[t].fCurrentValue = transform; | |
404 switch (transforms[t].fType) { | |
405 case kVec2f_GrSLType: { | |
406 uniformManager.setFragmentInput(transforms[t].fHandle, 2, transf orm); | |
407 break; | |
408 } | |
409 case kVec3f_GrSLType: { | |
410 uniformManager.setFragmentInput(transforms[t].fHandle, 3, transf orm); | |
411 break; | |
412 } | |
413 default: | |
414 SkFAIL("Unexpected matrixs type."); | |
415 } | |
416 } | |
417 } | |
418 | |
371 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB uilder* builder, | 419 GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB uilder* builder, |
372 int reserveCoun t) | 420 int reserveCoun t) |
373 : fBuilder(builder) | 421 : fBuilder(builder) |
374 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects, | 422 , fProgramEffects(SkNEW_ARGS(GrGLVertexProgramEffects, |
375 (reserveCount, fBuilder->hasExplicitLocalCoords ()))) { | 423 (reserveCount, fBuilder->hasExplicitLocalCoords ()))) { |
376 } | 424 } |
377 | 425 |
378 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 426 void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
379 GrGLProgramEffects::EffectKey k ey, | 427 GrGLProgramEffects::EffectKey k ey, |
380 const char* outColor, | 428 const char* outColor, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 for (int t = 0; t < numTransforms; ++t) { | 475 for (int t = 0; t < numTransforms; ++t) { |
428 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? | 476 GrSLType type = kGeneral_MatrixType == get_matrix_type(totalKey, t) ? |
429 kVec3f_GrSLType : | 477 kVec3f_GrSLType : |
430 kVec2f_GrSLType; | 478 kVec2f_GrSLType; |
431 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); | 479 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex ++); |
432 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); | 480 SkNEW_APPEND_TO_TARRAY(outCoords, TransformedCoords, (name, type)); |
433 } | 481 } |
434 } | 482 } |
435 | 483 |
436 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, | 484 void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu, |
485 GrGpu::DrawType, | |
437 const GrGLUniformManager& uniformManager, | 486 const GrGLUniformManager& uniformManager, |
438 const GrEffectStage* effectStages[]) { | 487 const GrEffectStage* effectStages[]) { |
439 int numEffects = fGLEffects.count(); | 488 int numEffects = fGLEffects.count(); |
440 SkASSERT(numEffects == fTransforms.count()); | 489 SkASSERT(numEffects == fTransforms.count()); |
441 SkASSERT(numEffects == fSamplers.count()); | 490 SkASSERT(numEffects == fSamplers.count()); |
442 for (int e = 0; e < numEffects; ++e) { | 491 for (int e = 0; e < numEffects; ++e) { |
443 GrDrawEffect drawEffect(*effectStages[e], false); | 492 GrDrawEffect drawEffect(*effectStages[e], false); |
444 fGLEffects[e]->setData(uniformManager, drawEffect); | 493 fGLEffects[e]->setData(uniformManager, drawEffect); |
445 this->setPathTexGenState(gpu, drawEffect, e); | 494 this->setPathTexGenState(gpu, drawEffect, e); |
446 this->bindTextures(gpu, *drawEffect.effect(), e); | 495 this->bindTextures(gpu, *drawEffect.effect(), e); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 } | 532 } |
484 | 533 |
485 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, | 534 void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage, |
486 GrGLProgramEffects::EffectK ey key, | 535 GrGLProgramEffects::EffectK ey key, |
487 const char* outColor, | 536 const char* outColor, |
488 const char* inColor, | 537 const char* inColor, |
489 int stageIndex) { | 538 int stageIndex) { |
490 SkASSERT(NULL != fProgramEffects.get()); | 539 SkASSERT(NULL != fProgramEffects.get()); |
491 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); | 540 fProgramEffects->emitEffect(fBuilder, stage, key, outColor, inColor, stageIn dex); |
492 } | 541 } |
OLD | NEW |