blob: 36cc546c4c4a202f25bb0e932b45dbbbbf0f2b71 [file] [log] [blame]
commit-bot@chromium.org261dc562013-10-04 15:42:56 +00001/*
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
egdaniele659a582015-11-13 09:55:43 -08008#ifndef GrGLSLGeometryProcessor_DEFINED
9#define GrGLSLGeometryProcessor_DEFINED
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000010
egdaniele659a582015-11-13 09:55:43 -080011#include "GrGLSLPrimitiveProcessor.h"
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000012
egdaniel8dcdedc2015-11-11 06:27:20 -080013class GrGLSLGPBuilder;
joshualitt8072caa2015-02-12 14:20:52 -080014
joshualittabb52a12015-01-13 15:02:10 -080015/**
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 */
egdaniele659a582015-11-13 09:55:43 -080020class GrGLSLGeometryProcessor : public GrGLSLPrimitiveProcessor {
joshualittabb52a12015-01-13 15:02:10 -080021public:
22 /* Any general emit code goes in the base class emitCode. Subclasses override onEmitCode */
Brian Salomon7f235432017-08-16 09:41:48 -040023 void emitCode(EmitArgs&) final;
joshualittabb52a12015-01-13 15:02:10 -080024
bsalomon1d417a82016-03-23 11:50:26 -070025protected:
Brian Salomon7f235432017-08-16 09:41:48 -040026 // A helper which subclasses can use to upload coord transform matrices in setData().
bsalomone4f24612016-08-17 10:30:17 -070027 void setTransformDataHelper(const SkMatrix& localMatrix,
egdaniel018fb622015-10-28 07:26:40 -070028 const GrGLSLProgramDataManager& pdman,
bsalomona624bf32016-09-20 09:12:47 -070029 FPCoordTransformIter*);
joshualittabb52a12015-01-13 15:02:10 -080030
Brian Salomon04460cc2017-12-06 14:47:42 -050031 // Emit transformed local coords from the vertex shader as a uniform matrix and varying per
Brian Salomon5c6ac642017-12-19 11:09:32 -050032 // 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.
egdaniel7ea439b2015-12-03 09:20:44 -080034 void emitTransforms(GrGLSLVertexBuilder*,
egdaniel0eafe792015-11-20 14:01:22 -080035 GrGLSLVaryingHandler*,
egdaniel7ea439b2015-12-03 09:20:44 -080036 GrGLSLUniformHandler*,
Brian Salomon04460cc2017-12-06 14:47:42 -050037 const GrShaderVar& localCoordsVar,
joshualittabb52a12015-01-13 15:02:10 -080038 const SkMatrix& localMatrix,
bsalomona624bf32016-09-20 09:12:47 -070039 FPCoordTransformHandler*);
joshualittabb52a12015-01-13 15:02:10 -080040
Brian Salomon04460cc2017-12-06 14:47:42 -050041 // 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
robertphillips46d36f02015-01-18 08:14:14 -080051 struct GrGPArgs {
Brian Salomon7f235432017-08-16 09:41:48 -040052 // 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().
robertphillips46d36f02015-01-18 08:14:14 -080055 GrShaderVar fPositionVar;
56 };
57
Brian Salomon7f235432017-08-16 09:41:48 -040058 // 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);
robertphillips46d36f02015-01-18 08:14:14 -080071
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
joshualittabb52a12015-01-13 15:02:10 -080082private:
robertphillips46d36f02015-01-18 08:14:14 -080083 virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0;
joshualittabb52a12015-01-13 15:02:10 -080084
bsalomon790c90b2016-09-12 12:56:58 -070085 struct TransformUniform {
egdanielfe8a8392016-05-09 10:22:19 -070086 UniformHandle fHandle;
bsalomon790c90b2016-09-12 12:56:58 -070087 SkMatrix fCurrentValue = SkMatrix::InvalidMatrix();
egdanielfe8a8392016-05-09 10:22:19 -070088 };
89
bsalomona624bf32016-09-20 09:12:47 -070090 SkTArray<TransformUniform, true> fInstalledTransforms;
egdanielfe8a8392016-05-09 10:22:19 -070091
egdaniele659a582015-11-13 09:55:43 -080092 typedef GrGLSLPrimitiveProcessor INHERITED;
joshualittabb52a12015-01-13 15:02:10 -080093};
94
commit-bot@chromium.org261dc562013-10-04 15:42:56 +000095#endif