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