joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [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 | |
| 8 | #ifndef GrGLPrimitiveProcessor_DEFINED |
| 9 | #define GrGLPrimitiveProcessor_DEFINED |
| 10 | |
| 11 | #include "GrPrimitiveProcessor.h" |
| 12 | #include "GrGLProcessor.h" |
| 13 | |
| 14 | class GrBatchTracker; |
| 15 | class GrPrimitiveProcessor; |
| 16 | class GrGLGPBuilder; |
| 17 | |
| 18 | class GrGLPrimitiveProcessor { |
| 19 | public: |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 20 | virtual ~GrGLPrimitiveProcessor() {} |
| 21 | |
| 22 | typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 23 | typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
| 24 | |
| 25 | typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; |
| 26 | typedef SkSTArray<8, ProcCoords> TransformsIn; |
| 27 | typedef SkSTArray<8, GrGLProcessor::TransformedCoordsArray> TransformsOut; |
| 28 | |
| 29 | struct EmitArgs { |
| 30 | EmitArgs(GrGLGPBuilder* pb, |
| 31 | const GrPrimitiveProcessor& gp, |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 32 | const char* outputColor, |
| 33 | const char* outputCoverage, |
| 34 | const TextureSamplerArray& samplers, |
| 35 | const TransformsIn& transformsIn, |
| 36 | TransformsOut* transformsOut) |
| 37 | : fPB(pb) |
| 38 | , fGP(gp) |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 39 | , fOutputColor(outputColor) |
| 40 | , fOutputCoverage(outputCoverage) |
| 41 | , fSamplers(samplers) |
| 42 | , fTransformsIn(transformsIn) |
| 43 | , fTransformsOut(transformsOut) {} |
| 44 | GrGLGPBuilder* fPB; |
| 45 | const GrPrimitiveProcessor& fGP; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 46 | const char* fOutputColor; |
| 47 | const char* fOutputCoverage; |
| 48 | const TextureSamplerArray& fSamplers; |
| 49 | const TransformsIn& fTransformsIn; |
| 50 | TransformsOut* fTransformsOut; |
| 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * This is similar to emitCode() in the base class, except it takes a full shader builder. |
| 55 | * This allows the effect subclass to emit vertex code. |
| 56 | */ |
| 57 | virtual void emitCode(EmitArgs&) = 0; |
| 58 | |
| 59 | |
| 60 | /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitiveProcessor that |
| 61 | produces the same stage key; this function reads data from a GrGLPrimitiveProcessor and |
| 62 | uploads any uniform variables required by the shaders created in emitCode(). The |
| 63 | GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this |
| 64 | GrGLPrimitiveProcessor and to have an identical processor key as the one that created this |
| 65 | GrGLPrimitiveProcessor. */ |
joshualitt | 465283c | 2015-09-11 08:19:35 -0700 | [diff] [blame] | 66 | virtual void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) = 0; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 67 | |
| 68 | static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); |
| 69 | |
joshualitt | d8dd47b | 2015-09-11 11:45:01 -0700 | [diff] [blame^] | 70 | virtual void setTransformData(const GrPrimitiveProcessor&, |
| 71 | const GrGLProgramDataManager& pdman, |
| 72 | int index, |
| 73 | const SkTArray<const GrCoordTransform*, true>& transforms) = 0; |
| 74 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 75 | protected: |
joshualitt | b8c241a | 2015-05-19 08:23:30 -0700 | [diff] [blame] | 76 | void setupUniformColor(GrGLGPBuilder* pb, const char* outputName, UniformHandle* colorUniform); |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 77 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 78 | struct Transform { |
| 79 | Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); } |
joshualitt | e7afc2d | 2015-09-11 10:44:13 -0700 | [diff] [blame] | 80 | GrGLProgramDataManager::UniformHandle fHandle; |
| 81 | SkMatrix fCurrentValue; |
| 82 | GrSLType fType; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | #endif |