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