epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 10 | #ifndef GrGLProgram_DEFINED |
| 11 | #define GrGLProgram_DEFINED |
| 12 | |
| 13 | #include "GrGLInterface.h" |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 14 | #include "GrStringBuilder.h" |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 15 | #include "GrGpu.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 16 | |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 17 | #include "SkXfermode.h" |
| 18 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 19 | class GrBinHashKeyBuilder; |
junov@google.com | d31cbc4 | 2011-05-17 17:01:17 +0000 | [diff] [blame] | 20 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 21 | struct ShaderCodeSegments; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 23 | // optionally compile the experimental GS code. Set to GR_DEBUG |
| 24 | // so that debug build bots will execute the code. |
| 25 | #define GR_GL_EXPERIMENTAL_GS GR_DEBUG |
| 26 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 27 | /** |
| 28 | * This class manages a GPU program and records per-program information. |
| 29 | * We can specify the attribute locations so that they are constant |
| 30 | * across our shaders. But the driver determines the uniform locations |
| 31 | * at link time. We don't need to remember the sampler uniform location |
| 32 | * because we will bind a texture slot to it and never change it |
| 33 | * Uniforms are program-local so we can't rely on fHWState to hold the |
| 34 | * previous uniform state after a program change. |
| 35 | */ |
| 36 | class GrGLProgram { |
| 37 | public: |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 38 | // Limited set of GLSL versions we build shaders for. Caller should round |
| 39 | // down the GLSL version to one of these enums. |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 40 | enum GLSLVersion { |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Desktop GLSL 1.10 and ES2 shading lang (based on desktop GLSL 1.20) |
| 43 | */ |
| 44 | k110_GLSLVersion, |
| 45 | /** |
| 46 | * Desktop GLSL 1.30 |
| 47 | */ |
| 48 | k130_GLSLVersion, |
| 49 | /** |
| 50 | * Dekstop GLSL 1.50 |
| 51 | */ |
| 52 | k150_GLSLVersion, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 55 | class CachedData; |
| 56 | |
| 57 | GrGLProgram(); |
| 58 | ~GrGLProgram(); |
| 59 | |
| 60 | /** |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 61 | * This is the heavy initilization routine for building a GLProgram. |
| 62 | * The result of heavy init is not stored in datamembers of GrGLProgam, |
| 63 | * but in a separate cacheable container. |
| 64 | */ |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 65 | bool genProgram(const GrGLInterface* gl, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 66 | GLSLVersion glslVersion, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 67 | CachedData* programData) const; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 68 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 69 | /** |
| 70 | * The shader may modify the blend coeffecients. Params are in/out |
| 71 | */ |
| 72 | void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const; |
| 73 | |
| 74 | /** |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame] | 75 | * Attribute indices. These should not overlap. Matrices consume 3 slots. |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 76 | */ |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 77 | static int PositionAttributeIdx() { return 0; } |
| 78 | static int TexCoordAttributeIdx(int tcIdx) { return 1 + tcIdx; } |
| 79 | static int ColorAttributeIdx() { return 1 + GrDrawTarget::kMaxTexCoords; } |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 80 | static int CoverageAttributeIdx() { |
| 81 | return 2 + GrDrawTarget::kMaxTexCoords; |
| 82 | } |
| 83 | static int EdgeAttributeIdx() { return 3 + GrDrawTarget::kMaxTexCoords; } |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 84 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 85 | static int ViewMatrixAttributeIdx() { |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame] | 86 | return 4 + GrDrawTarget::kMaxTexCoords; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 87 | } |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 88 | static int TextureMatrixAttributeIdx(int stage) { |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame] | 89 | return 7 + GrDrawTarget::kMaxTexCoords + 3 * stage; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 90 | } |
| 91 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame^] | 92 | public: |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 93 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 94 | // Parameters that affect code generation |
| 95 | // These structs should be kept compact; they are the input to an |
| 96 | // expensive hash key generator. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 97 | struct ProgramDesc { |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 98 | ProgramDesc() { |
| 99 | // since we use this as part of a key we can't have any unitialized |
| 100 | // padding |
| 101 | memset(this, 0, sizeof(ProgramDesc)); |
| 102 | } |
| 103 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 104 | struct StageDesc { |
| 105 | enum OptFlagBits { |
| 106 | kNoPerspective_OptFlagBit = 1 << 0, |
| 107 | kIdentityMatrix_OptFlagBit = 1 << 1, |
| 108 | kCustomTextureDomain_OptFlagBit = 1 << 2, |
| 109 | kIsEnabled_OptFlagBit = 1 << 7 |
| 110 | }; |
| 111 | enum Modulation { |
| 112 | kColor_Modulation, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 113 | kAlpha_Modulation, |
| 114 | |
| 115 | kModulationCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 116 | }; |
| 117 | enum FetchMode { |
| 118 | kSingle_FetchMode, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 119 | k2x2_FetchMode, |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 120 | kConvolution_FetchMode, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 121 | |
| 122 | kFetchModeCnt, |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 123 | }; |
| 124 | enum CoordMapping { |
| 125 | kIdentity_CoordMapping, |
| 126 | kRadialGradient_CoordMapping, |
| 127 | kSweepGradient_CoordMapping, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 128 | kRadial2Gradient_CoordMapping, |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 129 | // need different shader computation when quadratic |
| 130 | // eq describing the gradient degenerates to a linear eq. |
| 131 | kRadial2GradientDegenerate_CoordMapping, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 132 | kCoordMappingCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 133 | }; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 134 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 135 | uint8_t fOptFlags; |
| 136 | uint8_t fModulation; // casts to enum Modulation |
| 137 | uint8_t fFetchMode; // casts to enum FetchMode |
| 138 | uint8_t fCoordMapping; // casts to enum CoordMapping |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 139 | uint8_t fKernelWidth; |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 140 | |
| 141 | inline bool isEnabled() const { |
bsalomon@google.com | c2c9b97 | 2011-10-03 13:17:22 +0000 | [diff] [blame] | 142 | return SkToBool(fOptFlags & kIsEnabled_OptFlagBit); |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 143 | } |
| 144 | inline void setEnabled(bool newValue) { |
| 145 | if (newValue) { |
| 146 | fOptFlags |= kIsEnabled_OptFlagBit; |
| 147 | } else { |
| 148 | fOptFlags &= ~kIsEnabled_OptFlagBit; |
| 149 | } |
| 150 | } |
| 151 | }; |
| 152 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 153 | // Specifies where the intitial color comes from before the stages are |
| 154 | // applied. |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 155 | enum ColorType { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 156 | kSolidWhite_ColorType, |
| 157 | kTransBlack_ColorType, |
| 158 | kAttribute_ColorType, |
| 159 | kUniform_ColorType, |
| 160 | |
| 161 | kColorTypeCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 162 | }; |
| 163 | // Dual-src blending makes use of a secondary output color that can be |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 164 | // used as a per-pixel blend coeffecient. This controls whether a |
| 165 | // secondary source is output and what value it holds. |
| 166 | enum DualSrcOutput { |
| 167 | kNone_DualSrcOutput, |
| 168 | kCoverage_DualSrcOutput, |
| 169 | kCoverageISA_DualSrcOutput, |
| 170 | kCoverageISC_DualSrcOutput, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 171 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 172 | kDualSrcOutputCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 173 | }; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 174 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 175 | GrDrawTarget::VertexEdgeType fVertexEdgeType; |
| 176 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 177 | // stripped of bits that don't affect prog generation |
| 178 | GrVertexLayout fVertexLayout; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 179 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 180 | StageDesc fStages[GrDrawTarget::kNumStages]; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 181 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 182 | // To enable experimental geometry shader code (not for use in |
| 183 | // production) |
| 184 | #if GR_GL_EXPERIMENTAL_GS |
| 185 | bool fExperimentalGS; |
| 186 | #endif |
| 187 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 188 | uint8_t fColorType; // casts to enum ColorType |
| 189 | uint8_t fDualSrcOutput; // casts to enum DualSrcOutput |
| 190 | int8_t fFirstCoverageStage; |
| 191 | SkBool8 fEmitsPointSize; |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 192 | SkBool8 fEdgeAAConcave; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 193 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 194 | int8_t fEdgeAANumEdges; |
| 195 | uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 196 | |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 197 | uint8_t fPadTo32bLengthMultiple [1]; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 198 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 199 | } fProgramDesc; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 200 | GR_STATIC_ASSERT(!(sizeof(ProgramDesc) % 4)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 201 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 202 | // for code readability |
| 203 | typedef ProgramDesc::StageDesc StageDesc; |
| 204 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame^] | 205 | private: |
| 206 | |
| 207 | const ProgramDesc& getDesc() { return fProgramDesc; } |
| 208 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 209 | public: |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 210 | enum { |
| 211 | kUnusedUniform = -1, |
| 212 | kSetAsAttribute = 1000, |
| 213 | }; |
| 214 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 215 | struct StageUniLocations { |
| 216 | GrGLint fTextureMatrixUni; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 217 | GrGLint fNormalizedTexelSizeUni; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 218 | GrGLint fSamplerUni; |
| 219 | GrGLint fRadial2Uni; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 220 | GrGLint fTexDomUni; |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 221 | GrGLint fKernelUni; |
| 222 | GrGLint fImageIncrementUni; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 223 | void reset() { |
| 224 | fTextureMatrixUni = kUnusedUniform; |
| 225 | fNormalizedTexelSizeUni = kUnusedUniform; |
| 226 | fSamplerUni = kUnusedUniform; |
| 227 | fRadial2Uni = kUnusedUniform; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 228 | fTexDomUni = kUnusedUniform; |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 229 | fKernelUni = kUnusedUniform; |
| 230 | fImageIncrementUni = kUnusedUniform; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 231 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | struct UniLocations { |
| 235 | GrGLint fViewMatrixUni; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 236 | GrGLint fColorUni; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 237 | GrGLint fEdgesUni; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 238 | GrGLint fColorFilterUni; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 239 | StageUniLocations fStages[GrDrawTarget::kNumStages]; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 240 | void reset() { |
| 241 | fViewMatrixUni = kUnusedUniform; |
| 242 | fColorUni = kUnusedUniform; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 243 | fEdgesUni = kUnusedUniform; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 244 | fColorFilterUni = kUnusedUniform; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 245 | for (int s = 0; s < GrDrawTarget::kNumStages; ++s) { |
| 246 | fStages[s].reset(); |
| 247 | } |
| 248 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | class CachedData : public ::GrNoncopyable { |
| 252 | public: |
| 253 | CachedData() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | ~CachedData() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void copyAndTakeOwnership(CachedData& other) { |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 260 | memcpy(this, &other, sizeof(*this)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 261 | } |
| 262 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 263 | public: |
| 264 | |
| 265 | // IDs |
| 266 | GrGLuint fVShaderID; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 267 | GrGLuint fGShaderID; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 268 | GrGLuint fFShaderID; |
| 269 | GrGLuint fProgramID; |
| 270 | // shader uniform locations (-1 if shader doesn't use them) |
| 271 | UniLocations fUniLocations; |
| 272 | |
| 273 | GrMatrix fViewMatrix; |
| 274 | |
| 275 | // these reflect the current values of uniforms |
| 276 | // (GL uniform values travel with program) |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 277 | GrColor fColor; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 278 | GrColor fColorFilterColor; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 279 | GrMatrix fTextureMatrices[GrDrawTarget::kNumStages]; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 280 | // width and height used for normalized texel size |
| 281 | int fTextureWidth[GrDrawTarget::kNumStages]; |
| 282 | int fTextureHeight[GrDrawTarget::kNumStages]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 283 | GrScalar fRadial2CenterX1[GrDrawTarget::kNumStages]; |
| 284 | GrScalar fRadial2Radius0[GrDrawTarget::kNumStages]; |
| 285 | bool fRadial2PosRoot[GrDrawTarget::kNumStages]; |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 286 | GrRect fTextureDomain[GrDrawTarget::kNumStages]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 287 | |
| 288 | private: |
| 289 | enum Constants { |
| 290 | kUniLocationPreAllocSize = 8 |
| 291 | }; |
| 292 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 293 | }; // CachedData |
| 294 | |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 295 | enum Constants { |
| 296 | kProgramKeySize = sizeof(ProgramDesc) |
| 297 | }; |
| 298 | |
| 299 | // Provide an opaque ProgramDesc |
| 300 | const uint32_t* keyData() const{ |
| 301 | return reinterpret_cast<const uint32_t*>(&fProgramDesc); |
| 302 | } |
| 303 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 304 | private: |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 305 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame^] | 306 | // Determines which uniforms will need to be bound. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 307 | void genStageCode(const GrGLInterface* gl, |
| 308 | int stageNum, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 309 | const ProgramDesc::StageDesc& desc, |
| 310 | const char* fsInColor, // NULL means no incoming color |
| 311 | const char* fsOutColor, |
| 312 | const char* vsInCoord, |
| 313 | ShaderCodeSegments* segments, |
| 314 | StageUniLocations* locations) const; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 315 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 316 | void genGeometryShader(const GrGLInterface* gl, |
| 317 | GLSLVersion glslVersion, |
| 318 | ShaderCodeSegments* segments) const; |
| 319 | |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 320 | // generates code to compute coverage based on edge AA. |
| 321 | void genEdgeCoverage(const GrGLInterface* gl, |
| 322 | GrVertexLayout layout, |
| 323 | CachedData* programData, |
| 324 | GrStringBuilder* coverageVar, |
| 325 | ShaderCodeSegments* segments) const; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 326 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 327 | static bool CompileShaders(const GrGLInterface* gl, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 328 | GLSLVersion glslVersion, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 329 | const ShaderCodeSegments& segments, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 330 | CachedData* programData); |
| 331 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 332 | // Compiles a GL shader, returns shader ID or 0 if failed |
| 333 | // params have same meaning as glShaderSource |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 334 | static GrGLuint CompileShader(const GrGLInterface* gl, |
| 335 | GrGLenum type, int stringCnt, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 336 | const char** strings, |
| 337 | int* stringLengths); |
| 338 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 339 | // Creates a GL program ID, binds shader attributes to GL vertex attrs, and |
| 340 | // links the program |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 341 | bool bindOutputsAttribsAndLinkProgram( |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 342 | const GrGLInterface* gl, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 343 | GrStringBuilder texCoordAttrNames[GrDrawTarget::kMaxTexCoords], |
| 344 | bool bindColorOut, |
| 345 | bool bindDualSrcOut, |
| 346 | CachedData* programData) const; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 347 | |
tomhudson@google.com | 2a2e3ef | 2011-10-25 19:51:09 +0000 | [diff] [blame^] | 348 | // Binds uniforms; initializes cache to invalid values. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 349 | void getUniformLocationsAndInitCache(const GrGLInterface* gl, |
| 350 | CachedData* programData) const; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 351 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 352 | friend class GrGpuGLShaders; |
| 353 | }; |
| 354 | |
| 355 | #endif |