junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 8 | #include "GrGpuGL.h" |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | a469c28 | 2012-10-24 18:28:34 +0000 | [diff] [blame] | 10 | #include "GrEffect.h" |
bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 11 | #include "GrGLEffect.h" |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 12 | |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 13 | typedef GrGLUniformManager::UniformHandle UniformHandle; |
| 14 | static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidUniformHandle; |
| 15 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 16 | #define SKIP_CACHE_CHECK true |
| 17 | #define GR_UINT32_MAX static_cast<uint32_t>(-1) |
| 18 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 19 | GrGpuGL::ProgramCache::ProgramCache(const GrGLContextInfo& gl) |
| 20 | : fCount(0) |
| 21 | , fCurrLRUStamp(0) |
| 22 | , fGL(gl) { |
| 23 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 25 | void GrGpuGL::ProgramCache::abandon() { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 26 | for (int i = 0; i < fCount; ++i) { |
| 27 | GrAssert(NULL != fEntries[i].fProgram.get()); |
| 28 | fEntries[i].fProgram->abandon(); |
| 29 | fEntries[i].fProgram.reset(NULL); |
| 30 | } |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 31 | fCount = 0; |
| 32 | } |
| 33 | |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 34 | GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgram::Desc& desc, |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 35 | const GrEffectStage* stages[]) { |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 36 | Entry newEntry; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 37 | newEntry.fKey.setKeyData(desc.asKey()); |
| 38 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 39 | Entry* entry = fHashCache.find(newEntry.fKey); |
| 40 | if (NULL == entry) { |
bsalomon@google.com | ecb60aa | 2012-07-18 13:20:29 +0000 | [diff] [blame] | 41 | newEntry.fProgram.reset(GrGLProgram::Create(fGL, desc, stages)); |
| 42 | if (NULL == newEntry.fProgram.get()) { |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 43 | return NULL; |
| 44 | } |
| 45 | if (fCount < kMaxEntries) { |
| 46 | entry = fEntries + fCount; |
| 47 | ++fCount; |
| 48 | } else { |
| 49 | GrAssert(kMaxEntries == fCount); |
| 50 | entry = fEntries; |
| 51 | for (int i = 1; i < kMaxEntries; ++i) { |
| 52 | if (fEntries[i].fLRUStamp < entry->fLRUStamp) { |
| 53 | entry = fEntries + i; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 54 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 55 | } |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 56 | fHashCache.remove(entry->fKey, entry); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 57 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 58 | *entry = newEntry; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 59 | fHashCache.insert(entry->fKey, entry); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 60 | } |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 61 | |
| 62 | entry->fLRUStamp = fCurrLRUStamp; |
| 63 | if (GR_UINT32_MAX == fCurrLRUStamp) { |
| 64 | // wrap around! just trash our LRU, one time hit. |
| 65 | for (int i = 0; i < fCount; ++i) { |
| 66 | fEntries[i].fLRUStamp = 0; |
| 67 | } |
| 68 | } |
| 69 | ++fCurrLRUStamp; |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 70 | return entry->fProgram; |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 71 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 72 | |
bsalomon@google.com | 1e257a5 | 2011-07-06 19:52:16 +0000 | [diff] [blame] | 73 | //////////////////////////////////////////////////////////////////////////////// |
| 74 | |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 75 | void GrGpuGL::abandonResources(){ |
| 76 | INHERITED::abandonResources(); |
| 77 | fProgramCache->abandon(); |
| 78 | fHWProgramID = 0; |
| 79 | } |
| 80 | |
| 81 | //////////////////////////////////////////////////////////////////////////////// |
| 82 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 83 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
| 84 | |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 85 | void GrGpuGL::flushPathStencilMatrix() { |
| 86 | const SkMatrix& viewMatrix = this->getDrawState().getViewMatrix(); |
| 87 | const GrRenderTarget* rt = this->getDrawState().getRenderTarget(); |
| 88 | SkISize size; |
| 89 | size.set(rt->width(), rt->height()); |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 90 | const SkMatrix& vm = this->getDrawState().getViewMatrix(); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 91 | |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 92 | if (fHWPathStencilMatrixState.fRenderTargetOrigin != rt->origin() || |
| 93 | fHWPathStencilMatrixState.fViewMatrix.cheapEqualTo(viewMatrix) || |
| 94 | fHWPathStencilMatrixState.fRenderTargetSize!= size) { |
| 95 | // rescale the coords from skia's "device" coords to GL's normalized coords, |
| 96 | // and perform a y-flip if required. |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 97 | SkMatrix m; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 98 | if (kBottomLeft_GrSurfaceOrigin == rt->origin()) { |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 99 | m.setScale(SkIntToScalar(2) / rt->width(), SkIntToScalar(-2) / rt->height()); |
| 100 | m.postTranslate(-SK_Scalar1, SK_Scalar1); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 101 | } else { |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 102 | m.setScale(SkIntToScalar(2) / rt->width(), SkIntToScalar(2) / rt->height()); |
| 103 | m.postTranslate(-SK_Scalar1, -SK_Scalar1); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 104 | } |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 105 | m.preConcat(vm); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 106 | |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 107 | // GL wants a column-major 4x4. |
| 108 | GrGLfloat mv[] = { |
| 109 | // col 0 |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 110 | SkScalarToFloat(m[SkMatrix::kMScaleX]), |
| 111 | SkScalarToFloat(m[SkMatrix::kMSkewY]), |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 112 | 0, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 113 | SkScalarToFloat(m[SkMatrix::kMPersp0]), |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 114 | |
| 115 | // col 1 |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 116 | SkScalarToFloat(m[SkMatrix::kMSkewX]), |
| 117 | SkScalarToFloat(m[SkMatrix::kMScaleY]), |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 118 | 0, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 119 | SkScalarToFloat(m[SkMatrix::kMPersp1]), |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 120 | |
| 121 | // col 2 |
| 122 | 0, 0, 0, 0, |
| 123 | |
| 124 | // col3 |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 125 | SkScalarToFloat(m[SkMatrix::kMTransX]), |
| 126 | SkScalarToFloat(m[SkMatrix::kMTransY]), |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 127 | 0.0f, |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 128 | SkScalarToFloat(m[SkMatrix::kMPersp2]) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 129 | }; |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 130 | GL_CALL(MatrixMode(GR_GL_PROJECTION)); |
| 131 | GL_CALL(LoadMatrixf(mv)); |
| 132 | fHWPathStencilMatrixState.fViewMatrix = vm; |
| 133 | fHWPathStencilMatrixState.fRenderTargetSize = size; |
| 134 | fHWPathStencilMatrixState.fRenderTargetOrigin = rt->origin(); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 135 | } |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 138 | bool GrGpuGL::flushGraphicsState(DrawType type) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 139 | const GrDrawState& drawState = this->getDrawState(); |
| 140 | |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 141 | // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 142 | GrAssert(NULL != drawState.getRenderTarget()); |
| 143 | |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 144 | if (kStencilPath_DrawType == type) { |
| 145 | this->flushPathStencilMatrix(); |
| 146 | } else { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 147 | this->flushMiscFixedFunctionState(); |
bsalomon@google.com | c96cb3a | 2012-06-04 19:31:00 +0000 | [diff] [blame] | 148 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 149 | GrBlendCoeff srcCoeff; |
| 150 | GrBlendCoeff dstCoeff; |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 151 | GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &srcCoeff, &dstCoeff); |
| 152 | if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 153 | return false; |
| 154 | } |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 155 | |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 156 | const GrEffectStage* stages[GrDrawState::kNumStages]; |
| 157 | for (int i = 0; i < GrDrawState::kNumStages; ++i) { |
| 158 | stages[i] = drawState.isStageEnabled(i) ? &drawState.getStage(i) : NULL; |
| 159 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 160 | GrGLProgram::Desc desc; |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 161 | GrGLProgram::BuildDesc(this->getDrawState(), |
| 162 | kDrawPoints_DrawType == type, |
| 163 | blendOpts, |
| 164 | srcCoeff, |
| 165 | dstCoeff, |
| 166 | this, |
| 167 | &desc); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 168 | |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 169 | fCurrentProgram.reset(fProgramCache->getProgram(desc, stages)); |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 170 | if (NULL == fCurrentProgram.get()) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 171 | GrAssert(!"Failed to create program!"); |
| 172 | return false; |
| 173 | } |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 174 | fCurrentProgram.get()->ref(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 175 | |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 176 | GrGLuint programID = fCurrentProgram->programID(); |
| 177 | if (fHWProgramID != programID) { |
| 178 | GL_CALL(UseProgram(programID)); |
| 179 | fHWProgramID = programID; |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 180 | } |
bsalomon@google.com | d2afa6e | 2013-02-13 13:53:29 +0000 | [diff] [blame^] | 181 | |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 182 | fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 183 | this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 184 | |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 185 | GrColor color; |
| 186 | GrColor coverage; |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 187 | if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 188 | color = 0; |
| 189 | coverage = 0; |
bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 190 | } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 191 | color = 0xffffffff; |
| 192 | coverage = drawState.getCoverage(); |
| 193 | } else { |
| 194 | color = drawState.getColor(); |
| 195 | coverage = drawState.getCoverage(); |
| 196 | } |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 197 | fCurrentProgram->setData(this, color, coverage, &fSharedGLProgramState); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 198 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 199 | this->flushStencil(type); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 200 | this->flushScissor(); |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 201 | this->flushAAState(type); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 202 | |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 203 | GrIRect* devRect = NULL; |
| 204 | GrIRect devClipBounds; |
robertphillips@google.com | 3e11c0b | 2012-07-11 18:20:35 +0000 | [diff] [blame] | 205 | if (drawState.isClipState()) { |
bsalomon@google.com | 02ddc8b | 2013-01-28 15:35:28 +0000 | [diff] [blame] | 206 | this->getClip()->getConservativeBounds(drawState.getRenderTarget(), &devClipBounds); |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 207 | devRect = &devClipBounds; |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 208 | } |
| 209 | // This must come after textures are flushed because a texture may need |
| 210 | // to be msaa-resolved (which will modify bound FBO state). |
robertphillips@google.com | 7b11289 | 2012-07-31 15:18:21 +0000 | [diff] [blame] | 211 | this->flushRenderTarget(devRect); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 212 | |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 213 | return true; |
| 214 | } |
| 215 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 216 | void GrGpuGL::setupGeometry(const DrawInfo& info, int* startIndexOffset) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 217 | |
| 218 | int newColorOffset; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 219 | int newCoverageOffset; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 220 | int newTexCoordOffsets[GrDrawState::kMaxTexCoords]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 221 | int newEdgeOffset; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 222 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 223 | GrVertexLayout currLayout = this->getDrawState().getVertexLayout(); |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 224 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 225 | GrGLsizei newStride = GrDrawState::VertexSizeAndOffsetsByIdx(currLayout, |
| 226 | newTexCoordOffsets, |
| 227 | &newColorOffset, |
| 228 | &newCoverageOffset, |
| 229 | &newEdgeOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 230 | int oldColorOffset; |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 231 | int oldCoverageOffset; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 232 | int oldTexCoordOffsets[GrDrawState::kMaxTexCoords]; |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 233 | int oldEdgeOffset; |
| 234 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 235 | GrGLsizei oldStride = GrDrawState::VertexSizeAndOffsetsByIdx(fHWGeometryState.fVertexLayout, |
| 236 | oldTexCoordOffsets, |
| 237 | &oldColorOffset, |
| 238 | &oldCoverageOffset, |
| 239 | &oldEdgeOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 240 | |
| 241 | int extraVertexOffset; |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 242 | this->setBuffers(info.isIndexed(), &extraVertexOffset, startIndexOffset); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 243 | |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 244 | size_t vertexOffset = (info.startVertex() + extraVertexOffset) * newStride; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 245 | |
| 246 | // all the Pointers must be set if any of these are true |
| 247 | bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty || |
| 248 | vertexOffset != fHWGeometryState.fVertexOffset || |
| 249 | newStride != oldStride; |
| 250 | |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 251 | if (allOffsetsChange) { |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 252 | int idx = GrGLProgram::PositionAttributeIdx(); |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 253 | GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, (GrGLvoid*)vertexOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 254 | fHWGeometryState.fVertexOffset = vertexOffset; |
| 255 | } |
| 256 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 257 | for (int t = 0; t < GrDrawState::kMaxTexCoords; ++t) { |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 258 | if (newTexCoordOffsets[t] > 0) { |
| 259 | GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[t]); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 260 | int idx = GrGLProgram::TexCoordAttributeIdx(t); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 261 | if (oldTexCoordOffsets[t] <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 262 | GL_CALL(EnableVertexAttribArray(idx)); |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 263 | GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset)); |
| 264 | } else if (allOffsetsChange || newTexCoordOffsets[t] != oldTexCoordOffsets[t]) { |
| 265 | GL_CALL(VertexAttribPointer(idx, 2, GR_GL_FLOAT, false, newStride, texCoordOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 266 | } |
| 267 | } else if (oldTexCoordOffsets[t] > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 268 | GL_CALL(DisableVertexAttribArray(GrGLProgram::TexCoordAttributeIdx(t))); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | |
| 272 | if (newColorOffset > 0) { |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 273 | fSharedGLProgramState.fConstAttribColor = GrColor_ILLEGAL; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 274 | GrGLvoid* colorOffset = (int8_t*)(vertexOffset + newColorOffset); |
bsalomon@google.com | 9196130 | 2011-05-09 18:39:58 +0000 | [diff] [blame] | 275 | int idx = GrGLProgram::ColorAttributeIdx(); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 276 | if (oldColorOffset <= 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 277 | GL_CALL(EnableVertexAttribArray(idx)); |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 278 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, true, newStride, colorOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 279 | } else if (allOffsetsChange || newColorOffset != oldColorOffset) { |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 280 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, true, newStride, colorOffset)); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 281 | } |
| 282 | } else if (oldColorOffset > 0) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 283 | GL_CALL(DisableVertexAttribArray(GrGLProgram::ColorAttributeIdx())); |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 284 | } |
| 285 | |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 286 | if (newCoverageOffset > 0) { |
bsalomon@google.com | 9120748 | 2013-02-12 21:45:24 +0000 | [diff] [blame] | 287 | fSharedGLProgramState.fConstAttribColor = GrColor_ILLEGAL; |
bsalomon@google.com | e10f6fd | 2011-10-11 20:15:26 +0000 | [diff] [blame] | 288 | GrGLvoid* coverageOffset = (int8_t*)(vertexOffset + newCoverageOffset); |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 289 | int idx = GrGLProgram::CoverageAttributeIdx(); |
| 290 | if (oldCoverageOffset <= 0) { |
| 291 | GL_CALL(EnableVertexAttribArray(idx)); |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 292 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 293 | true, newStride, coverageOffset)); |
| 294 | } else if (allOffsetsChange || newCoverageOffset != oldCoverageOffset) { |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 295 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_UNSIGNED_BYTE, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 296 | true, newStride, coverageOffset)); |
| 297 | } |
| 298 | } else if (oldCoverageOffset > 0) { |
| 299 | GL_CALL(DisableVertexAttribArray(GrGLProgram::CoverageAttributeIdx())); |
| 300 | } |
| 301 | |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 302 | if (newEdgeOffset > 0) { |
| 303 | GrGLvoid* edgeOffset = (int8_t*)(vertexOffset + newEdgeOffset); |
| 304 | int idx = GrGLProgram::EdgeAttributeIdx(); |
| 305 | if (oldEdgeOffset <= 0) { |
| 306 | GL_CALL(EnableVertexAttribArray(idx)); |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 307 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_FLOAT, false, newStride, edgeOffset)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 308 | } else if (allOffsetsChange || newEdgeOffset != oldEdgeOffset) { |
bsalomon@google.com | 8598328 | 2013-02-07 22:00:29 +0000 | [diff] [blame] | 309 | GL_CALL(VertexAttribPointer(idx, 4, GR_GL_FLOAT, false, newStride, edgeOffset)); |
bsalomon@google.com | aeb2160 | 2011-08-30 18:13:44 +0000 | [diff] [blame] | 310 | } |
| 311 | } else if (oldEdgeOffset > 0) { |
| 312 | GL_CALL(DisableVertexAttribArray(GrGLProgram::EdgeAttributeIdx())); |
| 313 | } |
| 314 | |
bsalomon@google.com | e79c815 | 2012-03-29 19:07:12 +0000 | [diff] [blame] | 315 | fHWGeometryState.fVertexLayout = currLayout; |
junov@google.com | f93e717 | 2011-03-31 21:26:24 +0000 | [diff] [blame] | 316 | fHWGeometryState.fArrayPtrsDirty = false; |
| 317 | } |