Showing the changes to interface/src/renderer/Model.cpp (1 of 12 files). Show all
Unified · Split
| @@ -1484,8 +1484,10 @@ void Model::deleteGeometry() { · 1483 unmodified lines | |||
| 1484 | // Scene rendering support | 1484 | // Scene rendering support |
| 1485 | QVector<Model*> Model::_modelsInScene; | 1485 | QVector<Model*> Model::_modelsInScene; |
| 1486 | gpu::Batch Model::_sceneRenderBatch; | 1486 | gpu::Batch Model::_sceneRenderBatch; |
| 1487 | void Model::startScene() { | 1487 | void Model::startScene(RenderArgs::RenderSide renderSide) { |
| 1488 | _modelsInScene.clear(); | 1488 | if (renderSide != RenderArgs::STEREO_RIGHT) { |
| 1489 | _modelsInScene.clear(); | ||
| 1490 | } | ||
| 1489 | } | 1491 | } |
| 1490 | 1492 | ||
| 1491 | void Model::setupBatchTransform(gpu::Batch& batch) { | 1493 | void Model::setupBatchTransform(gpu::Batch& batch) { |
| @@ -1503,146 +1505,152 @@ void Model::setupBatchTransform(gpu::Batch& batch) { · 11 unmodified lines | |||
| 1503 | void Model::endScene(RenderMode mode, RenderArgs* args) { | 1505 | void Model::endScene(RenderMode mode, RenderArgs* args) { |
| 1504 | PROFILE_RANGE(__FUNCTION__); | 1506 | PROFILE_RANGE(__FUNCTION__); |
| 1505 | 1507 | ||
| 1506 | // Let's introduce a gpu::Batch to capture all the calls to the graphics api | 1508 | auto side = RenderArgs::MONO; |
| 1507 | _sceneRenderBatch.clear(); | 1509 | if (args) side = args->_renderSide; |
| 1508 | gpu::Batch& batch = _sceneRenderBatch; | ||
| 1509 | 1510 | ||
| 1510 | GLBATCH(glDisable)(GL_COLOR_MATERIAL); | 1511 | if (side != RenderArgs::STEREO_RIGHT) { |
| 1512 | // Let's introduce a gpu::Batch to capture all the calls to the graphics api | ||
| 1513 | _sceneRenderBatch.clear(); | ||
| 1514 | gpu::Batch& batch = _sceneRenderBatch; | ||
| 1515 | |||
| 1516 | GLBATCH(glDisable)(GL_COLOR_MATERIAL); | ||
| 1511 | 1517 | ||
| 1512 | if (mode == DIFFUSE_RENDER_MODE || mode == NORMAL_RENDER_MODE) { | 1518 | if (mode == DIFFUSE_RENDER_MODE || mode == NORMAL_RENDER_MODE) { |
| 1513 | GLBATCH(glDisable)(GL_CULL_FACE); | 1519 | GLBATCH(glDisable)(GL_CULL_FACE); |
| 1514 | } else { | 1520 | } else { |
| 1515 | GLBATCH(glEnable)(GL_CULL_FACE); | 1521 | GLBATCH(glEnable)(GL_CULL_FACE); |
| 1516 | if (mode == SHADOW_RENDER_MODE) { | 1522 | if (mode == SHADOW_RENDER_MODE) { |
| 1517 | GLBATCH(glCullFace)(GL_FRONT); | 1523 | GLBATCH(glCullFace)(GL_FRONT); |
| 1524 | } | ||
| 1518 | } | 1525 | } |
| 1519 | } | ||
| 1520 | 1526 | ||
| 1521 | // render opaque meshes with alpha testing | 1527 | // render opaque meshes with alpha testing |
| 1522 | 1528 | ||
| 1523 | GLBATCH(glDisable)(GL_BLEND); | 1529 | GLBATCH(glDisable)(GL_BLEND); |
| 1524 | GLBATCH(glEnable)(GL_ALPHA_TEST); | 1530 | GLBATCH(glEnable)(GL_ALPHA_TEST); |
| 1525 | 1531 | ||
| 1526 | if (mode == SHADOW_RENDER_MODE) { | 1532 | if (mode == SHADOW_RENDER_MODE) { |
| 1527 | GLBATCH(glAlphaFunc)(GL_EQUAL, 0.0f); | 1533 | GLBATCH(glAlphaFunc)(GL_EQUAL, 0.0f); |
| 1528 | } | 1534 | } |
| 1529 | 1535 | ||
| 1530 | 1536 | ||
| 1531 | /*Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers( | 1537 | /*Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers( |
| 1532 | mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE, | 1538 | mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE, |
| 1533 | mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE, | 1539 | mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE, |
| 1534 | mode == DEFAULT_RENDER_MODE); | 1540 | mode == DEFAULT_RENDER_MODE); |
| 1535 | */ | 1541 | */ |
| 1536 | { | 1542 | { |
| 1537 | GLenum buffers[3]; | 1543 | GLenum buffers[3]; |
| 1538 | int bufferCount = 0; | 1544 | int bufferCount = 0; |
| 1539 | if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE) { | 1545 | if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE) { |
| 1540 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; | 1546 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; |
| 1541 | } | 1547 | } |
| 1542 | if (mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE) { | 1548 | if (mode == DEFAULT_RENDER_MODE || mode == NORMAL_RENDER_MODE) { |
| 1543 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; | 1549 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; |
| 1544 | } | 1550 | } |
| 1545 | if (mode == DEFAULT_RENDER_MODE) { | 1551 | if (mode == DEFAULT_RENDER_MODE) { |
| 1546 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; | 1552 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; |
| 1553 | } | ||
| 1554 | GLBATCH(glDrawBuffers)(bufferCount, buffers); | ||
| 1547 | } | 1555 | } |
| 1548 | GLBATCH(glDrawBuffers)(bufferCount, buffers); | ||
| 1549 | } | ||
| 1550 | 1556 | ||
| 1551 | const float DEFAULT_ALPHA_THRESHOLD = 0.5f; | 1557 | const float DEFAULT_ALPHA_THRESHOLD = 0.5f; |
| 1552 | 1558 | ||
| 1553 | int opaqueMeshPartsRendered = 0; | 1559 | int opaqueMeshPartsRendered = 0; |
| 1554 | 1560 | ||
| 1555 | // now, for each model in the scene, render the mesh portions | 1561 | // now, for each model in the scene, render the mesh portions |
| 1556 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, false, false, args); | 1562 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, false, false, args); |
| 1557 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, false, true, args); | 1563 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, false, true, args); |
| 1558 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, true, false, args); | 1564 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, true, false, args); |
| 1559 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, true, true, args); | 1565 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, false, true, true, args); |
| 1560 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, false, false, args); | 1566 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, false, false, args); |
| 1561 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, false, true, args); | 1567 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, false, true, args); |
| 1562 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, true, false, args); | 1568 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, true, false, args); |
| 1563 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, true, true, args); | 1569 | opaqueMeshPartsRendered += renderMeshesForModelsInScene(batch, mode, false, DEFAULT_ALPHA_THRESHOLD, true, true, true, args); |
| 1564 | 1570 | ||
| 1565 | // render translucent meshes afterwards | 1571 | // render translucent meshes afterwards |
| 1566 | //Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true, true); | 1572 | //Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(false, true, true); |
| 1567 | { | 1573 | { |
| 1568 | GLenum buffers[2]; | 1574 | GLenum buffers[2]; |
| 1569 | int bufferCount = 0; | 1575 | int bufferCount = 0; |
| 1570 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; | 1576 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT1; |
| 1571 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; | 1577 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT2; |
| 1572 | GLBATCH(glDrawBuffers)(bufferCount, buffers); | 1578 | GLBATCH(glDrawBuffers)(bufferCount, buffers); |
| 1573 | } | 1579 | } |
| 1574 | 1580 | ||
| 1575 | int translucentParts = 0; | 1581 | int translucentParts = 0; |
| 1576 | const float MOSTLY_OPAQUE_THRESHOLD = 0.75f; | 1582 | const float MOSTLY_OPAQUE_THRESHOLD = 0.75f; |
| 1577 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, false, false, args); | 1583 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, false, false, args); |
| 1578 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, false, true, args); | 1584 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, false, true, args); |
| 1579 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, false, args); | 1585 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, false, args); |
| 1580 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, true, args); | 1586 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, false, true, true, args); |
| 1581 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, false, false, args); | 1587 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, false, false, args); |
| 1582 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, false, true, args); | 1588 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, false, true, args); |
| 1583 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, true, false, args); | 1589 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, true, false, args); |
| 1584 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, true, true, args); | 1590 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_OPAQUE_THRESHOLD, true, true, true, args); |
| 1585 | 1591 | ||
| 1586 | GLBATCH(glDisable)(GL_ALPHA_TEST); | 1592 | GLBATCH(glDisable)(GL_ALPHA_TEST); |
| 1587 | GLBATCH(glEnable)(GL_BLEND); | 1593 | GLBATCH(glEnable)(GL_BLEND); |
| 1588 | GLBATCH(glDepthMask)(false); | 1594 | GLBATCH(glDepthMask)(false); |
| 1589 | GLBATCH(glDepthFunc)(GL_LEQUAL); | 1595 | GLBATCH(glDepthFunc)(GL_LEQUAL); |
| 1590 | 1596 | ||
| 1591 | //Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true); | 1597 | //Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true); |
| 1592 | { | 1598 | { |
| 1593 | GLenum buffers[1]; | 1599 | GLenum buffers[1]; |
| 1594 | int bufferCount = 0; | 1600 | int bufferCount = 0; |
| 1595 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; | 1601 | buffers[bufferCount++] = GL_COLOR_ATTACHMENT0; |
| 1596 | GLBATCH(glDrawBuffers)(bufferCount, buffers); | 1602 | GLBATCH(glDrawBuffers)(bufferCount, buffers); |
| 1597 | } | 1603 | } |
| 1598 | 1604 | ||
| 1599 | if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE) { | 1605 | if (mode == DEFAULT_RENDER_MODE || mode == DIFFUSE_RENDER_MODE) { |
| 1600 | const float MOSTLY_TRANSPARENT_THRESHOLD = 0.0f; | 1606 | const float MOSTLY_TRANSPARENT_THRESHOLD = 0.0f; |
| 1601 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, false, args); | 1607 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, false, args); |
| 1602 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, true, args); | 1608 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, false, true, args); |
| 1603 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, true, false, args); | 1609 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, true, false, args); |
| 1604 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, true, true, args); | 1610 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, false, true, true, args); |
| 1605 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, false, false, args); | 1611 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, false, false, args); |
| 1606 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, false, true, args); | 1612 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, false, true, args); |
| 1607 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, true, false, args); | 1613 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, true, false, args); |
| 1608 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, true, true, args); | 1614 | translucentParts += renderMeshesForModelsInScene(batch, mode, true, MOSTLY_TRANSPARENT_THRESHOLD, true, true, true, args); |
| 1609 | } | 1615 | } |
| 1610 | 1616 | ||
| 1611 | GLBATCH(glDepthMask)(true); | 1617 | GLBATCH(glDepthMask)(true); |
| 1612 | GLBATCH(glDepthFunc)(GL_LESS); | 1618 | GLBATCH(glDepthFunc)(GL_LESS); |
| 1613 | GLBATCH(glDisable)(GL_CULL_FACE); | 1619 | GLBATCH(glDisable)(GL_CULL_FACE); |
| 1614 | 1620 | ||
| 1615 | if (mode == SHADOW_RENDER_MODE) { | 1621 | if (mode == SHADOW_RENDER_MODE) { |
| 1616 | GLBATCH(glCullFace)(GL_BACK); | 1622 | GLBATCH(glCullFace)(GL_BACK); |
| 1617 | } | 1623 | } |
| 1618 | 1624 | ||
| 1619 | // deactivate vertex arrays after drawing | 1625 | // deactivate vertex arrays after drawing |
| 1620 | GLBATCH(glDisableClientState)(GL_NORMAL_ARRAY); | 1626 | GLBATCH(glDisableClientState)(GL_NORMAL_ARRAY); |
| 1621 | GLBATCH(glDisableClientState)(GL_VERTEX_ARRAY); | 1627 | GLBATCH(glDisableClientState)(GL_VERTEX_ARRAY); |
| 1622 | GLBATCH(glDisableClientState)(GL_TEXTURE_COORD_ARRAY); | 1628 | GLBATCH(glDisableClientState)(GL_TEXTURE_COORD_ARRAY); |
| 1623 | GLBATCH(glDisableClientState)(GL_COLOR_ARRAY); | 1629 | GLBATCH(glDisableClientState)(GL_COLOR_ARRAY); |
| 1624 | GLBATCH(glDisableVertexAttribArray)(gpu::Stream::TANGENT); | 1630 | GLBATCH(glDisableVertexAttribArray)(gpu::Stream::TANGENT); |
| 1625 | GLBATCH(glDisableVertexAttribArray)(gpu::Stream::SKIN_CLUSTER_INDEX); | 1631 | GLBATCH(glDisableVertexAttribArray)(gpu::Stream::SKIN_CLUSTER_INDEX); |
| 1626 | GLBATCH(glDisableVertexAttribArray)(gpu::Stream::SKIN_CLUSTER_WEIGHT); | 1632 | GLBATCH(glDisableVertexAttribArray)(gpu::Stream::SKIN_CLUSTER_WEIGHT); |
| 1627 | 1633 | ||
| 1628 | // bind with 0 to switch back to normal operation | 1634 | // bind with 0 to switch back to normal operation |
| 1629 | GLBATCH(glBindBuffer)(GL_ARRAY_BUFFER, 0); | 1635 | GLBATCH(glBindBuffer)(GL_ARRAY_BUFFER, 0); |
| 1630 | GLBATCH(glBindBuffer)(GL_ELEMENT_ARRAY_BUFFER, 0); | 1636 | GLBATCH(glBindBuffer)(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 1631 | GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0); | 1637 | GLBATCH(glBindTexture)(GL_TEXTURE_2D, 0); |
| 1638 | if (args) { | ||
| 1639 | args->_translucentMeshPartsRendered = translucentParts; | ||
| 1640 | args->_opaqueMeshPartsRendered = opaqueMeshPartsRendered; | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | } | ||
| 1632 | 1644 | ||
| 1633 | // Render! | 1645 | // Render! |
| 1634 | { | 1646 | { |
| 1635 | PROFILE_RANGE("render Batch"); | 1647 | PROFILE_RANGE("render Batch"); |
| 1636 | ::gpu::GLBackend::renderBatch(batch); | 1648 | ::gpu::GLBackend::renderBatch(_sceneRenderBatch); |
| 1637 | } | 1649 | } |
| 1638 | 1650 | ||
| 1639 | // restore all the default material settings | 1651 | // restore all the default material settings |
| 1640 | Application::getInstance()->setupWorldLight(); | 1652 | Application::getInstance()->setupWorldLight(); |
| 1641 | 1653 | ||
| 1642 | if (args) { | ||
| 1643 | args->_translucentMeshPartsRendered = translucentParts; | ||
| 1644 | args->_opaqueMeshPartsRendered = opaqueMeshPartsRendered; | ||
| 1645 | } | ||
| 1646 | } | 1654 | } |
| 1647 | 1655 | ||
| 1648 | bool Model::renderInScene(float alpha, RenderArgs* args) { | 1656 | bool Model::renderInScene(float alpha, RenderArgs* args) { |