OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1297 } | 1297 } |
1298 GL_CALL(DeleteTextures(1, &colorID)); | 1298 GL_CALL(DeleteTextures(1, &colorID)); |
1299 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); | 1299 GL_CALL(DeleteRenderbuffers(1, &sbRBID)); |
1300 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); | 1300 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, 0)); |
1301 GL_CALL(DeleteFramebuffers(1, &fb)); | 1301 GL_CALL(DeleteFramebuffers(1, &fb)); |
1302 } | 1302 } |
1303 SkASSERT(kUnknownStencilIndex != fPixelConfigToStencilIndex[config]); | 1303 SkASSERT(kUnknownStencilIndex != fPixelConfigToStencilIndex[config]); |
1304 return fPixelConfigToStencilIndex[config]; | 1304 return fPixelConfigToStencilIndex[config]; |
1305 } | 1305 } |
1306 | 1306 |
1307 bool GrGLGpu::createStencilAttachmentForRenderTarget(GrRenderTarget* rt, int wid th, int height) { | 1307 GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(const GrRen derTarget* rt, |
1308 int width, | |
1309 int height) { | |
1308 // All internally created RTs are also textures. We don't create | 1310 // All internally created RTs are also textures. We don't create |
1309 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . | 1311 // SBs for a client's standalone RT (that is a RT that isn't also a texture) . |
1310 SkASSERT(rt->asTexture()); | 1312 SkASSERT(rt->asTexture()); |
1311 SkASSERT(width >= rt->width()); | 1313 SkASSERT(width >= rt->width()); |
1312 SkASSERT(height >= rt->height()); | 1314 SkASSERT(height >= rt->height()); |
1313 | 1315 |
1314 int samples = rt->numStencilSamples(); | 1316 int samples = rt->numStencilSamples(); |
1315 GrGLStencilAttachment::IDDesc sbDesc; | 1317 GrGLStencilAttachment::IDDesc sbDesc; |
1316 | 1318 |
1317 int sIdx = this->getCompatibleStencilIndex(rt->config()); | 1319 int sIdx = this->getCompatibleStencilIndex(rt->config()); |
1318 if (sIdx == kUnsupportedStencilIndex) { | 1320 if (sIdx == kUnsupportedStencilIndex) { |
1319 return false; | 1321 return nullptr; |
1320 } | 1322 } |
1321 | 1323 |
1322 if (!sbDesc.fRenderbufferID) { | 1324 if (!sbDesc.fRenderbufferID) { |
1323 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID)); | 1325 GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID)); |
1324 } | 1326 } |
1325 if (!sbDesc.fRenderbufferID) { | 1327 if (!sbDesc.fRenderbufferID) { |
1326 return false; | 1328 return nullptr; |
1327 } | 1329 } |
1328 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); | 1330 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); |
1329 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sIdx]; | 1331 const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sIdx]; |
1330 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); | 1332 CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
1331 // we do this "if" so that we don't call the multisample | 1333 // we do this "if" so that we don't call the multisample |
1332 // version on a GL that doesn't have an MSAA extension. | 1334 // version on a GL that doesn't have an MSAA extension. |
1333 if (samples > 0) { | 1335 if (samples > 0) { |
1334 SkAssertResult(renderbuffer_storage_msaa(*fGLContext, | 1336 SkAssertResult(renderbuffer_storage_msaa(*fGLContext, |
1335 samples, | 1337 samples, |
1336 sFmt.fInternalFormat, | 1338 sFmt.fInternalFormat, |
1337 width, height)); | 1339 width, height)); |
1338 } else { | 1340 } else { |
1339 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFE R, | 1341 GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFE R, |
1340 sFmt.fInternalFor mat, | 1342 sFmt.fInternalFor mat, |
1341 width, height)); | 1343 width, height)); |
1342 SkASSERT(GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterfa ce())); | 1344 SkASSERT(GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterfa ce())); |
1343 } | 1345 } |
1344 fStats.incStencilAttachmentCreates(); | 1346 fStats.incStencilAttachmentCreates(); |
1345 // After sized formats we attempt an unsized format and take | 1347 // After sized formats we attempt an unsized format and take |
1346 // whatever sizes GL gives us. In that case we query for the size. | 1348 // whatever sizes GL gives us. In that case we query for the size. |
1347 GrGLStencilAttachment::Format format = sFmt; | 1349 GrGLStencilAttachment::Format format = sFmt; |
1348 get_stencil_rb_sizes(this->glInterface(), &format); | 1350 get_stencil_rb_sizes(this->glInterface(), &format); |
1349 SkAutoTUnref<GrGLStencilAttachment> sb( | 1351 GrGLStencilAttachment* stencil = new GrGLStencilAttachment(this, |
1350 new GrGLStencilAttachment(this, sbDesc, width, height, samples, format)) ; | 1352 sbDesc, |
1351 SkAssertResult(this->attachStencilAttachmentToRenderTarget(sb, rt)); | 1353 width, |
1352 rt->renderTargetPriv().didAttachStencilAttachment(sb); | 1354 height, |
1353 // This work around is currently breaking on windows 7 hd2000 bot when we bi nd a color buffer | 1355 samples, |
1354 #if 0 | 1356 format); |
egdaniel
2015/09/11 17:59:49
I removed this workaround code here. Happy to but
bsalomon
2015/09/14 19:35:10
I think it is ok to delete for now.
| |
1355 // Clear the stencil buffer. We use a special purpose FBO for this so that t he | 1357 return stencil; |
1356 // entire stencil buffer is cleared, even if it is attached to an FBO with a | |
1357 // smaller color target. | |
1358 if (0 == fStencilClearFBOID) { | |
1359 GL_CALL(GenFramebuffers(1, &fStencilClearFBOID)); | |
1360 } | |
1361 | |
1362 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID)); | |
1363 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | |
1364 fStats.incRenderTargetBinds(); | |
1365 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1366 GR_GL_STENCIL_ATTACHMENT, | |
1367 GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)) ; | |
1368 if (sFmt.fPacked) { | |
1369 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1370 GR_GL_DEPTH_ATTACHMENT, | |
1371 GR_GL_RENDERBUFFER, sbDesc.fRenderbuffer ID)); | |
1372 } | |
1373 | |
1374 GL_CALL(ClearStencil(0)); | |
1375 // Many GL implementations seem to have trouble with clearing an FBO with on ly | |
1376 // a stencil buffer. | |
1377 GrGLuint tempRB; | |
1378 GL_CALL(GenRenderbuffers(1, &tempRB)); | |
1379 GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, tempRB)); | |
1380 if (samples > 0) { | |
1381 renderbuffer_storage_msaa(fGLContext, samples, GR_GL_RGBA8, width, heigh t); | |
1382 } else { | |
1383 GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, heig ht)); | |
1384 } | |
1385 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1386 GR_GL_COLOR_ATTACHMENT0, | |
1387 GR_GL_RENDERBUFFER, tempRB)); | |
1388 | |
1389 GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); | |
1390 | |
1391 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1392 GR_GL_COLOR_ATTACHMENT0, | |
1393 GR_GL_RENDERBUFFER, 0)); | |
1394 GL_CALL(DeleteRenderbuffers(1, &tempRB)); | |
1395 | |
1396 // Unbind the SB from the FBO so that we don't keep it alive. | |
1397 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1398 GR_GL_STENCIL_ATTACHMENT, | |
1399 GR_GL_RENDERBUFFER, 0)); | |
1400 if (sFmt.fPacked) { | |
1401 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1402 GR_GL_DEPTH_ATTACHMENT, | |
1403 GR_GL_RENDERBUFFER, 0)); | |
1404 } | |
1405 #endif | |
1406 return true; | |
1407 } | |
1408 | |
1409 bool GrGLGpu::attachStencilAttachmentToRenderTarget(GrStencilAttachment* sb, GrR enderTarget* rt) { | |
1410 GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); | |
1411 | |
1412 GrGLuint fbo = glrt->renderFBOID(); | |
1413 | |
1414 if (nullptr == sb) { | |
1415 if (rt->renderTargetPriv().getStencilAttachment()) { | |
1416 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1417 GR_GL_STENCIL_ATTACHMENT, | |
1418 GR_GL_RENDERBUFFER, 0)); | |
1419 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1420 GR_GL_DEPTH_ATTACHMENT, | |
1421 GR_GL_RENDERBUFFER, 0)); | |
1422 #ifdef SK_DEBUG | |
1423 GrGLenum status; | |
1424 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | |
1425 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | |
1426 #endif | |
1427 } | |
1428 return true; | |
1429 } else { | |
1430 GrGLStencilAttachment* glsb = static_cast<GrGLStencilAttachment*>(sb); | |
1431 GrGLuint rb = glsb->renderbufferID(); | |
1432 | |
1433 fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; | |
1434 fStats.incRenderTargetBinds(); | |
1435 GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); | |
1436 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1437 GR_GL_STENCIL_ATTACHMENT, | |
1438 GR_GL_RENDERBUFFER, rb)); | |
1439 if (glsb->format().fPacked) { | |
1440 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1441 GR_GL_DEPTH_ATTACHMENT, | |
1442 GR_GL_RENDERBUFFER, rb)); | |
1443 } else { | |
1444 GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | |
1445 GR_GL_DEPTH_ATTACHMENT, | |
1446 GR_GL_RENDERBUFFER, 0)); | |
1447 } | |
1448 | |
1449 #ifdef SK_DEBUG | |
1450 GrGLenum status; | |
1451 GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); | |
1452 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); | |
1453 #endif | |
1454 return true; | |
1455 } | |
1456 } | 1358 } |
1457 | 1359 |
1458 //////////////////////////////////////////////////////////////////////////////// | 1360 //////////////////////////////////////////////////////////////////////////////// |
1459 | 1361 |
1460 GrVertexBuffer* GrGLGpu::onCreateVertexBuffer(size_t size, bool dynamic) { | 1362 GrVertexBuffer* GrGLGpu::onCreateVertexBuffer(size_t size, bool dynamic) { |
1461 GrGLVertexBuffer::Desc desc; | 1363 GrGLVertexBuffer::Desc desc; |
1462 desc.fDynamic = dynamic; | 1364 desc.fDynamic = dynamic; |
1463 desc.fSizeInBytes = size; | 1365 desc.fSizeInBytes = size; |
1464 | 1366 |
1465 if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { | 1367 if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3272 this->setVertexArrayID(gpu, 0); | 3174 this->setVertexArrayID(gpu, 0); |
3273 } | 3175 } |
3274 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3176 int attrCount = gpu->glCaps().maxVertexAttributes(); |
3275 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3177 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
3276 fDefaultVertexArrayAttribState.resize(attrCount); | 3178 fDefaultVertexArrayAttribState.resize(attrCount); |
3277 } | 3179 } |
3278 attribState = &fDefaultVertexArrayAttribState; | 3180 attribState = &fDefaultVertexArrayAttribState; |
3279 } | 3181 } |
3280 return attribState; | 3182 return attribState; |
3281 } | 3183 } |
OLD | NEW |