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