Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 14 files). Show all
Unified · Split
| @@ -37,8 +37,6 @@ REGISTER_META_OBJECT(SphereRenderer) · 36 unmodified lines | |||
| 37 | REGISTER_META_OBJECT(CuboidRenderer) | 37 | REGISTER_META_OBJECT(CuboidRenderer) |
| 38 | REGISTER_META_OBJECT(StaticModelRenderer) | 38 | REGISTER_META_OBJECT(StaticModelRenderer) |
| 39 | 39 | ||
| 40 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); | ||
| 41 | |||
| 42 | MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate, | 40 | MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate, |
| 43 | int minimumDelay, int maximumDelay, int bandwidthLimit) : | 41 | int minimumDelay, int maximumDelay, int bandwidthLimit) : |
| 44 | dropRate(dropRate), | 42 | dropRate(dropRate), |
| @@ -59,8 +57,6 @@ void MetavoxelSystem::init() { · 14 unmodified lines | |||
| 59 | MetavoxelClientManager::init(); | 57 | MetavoxelClientManager::init(); |
| 60 | DefaultMetavoxelRendererImplementation::init(); | 58 | DefaultMetavoxelRendererImplementation::init(); |
| 61 | 59 | ||
| 62 | _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new BufferDataAttribute("pointBuffer")); | ||
| 63 | |||
| 64 | _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute( | 60 | _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute( |
| 65 | new BufferDataAttribute("heightfieldBuffer")); | 61 | new BufferDataAttribute("heightfieldBuffer")); |
| 66 | _heightfieldBufferAttribute->setLODThresholdMultiplier( | 62 | _heightfieldBufferAttribute->setLODThresholdMultiplier( |
| @@ -920,36 +916,6 @@ void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { · 853 unmodified lines | |||
| 920 | BufferData::~BufferData() { | 916 | BufferData::~BufferData() { |
| 921 | } | 917 | } |
| 922 | 918 | ||
| 923 | PointBuffer::PointBuffer(const BufferPointVector& points) : | ||
| 924 | _points(points) { | ||
| 925 | } | ||
| 926 | |||
| 927 | void PointBuffer::render(bool cursor) { | ||
| 928 | // initialize buffer, etc. on first render | ||
| 929 | if (!_buffer.isCreated()) { | ||
| 930 | _buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); | ||
| 931 | _buffer.create(); | ||
| 932 | _buffer.bind(); | ||
| 933 | _pointCount = _points.size(); | ||
| 934 | _buffer.allocate(_points.constData(), _pointCount * sizeof(BufferPoint)); | ||
| 935 | _points.clear(); | ||
| 936 | _buffer.release(); | ||
| 937 | } | ||
| 938 | if (_pointCount == 0) { | ||
| 939 | return; | ||
| 940 | } | ||
| 941 | _buffer.bind(); | ||
| 942 | |||
| 943 | BufferPoint* point = 0; | ||
| 944 | glVertexPointer(4, GL_FLOAT, sizeof(BufferPoint), &point->vertex); | ||
| 945 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(BufferPoint), &point->color); | ||
| 946 | glNormalPointer(GL_BYTE, sizeof(BufferPoint), &point->normal); | ||
| 947 | |||
| 948 | glDrawArrays(GL_POINTS, 0, _pointCount); | ||
| 949 | |||
| 950 | _buffer.release(); | ||
| 951 | } | ||
| 952 | |||
| 953 | const int HeightfieldBuffer::HEIGHT_BORDER = 1; | 919 | const int HeightfieldBuffer::HEIGHT_BORDER = 1; |
| 954 | const int HeightfieldBuffer::SHARED_EDGE = 1; | 920 | const int HeightfieldBuffer::SHARED_EDGE = 1; |
| 955 | const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE; | 921 | const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE; |
| @@ -1576,17 +1542,7 @@ AttributeValue BufferDataAttribute::inherit(const AttributeValue& parentValue) c · 620 unmodified lines | |||
| 1576 | } | 1542 | } |
| 1577 | 1543 | ||
| 1578 | void DefaultMetavoxelRendererImplementation::init() { | 1544 | void DefaultMetavoxelRendererImplementation::init() { |
| 1579 | if (!_pointProgram.isLinked()) { | 1545 | if (!_baseHeightfieldProgram.isLinked()) { |
| 1580 | _pointProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | ||
| 1581 | "shaders/metavoxel_point.vert"); | ||
| 1582 | _pointProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1583 | "shaders/metavoxel_voxel_base.frag"); | ||
| 1584 | _pointProgram.link(); | ||
| 1585 | |||
| 1586 | _pointProgram.bind(); | ||
| 1587 | _pointScaleLocation = _pointProgram.uniformLocation("pointScale"); | ||
| 1588 | _pointProgram.release(); | ||
| 1589 | |||
| 1590 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + | 1546 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + |
| 1591 | "shaders/metavoxel_heightfield_base.vert"); | 1547 | "shaders/metavoxel_heightfield_base.vert"); |
| 1592 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | 1548 | _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + |
| @@ -1631,76 +1587,6 @@ void DefaultMetavoxelRendererImplementation::init() { · 38 unmodified lines | |||
| 1631 | DefaultMetavoxelRendererImplementation::DefaultMetavoxelRendererImplementation() { | 1587 | DefaultMetavoxelRendererImplementation::DefaultMetavoxelRendererImplementation() { |
| 1632 | } | 1588 | } |
| 1633 | 1589 | ||
| 1634 | class PointAugmentVisitor : public MetavoxelVisitor { | ||
| 1635 | public: | ||
| 1636 | |||
| 1637 | PointAugmentVisitor(const MetavoxelLOD& lod); | ||
| 1638 | |||
| 1639 | virtual void prepare(MetavoxelData* data); | ||
| 1640 | virtual int visit(MetavoxelInfo& info); | ||
| 1641 | virtual bool postVisit(MetavoxelInfo& info); | ||
| 1642 | |||
| 1643 | private: | ||
| 1644 | |||
| 1645 | BufferPointVector _points; | ||
| 1646 | float _pointLeafSize; | ||
| 1647 | }; | ||
| 1648 | |||
| 1649 | PointAugmentVisitor::PointAugmentVisitor(const MetavoxelLOD& lod) : | ||
| 1650 | MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() << | ||
| 1651 | AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>() << | ||
| 1652 | Application::getInstance()->getMetavoxels()->getPointBufferAttribute(), lod) { | ||
| 1653 | } | ||
| 1654 | |||
| 1655 | const int ALPHA_RENDER_THRESHOLD = 0; | ||
| 1656 | |||
| 1657 | void PointAugmentVisitor::prepare(MetavoxelData* data) { | ||
| 1658 | MetavoxelVisitor::prepare(data); | ||
| 1659 | const float MAX_POINT_LEAF_SIZE = 64.0f; | ||
| 1660 | _pointLeafSize = qMin(data->getSize(), MAX_POINT_LEAF_SIZE); | ||
| 1661 | } | ||
| 1662 | |||
| 1663 | int PointAugmentVisitor::visit(MetavoxelInfo& info) { | ||
| 1664 | if (!info.isLeaf) { | ||
| 1665 | return (info.size > _pointLeafSize) ? DEFAULT_ORDER : (DEFAULT_ORDER | ALL_NODES_REST); | ||
| 1666 | } | ||
| 1667 | QRgb color = info.inputValues.at(0).getInlineValue<QRgb>(); | ||
| 1668 | quint8 alpha = qAlpha(color); | ||
| 1669 | if (alpha > ALPHA_RENDER_THRESHOLD) { | ||
| 1670 | QRgb normal = info.inputValues.at(1).getInlineValue<QRgb>(); | ||
| 1671 | BufferPoint point = { glm::vec4(info.minimum + glm::vec3(info.size, info.size, info.size) * 0.5f, info.size), | ||
| 1672 | { quint8(qRed(color)), quint8(qGreen(color)), quint8(qBlue(color)) }, | ||
| 1673 | { quint8(qRed(normal)), quint8(qGreen(normal)), quint8(qBlue(normal)) } }; | ||
| 1674 | _points.append(point); | ||
| 1675 | } | ||
| 1676 | if (info.size >= _pointLeafSize) { | ||
| 1677 | PointBuffer* buffer = NULL; | ||
| 1678 | if (!_points.isEmpty()) { | ||
| 1679 | BufferPointVector swapPoints; | ||
| 1680 | _points.swap(swapPoints); | ||
| 1681 | buffer = new PointBuffer(swapPoints); | ||
| 1682 | } | ||
| 1683 | BufferDataPointer pointer(buffer); | ||
| 1684 | info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer)); | ||
| 1685 | } | ||
| 1686 | return STOP_RECURSION; | ||
| 1687 | } | ||
| 1688 | |||
| 1689 | bool PointAugmentVisitor::postVisit(MetavoxelInfo& info) { | ||
| 1690 | if (info.size != _pointLeafSize) { | ||
| 1691 | return false; | ||
| 1692 | } | ||
| 1693 | PointBuffer* buffer = NULL; | ||
| 1694 | if (!_points.isEmpty()) { | ||
| 1695 | BufferPointVector swapPoints; | ||
| 1696 | _points.swap(swapPoints); | ||
| 1697 | buffer = new PointBuffer(swapPoints); | ||
| 1698 | } | ||
| 1699 | BufferDataPointer pointer(buffer); | ||
| 1700 | info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer)); | ||
| 1701 | return true; | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | class HeightfieldFetchVisitor : public MetavoxelVisitor { | 1590 | class HeightfieldFetchVisitor : public MetavoxelVisitor { |
| 1705 | public: | 1591 | public: |
| 1706 | 1592 | ||
| @@ -2749,15 +2635,9 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 1042 unmodified lines | |||
| 2749 | while (expandedPrevious.getSize() < data.getSize()) { | 2635 | while (expandedPrevious.getSize() < data.getSize()) { |
| 2750 | expandedPrevious.expand(); | 2636 | expandedPrevious.expand(); |
| 2751 | } | 2637 | } |
| 2752 | const AttributePointer& pointBufferAttribute = Application::getInstance()->getMetavoxels()->getPointBufferAttribute(); | ||
| 2753 | MetavoxelNode* root = expandedPrevious.getRoot(pointBufferAttribute); | ||
| 2754 | if (root) { | ||
| 2755 | data.setRoot(pointBufferAttribute, root); | ||
| 2756 | root->incrementReferenceCount(); | ||
| 2757 | } | ||
| 2758 | const AttributePointer& heightfieldBufferAttribute = | 2638 | const AttributePointer& heightfieldBufferAttribute = |
| 2759 | Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(); | 2639 | Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(); |
| 2760 | root = expandedPrevious.getRoot(heightfieldBufferAttribute); | 2640 | MetavoxelNode* root = expandedPrevious.getRoot(heightfieldBufferAttribute); |
| 2761 | if (root) { | 2641 | if (root) { |
| 2762 | data.setRoot(heightfieldBufferAttribute, root); | 2642 | data.setRoot(heightfieldBufferAttribute, root); |
| 2763 | root->incrementReferenceCount(); | 2643 | root->incrementReferenceCount(); |
| @@ -2769,10 +2649,6 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 5 unmodified lines | |||
| 2769 | data.setRoot(voxelBufferAttribute, root); | 2649 | data.setRoot(voxelBufferAttribute, root); |
| 2770 | root->incrementReferenceCount(); | 2650 | root->incrementReferenceCount(); |
| 2771 | } | 2651 | } |
| 2772 | |||
| 2773 | PointAugmentVisitor pointAugmentVisitor(lod); | ||
| 2774 | data.guideToDifferent(expandedPrevious, pointAugmentVisitor); | ||
| 2775 | |||
| 2776 | HeightfieldRegionVisitor heightfieldRegionVisitor(lod); | 2652 | HeightfieldRegionVisitor heightfieldRegionVisitor(lod); |
| 2777 | data.guideToDifferent(expandedPrevious, heightfieldRegionVisitor); | 2653 | data.guideToDifferent(expandedPrevious, heightfieldRegionVisitor); |
| 2778 | 2654 | ||
| @@ -2789,7 +2665,7 @@ public: · 10 unmodified lines | |||
| 2789 | 2665 | ||
| 2790 | SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod); | 2666 | SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod); |
| 2791 | 2667 | ||
| 2792 | virtual bool visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize); | 2668 | virtual bool visit(Spanner* spanner); |
| 2793 | 2669 | ||
| 2794 | private: | 2670 | private: |
| 2795 | 2671 | ||
| @@ -2798,11 +2674,11 @@ private: · 2 unmodified lines | |||
| 2798 | 2674 | ||
| 2799 | SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) : | 2675 | SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) : |
| 2800 | SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), | 2676 | SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), |
| 2801 | QVector<AttributePointer>(), QVector<AttributePointer>(), QVector<AttributePointer>(), lod), | 2677 | QVector<AttributePointer>(), QVector<AttributePointer>(), lod), |
| 2802 | _deltaTime(deltaTime) { | 2678 | _deltaTime(deltaTime) { |
| 2803 | } | 2679 | } |
| 2804 | 2680 | ||
| 2805 | bool SpannerSimulateVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { | 2681 | bool SpannerSimulateVisitor::visit(Spanner* spanner) { |
| 2806 | spanner->getRenderer()->simulate(_deltaTime); | 2682 | spanner->getRenderer()->simulate(_deltaTime); |
| 2807 | return true; | 2683 | return true; |
| 2808 | } | 2684 | } |
| @@ -2819,7 +2695,7 @@ public: · 10 unmodified lines | |||
| 2819 | SpannerRenderVisitor(const MetavoxelLOD& lod); | 2695 | SpannerRenderVisitor(const MetavoxelLOD& lod); |
| 2820 | 2696 | ||
| 2821 | virtual int visit(MetavoxelInfo& info); | 2697 | virtual int visit(MetavoxelInfo& info); |
| 2822 | virtual bool visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize); | 2698 | virtual bool visit(Spanner* spanner); |
| 2823 | 2699 | ||
| 2824 | private: | 2700 | private: |
| 2825 | 2701 | ||
| @@ -2828,8 +2704,8 @@ private: · 2 unmodified lines | |||
| 2828 | 2704 | ||
| 2829 | SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) : | 2705 | SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) : |
| 2830 | SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), | 2706 | SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(), |
| 2831 | QVector<AttributePointer>(), QVector<AttributePointer>(), QVector<AttributePointer>(), | 2707 | QVector<AttributePointer>(), QVector<AttributePointer>(), lod, |
| 2832 | lod, encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())), | 2708 | encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())), |
| 2833 | _containmentDepth(INT_MAX) { | 2709 | _containmentDepth(INT_MAX) { |
| 2834 | } | 2710 | } |
| 2835 | 2711 | ||
| @@ -2845,9 +2721,9 @@ int SpannerRenderVisitor::visit(MetavoxelInfo& info) { · 9 unmodified lines | |||
| 2845 | return SpannerVisitor::visit(info); | 2721 | return SpannerVisitor::visit(info); |
| 2846 | } | 2722 | } |
| 2847 | 2723 | ||
| 2848 | bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { | 2724 | bool SpannerRenderVisitor::visit(Spanner* spanner) { |
| 2849 | const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); | 2725 | const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); |
| 2850 | spanner->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | 2726 | spanner->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DEFAULT_MODE); |
| 2851 | return true; | 2727 | return true; |
| 2852 | } | 2728 | } |
| 2853 | 2729 | ||
| @@ -2893,40 +2769,10 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 39 unmodified lines | |||
| 2893 | SpannerRenderVisitor spannerRenderVisitor(lod); | 2769 | SpannerRenderVisitor spannerRenderVisitor(lod); |
| 2894 | data.guide(spannerRenderVisitor); | 2770 | data.guide(spannerRenderVisitor); |
| 2895 | 2771 | ||
| 2896 | int viewport[4]; | ||
| 2897 | glGetIntegerv(GL_VIEWPORT, viewport); | ||
| 2898 | const int VIEWPORT_WIDTH_INDEX = 2; | ||
| 2899 | const int VIEWPORT_HEIGHT_INDEX = 3; | ||
| 2900 | float viewportWidth = viewport[VIEWPORT_WIDTH_INDEX]; | ||
| 2901 | float viewportHeight = viewport[VIEWPORT_HEIGHT_INDEX]; | ||
| 2902 | float viewportDiagonal = sqrtf(viewportWidth * viewportWidth + viewportHeight * viewportHeight); | ||
| 2903 | float worldDiagonal = glm::distance(Application::getInstance()->getDisplayViewFrustum()->getNearBottomLeft(), | ||
| 2904 | Application::getInstance()->getDisplayViewFrustum()->getNearTopRight()); | ||
| 2905 | |||
| 2906 | _pointProgram.bind(); | ||
| 2907 | _pointProgram.setUniformValue(_pointScaleLocation, viewportDiagonal * | ||
| 2908 | Application::getInstance()->getDisplayViewFrustum()->getNearClip() / worldDiagonal); | ||
| 2909 | |||
| 2910 | glEnableClientState(GL_VERTEX_ARRAY); | ||
| 2911 | glEnableClientState(GL_COLOR_ARRAY); | ||
| 2912 | glEnableClientState(GL_NORMAL_ARRAY); | ||
| 2913 | |||
| 2914 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | ||
| 2915 | |||
| 2916 | glDisable(GL_BLEND); | ||
| 2917 | |||
| 2918 | BufferRenderVisitor pointRenderVisitor(Application::getInstance()->getMetavoxels()->getPointBufferAttribute()); | ||
| 2919 | data.guide(pointRenderVisitor); | ||
| 2920 | |||
| 2921 | glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | ||
| 2922 | |||
| 2923 | glDisableClientState(GL_COLOR_ARRAY); | ||
| 2924 | glDisableClientState(GL_NORMAL_ARRAY); | ||
| 2925 | |||
| 2926 | _pointProgram.release(); | ||
| 2927 | |||
| 2928 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true); | 2772 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true); |
| 2929 | 2773 | ||
| 2774 | glEnableClientState(GL_VERTEX_ARRAY); | ||
| 2775 | glDisable(GL_BLEND); | ||
| 2930 | glEnable(GL_CULL_FACE); | 2776 | glEnable(GL_CULL_FACE); |
| 2931 | glEnable(GL_ALPHA_TEST); | 2777 | glEnable(GL_ALPHA_TEST); |
| 2932 | glAlphaFunc(GL_EQUAL, 0.0f); | 2778 | glAlphaFunc(GL_EQUAL, 0.0f); |
| @@ -2994,8 +2840,6 @@ void DefaultMetavoxelRendererImplementation::loadSplatProgram(const char* type, · 61 unmodified lines | |||
| 2994 | program.release(); | 2840 | program.release(); |
| 2995 | } | 2841 | } |
| 2996 | 2842 | ||
| 2997 | ProgramObject DefaultMetavoxelRendererImplementation::_pointProgram; | ||
| 2998 | int DefaultMetavoxelRendererImplementation::_pointScaleLocation; | ||
| 2999 | ProgramObject DefaultMetavoxelRendererImplementation::_baseHeightfieldProgram; | 2843 | ProgramObject DefaultMetavoxelRendererImplementation::_baseHeightfieldProgram; |
| 3000 | int DefaultMetavoxelRendererImplementation::_baseHeightScaleLocation; | 2844 | int DefaultMetavoxelRendererImplementation::_baseHeightScaleLocation; |
| 3001 | int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation; | 2845 | int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation; |
| @@ -3007,55 +2851,10 @@ ProgramObject DefaultMetavoxelRendererImplementation::_splatVoxelProgram; · 5 unmodified lines | |||
| 3007 | DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations; | 2851 | DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations; |
| 3008 | ProgramObject DefaultMetavoxelRendererImplementation::_voxelCursorProgram; | 2852 | ProgramObject DefaultMetavoxelRendererImplementation::_voxelCursorProgram; |
| 3009 | 2853 | ||
| 3010 | static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { | ||
| 3011 | GLdouble coefficients[] = { x, y, z, w }; | ||
| 3012 | glClipPlane(plane, coefficients); | ||
| 3013 | glEnable(plane); | ||
| 3014 | } | ||
| 3015 | |||
| 3016 | void ClippedRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | ||
| 3017 | if (clipSize == 0.0f) { | ||
| 3018 | renderUnclipped(color, mode); | ||
| 3019 | return; | ||
| 3020 | } | ||
| 3021 | enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize); | ||
| 3022 | enableClipPlane(GL_CLIP_PLANE1, 1.0f, 0.0f, 0.0f, -clipMinimum.x); | ||
| 3023 | enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipSize); | ||
| 3024 | enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); | ||
| 3025 | enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize); | ||
| 3026 | enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z); | ||
| 3027 | |||
| 3028 | renderUnclipped(color, mode); | ||
| 3029 | |||
| 3030 | glDisable(GL_CLIP_PLANE0); | ||
| 3031 | glDisable(GL_CLIP_PLANE1); | ||
| 3032 | glDisable(GL_CLIP_PLANE2); | ||
| 3033 | glDisable(GL_CLIP_PLANE3); | ||
| 3034 | glDisable(GL_CLIP_PLANE4); | ||
| 3035 | glDisable(GL_CLIP_PLANE5); | ||
| 3036 | } | ||
| 3037 | |||
| 3038 | SphereRenderer::SphereRenderer() { | 2854 | SphereRenderer::SphereRenderer() { |
| 3039 | } | 2855 | } |
| 3040 | 2856 | ||
| 3041 | void SphereRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | 2857 | void SphereRenderer::render(const glm::vec4& color, Mode mode) { |
| 3042 | if (clipSize == 0.0f) { | ||
| 3043 | renderUnclipped(color, mode); | ||
| 3044 | return; | ||
| 3045 | } | ||
| 3046 | // slight performance optimization: don't render if clip bounds are entirely within sphere | ||
| 3047 | Sphere* sphere = static_cast<Sphere*>(_spanner); | ||
| 3048 | Box clipBox(clipMinimum, clipMinimum + glm::vec3(clipSize, clipSize, clipSize)); | ||
| 3049 | for (int i = 0; i < Box::VERTEX_COUNT; i++) { | ||
| 3050 | const float CLIP_PROPORTION = 0.95f; | ||
| 3051 | if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) { | ||
| 3052 | ClippedRenderer::render(color, mode, clipMinimum, clipSize); | ||
| 3053 | return; | ||
| 3054 | } | ||
| 3055 | } | ||
| 3056 | } | ||
| 3057 | |||
| 3058 | void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | ||
| 3059 | Sphere* sphere = static_cast<Sphere*>(_spanner); | 2858 | Sphere* sphere = static_cast<Sphere*>(_spanner); |
| 3060 | const QColor& ownColor = sphere->getColor(); | 2859 | const QColor& ownColor = sphere->getColor(); |
| 3061 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); | 2860 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); |
| @@ -3075,7 +2874,7 @@ void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { · 13 unmodified lines | |||
| 3075 | CuboidRenderer::CuboidRenderer() { | 2874 | CuboidRenderer::CuboidRenderer() { |
| 3076 | } | 2875 | } |
| 3077 | 2876 | ||
| 3078 | void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | 2877 | void CuboidRenderer::render(const glm::vec4& color, Mode mode) { |
| 3079 | Cuboid* cuboid = static_cast<Cuboid*>(_spanner); | 2878 | Cuboid* cuboid = static_cast<Cuboid*>(_spanner); |
| 3080 | const QColor& ownColor = cuboid->getColor(); | 2879 | const QColor& ownColor = cuboid->getColor(); |
| 3081 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); | 2880 | glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); |
| @@ -3126,7 +2925,7 @@ void StaticModelRenderer::simulate(float deltaTime) { · 44 unmodified lines | |||
| 3126 | _model->simulate(deltaTime); | 2925 | _model->simulate(deltaTime); |
| 3127 | } | 2926 | } |
| 3128 | 2927 | ||
| 3129 | void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | 2928 | void StaticModelRenderer::render(const glm::vec4& color, Mode mode) { |
| 3130 | switch (mode) { | 2929 | switch (mode) { |
| 3131 | case DIFFUSE_MODE: | 2930 | case DIFFUSE_MODE: |
| 3132 | _model->render(color.a, Model::DIFFUSE_RENDER_MODE); | 2931 | _model->render(color.a, Model::DIFFUSE_RENDER_MODE); |
| @@ -3143,8 +2942,7 @@ void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { · 10 unmodified lines | |||
| 3143 | _model->render(color.a); | 2942 | _model->render(color.a); |
| 3144 | } | 2943 | } |
| 3145 | 2944 | ||
| 3146 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, | 2945 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const { |
| 3147 | const glm::vec3& clipMinimum, float clipSize, float& distance) const { | ||
| 3148 | RayIntersectionInfo info; | 2946 | RayIntersectionInfo info; |
| 3149 | info._rayStart = origin; | 2947 | info._rayStart = origin; |
| 3150 | info._rayDirection = direction; | 2948 | info._rayDirection = direction; |