commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 8 | #ifndef GrGLSLGeometryProcessor_DEFINED |
| 9 | #define GrGLSLGeometryProcessor_DEFINED |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 10 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 11 | #include "GrGLSLPrimitiveProcessor.h" |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 12 | |
egdaniel | 8dcdedc | 2015-11-11 06:27:20 -0800 | [diff] [blame] | 13 | class GrGLSLGPBuilder; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 14 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 15 | /** |
| 16 | * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, then it must inherit |
| 17 | * from this class. Since paths don't have vertices, this class is only meant to be used internally |
| 18 | * by skia, for special cases. |
| 19 | */ |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 20 | class GrGLSLGeometryProcessor : public GrGLSLPrimitiveProcessor { |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 21 | public: |
| 22 | /* Any general emit code goes in the base class emitCode. Subclasses override onEmitCode */ |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 23 | void emitCode(EmitArgs&) final; |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 24 | |
bsalomon | 1d417a8 | 2016-03-23 11:50:26 -0700 | [diff] [blame] | 25 | protected: |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 26 | // A helper which subclasses can use to upload coord transform matrices in setData(). |
bsalomon | e4f2461 | 2016-08-17 10:30:17 -0700 | [diff] [blame] | 27 | void setTransformDataHelper(const SkMatrix& localMatrix, |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 28 | const GrGLSLProgramDataManager& pdman, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 29 | FPCoordTransformIter*); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 30 | |
Brian Salomon | 04460cc | 2017-12-06 14:47:42 -0500 | [diff] [blame] | 31 | // Emit transformed local coords from the vertex shader as a uniform matrix and varying per |
Brian Salomon | 5c6ac64 | 2017-12-19 11:09:32 -0500 | [diff] [blame] | 32 | // coord-transform. localCoordsVar must be a 2- or 3-component vector. If it is 3 then it is |
| 33 | // assumed to be a 2D homogeneous coordinate. |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 34 | void emitTransforms(GrGLSLVertexBuilder*, |
egdaniel | 0eafe79 | 2015-11-20 14:01:22 -0800 | [diff] [blame] | 35 | GrGLSLVaryingHandler*, |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 36 | GrGLSLUniformHandler*, |
Brian Salomon | 04460cc | 2017-12-06 14:47:42 -0500 | [diff] [blame] | 37 | const GrShaderVar& localCoordsVar, |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 38 | const SkMatrix& localMatrix, |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 39 | FPCoordTransformHandler*); |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 40 | |
Brian Salomon | 04460cc | 2017-12-06 14:47:42 -0500 | [diff] [blame] | 41 | // Version of above that assumes identity for the local matrix. |
| 42 | void emitTransforms(GrGLSLVertexBuilder* vb, |
| 43 | GrGLSLVaryingHandler* varyingHandler, |
| 44 | GrGLSLUniformHandler* uniformHandler, |
| 45 | const GrShaderVar& localCoordsVar, |
| 46 | FPCoordTransformHandler* handler) { |
| 47 | this->emitTransforms(vb, varyingHandler, uniformHandler, localCoordsVar, SkMatrix::I(), |
| 48 | handler); |
| 49 | } |
| 50 | |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 51 | struct GrGPArgs { |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 52 | // Used to specify the output variable used by the GP to store its device position. It can |
| 53 | // either be a float2 or a float3 (in order to handle perspective). The subclass sets this |
| 54 | // in its onEmitCode(). |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 55 | GrShaderVar fPositionVar; |
| 56 | }; |
| 57 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 58 | // Helpers for adding code to write the transformed vertex position. The first simple version |
| 59 | // just writes a variable named by 'posName' into the position output variable with the |
| 60 | // assumption that the position is 2D. The second version transforms the input position by a |
| 61 | // view matrix and the output variable is 2D or 3D depending on whether the view matrix is |
| 62 | // perspective. Both versions declare the output position variable and will set |
| 63 | // GrGPArgs::fPositionVar. |
| 64 | void writeOutputPosition(GrGLSLVertexBuilder*, GrGPArgs*, const char* posName); |
| 65 | void writeOutputPosition(GrGLSLVertexBuilder*, |
| 66 | GrGLSLUniformHandler* uniformHandler, |
| 67 | GrGPArgs*, |
| 68 | const char* posName, |
| 69 | const SkMatrix& mat, |
| 70 | UniformHandle* viewMatrixUniform); |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 71 | |
| 72 | static uint32_t ComputePosKey(const SkMatrix& mat) { |
| 73 | if (mat.isIdentity()) { |
| 74 | return 0x0; |
| 75 | } else if (!mat.hasPerspective()) { |
| 76 | return 0x01; |
| 77 | } else { |
| 78 | return 0x02; |
| 79 | } |
| 80 | } |
| 81 | |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 82 | private: |
robertphillips | 46d36f0 | 2015-01-18 08:14:14 -0800 | [diff] [blame] | 83 | virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0; |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 84 | |
bsalomon | 790c90b | 2016-09-12 12:56:58 -0700 | [diff] [blame] | 85 | struct TransformUniform { |
egdaniel | fe8a839 | 2016-05-09 10:22:19 -0700 | [diff] [blame] | 86 | UniformHandle fHandle; |
bsalomon | 790c90b | 2016-09-12 12:56:58 -0700 | [diff] [blame] | 87 | SkMatrix fCurrentValue = SkMatrix::InvalidMatrix(); |
egdaniel | fe8a839 | 2016-05-09 10:22:19 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
bsalomon | a624bf3 | 2016-09-20 09:12:47 -0700 | [diff] [blame] | 90 | SkTArray<TransformUniform, true> fInstalledTransforms; |
egdaniel | fe8a839 | 2016-05-09 10:22:19 -0700 | [diff] [blame] | 91 | |
egdaniel | e659a58 | 2015-11-13 09:55:43 -0800 | [diff] [blame] | 92 | typedef GrGLSLPrimitiveProcessor INHERITED; |
joshualitt | abb52a1 | 2015-01-13 15:02:10 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 95 | #endif |