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 | /** |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame^] | 64 | * Attribute indices. These should not overlap. Matrices consume 3 slots. |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 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() { |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame^] | 75 | return 4 + 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) { |
bsalomon@google.com | b5b5eaf | 2011-10-19 13:25:46 +0000 | [diff] [blame^] | 78 | return 7 + 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 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 142 | // Specifies where the intitial color comes from before the stages are |
| 143 | // applied. |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 144 | enum ColorType { |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 145 | kSolidWhite_ColorType, |
| 146 | kTransBlack_ColorType, |
| 147 | kAttribute_ColorType, |
| 148 | kUniform_ColorType, |
| 149 | |
| 150 | kColorTypeCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 151 | }; |
| 152 | // 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] | 153 | // used as a per-pixel blend coeffecient. This controls whether a |
| 154 | // secondary source is output and what value it holds. |
| 155 | enum DualSrcOutput { |
| 156 | kNone_DualSrcOutput, |
| 157 | kCoverage_DualSrcOutput, |
| 158 | kCoverageISA_DualSrcOutput, |
| 159 | kCoverageISC_DualSrcOutput, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 160 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 161 | kDualSrcOutputCnt |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 162 | }; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 163 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 164 | GrDrawTarget::VertexEdgeType fVertexEdgeType; |
| 165 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 166 | // stripped of bits that don't affect prog generation |
| 167 | GrVertexLayout fVertexLayout; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 168 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 169 | StageDesc fStages[GrDrawTarget::kNumStages]; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 170 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 171 | // To enable experimental geometry shader code (not for use in |
| 172 | // production) |
| 173 | #if GR_GL_EXPERIMENTAL_GS |
| 174 | bool fExperimentalGS; |
| 175 | #endif |
| 176 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 177 | uint8_t fColorType; // casts to enum ColorType |
| 178 | uint8_t fDualSrcOutput; // casts to enum DualSrcOutput |
| 179 | int8_t fFirstCoverageStage; |
| 180 | SkBool8 fEmitsPointSize; |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 181 | SkBool8 fEdgeAAConcave; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 182 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 183 | int8_t fEdgeAANumEdges; |
| 184 | uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 185 | |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 186 | uint8_t fPadTo32bLengthMultiple [1]; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 187 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 188 | } fProgramDesc; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 189 | GR_STATIC_ASSERT(!(sizeof(ProgramDesc) % 4)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 190 | |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 191 | const ProgramDesc& getDesc() { return fProgramDesc; } |
| 192 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 193 | // for code readability |
| 194 | typedef ProgramDesc::StageDesc StageDesc; |
| 195 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 196 | public: |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 197 | enum { |
| 198 | kUnusedUniform = -1, |
| 199 | kSetAsAttribute = 1000, |
| 200 | }; |
| 201 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 202 | struct StageUniLocations { |
| 203 | GrGLint fTextureMatrixUni; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 204 | GrGLint fNormalizedTexelSizeUni; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 205 | GrGLint fSamplerUni; |
| 206 | GrGLint fRadial2Uni; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 207 | GrGLint fTexDomUni; |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 208 | GrGLint fKernelUni; |
| 209 | GrGLint fImageIncrementUni; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 210 | void reset() { |
| 211 | fTextureMatrixUni = kUnusedUniform; |
| 212 | fNormalizedTexelSizeUni = kUnusedUniform; |
| 213 | fSamplerUni = kUnusedUniform; |
| 214 | fRadial2Uni = kUnusedUniform; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 215 | fTexDomUni = kUnusedUniform; |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 216 | fKernelUni = kUnusedUniform; |
| 217 | fImageIncrementUni = kUnusedUniform; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 218 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | struct UniLocations { |
| 222 | GrGLint fViewMatrixUni; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 223 | GrGLint fColorUni; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 224 | GrGLint fEdgesUni; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 225 | GrGLint fColorFilterUni; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 226 | StageUniLocations fStages[GrDrawTarget::kNumStages]; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 227 | void reset() { |
| 228 | fViewMatrixUni = kUnusedUniform; |
| 229 | fColorUni = kUnusedUniform; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 230 | fEdgesUni = kUnusedUniform; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 231 | fColorFilterUni = kUnusedUniform; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 232 | for (int s = 0; s < GrDrawTarget::kNumStages; ++s) { |
| 233 | fStages[s].reset(); |
| 234 | } |
| 235 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | class CachedData : public ::GrNoncopyable { |
| 239 | public: |
| 240 | CachedData() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | ~CachedData() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void copyAndTakeOwnership(CachedData& other) { |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 247 | memcpy(this, &other, sizeof(*this)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 248 | } |
| 249 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 250 | public: |
| 251 | |
| 252 | // IDs |
| 253 | GrGLuint fVShaderID; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 254 | GrGLuint fGShaderID; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 255 | GrGLuint fFShaderID; |
| 256 | GrGLuint fProgramID; |
| 257 | // shader uniform locations (-1 if shader doesn't use them) |
| 258 | UniLocations fUniLocations; |
| 259 | |
| 260 | GrMatrix fViewMatrix; |
| 261 | |
| 262 | // these reflect the current values of uniforms |
| 263 | // (GL uniform values travel with program) |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 264 | GrColor fColor; |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 265 | GrColor fColorFilterColor; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 266 | GrMatrix fTextureMatrices[GrDrawTarget::kNumStages]; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 267 | // width and height used for normalized texel size |
| 268 | int fTextureWidth[GrDrawTarget::kNumStages]; |
| 269 | int fTextureHeight[GrDrawTarget::kNumStages]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 270 | GrScalar fRadial2CenterX1[GrDrawTarget::kNumStages]; |
| 271 | GrScalar fRadial2Radius0[GrDrawTarget::kNumStages]; |
| 272 | bool fRadial2PosRoot[GrDrawTarget::kNumStages]; |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 273 | GrRect fTextureDomain[GrDrawTarget::kNumStages]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 274 | |
| 275 | private: |
| 276 | enum Constants { |
| 277 | kUniLocationPreAllocSize = 8 |
| 278 | }; |
| 279 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 280 | }; // CachedData |
| 281 | |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 282 | enum Constants { |
| 283 | kProgramKeySize = sizeof(ProgramDesc) |
| 284 | }; |
| 285 | |
| 286 | // Provide an opaque ProgramDesc |
| 287 | const uint32_t* keyData() const{ |
| 288 | return reinterpret_cast<const uint32_t*>(&fProgramDesc); |
| 289 | } |
| 290 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 291 | private: |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 292 | enum { |
| 293 | kUseUniform = 2000 |
| 294 | }; |
| 295 | |
| 296 | // should set all fields in locations var to kUseUniform if the |
| 297 | // corresponding uniform is required for the program. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 298 | void genStageCode(const GrGLInterface* gl, |
| 299 | int stageNum, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 300 | const ProgramDesc::StageDesc& desc, |
| 301 | const char* fsInColor, // NULL means no incoming color |
| 302 | const char* fsOutColor, |
| 303 | const char* vsInCoord, |
| 304 | ShaderCodeSegments* segments, |
| 305 | StageUniLocations* locations) const; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 306 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 307 | void genGeometryShader(const GrGLInterface* gl, |
| 308 | GLSLVersion glslVersion, |
| 309 | ShaderCodeSegments* segments) const; |
| 310 | |
bsalomon@google.com | 6610567 | 2011-09-15 15:12:00 +0000 | [diff] [blame] | 311 | // generates code to compute coverage based on edge AA. |
| 312 | void genEdgeCoverage(const GrGLInterface* gl, |
| 313 | GrVertexLayout layout, |
| 314 | CachedData* programData, |
| 315 | GrStringBuilder* coverageVar, |
| 316 | ShaderCodeSegments* segments) const; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 317 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 318 | static bool CompileShaders(const GrGLInterface* gl, |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 319 | GLSLVersion glslVersion, |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 320 | const ShaderCodeSegments& segments, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 321 | CachedData* programData); |
| 322 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 323 | // Compiles a GL shader, returns shader ID or 0 if failed |
| 324 | // params have same meaning as glShaderSource |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 325 | static GrGLuint CompileShader(const GrGLInterface* gl, |
| 326 | GrGLenum type, int stringCnt, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 327 | const char** strings, |
| 328 | int* stringLengths); |
| 329 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 330 | // Creates a GL program ID, binds shader attributes to GL vertex attrs, and |
| 331 | // links the program |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 332 | bool bindOutputsAttribsAndLinkProgram( |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 333 | const GrGLInterface* gl, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 334 | GrStringBuilder texCoordAttrNames[GrDrawTarget::kMaxTexCoords], |
| 335 | bool bindColorOut, |
| 336 | bool bindDualSrcOut, |
| 337 | CachedData* programData) const; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 338 | |
| 339 | // Gets locations for all uniforms set to kUseUniform and initializes cache |
| 340 | // to invalid values. |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 341 | void getUniformLocationsAndInitCache(const GrGLInterface* gl, |
| 342 | CachedData* programData) const; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 343 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 344 | friend class GrGpuGLShaders; |
| 345 | }; |
| 346 | |
| 347 | #endif |