blob: d719774a6623a02145b637fd150b58e79e0f3f65 [file] [log] [blame]
joshualitt8072caa2015-02-12 14:20:52 -08001/*
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
12SkMatrix 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
joshualittb8c241a2015-05-19 08:23:30 -070034void GrGLPrimitiveProcessor::setupUniformColor(GrGLGPBuilder* pb,
35 const char* outputName,
36 UniformHandle* colorUniform) {
egdaniel29bee0f2015-04-29 11:54:42 -070037 GrGLFragmentBuilder* fs = pb->getFragmentShaderBuilder();
joshualittb8c241a2015-05-19 08:23:30 -070038 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);
joshualitt8072caa2015-02-12 14:20:52 -080046}
47
48void GrGLPrimitiveProcessor::addUniformViewMatrix(GrGLGPBuilder* pb) {
49 fViewMatrixUniform = pb->addUniform(GrGLProgramBuilder::kVertex_Visibility,
50 kMat33f_GrSLType, kDefault_GrSLPrecision,
51 "uViewM",
52 &fViewMatrixName);
53}
54
55void GrGLPrimitiveProcessor::setUniformViewMatrix(const GrGLProgramDataManager& pdman,
56 const SkMatrix& viewMatrix) {
joshualittdd219872015-02-12 14:48:42 -080057 if (!viewMatrix.isIdentity() && !fViewMatrix.cheapEqualTo(viewMatrix)) {
joshualitt8072caa2015-02-12 14:20:52 -080058 SkASSERT(fViewMatrixUniform.isValid());
59 fViewMatrix = viewMatrix;
60
61 GrGLfloat viewMatrix[3 * 3];
62 GrGLGetMatrix<3>(viewMatrix, fViewMatrix);
63 pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
64 }
65}