blob: a3beab1a5999bfbaeed0dca446edd189cbda976f [file] [log] [blame]
junov@google.comf93e7172011-03-31 21:26:24 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.comf93e7172011-03-31 21:26:24 +00006 */
7
bsalomon@google.com5739d2c2012-05-31 15:07:19 +00008#include "GrGpuGL.h"
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
bsalomon@google.coma469c282012-10-24 18:28:34 +000010#include "GrEffect.h"
bsalomon@google.comd698f772012-10-25 13:22:00 +000011#include "GrGLEffect.h"
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000012#include "SkRTConf.h"
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000013#include "SkTSearch.h"
junov@google.comf93e7172011-03-31 21:26:24 +000014
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000015#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000016SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false,
17 "Display program cache usage.");
jvanverth@google.coma2f4b152013-09-16 20:00:46 +000018#endif
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000019
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000020typedef GrGLUniformManager::UniformHandle UniformHandle;
bsalomon@google.comdbbc4e22012-07-25 17:48:39 +000021
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000022struct GrGpuGL::ProgramCache::Entry {
23 SK_DECLARE_INST_COUNT_ROOT(Entry);
24 Entry() : fProgram(NULL), fLRUStamp(0) {}
25
26 SkAutoTUnref<GrGLProgram> fProgram;
27 unsigned int fLRUStamp;
28};
29
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000030struct GrGpuGL::ProgramCache::ProgDescLess {
31 bool operator() (const GrGLProgramDesc& desc, const Entry* entry) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000032 SkASSERT(NULL != entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000033 return GrGLProgramDesc::Less(desc, entry->fProgram->getDesc());
34 }
35
36 bool operator() (const Entry* entry, const GrGLProgramDesc& desc) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000037 SkASSERT(NULL != entry->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000038 return GrGLProgramDesc::Less(entry->fProgram->getDesc(), desc);
39 }
40};
junov@google.comf93e7172011-03-31 21:26:24 +000041
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000042GrGpuGL::ProgramCache::ProgramCache(GrGpuGL* gpu)
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000043 : fCount(0)
44 , fCurrLRUStamp(0)
commit-bot@chromium.org9188a152013-09-05 18:28:24 +000045 , fGpu(gpu)
jvanverth@google.com94878772013-03-12 16:00:54 +000046#ifdef PROGRAM_CACHE_STATS
47 , fTotalRequests(0)
48 , fCacheMisses(0)
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000049 , fHashMisses(0)
jvanverth@google.com94878772013-03-12 16:00:54 +000050#endif
51{
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000052 for (int i = 0; i < 1 << kHashBits; ++i) {
53 fHashTable[i] = NULL;
54 }
jvanverth@google.com94878772013-03-12 16:00:54 +000055}
56
57GrGpuGL::ProgramCache::~ProgramCache() {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000058 for (int i = 0; i < fCount; ++i){
59 SkDELETE(fEntries[i]);
60 }
jvanverth@google.com94878772013-03-12 16:00:54 +000061 // dump stats
62#ifdef PROGRAM_CACHE_STATS
jvanverth@google.com5c9b6fa2013-09-16 19:40:31 +000063 if (c_DisplayCache) {
64 SkDebugf("--- Program Cache ---\n");
65 SkDebugf("Total requests: %d\n", fTotalRequests);
66 SkDebugf("Cache misses: %d\n", fCacheMisses);
67 SkDebugf("Cache miss %%: %f\n", (fTotalRequests > 0) ?
68 100.f * fCacheMisses / fTotalRequests :
69 0.f);
70 int cacheHits = fTotalRequests - fCacheMisses;
71 SkDebugf("Hash miss %%: %f\n", (cacheHits > 0) ? 100.f * fHashMisses / cacheHits : 0.f);
72 SkDebugf("---------------------\n");
73 }
jvanverth@google.com94878772013-03-12 16:00:54 +000074#endif
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000075}
junov@google.comf93e7172011-03-31 21:26:24 +000076
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000077void GrGpuGL::ProgramCache::abandon() {
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000078 for (int i = 0; i < fCount; ++i) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000079 SkASSERT(NULL != fEntries[i]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000080 fEntries[i]->fProgram->abandon();
81 fEntries[i]->fProgram.reset(NULL);
bsalomon@google.comecb60aa2012-07-18 13:20:29 +000082 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +000083 fCount = 0;
84}
85
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000086int GrGpuGL::ProgramCache::search(const GrGLProgramDesc& desc) const {
87 ProgDescLess less;
88 return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less);
89}
90
bsalomon@google.com31ec7982013-03-27 18:14:57 +000091GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrGLProgramDesc& desc,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +000092 const GrEffectStage* colorStages[],
93 const GrEffectStage* coverageStages[]) {
jvanverth@google.com94878772013-03-12 16:00:54 +000094#ifdef PROGRAM_CACHE_STATS
95 ++fTotalRequests;
96#endif
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +000097
bsalomon@google.com2db3ded2013-05-22 14:34:04 +000098 Entry* entry = NULL;
99
100 uint32_t hashIdx = desc.getChecksum();
101 hashIdx ^= hashIdx >> 16;
102 if (kHashBits <= 8) {
103 hashIdx ^= hashIdx >> 8;
104 }
105 hashIdx &=((1 << kHashBits) - 1);
106 Entry* hashedEntry = fHashTable[hashIdx];
107 if (NULL != hashedEntry && hashedEntry->fProgram->getDesc() == desc) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000108 SkASSERT(NULL != hashedEntry->fProgram);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000109 entry = hashedEntry;
110 }
111
112 int entryIdx;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000113 if (NULL == entry) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000114 entryIdx = this->search(desc);
115 if (entryIdx >= 0) {
116 entry = fEntries[entryIdx];
117#ifdef PROGRAM_CACHE_STATS
118 ++fHashMisses;
119#endif
120 }
121 }
122
123 if (NULL == entry) {
124 // We have a cache miss
jvanverth@google.com94878772013-03-12 16:00:54 +0000125#ifdef PROGRAM_CACHE_STATS
126 ++fCacheMisses;
127#endif
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000128 GrGLProgram* program = GrGLProgram::Create(fGpu, desc, colorStages, coverageStages);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000129 if (NULL == program) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000130 return NULL;
131 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000132 int purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000133 if (fCount < kMaxEntries) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000134 entry = SkNEW(Entry);
135 purgeIdx = fCount++;
136 fEntries[purgeIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000137 } else {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000138 SkASSERT(fCount == kMaxEntries);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000139 purgeIdx = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000140 for (int i = 1; i < kMaxEntries; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000141 if (fEntries[i]->fLRUStamp < fEntries[purgeIdx]->fLRUStamp) {
142 purgeIdx = i;
junov@google.comf93e7172011-03-31 21:26:24 +0000143 }
junov@google.comf93e7172011-03-31 21:26:24 +0000144 }
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000145 entry = fEntries[purgeIdx];
146 int purgedHashIdx = entry->fProgram->getDesc().getChecksum() & ((1 << kHashBits) - 1);
147 if (fHashTable[purgedHashIdx] == entry) {
148 fHashTable[purgedHashIdx] = NULL;
149 }
junov@google.comf93e7172011-03-31 21:26:24 +0000150 }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000151 SkASSERT(fEntries[purgeIdx] == entry);
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000152 entry->fProgram.reset(program);
skia.committer@gmail.com2d816ad2013-05-23 07:01:22 +0000153 // We need to shift fEntries around so that the entry currently at purgeIdx is placed
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000154 // just before the entry at ~entryIdx (in order to keep fEntries sorted by descriptor).
155 entryIdx = ~entryIdx;
156 if (entryIdx < purgeIdx) {
157 // Let E and P be the entries at index entryIdx and purgeIdx, respectively.
158 // If the entries array looks like this:
159 // aaaaEbbbbbPccccc
160 // we rearrange it to look like this:
161 // aaaaPEbbbbbccccc
162 size_t copySize = (purgeIdx - entryIdx) * sizeof(Entry*);
163 memmove(fEntries + entryIdx + 1, fEntries + entryIdx, copySize);
164 fEntries[entryIdx] = entry;
165 } else if (purgeIdx < entryIdx) {
166 // If the entries array looks like this:
167 // aaaaPbbbbbEccccc
168 // we rearrange it to look like this:
169 // aaaabbbbbPEccccc
170 size_t copySize = (entryIdx - purgeIdx - 1) * sizeof(Entry*);
171 memmove(fEntries + purgeIdx, fEntries + purgeIdx + 1, copySize);
172 fEntries[entryIdx - 1] = entry;
173 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000174#ifdef SK_DEBUG
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000175 SkASSERT(NULL != fEntries[0]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000176 for (int i = 0; i < fCount - 1; ++i) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000177 SkASSERT(NULL != fEntries[i + 1]->fProgram.get());
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000178 const GrGLProgramDesc& a = fEntries[i]->fProgram->getDesc();
179 const GrGLProgramDesc& b = fEntries[i + 1]->fProgram->getDesc();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000180 SkASSERT(GrGLProgramDesc::Less(a, b));
181 SkASSERT(!GrGLProgramDesc::Less(b, a));
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000182 }
183#endif
junov@google.comf93e7172011-03-31 21:26:24 +0000184 }
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000185
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000186 fHashTable[hashIdx] = entry;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000187 entry->fLRUStamp = fCurrLRUStamp;
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000188
189 if (SK_MaxU32 == fCurrLRUStamp) {
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000190 // wrap around! just trash our LRU, one time hit.
191 for (int i = 0; i < fCount; ++i) {
bsalomon@google.com2db3ded2013-05-22 14:34:04 +0000192 fEntries[i]->fLRUStamp = 0;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000193 }
194 }
195 ++fCurrLRUStamp;
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000196 return entry->fProgram;
bsalomon@google.comc1d2a582012-06-01 15:08:19 +0000197}
junov@google.comf93e7172011-03-31 21:26:24 +0000198
bsalomon@google.com1e257a52011-07-06 19:52:16 +0000199////////////////////////////////////////////////////////////////////////////////
200
bsalomon@google.com5739d2c2012-05-31 15:07:19 +0000201void GrGpuGL::abandonResources(){
202 INHERITED::abandonResources();
203 fProgramCache->abandon();
204 fHWProgramID = 0;
205}
206
207////////////////////////////////////////////////////////////////////////////////
208
bsalomon@google.com0b77d682011-08-19 13:28:54 +0000209#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
210
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000211bool GrGpuGL::flushGraphicsState(DrawType type, const GrDeviceCoordTexture* dstCopy) {
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000212 const GrDrawState& drawState = this->getDrawState();
213
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000214 // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000215 SkASSERT(NULL != drawState.getRenderTarget());
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000216
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000217 if (kStencilPath_DrawType == type) {
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000218 const GrRenderTarget* rt = this->getDrawState().getRenderTarget();
219 SkISize size;
220 size.set(rt->width(), rt->height());
221 this->setProjectionMatrix(drawState.getViewMatrix(), size, rt->origin());
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000222 } else {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000223 this->flushMiscFixedFunctionState();
bsalomon@google.comc96cb3a2012-06-04 19:31:00 +0000224
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000225 GrBlendCoeff srcCoeff;
226 GrBlendCoeff dstCoeff;
bsalomon@google.com2b446732013-02-12 16:47:41 +0000227 GrDrawState::BlendOptFlags blendOpts = drawState.getBlendOpts(false, &srcCoeff, &dstCoeff);
228 if (GrDrawState::kSkipDraw_BlendOptFlag & blendOpts) {
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000229 return false;
230 }
bsalomon@google.com86c1f712011-10-12 14:54:26 +0000231
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000232 SkSTArray<8, const GrEffectStage*, true> colorStages;
233 SkSTArray<8, const GrEffectStage*, true> coverageStages;
bsalomon@google.com31ec7982013-03-27 18:14:57 +0000234 GrGLProgramDesc desc;
235 GrGLProgramDesc::Build(this->getDrawState(),
bsalomon@google.com91207482013-02-12 21:45:24 +0000236 kDrawPoints_DrawType == type,
237 blendOpts,
238 srcCoeff,
239 dstCoeff,
240 this,
bsalomon@google.com26e18b52013-03-29 19:22:36 +0000241 dstCopy,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000242 &colorStages,
243 &coverageStages,
bsalomon@google.com91207482013-02-12 21:45:24 +0000244 &desc);
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000245
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000246 fCurrentProgram.reset(fProgramCache->getProgram(desc,
247 colorStages.begin(),
248 coverageStages.begin()));
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000249 if (NULL == fCurrentProgram.get()) {
mtklein@google.com330313a2013-08-22 15:37:26 +0000250 SkDEBUGFAIL("Failed to create program!");
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000251 return false;
252 }
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000253
commit-bot@chromium.org32184d82013-10-09 15:14:18 +0000254 SkASSERT(kDrawPath_DrawType != type || !fCurrentProgram->hasVertexShader());
commit-bot@chromium.orgc4dc0ad2013-10-09 14:11:33 +0000255
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000256 fCurrentProgram.get()->ref();
junov@google.comf93e7172011-03-31 21:26:24 +0000257
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000258 GrGLuint programID = fCurrentProgram->programID();
259 if (fHWProgramID != programID) {
260 GL_CALL(UseProgram(programID));
261 fHWProgramID = programID;
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000262 }
bsalomon@google.com6a51dcb2013-02-13 16:03:51 +0000263
bsalomon@google.com9ba4fa62012-07-16 17:36:28 +0000264 fCurrentProgram->overrideBlend(&srcCoeff, &dstCoeff);
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000265 this->flushBlend(kDrawLines_DrawType == type, srcCoeff, dstCoeff);
junov@google.comf93e7172011-03-31 21:26:24 +0000266
commit-bot@chromium.org9188a152013-09-05 18:28:24 +0000267 fCurrentProgram->setData(blendOpts,
bsalomon@google.com2c84aa32013-06-06 20:28:57 +0000268 colorStages.begin(),
269 coverageStages.begin(),
270 dstCopy,
271 &fSharedGLProgramState);
junov@google.comf93e7172011-03-31 21:26:24 +0000272 }
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000273 this->flushStencil(type);
bsalomon@google.coma3201942012-06-21 19:58:20 +0000274 this->flushScissor();
bsalomon@google.comded4f4b2012-06-28 18:48:06 +0000275 this->flushAAState(type);
bsalomon@google.com4c883782012-06-04 19:05:11 +0000276
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000277 SkIRect* devRect = NULL;
278 SkIRect devClipBounds;
robertphillips@google.com3e11c0b2012-07-11 18:20:35 +0000279 if (drawState.isClipState()) {
bsalomon@google.com02ddc8b2013-01-28 15:35:28 +0000280 this->getClip()->getConservativeBounds(drawState.getRenderTarget(), &devClipBounds);
robertphillips@google.com7b112892012-07-31 15:18:21 +0000281 devRect = &devClipBounds;
bsalomon@google.com4c883782012-06-04 19:05:11 +0000282 }
283 // This must come after textures are flushed because a texture may need
284 // to be msaa-resolved (which will modify bound FBO state).
robertphillips@google.com7b112892012-07-31 15:18:21 +0000285 this->flushRenderTarget(devRect);
bsalomon@google.com4c883782012-06-04 19:05:11 +0000286
junov@google.comf93e7172011-03-31 21:26:24 +0000287 return true;
288}
289
bsalomon@google.com880b8fc2013-02-19 20:17:28 +0000290void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
junov@google.comf93e7172011-03-31 21:26:24 +0000291
robertphillips@google.coma4662862013-11-21 14:24:16 +0000292 GrGLsizei stride = static_cast<GrGLsizei>(this->getDrawState().getVertexSize());
bsalomon@google.comaeb21602011-08-30 18:13:44 +0000293
bsalomon@google.com6918d482013-03-07 19:09:11 +0000294 size_t vertexOffsetInBytes = stride * info.startVertex();
295
296 const GeometryPoolState& geoPoolState = this->getGeomPoolState();
297
298 GrGLVertexBuffer* vbuf;
299 switch (this->getGeomSrc().fVertexSrc) {
300 case kBuffer_GeometrySrcType:
301 vbuf = (GrGLVertexBuffer*) this->getGeomSrc().fVertexBuffer;
302 break;
303 case kArray_GeometrySrcType:
304 case kReserved_GeometrySrcType:
305 this->finalizeReservedVertices();
306 vertexOffsetInBytes += geoPoolState.fPoolStartVertex * this->getGeomSrc().fVertexSize;
307 vbuf = (GrGLVertexBuffer*) geoPoolState.fPoolVertexBuffer;
308 break;
309 default:
310 vbuf = NULL; // suppress warning
311 GrCrash("Unknown geometry src type!");
312 }
313
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000314 SkASSERT(NULL != vbuf);
315 SkASSERT(!vbuf->isLocked());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000316 vertexOffsetInBytes += vbuf->baseOffset();
317
318 GrGLIndexBuffer* ibuf = NULL;
319 if (info.isIndexed()) {
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000320 SkASSERT(NULL != indexOffsetInBytes);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000321
322 switch (this->getGeomSrc().fIndexSrc) {
323 case kBuffer_GeometrySrcType:
324 *indexOffsetInBytes = 0;
325 ibuf = (GrGLIndexBuffer*)this->getGeomSrc().fIndexBuffer;
326 break;
327 case kArray_GeometrySrcType:
328 case kReserved_GeometrySrcType:
329 this->finalizeReservedIndices();
330 *indexOffsetInBytes = geoPoolState.fPoolStartIndex * sizeof(GrGLushort);
331 ibuf = (GrGLIndexBuffer*) geoPoolState.fPoolIndexBuffer;
332 break;
333 default:
334 ibuf = NULL; // suppress warning
335 GrCrash("Unknown geometry src type!");
336 }
337
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000338 SkASSERT(NULL != ibuf);
339 SkASSERT(!ibuf->isLocked());
bsalomon@google.com6918d482013-03-07 19:09:11 +0000340 *indexOffsetInBytes += ibuf->baseOffset();
341 }
342 GrGLAttribArrayState* attribState =
343 fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
junov@google.comf93e7172011-03-31 21:26:24 +0000344
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000345 if (!fCurrentProgram->hasVertexShader()) {
346 int posIdx = this->getDrawState().positionAttributeIndex();
347 const GrVertexAttrib* vertexArray = this->getDrawState().getVertexAttribs() + posIdx;
348 GrVertexAttribType vertexArrayType = vertexArray->fType;
349 SkASSERT(!GrGLAttribTypeToLayout(vertexArrayType).fNormalized);
350 SkASSERT(GrGLAttribTypeToLayout(vertexArrayType).fCount == 2);
351 attribState->setFixedFunctionVertexArray(this,
352 vbuf,
353 2,
354 GrGLAttribTypeToLayout(vertexArrayType).fType,
355 stride,
356 reinterpret_cast<GrGLvoid*>(
357 vertexOffsetInBytes + vertexArray->fOffset));
358 attribState->disableUnusedArrays(this, 0, true);
359 } else {
360 uint32_t usedAttribArraysMask = 0;
361 const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs();
362 int vertexAttribCount = this->getDrawState().getVertexAttribCount();
363 for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
364 ++vertexAttribIndex, ++vertexAttrib) {
robertphillips@google.comaf3a3b92013-02-28 23:08:28 +0000365
commit-bot@chromium.org6b30e452013-10-04 20:02:53 +0000366 usedAttribArraysMask |= (1 << vertexAttribIndex);
367 GrVertexAttribType attribType = vertexAttrib->fType;
368 attribState->set(this,
369 vertexAttribIndex,
370 vbuf,
371 GrGLAttribTypeToLayout(attribType).fCount,
372 GrGLAttribTypeToLayout(attribType).fType,
373 GrGLAttribTypeToLayout(attribType).fNormalized,
374 stride,
375 reinterpret_cast<GrGLvoid*>(
376 vertexOffsetInBytes + vertexAttrib->fOffset));
377 }
378
379 attribState->disableUnusedArrays(this, usedAttribArraysMask, false);
bsalomon@google.com6918d482013-03-07 19:09:11 +0000380 }
junov@google.comf93e7172011-03-31 21:26:24 +0000381}