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