History

Cleanup on aisle three! Removed the color/normal/voxelized spanner bits, as well as the throbbing/scripted guides and the notion of spanner masking.

Andrzej Kapolka committed 12 years ago

Commit e08a0141 parent ae71bb614 files · +74 −1546Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 14 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+16−218
@@ -37,8 +37,6 @@ REGISTER_META_OBJECT(SphereRenderer) · 36 unmodified lines
3737 REGISTER_META_OBJECT(CuboidRenderer)
3838 REGISTER_META_OBJECT(StaticModelRenderer)
3939
40−static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
41−
4240 MetavoxelSystem::NetworkSimulation::NetworkSimulation(float dropRate, float repeatRate,
4341 int minimumDelay, int maximumDelay, int bandwidthLimit) :
4442 dropRate(dropRate),
@@ -59,8 +57,6 @@ void MetavoxelSystem::init() { · 14 unmodified lines
5957 MetavoxelClientManager::init();
6058 DefaultMetavoxelRendererImplementation::init();
6159
62− _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new BufferDataAttribute("pointBuffer"));
63−
6460 _heightfieldBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(
6561 new BufferDataAttribute("heightfieldBuffer"));
6662 _heightfieldBufferAttribute->setLODThresholdMultiplier(
@@ -920,36 +916,6 @@ void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { · 853 unmodified lines
920916 BufferData::~BufferData() {
921917 }
922918
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−
953919 const int HeightfieldBuffer::HEIGHT_BORDER = 1;
954920 const int HeightfieldBuffer::SHARED_EDGE = 1;
955921 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
15761542 }
15771543
15781544 void DefaultMetavoxelRendererImplementation::init() {
1579− if (!_pointProgram.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−
1545+ if (!_baseHeightfieldProgram.isLinked()) {
15901546 _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() +
15911547 "shaders/metavoxel_heightfield_base.vert");
15921548 _baseHeightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
@@ -1631,76 +1587,6 @@ void DefaultMetavoxelRendererImplementation::init() { · 38 unmodified lines
16311587 DefaultMetavoxelRendererImplementation::DefaultMetavoxelRendererImplementation() {
16321588 }
16331589
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−
17041590 class HeightfieldFetchVisitor : public MetavoxelVisitor {
17051591 public:
17061592
@@ -2749,15 +2635,9 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 1042 unmodified lines
27492635 while (expandedPrevious.getSize() < data.getSize()) {
27502636 expandedPrevious.expand();
27512637 }
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− }
27582638 const AttributePointer& heightfieldBufferAttribute =
27592639 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute();
2760− root = expandedPrevious.getRoot(heightfieldBufferAttribute);
2640+ MetavoxelNode* root = expandedPrevious.getRoot(heightfieldBufferAttribute);
27612641 if (root) {
27622642 data.setRoot(heightfieldBufferAttribute, root);
27632643 root->incrementReferenceCount();
@@ -2769,10 +2649,6 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 5 unmodified lines
27692649 data.setRoot(voxelBufferAttribute, root);
27702650 root->incrementReferenceCount();
27712651 }
2772−
2773− PointAugmentVisitor pointAugmentVisitor(lod);
2774− data.guideToDifferent(expandedPrevious, pointAugmentVisitor);
2775−
27762652 HeightfieldRegionVisitor heightfieldRegionVisitor(lod);
27772653 data.guideToDifferent(expandedPrevious, heightfieldRegionVisitor);
27782654
@@ -2789,7 +2665,7 @@ public: · 10 unmodified lines
27892665
27902666 SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod);
27912667
2792− virtual bool visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize);
2668+ virtual bool visit(Spanner* spanner);
27932669
27942670 private:
27952671
@@ -2798,11 +2674,11 @@ private: · 2 unmodified lines
27982674
27992675 SpannerSimulateVisitor::SpannerSimulateVisitor(float deltaTime, const MetavoxelLOD& lod) :
28002676 SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
2801− QVector<AttributePointer>(), QVector<AttributePointer>(), QVector<AttributePointer>(), lod),
2677+ QVector<AttributePointer>(), QVector<AttributePointer>(), lod),
28022678 _deltaTime(deltaTime) {
28032679 }
28042680
2805−bool SpannerSimulateVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) {
2681+bool SpannerSimulateVisitor::visit(Spanner* spanner) {
28062682 spanner->getRenderer()->simulate(_deltaTime);
28072683 return true;
28082684 }
@@ -2819,7 +2695,7 @@ public: · 10 unmodified lines
28192695 SpannerRenderVisitor(const MetavoxelLOD& lod);
28202696
28212697 virtual int visit(MetavoxelInfo& info);
2822− virtual bool visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize);
2698+ virtual bool visit(Spanner* spanner);
28232699
28242700 private:
28252701
@@ -2828,8 +2704,8 @@ private: · 2 unmodified lines
28282704
28292705 SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
28302706 SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
2831− QVector<AttributePointer>(), QVector<AttributePointer>(), QVector<AttributePointer>(),
2832− lod, encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
2707+ QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
2708+ encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
28332709 _containmentDepth(INT_MAX) {
28342710 }
28352711
@@ -2845,9 +2721,9 @@ int SpannerRenderVisitor::visit(MetavoxelInfo& info) { · 9 unmodified lines
28452721 return SpannerVisitor::visit(info);
28462722 }
28472723
2848−bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) {
2724+bool SpannerRenderVisitor::visit(Spanner* spanner) {
28492725 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);
28512727 return true;
28522728 }
28532729
@@ -2893,40 +2769,10 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 39 unmodified lines
28932769 SpannerRenderVisitor spannerRenderVisitor(lod);
28942770 data.guide(spannerRenderVisitor);
28952771
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−
29282772 Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
29292773
2774+ glEnableClientState(GL_VERTEX_ARRAY);
2775+ glDisable(GL_BLEND);
29302776 glEnable(GL_CULL_FACE);
29312777 glEnable(GL_ALPHA_TEST);
29322778 glAlphaFunc(GL_EQUAL, 0.0f);
@@ -2994,8 +2840,6 @@ void DefaultMetavoxelRendererImplementation::loadSplatProgram(const char* type, · 61 unmodified lines
29942840 program.release();
29952841 }
29962842
2997−ProgramObject DefaultMetavoxelRendererImplementation::_pointProgram;
2998−int DefaultMetavoxelRendererImplementation::_pointScaleLocation;
29992843 ProgramObject DefaultMetavoxelRendererImplementation::_baseHeightfieldProgram;
30002844 int DefaultMetavoxelRendererImplementation::_baseHeightScaleLocation;
30012845 int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation;
@@ -3007,55 +2851,10 @@ ProgramObject DefaultMetavoxelRendererImplementation::_splatVoxelProgram; · 5 unmodified lines
30072851 DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations;
30082852 ProgramObject DefaultMetavoxelRendererImplementation::_voxelCursorProgram;
30092853
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−
30382854 SphereRenderer::SphereRenderer() {
30392855 }
30402856
3041−void SphereRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) {
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) {
2857+void SphereRenderer::render(const glm::vec4& color, Mode mode) {
30592858 Sphere* sphere = static_cast<Sphere*>(_spanner);
30602859 const QColor& ownColor = sphere->getColor();
30612860 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
30752874 CuboidRenderer::CuboidRenderer() {
30762875 }
30772876
3078−void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {
2877+void CuboidRenderer::render(const glm::vec4& color, Mode mode) {
30792878 Cuboid* cuboid = static_cast<Cuboid*>(_spanner);
30802879 const QColor& ownColor = cuboid->getColor();
30812880 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
31262925 _model->simulate(deltaTime);
31272926 }
31282927
3129−void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {
2928+void StaticModelRenderer::render(const glm::vec4& color, Mode mode) {
31302929 switch (mode) {
31312930 case DIFFUSE_MODE:
31322931 _model->render(color.a, Model::DIFFUSE_RENDER_MODE);
@@ -3143,8 +2942,7 @@ void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { · 10 unmodified lines
31432942 _model->render(color.a);
31442943 }
31452944
3146−bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
3147− const glm::vec3& clipMinimum, float clipSize, float& distance) const {
2945+bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance) const {
31482946 RayIntersectionInfo info;
31492947 info._rayStart = origin;
31502948 info._rayDirection = direction;