joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrGLPrimitiveProcessor.h" |
| 9 | |
| 10 | #include "builders/GrGLProgramBuilder.h" |
| 11 | |
| 12 | SkMatrix GrGLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix, |
| 13 | const GrCoordTransform& coordTransform) { |
| 14 | SkMatrix combined; |
| 15 | // We only apply the localmatrix to localcoords |
| 16 | if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { |
| 17 | combined.setConcat(coordTransform.getMatrix(), localMatrix); |
| 18 | } else { |
| 19 | combined = coordTransform.getMatrix(); |
| 20 | } |
| 21 | if (coordTransform.reverseY()) { |
| 22 | // combined.postScale(1,-1); |
| 23 | // combined.postTranslate(0,1); |
| 24 | combined.set(SkMatrix::kMSkewY, |
| 25 | combined[SkMatrix::kMPersp0] - combined[SkMatrix::kMSkewY]); |
| 26 | combined.set(SkMatrix::kMScaleY, |
| 27 | combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 28 | combined.set(SkMatrix::kMTransY, |
| 29 | combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 30 | } |
| 31 | return combined; |
| 32 | } |
| 33 | |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame^] | 34 | void GrGLPrimitiveProcessor::setupUniformColor(GrGLGPBuilder* pb, |
| 35 | const char* outputName, |
| 36 | UniformHandle* colorUniform) { |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 37 | GrGLFragmentBuilder* fs = pb->getFragmentShaderBuilder(); |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame^] | 38 | SkASSERT(colorUniform); |
| 39 | const char* stagedLocalVarName; |
| 40 | *colorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 41 | kVec4f_GrSLType, |
| 42 | kDefault_GrSLPrecision, |
| 43 | "Color", |
| 44 | &stagedLocalVarName); |
| 45 | fs->codeAppendf("%s = %s;", outputName, stagedLocalVarName); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void GrGLPrimitiveProcessor::addUniformViewMatrix(GrGLGPBuilder* pb) { |
| 49 | fViewMatrixUniform = pb->addUniform(GrGLProgramBuilder::kVertex_Visibility, |
| 50 | kMat33f_GrSLType, kDefault_GrSLPrecision, |
| 51 | "uViewM", |
| 52 | &fViewMatrixName); |
| 53 | } |
| 54 | |
| 55 | void GrGLPrimitiveProcessor::setUniformViewMatrix(const GrGLProgramDataManager& pdman, |
| 56 | const SkMatrix& viewMatrix) { |
joshualitt | dd21987 | 2015-02-12 14:48:42 -0800 | [diff] [blame] | 57 | if (!viewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(viewMatrix)) { |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 58 | SkASSERT(fViewMatrixUniform.isValid()); |
| 59 | fViewMatrix = viewMatrix; |
| 60 | |
| 61 | GrGLfloat viewMatrix[3 * 3]; |
| 62 | GrGLGetMatrix<3>(viewMatrix, fViewMatrix); |
| 63 | pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); |
| 64 | } |
| 65 | } |