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 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 8 | #ifndef GrGLGeometryProcessor_DEFINED |
| 9 | #define GrGLGeometryProcessor_DEFINED |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 10 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 11 | #include "GrGLProcessor.h" |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 12 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 13 | class GrBatchTracker; |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 14 | class GrGLGPBuilder; |
| 15 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 16 | /** |
| 17 | * If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, then it must inherit |
| 18 | * from this class. Since paths don't have vertices, this class is only meant to be used internally |
| 19 | * by skia, for special cases. |
| 20 | */ |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 21 | class GrGLGeometryProcessor { |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 22 | public: |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 23 | GrGLGeometryProcessor() : fViewMatrixName(NULL) { fViewMatrix = SkMatrix::InvalidMatrix(); } |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 24 | virtual ~GrGLGeometryProcessor() {} |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 25 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 26 | typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 27 | typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 28 | |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 29 | struct EmitArgs { |
| 30 | EmitArgs(GrGLGPBuilder* pb, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 31 | const GrPrimitiveProcessor& gp, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 32 | const GrBatchTracker& bt, |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 33 | const char* outputColor, |
| 34 | const char* outputCoverage, |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 35 | const TextureSamplerArray& samplers) |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 36 | : fPB(pb) |
| 37 | , fGP(gp) |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 38 | , fBT(bt) |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 39 | , fOutputColor(outputColor) |
| 40 | , fOutputCoverage(outputCoverage) |
| 41 | , fSamplers(samplers) {} |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 42 | GrGLGPBuilder* fPB; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 43 | const GrPrimitiveProcessor& fGP; |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 44 | const GrBatchTracker& fBT; |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 45 | const char* fOutputColor; |
| 46 | const char* fOutputCoverage; |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 47 | const TextureSamplerArray& fSamplers; |
| 48 | }; |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 49 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 50 | /** |
| 51 | * This is similar to emitCode() in the base class, except it takes a full shader builder. |
| 52 | * This allows the effect subclass to emit vertex code. |
| 53 | */ |
joshualitt | c369e7c | 2014-10-22 10:56:26 -0700 | [diff] [blame] | 54 | virtual void emitCode(const EmitArgs&) = 0; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 55 | |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 56 | /** A GrGLGeometryProcessor instance can be reused with any GrGLGeometryProcessor that produces |
| 57 | the same stage key; this function reads data from a GrGLGeometryProcessor and uploads any |
| 58 | uniform variables required by the shaders created in emitCode(). The GrGeometryProcessor |
| 59 | parameter is guaranteed to be of the same type that created this GrGLGeometryProcessor and |
| 60 | to have an identical processor key as the one that created this GrGLGeometryProcessor. */ |
| 61 | virtual void setData(const GrGLProgramDataManager&, |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 62 | const GrPrimitiveProcessor&, |
joshualitt | 87f48d9 | 2014-12-04 10:41:40 -0800 | [diff] [blame] | 63 | const GrBatchTracker&) = 0; |
| 64 | |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 65 | protected: |
| 66 | /** a helper which can setup vertex, constant, or uniform color depending on inputType. |
| 67 | * This function will only do the minimum required to emit the correct shader code. If |
| 68 | * inputType == attribute, then colorAttr must not be NULL. Likewise, if inputType == Uniform |
| 69 | * then colorUniform must not be NULL. |
| 70 | */ |
| 71 | void setupColorPassThrough(GrGLGPBuilder* pb, |
| 72 | GrGPInput inputType, |
| 73 | const char* inputName, |
| 74 | const GrGeometryProcessor::GrAttribute* colorAttr, |
| 75 | UniformHandle* colorUniform); |
| 76 | |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 77 | const char* uViewM() const { return fViewMatrixName; } |
| 78 | |
| 79 | /** a helper function to setup the uniform handle for the uniform view matrix */ |
| 80 | void addUniformViewMatrix(GrGLGPBuilder*); |
| 81 | |
| 82 | |
| 83 | /** a helper function to upload a uniform viewmatrix. |
| 84 | * TODO we can remove this function when we have deferred geometry in place |
| 85 | */ |
| 86 | void setUniformViewMatrix(const GrGLProgramDataManager&, |
| 87 | const SkMatrix& viewMatrix); |
| 88 | |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 89 | private: |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 90 | UniformHandle fViewMatrixUniform; |
| 91 | SkMatrix fViewMatrix; |
| 92 | const char* fViewMatrixName; |
| 93 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 94 | typedef GrGLProcessor INHERITED; |
commit-bot@chromium.org | 261dc56 | 2013-10-04 15:42:56 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | #endif |