junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 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. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 9 | #ifndef GrGLProgram_DEFINED |
| 10 | #define GrGLProgram_DEFINED |
| 11 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 12 | #include "GrDrawState.h" |
bsalomon@google.com | dbe49f7 | 2012-11-05 16:36:02 +0000 | [diff] [blame] | 13 | #include "GrGLEffect.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 14 | #include "GrGLContext.h" |
tomhudson@google.com | 086e535 | 2011-12-08 14:44:10 +0000 | [diff] [blame] | 15 | #include "GrGLSL.h" |
bsalomon@google.com | 890e3b5 | 2012-06-01 19:01:37 +0000 | [diff] [blame] | 16 | #include "GrGLTexture.h" |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 17 | #include "GrGLUniformManager.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 18 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 19 | #include "SkString.h" |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 20 | #include "SkXfermode.h" |
| 21 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 22 | class GrBinHashKeyBuilder; |
bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 23 | class GrGLEffect; |
tomhudson@google.com | f9ad886 | 2012-05-11 20:38:48 +0000 | [diff] [blame] | 24 | class GrGLShaderBuilder; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 25 | class SkMWCRandom; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 26 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 27 | // optionally compile the experimental GS code. Set to GR_DEBUG |
| 28 | // so that debug build bots will execute the code. |
| 29 | #define GR_GL_EXPERIMENTAL_GS GR_DEBUG |
| 30 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 31 | /** |
| 32 | * This class manages a GPU program and records per-program information. |
| 33 | * We can specify the attribute locations so that they are constant |
| 34 | * across our shaders. But the driver determines the uniform locations |
| 35 | * at link time. We don't need to remember the sampler uniform location |
| 36 | * because we will bind a texture slot to it and never change it |
| 37 | * Uniforms are program-local so we can't rely on fHWState to hold the |
| 38 | * previous uniform state after a program change. |
| 39 | */ |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 40 | class GrGLProgram : public GrRefCnt { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 41 | public: |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 42 | SK_DECLARE_INST_COUNT(GrGLProgram) |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 44 | class Desc; |
| 45 | |
| 46 | /** |
| 47 | * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the |
| 48 | * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs. |
| 49 | */ |
| 50 | static void BuildDesc(const GrDrawState&, |
| 51 | bool isPoints, |
| 52 | GrDrawState::BlendOptFlags, |
| 53 | GrBlendCoeff srcCoeff, |
| 54 | GrBlendCoeff dstCoeff, |
| 55 | const GrGpuGL* gpu, |
| 56 | Desc* outDesc); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 57 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 58 | static GrGLProgram* Create(const GrGLContext& gl, |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 59 | const Desc& desc, |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 60 | const GrEffectStage* stages[]); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 61 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 62 | virtual ~GrGLProgram(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 63 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 64 | /** |
| 65 | * Call to abandon GL objects owned by this program. |
| 66 | */ |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 67 | void abandon(); |
| 68 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 69 | /** |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 70 | * The shader may modify the blend coefficients. Params are in/out |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 71 | */ |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 72 | void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 73 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 74 | const Desc& getDesc() { return fDesc; } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 75 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 76 | /** |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 77 | * Gets the GL program ID for this program. |
| 78 | */ |
| 79 | GrGLuint programID() const { return fProgramID; } |
| 80 | |
| 81 | /** |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 82 | * Some GL state that is relevant to programs is not stored per-program. In particular vertex |
| 83 | * attributes are global state. This struct is read and updated by GrGLProgram::setData to |
| 84 | * allow us to avoid setting this state redundantly. |
| 85 | */ |
| 86 | struct SharedGLState { |
| 87 | GrColor fConstAttribColor; |
| 88 | GrColor fConstAttribCoverage; |
| 89 | |
| 90 | SharedGLState() { this->invalidate(); } |
| 91 | void invalidate() { |
| 92 | fConstAttribColor = GrColor_ILLEGAL; |
| 93 | fConstAttribCoverage = GrColor_ILLEGAL; |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | /** |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 98 | * The GrDrawState's view matrix along with the aspects of the render target determine the |
| 99 | * matrix sent to GL. The size of the render target affects the GL matrix because we must |
| 100 | * convert from Skia device coords to GL's normalized coords. Also the origin of the render |
| 101 | * target may require us to perform a mirror-flip. |
| 102 | */ |
| 103 | struct MatrixState { |
| 104 | SkMatrix fViewMatrix; |
| 105 | SkISize fRenderTargetSize; |
| 106 | GrSurfaceOrigin fRenderTargetOrigin; |
| 107 | |
| 108 | MatrixState() { this->invalidate(); } |
| 109 | void invalidate() { |
| 110 | fViewMatrix = SkMatrix::InvalidMatrix(); |
bsalomon@google.com | 45a412e | 2013-02-13 16:13:13 +0000 | [diff] [blame] | 111 | fRenderTargetSize.fWidth = -1; |
| 112 | fRenderTargetSize.fHeight = -1; |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 113 | fRenderTargetOrigin = (GrSurfaceOrigin) -1; |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | /** |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 118 | * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a |
| 119 | * draw occurs using the program after the program has already been bound. It also uses the |
| 120 | * GrGpuGL object to bind the textures required by the GrGLEffects. |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 121 | * |
| 122 | * The color and coverage params override the GrDrawState's getColor() and getCoverage() values. |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 123 | */ |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 124 | void setData(GrGpuGL*, GrColor color, GrColor coverage, SharedGLState*); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 125 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 126 | // Parameters that affect code generation |
bsalomon@google.com | dbe49f7 | 2012-11-05 16:36:02 +0000 | [diff] [blame] | 127 | // This structs should be kept compact; it is input to an expensive hash key generator. |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 128 | class Desc { |
| 129 | public: |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 130 | Desc() { |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 131 | // since we use this as part of a key we can't have any uninitialized |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 132 | // padding |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 133 | memset(this, 0, sizeof(Desc)); |
| 134 | } |
| 135 | |
| 136 | // returns this as a uint32_t array to be used as a key in the program cache |
| 137 | const uint32_t* asKey() const { |
| 138 | return reinterpret_cast<const uint32_t*>(this); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 139 | } |
| 140 | |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 141 | // For unit testing. |
| 142 | void setRandom(SkMWCRandom*, |
| 143 | const GrGpuGL* gpu, |
| 144 | const GrEffectStage stages[GrDrawState::kNumStages]); |
| 145 | |
| 146 | private: |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 147 | // Specifies where the initial color comes from before the stages are applied. |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 148 | enum ColorInput { |
| 149 | kSolidWhite_ColorInput, |
| 150 | kTransBlack_ColorInput, |
| 151 | kAttribute_ColorInput, |
| 152 | kUniform_ColorInput, |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 153 | |
bsalomon@google.com | 85b505b | 2011-11-07 14:56:51 +0000 | [diff] [blame] | 154 | kColorInputCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 155 | }; |
| 156 | // Dual-src blending makes use of a secondary output color that can be |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 157 | // used as a per-pixel blend coefficient. This controls whether a |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 158 | // secondary source is output and what value it holds. |
| 159 | enum DualSrcOutput { |
| 160 | kNone_DualSrcOutput, |
| 161 | kCoverage_DualSrcOutput, |
| 162 | kCoverageISA_DualSrcOutput, |
| 163 | kCoverageISC_DualSrcOutput, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 165 | kDualSrcOutputCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 166 | }; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 167 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 168 | // TODO: remove these two members when edge-aa can be rewritten as a GrEffect. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 169 | GrDrawState::VertexEdgeType fVertexEdgeType; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 170 | // should the FS discard if the edge-aa coverage is zero (to avoid stencil manipulation) |
| 171 | bool fDiscardIfOutsideEdge; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 172 | |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 173 | // stripped of bits that don't affect program generation |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 174 | GrAttribBindings fAttribBindings; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 175 | |
bsalomon@google.com | dbe49f7 | 2012-11-05 16:36:02 +0000 | [diff] [blame] | 176 | /** Non-zero if this stage has an effect */ |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 177 | GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 178 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 179 | // To enable experimental geometry shader code (not for use in |
| 180 | // production) |
| 181 | #if GR_GL_EXPERIMENTAL_GS |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 182 | bool fExperimentalGS; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 183 | #endif |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 184 | uint8_t fColorInput; // casts to enum ColorInput |
| 185 | uint8_t fCoverageInput; // casts to enum ColorInput |
| 186 | uint8_t fDualSrcOutput; // casts to enum DualSrcOutput |
| 187 | int8_t fFirstCoverageStage; |
| 188 | SkBool8 fEmitsPointSize; |
| 189 | uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 190 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 191 | int8_t fPositionAttributeIndex; |
| 192 | int8_t fColorAttributeIndex; |
| 193 | int8_t fCoverageAttributeIndex; |
| 194 | int8_t fEdgeAttributeIndex; |
| 195 | int8_t fTexCoordAttributeIndex; |
| 196 | |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 197 | friend class GrGLProgram; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 198 | }; |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 199 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 200 | // Layout information for OpenGL vertex attributes |
| 201 | struct AttribLayout { |
| 202 | GrGLint fCount; |
| 203 | GrGLenum fType; |
| 204 | GrGLboolean fNormalized; |
| 205 | }; |
| 206 | static const AttribLayout kAttribLayouts[kGrVertexAttribTypeCount]; |
| 207 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 208 | private: |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 209 | GrGLProgram(const GrGLContext& gl, |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 210 | const Desc& desc, |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 211 | const GrEffectStage* stages[]); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 212 | |
| 213 | bool succeeded() const { return 0 != fProgramID; } |
| 214 | |
| 215 | /** |
bsalomon@google.com | 4285acc | 2012-10-22 14:11:24 +0000 | [diff] [blame] | 216 | * This is the heavy initialization routine for building a GLProgram. |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 217 | */ |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 218 | bool genProgram(const GrEffectStage* stages[]); |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 219 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 220 | void genInputColor(GrGLShaderBuilder* builder, SkString* inColor); |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 221 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 222 | void genGeometryShader(GrGLShaderBuilder* segments) const; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 223 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 224 | typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 225 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 226 | void genUniformCoverage(GrGLShaderBuilder* segments, SkString* inOutCoverage); |
| 227 | |
bsalomon@google.com | d472620 | 2012-08-03 14:34:46 +0000 | [diff] [blame] | 228 | // generates code to compute coverage based on edge AA. Returns true if edge coverage was |
| 229 | // inserted in which case coverageVar will be updated to refer to a scalar. Otherwise, |
| 230 | // coverageVar is set to an empty string. |
| 231 | bool genEdgeCoverage(SkString* coverageVar, GrGLShaderBuilder* builder) const; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 232 | |
| 233 | // Creates a GL program ID, binds shader attributes to GL vertex attrs, and links the program |
bsalomon@google.com | 17504f5 | 2012-10-30 12:34:25 +0000 | [diff] [blame] | 234 | bool bindOutputsAttribsAndLinkProgram(const GrGLShaderBuilder& builder, |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 235 | bool bindColorOut, |
| 236 | bool bindDualSrcOut); |
| 237 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 238 | // Sets the texture units for samplers |
| 239 | void initSamplerUniforms(); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 240 | |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 241 | bool compileShaders(const GrGLShaderBuilder& builder); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 242 | |
bsalomon@google.com | f0a104e | 2012-07-10 17:51:07 +0000 | [diff] [blame] | 243 | const char* adjustInColor(const SkString& inColor) const; |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame] | 244 | |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 245 | // Helper for setData(). Makes GL calls to specify the initial color when there is not |
| 246 | // per-vertex colors. |
| 247 | void setColor(const GrDrawState&, GrColor color, SharedGLState*); |
| 248 | |
| 249 | // Helper for setData(). Makes GL calls to specify the initial coverage when there is not |
| 250 | // per-vertex coverages. |
| 251 | void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*); |
| 252 | |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 253 | // Helper for setData() that sets the view matrix and loads the render target height uniform |
| 254 | void setMatrixAndRenderTargetHeight(const GrDrawState&); |
| 255 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 256 | typedef SkSTArray<4, UniformHandle, true> SamplerUniSArray; |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 257 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 258 | struct UniformHandles { |
| 259 | UniformHandle fViewMatrixUni; |
| 260 | UniformHandle fColorUni; |
| 261 | UniformHandle fCoverageUni; |
| 262 | UniformHandle fColorFilterUni; |
bsalomon@google.com | 706f668 | 2012-10-23 14:53:55 +0000 | [diff] [blame] | 263 | // We use the render target height to provide a y-down frag coord when specifying |
| 264 | // origin_upper_left is not supported. |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 265 | UniformHandle fRTHeightUni; |
| 266 | // An array of sampler uniform handles for each effect. |
| 267 | SamplerUniSArray fSamplerUnis[GrDrawState::kNumStages]; |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 268 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 269 | UniformHandles() { |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 270 | fViewMatrixUni = GrGLUniformManager::kInvalidUniformHandle; |
| 271 | fColorUni = GrGLUniformManager::kInvalidUniformHandle; |
| 272 | fCoverageUni = GrGLUniformManager::kInvalidUniformHandle; |
| 273 | fColorFilterUni = GrGLUniformManager::kInvalidUniformHandle; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 274 | fRTHeightUni = GrGLUniformManager::kInvalidUniformHandle; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 275 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 276 | }; |
| 277 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 278 | // GL IDs |
| 279 | GrGLuint fVShaderID; |
| 280 | GrGLuint fGShaderID; |
| 281 | GrGLuint fFShaderID; |
| 282 | GrGLuint fProgramID; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 283 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 284 | // these reflect the current values of uniforms (GL uniform values travel with program) |
bsalomon@google.com | 6a51dcb | 2013-02-13 16:03:51 +0000 | [diff] [blame] | 285 | MatrixState fMatrixState; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 286 | GrColor fColor; |
| 287 | GrColor fCoverage; |
| 288 | GrColor fColorFilterColor; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 289 | |
bsalomon@google.com | 46fba0d | 2012-10-25 21:42:05 +0000 | [diff] [blame] | 290 | GrGLEffect* fEffects[GrDrawState::kNumStages]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 291 | |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 292 | Desc fDesc; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 293 | const GrGLContext& fContext; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 294 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 295 | GrGLUniformManager fUniformManager; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 296 | UniformHandles fUniformHandles; |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 297 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 298 | typedef GrRefCnt INHERITED; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | #endif |