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 | #include "GrBinHashKey.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 11 | #include "GrGLProgram.h" |
| 12 | #include "GrGpuGLShaders.h" |
| 13 | #include "GrGpuVertex.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 14 | #include "GrNoncopyable.h" |
| 15 | #include "GrStringBuilder.h" |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 16 | #include "GrRandom.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 17 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 18 | #define SKIP_CACHE_CHECK true |
| 19 | #define GR_UINT32_MAX static_cast<uint32_t>(-1) |
| 20 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 21 | #include "GrTHashCache.h" |
| 22 | |
| 23 | class GrGpuGLShaders::ProgramCache : public ::GrNoncopyable { |
| 24 | private: |
| 25 | class Entry; |
| 26 | |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 27 | typedef GrBinHashKey<Entry, GrGLProgram::kProgramKeySize> ProgramHashKey; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 28 | |
| 29 | class Entry : public ::GrNoncopyable { |
| 30 | public: |
| 31 | Entry() {} |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 32 | void copyAndTakeOwnership(Entry& entry) { |
| 33 | fProgramData.copyAndTakeOwnership(entry.fProgramData); |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 34 | fKey = entry.fKey; // ownership transfer |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 35 | fLRUStamp = entry.fLRUStamp; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | public: |
| 39 | int compare(const ProgramHashKey& key) const { return fKey.compare(key); } |
| 40 | |
| 41 | public: |
| 42 | GrGLProgram::CachedData fProgramData; |
| 43 | ProgramHashKey fKey; |
| 44 | unsigned int fLRUStamp; |
| 45 | }; |
| 46 | |
| 47 | GrTHashTable<Entry, ProgramHashKey, 8> fHashCache; |
| 48 | |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 49 | // We may have kMaxEntries+1 shaders in the GL context because |
| 50 | // we create a new shader before evicting from the cache. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 51 | enum { |
| 52 | kMaxEntries = 32 |
| 53 | }; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 54 | Entry fEntries[kMaxEntries]; |
| 55 | int fCount; |
| 56 | unsigned int fCurrLRUStamp; |
| 57 | const GrGLInterface* fGL; |
| 58 | GrGLProgram::GLSLVersion fGLSLVersion; |
| 59 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 60 | public: |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 61 | ProgramCache(const GrGLInterface* gl, |
| 62 | GrGLProgram::GLSLVersion glslVersion) |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 63 | : fCount(0) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 64 | , fCurrLRUStamp(0) |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 65 | , fGL(gl) |
| 66 | , fGLSLVersion(glslVersion) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | ~ProgramCache() { |
| 70 | for (int i = 0; i < fCount; ++i) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 71 | GrGpuGLShaders::DeleteProgram(fGL, &fEntries[i].fProgramData); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | void abandon() { |
| 76 | fCount = 0; |
| 77 | } |
| 78 | |
| 79 | void invalidateViewMatrices() { |
| 80 | for (int i = 0; i < fCount; ++i) { |
| 81 | // set to illegal matrix |
| 82 | fEntries[i].fProgramData.fViewMatrix = GrMatrix::InvalidMatrix(); |
| 83 | } |
| 84 | } |
| 85 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 86 | GrGLProgram::CachedData* getProgramData(const GrGLProgram& desc) { |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 87 | Entry newEntry; |
junov@google.com | f7c00f6 | 2011-08-18 18:15:16 +0000 | [diff] [blame] | 88 | newEntry.fKey.setKeyData(desc.keyData()); |
| 89 | |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 90 | Entry* entry = fHashCache.find(newEntry.fKey); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 91 | if (NULL == entry) { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 92 | if (!desc.genProgram(fGL, fGLSLVersion, &newEntry.fProgramData)) { |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 93 | return NULL; |
| 94 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 95 | if (fCount < kMaxEntries) { |
| 96 | entry = fEntries + fCount; |
| 97 | ++fCount; |
| 98 | } else { |
| 99 | GrAssert(kMaxEntries == fCount); |
| 100 | entry = fEntries; |
| 101 | for (int i = 1; i < kMaxEntries; ++i) { |
| 102 | if (fEntries[i].fLRUStamp < entry->fLRUStamp) { |
| 103 | entry = fEntries + i; |
| 104 | } |
| 105 | } |
| 106 | fHashCache.remove(entry->fKey, entry); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 107 | GrGpuGLShaders::DeleteProgram(fGL, &entry->fProgramData); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 108 | } |
bsalomon@google.com | 2d9ddf9 | 2011-05-11 16:52:59 +0000 | [diff] [blame] | 109 | entry->copyAndTakeOwnership(newEntry); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 110 | fHashCache.insert(entry->fKey, entry); |
| 111 | } |
| 112 | |
| 113 | entry->fLRUStamp = fCurrLRUStamp; |
| 114 | if (GR_UINT32_MAX == fCurrLRUStamp) { |
| 115 | // wrap around! just trash our LRU, one time hit. |
| 116 | for (int i = 0; i < fCount; ++i) { |
| 117 | fEntries[i].fLRUStamp = 0; |
| 118 | } |
| 119 | } |
| 120 | ++fCurrLRUStamp; |
| 121 | return &entry->fProgramData; |
| 122 | } |
| 123 | }; |
| 124 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 125 | void GrGpuGLShaders::abandonResources(){ |
| 126 | INHERITED::abandonResources(); |
| 127 | fProgramCache->abandon(); |
| 128 | } |
| 129 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 130 | void GrGpuGLShaders::DeleteProgram(const GrGLInterface* gl, |
| 131 | CachedData* programData) { |
| 132 | GR_GL_CALL(gl, DeleteShader(programData->fVShaderID)); |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 133 | if (programData->fGShaderID) { |
| 134 | GR_GL_CALL(gl, DeleteShader(programData->fGShaderID)); |
| 135 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 136 | GR_GL_CALL(gl, DeleteShader(programData->fFShaderID)); |
| 137 | GR_GL_CALL(gl, DeleteProgram(programData->fProgramID)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 138 | GR_DEBUGCODE(memset(programData, 0, sizeof(*programData));) |
| 139 | } |
| 140 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 141 | //////////////////////////////////////////////////////////////////////////////// |
| 142 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 143 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 144 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 145 | namespace { |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 146 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 147 | GrGLProgram::GLSLVersion get_glsl_version(GrGLBinding binding, |
| 148 | const GrGLInterface* gl) { |
| 149 | GrGLSLVersion ver = GrGLGetGLSLVersion(gl); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 150 | switch (binding) { |
| 151 | case kDesktop_GrGLBinding: |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 152 | GrAssert(ver >= GR_GLSL_VER(1,20)); |
| 153 | if (ver >= GR_GLSL_VER(1,50)) { |
| 154 | return GrGLProgram::k150_GLSLVersion; |
| 155 | } else if (ver >= GR_GLSL_VER(1,30)) { |
| 156 | return GrGLProgram::k130_GLSLVersion; |
| 157 | } else { |
| 158 | return GrGLProgram::k120_GLSLVersion; |
| 159 | } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 160 | case kES2_GrGLBinding: |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 161 | // version 1.00 of ES GLSL based on ver 1.20 of desktop GLSL |
| 162 | GrAssert(ver >= GR_GL_VER(1,00)); |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 163 | return GrGLProgram::k120_GLSLVersion; |
| 164 | default: |
| 165 | GrCrash("Attempting to get GLSL version in unknown or fixed-" |
| 166 | "function GL binding."); |
| 167 | return GrGLProgram::k120_GLSLVersion; // suppress warning |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 168 | } |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | template <typename T> |
| 172 | T random_val(GrRandom* r, T count) { |
| 173 | return (T)(int)(r->nextF() * count); |
| 174 | } |
| 175 | |
| 176 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 177 | |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 178 | bool GrGpuGLShaders::programUnitTest() { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 179 | |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 180 | GrGLProgram::GLSLVersion glslVersion = |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 181 | get_glsl_version(this->glBinding(), this->glInterface()); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 182 | static const int STAGE_OPTS[] = { |
| 183 | 0, |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 184 | StageDesc::kNoPerspective_OptFlagBit, |
| 185 | StageDesc::kIdentity_CoordMapping |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 186 | }; |
| 187 | GrGLProgram program; |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 188 | ProgramDesc& pdesc = program.fProgramDesc; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 189 | |
| 190 | static const int NUM_TESTS = 512; |
| 191 | |
| 192 | // GrRandoms nextU() values have patterns in the low bits |
| 193 | // So using nextU() % array_count might never take some values. |
| 194 | GrRandom random; |
| 195 | for (int t = 0; t < NUM_TESTS; ++t) { |
| 196 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 197 | #if 0 |
| 198 | GrPrintf("\nTest Program %d\n-------------\n", t); |
| 199 | static const int stop = -1; |
| 200 | if (t == stop) { |
| 201 | int breakpointhere = 9; |
| 202 | } |
| 203 | #endif |
| 204 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 205 | pdesc.fVertexLayout = 0; |
| 206 | pdesc.fEmitsPointSize = random.nextF() > .5f; |
| 207 | float colorType = random.nextF(); |
| 208 | if (colorType < 1.f / 3.f) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 209 | pdesc.fColorType = ProgramDesc::kAttribute_ColorType; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 210 | } else if (colorType < 2.f / 3.f) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 211 | pdesc.fColorType = ProgramDesc::kUniform_ColorType; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 212 | } else { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 213 | pdesc.fColorType = ProgramDesc::kNone_ColorType; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 214 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 215 | |
| 216 | int idx = (int)(random.nextF() * (SkXfermode::kCoeffModesCnt)); |
| 217 | pdesc.fColorFilterXfermode = (SkXfermode::Mode)idx; |
| 218 | |
| 219 | idx = (int)(random.nextF() * (kNumStages+1)); |
| 220 | pdesc.fFirstCoverageStage = idx; |
| 221 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 222 | pdesc.fVertexLayout |= (random.nextF() > .5f) ? |
| 223 | GrDrawTarget::kCoverage_VertexLayoutBit : |
| 224 | 0; |
| 225 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 226 | #if GR_GL_EXPERIMENTAL_GS |
bsalomon@google.com | 6f92f18 | 2011-09-29 15:05:48 +0000 | [diff] [blame] | 227 | pdesc.fExperimentalGS = this->getCaps().fGeometryShaderSupport && |
| 228 | random.nextF() > .5f; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 229 | #endif |
| 230 | |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 231 | bool edgeAA = random.nextF() > .5f; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 232 | if (edgeAA) { |
| 233 | bool vertexEdgeAA = random.nextF() > .5f; |
| 234 | if (vertexEdgeAA) { |
| 235 | pdesc.fVertexLayout |= GrDrawTarget::kEdge_VertexLayoutBit; |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 236 | if (this->getCaps().fShaderDerivativeSupport) { |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 237 | pdesc.fVertexEdgeType = random.nextF() > 0.5f ? |
| 238 | kHairQuad_EdgeType : |
| 239 | kHairLine_EdgeType; |
| 240 | } else { |
| 241 | pdesc.fVertexEdgeType = kHairLine_EdgeType; |
| 242 | } |
| 243 | pdesc.fEdgeAANumEdges = 0; |
| 244 | } else { |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 245 | pdesc.fEdgeAANumEdges = static_cast<int>(1 + random.nextF() * |
| 246 | this->getMaxEdges()); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 247 | pdesc.fEdgeAAConcave = random.nextF() > .5f; |
| 248 | } |
| 249 | } else { |
| 250 | pdesc.fEdgeAANumEdges = 0; |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 251 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 252 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 253 | if (this->getCaps().fDualSourceBlendingSupport) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 254 | pdesc.fDualSrcOutput = |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 255 | (ProgramDesc::DualSrcOutput) |
| 256 | (int)(random.nextF() * ProgramDesc::kDualSrcOutputCnt); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 257 | } else { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 258 | pdesc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 259 | } |
| 260 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 261 | for (int s = 0; s < kNumStages; ++s) { |
| 262 | // enable the stage? |
| 263 | if (random.nextF() > .5f) { |
| 264 | // use separate tex coords? |
| 265 | if (random.nextF() > .5f) { |
| 266 | int t = (int)(random.nextF() * kMaxTexCoords); |
| 267 | pdesc.fVertexLayout |= StageTexCoordVertexLayoutBit(s, t); |
| 268 | } else { |
| 269 | pdesc.fVertexLayout |= StagePosAsTexCoordVertexLayoutBit(s); |
| 270 | } |
| 271 | } |
| 272 | // use text-formatted verts? |
| 273 | if (random.nextF() > .5f) { |
| 274 | pdesc.fVertexLayout |= kTextFormat_VertexLayoutBit; |
| 275 | } |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 276 | idx = (int)(random.nextF() * GR_ARRAY_COUNT(STAGE_OPTS)); |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 277 | StageDesc& stage = pdesc.fStages[s]; |
| 278 | stage.fOptFlags = STAGE_OPTS[idx]; |
| 279 | stage.fModulation = random_val(&random, StageDesc::kModulationCnt); |
| 280 | stage.fCoordMapping = random_val(&random, StageDesc::kCoordMappingCnt); |
| 281 | stage.fFetchMode = random_val(&random, StageDesc::kFetchModeCnt); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 282 | // convolution shaders don't work with persp tex matrix |
| 283 | if (stage.fFetchMode == StageDesc::kConvolution_FetchMode) { |
| 284 | stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit; |
| 285 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 286 | stage.setEnabled(VertexUsesStage(s, pdesc.fVertexLayout)); |
bsalomon@google.com | 9d12f5c | 2011-09-29 18:08:18 +0000 | [diff] [blame] | 287 | stage.fKernelWidth = static_cast<int8_t>(4 * random.nextF() + 2); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 288 | } |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 289 | CachedData cachedData; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 290 | if (!program.genProgram(this->glInterface(), |
| 291 | glslVersion, |
| 292 | &cachedData)) { |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 293 | return false; |
| 294 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 295 | DeleteProgram(this->glInterface(), &cachedData); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 296 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 297 | return true; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 298 | } |
| 299 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 300 | namespace { |
| 301 | GrGLBinding get_binding_in_use(const GrGLInterface* gl) { |
| 302 | if (gl->supportsDesktop()) { |
| 303 | return kDesktop_GrGLBinding; |
| 304 | } else { |
| 305 | GrAssert(gl->supportsES2()); |
| 306 | return kES2_GrGLBinding; |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | GrGpuGLShaders::GrGpuGLShaders(const GrGLInterface* gl) |
| 312 | : GrGpuGL(gl, get_binding_in_use(gl)) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 313 | |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 314 | GrGLProgram::GLSLVersion glslVersion = |
| 315 | get_glsl_version(this->glBinding(), gl); |
| 316 | |
| 317 | // Enable supported shader-releated caps |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 318 | fCaps.fShaderSupport = true; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 319 | fCaps.fSupportPerVertexCoverage = true; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 320 | if (kDesktop_GrGLBinding == this->glBinding()) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 321 | fCaps.fDualSourceBlendingSupport = |
bsalomon@google.com | c82b889 | 2011-09-22 14:10:33 +0000 | [diff] [blame] | 322 | this->glVersion() >= GR_GL_VER(3,3) || |
bsalomon@google.com | 2c17fcd | 2011-07-06 17:47:02 +0000 | [diff] [blame] | 323 | this->hasExtension("GL_ARB_blend_func_extended"); |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 324 | fCaps.fShaderDerivativeSupport = true; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 325 | // we don't support GL_ARB_geometry_shader4, just GL 3.2+ GS |
| 326 | fCaps.fGeometryShaderSupport = |
| 327 | this->glVersion() >= GR_GL_VER(3,2) && |
| 328 | glslVersion >= GrGLProgram::k150_GLSLVersion; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 329 | } else { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 330 | fCaps.fShaderDerivativeSupport = |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 331 | this->hasExtension("GL_OES_standard_derivatives"); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 332 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 333 | |
| 334 | fProgramData = NULL; |
bsalomon@google.com | 4fa6694 | 2011-09-20 19:06:12 +0000 | [diff] [blame] | 335 | fProgramCache = new ProgramCache(gl, glslVersion); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 336 | |
| 337 | #if 0 |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 338 | this->programUnitTest(); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 339 | #endif |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | GrGpuGLShaders::~GrGpuGLShaders() { |
| 343 | delete fProgramCache; |
| 344 | } |
| 345 | |
| 346 | const GrMatrix& GrGpuGLShaders::getHWSamplerMatrix(int stage) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 347 | GrAssert(fProgramData); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 348 | |
| 349 | if (GrGLProgram::kSetAsAttribute == |
| 350 | fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) { |
| 351 | return fHWDrawState.fSamplerStates[stage].getMatrix(); |
| 352 | } else { |
| 353 | return fProgramData->fTextureMatrices[stage]; |
| 354 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void GrGpuGLShaders::recordHWSamplerMatrix(int stage, const GrMatrix& matrix) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 358 | GrAssert(fProgramData); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 359 | if (GrGLProgram::kSetAsAttribute == |
| 360 | fProgramData->fUniLocations.fStages[stage].fTextureMatrixUni) { |
| 361 | fHWDrawState.fSamplerStates[stage].setMatrix(matrix); |
| 362 | } else { |
| 363 | fProgramData->fTextureMatrices[stage] = matrix; |
| 364 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | void GrGpuGLShaders::resetContext() { |
| 368 | INHERITED::resetContext(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 369 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 370 | fHWGeometryState.fVertexLayout = 0; |
| 371 | fHWGeometryState.fVertexOffset = ~0; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 372 | GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx())); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 373 | GL_CALL(DisableVertexAttribArray(GrGLProgram::EdgeAttributeIdx())); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 374 | for (int t = 0; t < kMaxTexCoords; ++t) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 375 | GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t))); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 376 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 377 | GL_CALL(EnableVertexAttribArray(GrGLProgram::PositionAttributeIdx())); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 378 | |
| 379 | fHWProgramID = 0; |
| 380 | } |
| 381 | |
| 382 | void GrGpuGLShaders::flushViewMatrix() { |
| 383 | GrAssert(NULL != fCurrDrawState.fRenderTarget); |
bsalomon@google.com | cc4dac3 | 2011-05-10 13:52:42 +0000 | [diff] [blame] | 384 | GrMatrix m; |
| 385 | m.setAll( |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 386 | GrIntToScalar(2) / fCurrDrawState.fRenderTarget->width(), 0, -GR_Scalar1, |
| 387 | 0,-GrIntToScalar(2) / fCurrDrawState.fRenderTarget->height(), GR_Scalar1, |
| 388 | 0, 0, GrMatrix::I()[8]); |
| 389 | m.setConcat(m, fCurrDrawState.fViewMatrix); |
| 390 | |
| 391 | // ES doesn't allow you to pass true to the transpose param, |
| 392 | // so do our own transpose |
bsalomon@google.com | 27a4dc4 | 2011-05-16 13:14:03 +0000 | [diff] [blame] | 393 | GrGLfloat mt[] = { |
| 394 | GrScalarToFloat(m[GrMatrix::kMScaleX]), |
| 395 | GrScalarToFloat(m[GrMatrix::kMSkewY]), |
| 396 | GrScalarToFloat(m[GrMatrix::kMPersp0]), |
| 397 | GrScalarToFloat(m[GrMatrix::kMSkewX]), |
| 398 | GrScalarToFloat(m[GrMatrix::kMScaleY]), |
| 399 | GrScalarToFloat(m[GrMatrix::kMPersp1]), |
| 400 | GrScalarToFloat(m[GrMatrix::kMTransX]), |
| 401 | GrScalarToFloat(m[GrMatrix::kMTransY]), |
| 402 | GrScalarToFloat(m[GrMatrix::kMPersp2]) |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 403 | }; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 404 | |
| 405 | if (GrGLProgram::kSetAsAttribute == |
| 406 | fProgramData->fUniLocations.fViewMatrixUni) { |
| 407 | int baseIdx = GrGLProgram::ViewMatrixAttributeIdx(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 408 | GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0)); |
| 409 | GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3)); |
| 410 | GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 411 | } else { |
| 412 | GrAssert(GrGLProgram::kUnusedUniform != |
| 413 | fProgramData->fUniLocations.fViewMatrixUni); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 414 | GL_CALL(UniformMatrix3fv(fProgramData->fUniLocations.fViewMatrixUni, |
| 415 | 1, false, mt)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 416 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 417 | } |
| 418 | |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 419 | void GrGpuGLShaders::flushTextureDomain(int s) { |
| 420 | const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTexDomUni; |
| 421 | if (GrGLProgram::kUnusedUniform != uni) { |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 422 | const GrRect &texDom = |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 423 | fCurrDrawState.fSamplerStates[s].getTextureDomain(); |
| 424 | |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 425 | if (((1 << s) & fDirtyFlags.fTextureChangedMask) || |
| 426 | fProgramData->fTextureDomain[s] != texDom) { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 427 | |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 428 | fProgramData->fTextureDomain[s] = texDom; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 429 | |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 430 | float values[4] = { |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 431 | GrScalarToFloat(texDom.left()), |
| 432 | GrScalarToFloat(texDom.top()), |
| 433 | GrScalarToFloat(texDom.right()), |
| 434 | GrScalarToFloat(texDom.bottom()) |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; |
| 438 | GrGLTexture::Orientation orientation = texture->orientation(); |
| 439 | |
| 440 | // vertical flip if necessary |
| 441 | if (GrGLTexture::kBottomUp_Orientation == orientation) { |
| 442 | values[1] = 1.0f - values[1]; |
| 443 | values[3] = 1.0f - values[3]; |
twiz@google.com | 76b8274 | 2011-06-02 20:30:02 +0000 | [diff] [blame] | 444 | // The top and bottom were just flipped, so correct the ordering |
| 445 | // of elements so that values = (l, t, r, b). |
| 446 | SkTSwap(values[1], values[3]); |
junov@google.com | 2f83940 | 2011-05-24 15:13:01 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | values[0] *= SkScalarToFloat(texture->contentScaleX()); |
| 450 | values[2] *= SkScalarToFloat(texture->contentScaleX()); |
| 451 | values[1] *= SkScalarToFloat(texture->contentScaleY()); |
| 452 | values[3] *= SkScalarToFloat(texture->contentScaleY()); |
| 453 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 454 | GL_CALL(Uniform4fv(uni, 1, values)); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 455 | } |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 459 | void GrGpuGLShaders::flushTextureMatrix(int s) { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 460 | const GrGLint& uni = fProgramData->fUniLocations.fStages[s].fTextureMatrixUni; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 461 | GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; |
| 462 | if (NULL != texture) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 463 | if (GrGLProgram::kUnusedUniform != uni && |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 464 | (((1 << s) & fDirtyFlags.fTextureChangedMask) || |
| 465 | getHWSamplerMatrix(s) != getSamplerMatrix(s))) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 466 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 467 | GrAssert(NULL != fCurrDrawState.fTextures[s]); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 468 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 469 | GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 470 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 471 | GrMatrix m = getSamplerMatrix(s); |
| 472 | GrSamplerState::SampleMode mode = |
| 473 | fCurrDrawState.fSamplerStates[s].getSampleMode(); |
| 474 | AdjustTextureMatrix(texture, mode, &m); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 475 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 476 | // ES doesn't allow you to pass true to the transpose param, |
| 477 | // so do our own transpose |
bsalomon@google.com | 27a4dc4 | 2011-05-16 13:14:03 +0000 | [diff] [blame] | 478 | GrGLfloat mt[] = { |
| 479 | GrScalarToFloat(m[GrMatrix::kMScaleX]), |
| 480 | GrScalarToFloat(m[GrMatrix::kMSkewY]), |
| 481 | GrScalarToFloat(m[GrMatrix::kMPersp0]), |
| 482 | GrScalarToFloat(m[GrMatrix::kMSkewX]), |
| 483 | GrScalarToFloat(m[GrMatrix::kMScaleY]), |
| 484 | GrScalarToFloat(m[GrMatrix::kMPersp1]), |
| 485 | GrScalarToFloat(m[GrMatrix::kMTransX]), |
| 486 | GrScalarToFloat(m[GrMatrix::kMTransY]), |
| 487 | GrScalarToFloat(m[GrMatrix::kMPersp2]) |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 488 | }; |
bsalomon@google.com | 27a4dc4 | 2011-05-16 13:14:03 +0000 | [diff] [blame] | 489 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 490 | if (GrGLProgram::kSetAsAttribute == |
| 491 | fProgramData->fUniLocations.fStages[s].fTextureMatrixUni) { |
| 492 | int baseIdx = GrGLProgram::TextureMatrixAttributeIdx(s); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 493 | GL_CALL(VertexAttrib4fv(baseIdx + 0, mt+0)); |
| 494 | GL_CALL(VertexAttrib4fv(baseIdx + 1, mt+3)); |
| 495 | GL_CALL(VertexAttrib4fv(baseIdx + 2, mt+6)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 496 | } else { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 497 | GL_CALL(UniformMatrix3fv(uni, 1, false, mt)); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 498 | } |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 499 | recordHWSamplerMatrix(s, getSamplerMatrix(s)); |
| 500 | } |
| 501 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 502 | } |
| 503 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 504 | void GrGpuGLShaders::flushRadial2(int s) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 505 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 506 | const int &uni = fProgramData->fUniLocations.fStages[s].fRadial2Uni; |
| 507 | const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s]; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 508 | if (GrGLProgram::kUnusedUniform != uni && |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 509 | (fProgramData->fRadial2CenterX1[s] != sampler.getRadial2CenterX1() || |
| 510 | fProgramData->fRadial2Radius0[s] != sampler.getRadial2Radius0() || |
| 511 | fProgramData->fRadial2PosRoot[s] != sampler.isRadial2PosRoot())) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 512 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 513 | GrScalar centerX1 = sampler.getRadial2CenterX1(); |
| 514 | GrScalar radius0 = sampler.getRadial2Radius0(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 515 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 516 | GrScalar a = GrMul(centerX1, centerX1) - GR_Scalar1; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 517 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 518 | // when were in the degenerate (linear) case the second |
| 519 | // value will be INF but the program doesn't read it. (We |
| 520 | // use the same 6 uniforms even though we don't need them |
| 521 | // all in the linear case just to keep the code complexity |
| 522 | // down). |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 523 | float values[6] = { |
| 524 | GrScalarToFloat(a), |
| 525 | 1 / (2.f * values[0]), |
| 526 | GrScalarToFloat(centerX1), |
| 527 | GrScalarToFloat(radius0), |
| 528 | GrScalarToFloat(GrMul(radius0, radius0)), |
| 529 | sampler.isRadial2PosRoot() ? 1.f : -1.f |
| 530 | }; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 531 | GL_CALL(Uniform1fv(uni, 6, values)); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 532 | fProgramData->fRadial2CenterX1[s] = sampler.getRadial2CenterX1(); |
| 533 | fProgramData->fRadial2Radius0[s] = sampler.getRadial2Radius0(); |
| 534 | fProgramData->fRadial2PosRoot[s] = sampler.isRadial2PosRoot(); |
| 535 | } |
| 536 | } |
| 537 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 538 | void GrGpuGLShaders::flushConvolution(int s) { |
| 539 | const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s]; |
| 540 | int kernelUni = fProgramData->fUniLocations.fStages[s].fKernelUni; |
| 541 | if (GrGLProgram::kUnusedUniform != kernelUni) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 542 | GL_CALL(Uniform1fv(kernelUni, sampler.getKernelWidth(), |
| 543 | sampler.getKernel())); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 544 | } |
| 545 | int imageIncrementUni = fProgramData->fUniLocations.fStages[s].fImageIncrementUni; |
| 546 | if (GrGLProgram::kUnusedUniform != imageIncrementUni) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 547 | GL_CALL(Uniform2fv(imageIncrementUni, 1, sampler.getImageIncrement())); |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 551 | void GrGpuGLShaders::flushTexelSize(int s) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 552 | const int& uni = fProgramData->fUniLocations.fStages[s].fNormalizedTexelSizeUni; |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 553 | if (GrGLProgram::kUnusedUniform != uni) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 554 | GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 555 | if (texture->allocatedWidth() != fProgramData->fTextureWidth[s] || |
| 556 | texture->allocatedHeight() != fProgramData->fTextureWidth[s]) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 557 | |
bsalomon@google.com | 0168afc | 2011-08-08 13:21:05 +0000 | [diff] [blame] | 558 | float texelSize[] = {1.f / texture->allocatedWidth(), |
| 559 | 1.f / texture->allocatedHeight()}; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 560 | GL_CALL(Uniform2fv(uni, 1, texelSize)); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 561 | } |
| 562 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 563 | } |
| 564 | |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 565 | void GrGpuGLShaders::flushEdgeAAData() { |
| 566 | const int& uni = fProgramData->fUniLocations.fEdgesUni; |
| 567 | if (GrGLProgram::kUnusedUniform != uni) { |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 568 | int count = fCurrDrawState.fEdgeAANumEdges; |
| 569 | Edge edges[kMaxEdges]; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 570 | // Flip the edges in Y |
bsalomon@google.com | 9d12f5c | 2011-09-29 18:08:18 +0000 | [diff] [blame] | 571 | float height = |
| 572 | static_cast<float>(fCurrDrawState.fRenderTarget->height()); |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 573 | for (int i = 0; i < count; ++i) { |
| 574 | edges[i] = fCurrDrawState.fEdgeAAEdges[i]; |
| 575 | float b = edges[i].fY; |
| 576 | edges[i].fY = -b; |
| 577 | edges[i].fZ += b * height; |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 578 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 579 | GL_CALL(Uniform3fv(uni, count, &edges[0].fX)); |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Scroggo | 01b87ec | 2011-05-11 18:05:38 +0000 | [diff] [blame] | 583 | static const float ONE_OVER_255 = 1.f / 255.f; |
| 584 | |
| 585 | #define GR_COLOR_TO_VEC4(color) {\ |
| 586 | GrColorUnpackR(color) * ONE_OVER_255,\ |
| 587 | GrColorUnpackG(color) * ONE_OVER_255,\ |
| 588 | GrColorUnpackB(color) * ONE_OVER_255,\ |
| 589 | GrColorUnpackA(color) * ONE_OVER_255 \ |
| 590 | } |
| 591 | |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 592 | void GrGpuGLShaders::flushColor() { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 593 | const ProgramDesc& desc = fCurrentProgram.getDesc(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 594 | if (this->getGeomSrc().fVertexLayout & kColor_VertexLayoutBit) { |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 595 | // color will be specified per-vertex as an attribute |
| 596 | // invalidate the const vertex attrib color |
| 597 | fHWDrawState.fColor = GrColor_ILLEGAL; |
| 598 | } else { |
| 599 | switch (desc.fColorType) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 600 | case ProgramDesc::kAttribute_ColorType: |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 601 | if (fHWDrawState.fColor != fCurrDrawState.fColor) { |
| 602 | // OpenGL ES only supports the float varities of glVertexAttrib |
Scroggo | 01b87ec | 2011-05-11 18:05:38 +0000 | [diff] [blame] | 603 | float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColor); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 604 | GL_CALL(VertexAttrib4fv(GrGLProgram::ColorAttributeIdx(), |
| 605 | c)); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 606 | fHWDrawState.fColor = fCurrDrawState.fColor; |
| 607 | } |
| 608 | break; |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 609 | case ProgramDesc::kUniform_ColorType: |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 610 | if (fProgramData->fColor != fCurrDrawState.fColor) { |
| 611 | // OpenGL ES only supports the float varities of glVertexAttrib |
Scroggo | 01b87ec | 2011-05-11 18:05:38 +0000 | [diff] [blame] | 612 | float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColor); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 613 | GrAssert(GrGLProgram::kUnusedUniform != |
| 614 | fProgramData->fUniLocations.fColorUni); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 615 | GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorUni, |
| 616 | 1, c)); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 617 | fProgramData->fColor = fCurrDrawState.fColor; |
| 618 | } |
| 619 | break; |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 620 | case ProgramDesc::kNone_ColorType: |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 621 | GrAssert(0xffffffff == fCurrDrawState.fColor); |
| 622 | break; |
| 623 | default: |
| 624 | GrCrash("Unknown color type."); |
| 625 | } |
| 626 | } |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 627 | if (fProgramData->fUniLocations.fColorFilterUni |
| 628 | != GrGLProgram::kUnusedUniform |
| 629 | && fProgramData->fColorFilterColor |
| 630 | != fCurrDrawState.fColorFilterColor) { |
Scroggo | 01b87ec | 2011-05-11 18:05:38 +0000 | [diff] [blame] | 631 | float c[] = GR_COLOR_TO_VEC4(fCurrDrawState.fColorFilterColor); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 632 | GL_CALL(Uniform4fv(fProgramData->fUniLocations.fColorFilterUni, 1, c)); |
Scroggo | 97c88c2 | 2011-05-11 14:05:25 +0000 | [diff] [blame] | 633 | fProgramData->fColorFilterColor = fCurrDrawState.fColorFilterColor; |
| 634 | } |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 638 | bool GrGpuGLShaders::flushGraphicsState(GrPrimitiveType type) { |
| 639 | if (!flushGLStateCommon(type)) { |
| 640 | return false; |
| 641 | } |
| 642 | |
| 643 | if (fDirtyFlags.fRenderTargetChanged) { |
| 644 | // our coords are in pixel space and the GL matrices map to NDC |
| 645 | // so if the viewport changed, our matrix is now wrong. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 646 | fHWDrawState.fViewMatrix = GrMatrix::InvalidMatrix(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 647 | // we assume all shader matrices may be wrong after viewport changes |
| 648 | fProgramCache->invalidateViewMatrices(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 649 | } |
| 650 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 651 | buildProgram(type); |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 652 | fProgramData = fProgramCache->getProgramData(fCurrentProgram); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 653 | if (NULL == fProgramData) { |
| 654 | GrAssert(!"Failed to create program!"); |
| 655 | return false; |
| 656 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 657 | |
| 658 | if (fHWProgramID != fProgramData->fProgramID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 659 | GL_CALL(UseProgram(fProgramData->fProgramID)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 660 | fHWProgramID = fProgramData->fProgramID; |
| 661 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 662 | GrBlendCoeff srcCoeff = fCurrDrawState.fSrcBlend; |
| 663 | GrBlendCoeff dstCoeff = fCurrDrawState.fDstBlend; |
| 664 | |
| 665 | fCurrentProgram.overrideBlend(&srcCoeff, &dstCoeff); |
| 666 | this->flushBlend(type, srcCoeff, dstCoeff); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 667 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 668 | this->flushColor(); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 669 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 670 | GrMatrix* currViewMatrix; |
| 671 | if (GrGLProgram::kSetAsAttribute == |
| 672 | fProgramData->fUniLocations.fViewMatrixUni) { |
| 673 | currViewMatrix = &fHWDrawState.fViewMatrix; |
| 674 | } else { |
| 675 | currViewMatrix = &fProgramData->fViewMatrix; |
| 676 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 677 | |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 678 | if (*currViewMatrix != fCurrDrawState.fViewMatrix) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 679 | flushViewMatrix(); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 680 | *currViewMatrix = fCurrDrawState.fViewMatrix; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 684 | this->flushTextureMatrix(s); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 685 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 686 | this->flushRadial2(s); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 687 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 688 | this->flushConvolution(s); |
| 689 | |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 690 | this->flushTexelSize(s); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 691 | |
| 692 | this->flushTextureDomain(s); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 693 | } |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 694 | this->flushEdgeAAData(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 695 | resetDirtyFlags(); |
| 696 | return true; |
| 697 | } |
| 698 | |
| 699 | void GrGpuGLShaders::postDraw() { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void GrGpuGLShaders::setupGeometry(int* startVertex, |
| 703 | int* startIndex, |
| 704 | int vertexCount, |
| 705 | int indexCount) { |
| 706 | |
| 707 | int newColorOffset; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 708 | int newCoverageOffset; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 709 | int newTexCoordOffsets[kMaxTexCoords]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 710 | int newEdgeOffset; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 711 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 712 | GrGLsizei newStride = VertexSizeAndOffsetsByIdx( |
| 713 | this->getGeomSrc().fVertexLayout, |
| 714 | newTexCoordOffsets, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 715 | &newColorOffset, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 716 | &newCoverageOffset, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 717 | &newEdgeOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 718 | int oldColorOffset; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 719 | int oldCoverageOffset; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 720 | int oldTexCoordOffsets[kMaxTexCoords]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 721 | int oldEdgeOffset; |
| 722 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 723 | GrGLsizei oldStride = VertexSizeAndOffsetsByIdx( |
| 724 | fHWGeometryState.fVertexLayout, |
| 725 | oldTexCoordOffsets, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 726 | &oldColorOffset, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 727 | &oldCoverageOffset, |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 728 | &oldEdgeOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 729 | bool indexed = NULL != startIndex; |
| 730 | |
| 731 | int extraVertexOffset; |
| 732 | int extraIndexOffset; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 733 | this->setBuffers(indexed, &extraVertexOffset, &extraIndexOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 734 | |
| 735 | GrGLenum scalarType; |
| 736 | bool texCoordNorm; |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 737 | if (this->getGeomSrc().fVertexLayout & kTextFormat_VertexLayoutBit) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 738 | scalarType = GrGLTextType; |
| 739 | texCoordNorm = GR_GL_TEXT_TEXTURE_NORMALIZED; |
| 740 | } else { |
| 741 | scalarType = GrGLType; |
| 742 | texCoordNorm = false; |
| 743 | } |
| 744 | |
| 745 | size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride; |
| 746 | *startVertex = 0; |
| 747 | if (indexed) { |
| 748 | *startIndex += extraIndexOffset; |
| 749 | } |
| 750 | |
| 751 | // all the Pointers must be set if any of these are true |
| 752 | bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty || |
| 753 | vertexOffset != fHWGeometryState.fVertexOffset || |
| 754 | newStride != oldStride; |
| 755 | |
| 756 | // position and tex coord offsets change if above conditions are true |
| 757 | // or the type/normalization changed based on text vs nontext type coords. |
| 758 | bool posAndTexChange = allOffsetsChange || |
| 759 | (((GrGLTextType != GrGLType) || GR_GL_TEXT_TEXTURE_NORMALIZED) && |
| 760 | (kTextFormat_VertexLayoutBit & |
| 761 | (fHWGeometryState.fVertexLayout ^ |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 762 | this->getGeomSrc().fVertexLayout))); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 763 | |
| 764 | if (posAndTexChange) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 765 | int idx = GrGLProgram::PositionAttributeIdx(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 766 | GL_CALL(VertexAttribPointer(idx, 2, scalarType, false, newStride, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 767 | (GrGLvoid*)vertexOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 768 | fHWGeometryState.fVertexOffset = vertexOffset; |
| 769 | } |
| 770 | |
| 771 | for (int t = 0; t < kMaxTexCoords; ++t) { |
| 772 | if (newTexCoordOffsets[t] > 0) { |
| 773 | GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[t]); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 774 | int idx = GrGLProgram::TexCoordAttributeIdx(t); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 775 | if (oldTexCoordOffsets[t] <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 776 | GL_CALL(EnableVertexAttribArray(idx)); |
| 777 | GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 778 | newStride, texCoordOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 779 | } else if (posAndTexChange || |
| 780 | newTexCoordOffsets[t] != oldTexCoordOffsets[t]) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 781 | GL_CALL(VertexAttribPointer(idx, 2, scalarType, texCoordNorm, |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 782 | newStride, texCoordOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 783 | } |
| 784 | } else if (oldTexCoordOffsets[t] > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 785 | GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t))); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
| 789 | if (newColorOffset > 0) { |
| 790 | GrGLvoid* colorOffset = (int8_t*)(vertexOffset + newColorOffset); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 791 | int idx = GrGLProgram::ColorAttributeIdx(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 792 | if (oldColorOffset <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 793 | GL_CALL(EnableVertexAttribArray(idx)); |
| 794 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 795 | true, newStride, colorOffset)); |
| 796 | } else if (allOffsetsChange || newColorOffset != oldColorOffset) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 797 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 798 | true, newStride, colorOffset)); |
| 799 | } |
| 800 | } else if (oldColorOffset > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 801 | GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx())); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 802 | } |
| 803 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 804 | if (newCoverageOffset > 0) { |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame^] | 805 | // bind a single channel, they should all have the same value. |
| 806 | GrGLvoid* coverageOffset = (int8_t*)(vertexOffset + newCoverageOffset); |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 807 | int idx = GrGLProgram::CoverageAttributeIdx(); |
| 808 | if (oldCoverageOffset <= 0) { |
| 809 | GL_CALL(EnableVertexAttribArray(idx)); |
| 810 | GL_CALL(VertexAttribPointer(idx, 1, GR_GL_UNSIGNED_BYTE, |
| 811 | true, newStride, coverageOffset)); |
| 812 | } else if (allOffsetsChange || newCoverageOffset != oldCoverageOffset) { |
| 813 | GL_CALL(VertexAttribPointer(idx, 1, GR_GL_UNSIGNED_BYTE, |
| 814 | true, newStride, coverageOffset)); |
| 815 | } |
| 816 | } else if (oldCoverageOffset > 0) { |
| 817 | GL_CALL(DisableVertexAttribArray(GrGLProgram::CoverageAttributeIdx())); |
| 818 | } |
| 819 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 820 | if (newEdgeOffset > 0) { |
| 821 | GrGLvoid* edgeOffset = (int8_t*)(vertexOffset + newEdgeOffset); |
| 822 | int idx = GrGLProgram::EdgeAttributeIdx(); |
| 823 | if (oldEdgeOffset <= 0) { |
| 824 | GL_CALL(EnableVertexAttribArray(idx)); |
| 825 | GL_CALL(VertexAttribPointer(idx, 4, scalarType, |
| 826 | false, newStride, edgeOffset)); |
| 827 | } else if (allOffsetsChange || newEdgeOffset != oldEdgeOffset) { |
| 828 | GL_CALL(VertexAttribPointer(idx, 4, scalarType, |
| 829 | false, newStride, edgeOffset)); |
| 830 | } |
| 831 | } else if (oldEdgeOffset > 0) { |
| 832 | GL_CALL(DisableVertexAttribArray(GrGLProgram::EdgeAttributeIdx())); |
| 833 | } |
| 834 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 835 | fHWGeometryState.fVertexLayout = this->getGeomSrc().fVertexLayout; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 836 | fHWGeometryState.fArrayPtrsDirty = false; |
| 837 | } |
| 838 | |
| 839 | void GrGpuGLShaders::buildProgram(GrPrimitiveType type) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 840 | ProgramDesc& desc = fCurrentProgram.fProgramDesc; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 841 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 842 | // The descriptor is used as a cache key. Thus when a field of the |
| 843 | // descriptor will not affect program generation (because of the vertex |
| 844 | // layout in use or other descriptor field settings) it should be set |
| 845 | // to a canonical value to avoid duplicate programs with different keys. |
| 846 | |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 847 | // Must initialize all fields or cache will have false negatives! |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 848 | desc.fVertexLayout = this->getGeomSrc().fVertexLayout; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 849 | |
| 850 | desc.fEmitsPointSize = kPoints_PrimitiveType == type; |
| 851 | |
bsalomon@google.com | 9d12f5c | 2011-09-29 18:08:18 +0000 | [diff] [blame] | 852 | bool requiresAttributeColors = 0 != (desc.fVertexLayout & kColor_VertexLayoutBit); |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 853 | // fColorType records how colors are specified for the program. Strip |
| 854 | // the bit from the layout to avoid false negatives when searching for an |
| 855 | // existing program in the cache. |
| 856 | desc.fVertexLayout &= ~(kColor_VertexLayoutBit); |
| 857 | |
bsalomon@google.com | f2d9155 | 2011-05-16 20:56:06 +0000 | [diff] [blame] | 858 | desc.fColorFilterXfermode = fCurrDrawState.fColorFilterXfermode; |
| 859 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 860 | #if GR_AGGRESSIVE_SHADER_OPTS |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 861 | if (!requiresAttributeColors && (0xffffffff == fCurrDrawState.fColor)) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 862 | desc.fColorType = ProgramDesc::kNone_ColorType; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 863 | } else |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 864 | #endif |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 865 | #if GR_GL_NO_CONSTANT_ATTRIBUTES |
| 866 | if (!requiresAttributeColors) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 867 | desc.fColorType = ProgramDesc::kUniform_ColorType; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 868 | } else |
| 869 | #endif |
| 870 | { |
bsalomon@google.com | 6a77cc5 | 2011-04-28 17:33:34 +0000 | [diff] [blame] | 871 | if (requiresAttributeColors) {} // suppress unused var warning |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 872 | desc.fColorType = ProgramDesc::kAttribute_ColorType; |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 873 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 874 | |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 875 | desc.fEdgeAANumEdges = fCurrDrawState.fEdgeAANumEdges; |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 876 | desc.fEdgeAAConcave = desc.fEdgeAANumEdges > 0 && SkToBool(fCurrDrawState.fFlagBits & kEdgeAAConcave_StateBit); |
senorblanco@chromium.org | 92e0f22 | 2011-05-12 15:49:15 +0000 | [diff] [blame] | 877 | |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 878 | int lastEnabledStage = -1; |
| 879 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 880 | if (desc.fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit) { |
| 881 | desc.fVertexEdgeType = fCurrDrawState.fVertexEdgeType; |
| 882 | } else { |
| 883 | // use canonical value when not set to avoid cache misses |
| 884 | desc.fVertexEdgeType = GrDrawTarget::kHairLine_EdgeType; |
| 885 | } |
| 886 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 887 | for (int s = 0; s < kNumStages; ++s) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 888 | StageDesc& stage = desc.fStages[s]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 889 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 890 | stage.fOptFlags = 0; |
| 891 | stage.setEnabled(this->isStageEnabled(s)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 892 | |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 893 | if (stage.isEnabled()) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 894 | lastEnabledStage = s; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 895 | GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s]; |
| 896 | GrAssert(NULL != texture); |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 897 | const GrSamplerState& sampler = fCurrDrawState.fSamplerStates[s]; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 898 | // we matrix to invert when orientation is TopDown, so make sure |
| 899 | // we aren't in that case before flagging as identity. |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 900 | if (TextureMatrixIsIdentity(texture, sampler)) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 901 | stage.fOptFlags |= StageDesc::kIdentityMatrix_OptFlagBit; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 902 | } else if (!getSamplerMatrix(s).hasPerspective()) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 903 | stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 904 | } |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 905 | switch (sampler.getSampleMode()) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 906 | case GrSamplerState::kNormal_SampleMode: |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 907 | stage.fCoordMapping = StageDesc::kIdentity_CoordMapping; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 908 | break; |
| 909 | case GrSamplerState::kRadial_SampleMode: |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 910 | stage.fCoordMapping = StageDesc::kRadialGradient_CoordMapping; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 911 | break; |
| 912 | case GrSamplerState::kRadial2_SampleMode: |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 913 | if (sampler.radial2IsDegenerate()) { |
| 914 | stage.fCoordMapping = |
| 915 | StageDesc::kRadial2GradientDegenerate_CoordMapping; |
| 916 | } else { |
| 917 | stage.fCoordMapping = |
| 918 | StageDesc::kRadial2Gradient_CoordMapping; |
| 919 | } |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 920 | break; |
| 921 | case GrSamplerState::kSweep_SampleMode: |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 922 | stage.fCoordMapping = StageDesc::kSweepGradient_CoordMapping; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 923 | break; |
| 924 | default: |
| 925 | GrCrash("Unexpected sample mode!"); |
| 926 | break; |
| 927 | } |
| 928 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 929 | switch (sampler.getFilter()) { |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 930 | // these both can use a regular texture2D() |
| 931 | case GrSamplerState::kNearest_Filter: |
| 932 | case GrSamplerState::kBilinear_Filter: |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 933 | stage.fFetchMode = StageDesc::kSingle_FetchMode; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 934 | break; |
| 935 | // performs 4 texture2D()s |
| 936 | case GrSamplerState::k4x4Downsample_Filter: |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 937 | stage.fFetchMode = StageDesc::k2x2_FetchMode; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 938 | break; |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 939 | // performs fKernelWidth texture2D()s |
| 940 | case GrSamplerState::kConvolution_Filter: |
| 941 | stage.fFetchMode = StageDesc::kConvolution_FetchMode; |
| 942 | break; |
bsalomon@google.com | 6aef1fb | 2011-05-05 12:33:22 +0000 | [diff] [blame] | 943 | default: |
| 944 | GrCrash("Unexpected filter!"); |
| 945 | break; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 946 | } |
| 947 | |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 948 | if (sampler.hasTextureDomain()) { |
tomhudson@google.com | 0d83172 | 2011-06-02 15:37:14 +0000 | [diff] [blame] | 949 | GrAssert(GrSamplerState::kClamp_WrapMode == |
bsalomon@google.com | 22c5dea | 2011-07-07 14:38:03 +0000 | [diff] [blame] | 950 | sampler.getWrapX() && |
| 951 | GrSamplerState::kClamp_WrapMode == |
| 952 | sampler.getWrapY()); |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 953 | stage.fOptFlags |= StageDesc::kCustomTextureDomain_OptFlagBit; |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 954 | } |
| 955 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 956 | if (GrPixelConfigIsAlphaOnly(texture->config())) { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 957 | stage.fModulation = StageDesc::kAlpha_Modulation; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 958 | } else { |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 959 | stage.fModulation = StageDesc::kColor_Modulation; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 960 | } |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 961 | if (sampler.getFilter() == GrSamplerState::kConvolution_Filter) { |
| 962 | stage.fKernelWidth = sampler.getKernelWidth(); |
| 963 | } else { |
| 964 | stage.fKernelWidth = 0; |
| 965 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 966 | } else { |
| 967 | stage.fOptFlags = 0; |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 968 | stage.fCoordMapping = (StageDesc::CoordMapping)0; |
| 969 | stage.fModulation = (StageDesc::Modulation)0; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 970 | } |
| 971 | } |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 972 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 973 | desc.fDualSrcOutput = ProgramDesc::kNone_DualSrcOutput; |
bsalomon@google.com | edfe1aa | 2011-09-29 14:40:26 +0000 | [diff] [blame] | 974 | |
| 975 | // currently the experimental GS will only work with triangle prims |
| 976 | // (and it doesn't do anything other than pass through values from |
| 977 | // the VS to the FS anyway). |
| 978 | #if 0 && GR_GL_EXPERIMENTAL_GS |
| 979 | desc.fExperimentalGS = this->getCaps().fGeometryShaderSupport; |
| 980 | #endif |
| 981 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 982 | // we want to avoid generating programs with different "first cov stage" |
| 983 | // values when they would compute the same result. |
| 984 | // We set field in the desc to kNumStages when either there are no |
| 985 | // coverage stages or the distinction between coverage and color is |
| 986 | // immaterial. |
| 987 | int firstCoverageStage = kNumStages; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 988 | desc.fFirstCoverageStage = kNumStages; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 989 | bool hasCoverage = fCurrDrawState.fFirstCoverageStage <= lastEnabledStage; |
| 990 | if (hasCoverage) { |
| 991 | firstCoverageStage = fCurrDrawState.fFirstCoverageStage; |
| 992 | } |
| 993 | |
| 994 | // other coverage inputs |
| 995 | if (!hasCoverage) { |
| 996 | hasCoverage = |
| 997 | desc.fEdgeAANumEdges || |
| 998 | (desc.fVertexLayout & GrDrawTarget::kCoverage_VertexLayoutBit) || |
| 999 | (desc.fVertexLayout & GrDrawTarget::kEdge_VertexLayoutBit); |
| 1000 | } |
| 1001 | |
| 1002 | if (hasCoverage) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1003 | // color filter is applied between color/coverage computation |
| 1004 | if (SkXfermode::kDst_Mode != desc.fColorFilterXfermode) { |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1005 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | // We could consider cases where the final color is solid (0xff alpha) |
| 1009 | // and the dst coeff can correctly be set to a non-dualsrc gl value. |
| 1010 | // (e.g. solid draw, and dst coeff is kZero. It's correct to make |
| 1011 | // the dst coeff be kISA. Or solid draw with kSA can be tweaked to be |
| 1012 | // kOne). |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 1013 | if (this->getCaps().fDualSourceBlendingSupport) { |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1014 | if (kZero_BlendCoeff == fCurrDrawState.fDstBlend) { |
| 1015 | // write the coverage value to second color |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1016 | desc.fDualSrcOutput = ProgramDesc::kCoverage_DualSrcOutput; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1017 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1018 | } else if (kSA_BlendCoeff == fCurrDrawState.fDstBlend) { |
| 1019 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially |
| 1020 | // cover |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1021 | desc.fDualSrcOutput = ProgramDesc::kCoverageISA_DualSrcOutput; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1022 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1023 | } else if (kSC_BlendCoeff == fCurrDrawState.fDstBlend) { |
| 1024 | // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially |
| 1025 | // cover |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 1026 | desc.fDualSrcOutput = ProgramDesc::kCoverageISC_DualSrcOutput; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 1027 | desc.fFirstCoverageStage = firstCoverageStage; |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 1028 | } |
| 1029 | } |
| 1030 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1031 | } |