History

resolve conflicts on merge with upstream master

Stephen Birarda committed 11 years ago

Commit 8549e9c2 parents 5c3e90f 0b85a4c204 files · +9159 −14298Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+220−212
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121
2222 #include <glm/gtx/transform.hpp>
2323
24+#include <GeometryUtil.h>
2425 #include <SharedUtil.h>
2526
2627 #include <MetavoxelMessages.h>
@@ -461,6 +462,34 @@ void MetavoxelSystem::render() { · 434 unmodified lines
461462 _voxelBaseBatches.clear();
462463 }
463464
465+ if (!_hermiteBatches.isEmpty() && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
466+ Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, true);
467+
468+ glEnableClientState(GL_VERTEX_ARRAY);
469+
470+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
471+ glNormal3f(0.0f, 1.0f, 0.0f);
472+
473+ Application::getInstance()->getDeferredLightingEffect()->bindSimpleProgram();
474+
475+ foreach (const HermiteBatch& batch, _hermiteBatches) {
476+ batch.vertexBuffer->bind();
477+
478+ glVertexPointer(3, GL_FLOAT, 0, 0);
479+
480+ glDrawArrays(GL_LINES, 0, batch.vertexCount);
481+
482+ batch.vertexBuffer->release();
483+ }
484+
485+ Application::getInstance()->getDeferredLightingEffect()->releaseSimpleProgram();
486+
487+ glDisableClientState(GL_VERTEX_ARRAY);
488+
489+ Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false);
490+ }
491+ _hermiteBatches.clear();
492+
464493 // give external parties a chance to join in
465494 emit rendering();
466495 }
@@ -550,10 +579,53 @@ void MetavoxelSystem::setVoxelMaterial(const SharedObjectPointer& spanner, const · 83 unmodified lines
550579 applyMaterialEdit(edit, true);
551580 }
552581
553−class SpannerCursorRenderVisitor : public SpannerVisitor {
582+void MetavoxelSystem::deleteTextures(int heightTextureID, int colorTextureID, int materialTextureID) const {
583+ glDeleteTextures(1, (const GLuint*)&heightTextureID);
584+ glDeleteTextures(1, (const GLuint*)&colorTextureID);
585+ glDeleteTextures(1, (const GLuint*)&materialTextureID);
586+}
587+
588+class SpannerRenderVisitor : public SpannerVisitor {
589+public:
590+
591+ SpannerRenderVisitor(const MetavoxelLOD& lod);
592+
593+ virtual int visit(MetavoxelInfo& info);
594+ virtual bool visit(Spanner* spanner);
595+
596+protected:
597+
598+ int _containmentDepth;
599+};
600+
601+SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
602+ SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
603+ QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
604+ encodeOrder(Application::getInstance()->getViewFrustum()->getDirection())),
605+ _containmentDepth(INT_MAX) {
606+}
607+
608+int SpannerRenderVisitor::visit(MetavoxelInfo& info) {
609+ if (_containmentDepth >= _depth) {
610+ Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
611+ info.getBounds());
612+ if (intersection == Frustum::NO_INTERSECTION) {
613+ return STOP_RECURSION;
614+ }
615+ _containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX;
616+ }
617+ return SpannerVisitor::visit(info);
618+}
619+
620+bool SpannerRenderVisitor::visit(Spanner* spanner) {
621+ spanner->getRenderer()->render(_lod, _containmentDepth <= _depth);
622+ return true;
623+}
624+
625+class SpannerCursorRenderVisitor : public SpannerRenderVisitor {
554626 public:
555627
556− SpannerCursorRenderVisitor(const Box& bounds);
628+ SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds);
557629
558630 virtual bool visit(Spanner* spanner);
559631
@@ -564,20 +636,20 @@ private: · 4 unmodified lines
564636 Box _bounds;
565637 };
566638
567−SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const Box& bounds) :
568−SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute()),
569−_bounds(bounds) {
639+SpannerCursorRenderVisitor::SpannerCursorRenderVisitor(const MetavoxelLOD& lod, const Box& bounds) :
640+ SpannerRenderVisitor(lod),
641+ _bounds(bounds) {
570642 }
571643
572644 bool SpannerCursorRenderVisitor::visit(Spanner* spanner) {
573645 if (spanner->isHeightfield()) {
574− spanner->getRenderer()->render(true);
646+ spanner->getRenderer()->render(_lod, _containmentDepth <= _depth, true);
575647 }
576648 return true;
577649 }
578650
579651 int SpannerCursorRenderVisitor::visit(MetavoxelInfo& info) {
580− return info.getBounds().intersects(_bounds) ? SpannerVisitor::visit(info) : STOP_RECURSION;
652+ return info.getBounds().intersects(_bounds) ? SpannerRenderVisitor::visit(info) : STOP_RECURSION;
581653 }
582654
583655 void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float radius) {
@@ -604,7 +676,7 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 20 unmodified lines
604676 glActiveTexture(GL_TEXTURE0);
605677
606678 glm::vec3 extents(radius, radius, radius);
607− SpannerCursorRenderVisitor visitor(Box(position - extents, position + extents));
679+ SpannerCursorRenderVisitor visitor(getLOD(), Box(position - extents, position + extents));
608680 guide(visitor);
609681
610682 _heightfieldCursorProgram.release();
@@ -678,7 +750,7 @@ void MetavoxelSystem::renderVoxelCursor(const glm::vec3& position, float radius) · 67 unmodified lines
678750
679751 _heightfieldCursorProgram.bind();
680752
681− SpannerCursorRenderVisitor spannerVisitor(bounds);
753+ SpannerCursorRenderVisitor spannerVisitor(getLOD(), bounds);
682754 guide(spannerVisitor);
683755
684756 _heightfieldCursorProgram.release();
@@ -1024,30 +1096,6 @@ _indexBuffer(QOpenGLBuffer::IndexBuffer), · 339 unmodified lines
10241096 _materials(materials) {
10251097 }
10261098
1027−static bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
1028− const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance) {
1029− glm::vec3 firstSide = v0 - v1;
1030− glm::vec3 secondSide = v2 - v1;
1031− glm::vec3 normal = glm::cross(secondSide, firstSide);
1032− float dividend = glm::dot(normal, v1) - glm::dot(origin, normal);
1033− if (dividend > 0.0f) {
1034− return false; // origin below plane
1035− }
1036− float divisor = glm::dot(normal, direction);
1037− if (divisor > -EPSILON) {
1038− return false;
1039− }
1040− float t = dividend / divisor;
1041− glm::vec3 point = origin + direction * t;
1042− if (glm::dot(normal, glm::cross(point - v1, firstSide)) > 0.0f &&
1043− glm::dot(normal, glm::cross(secondSide, point - v1)) > 0.0f &&
1044− glm::dot(normal, glm::cross(point - v0, v2 - v0)) > 0.0f) {
1045− distance = t;
1046− return true;
1047− }
1048− return false;
1049−}
1050−
10511099 bool VoxelBuffer::findFirstRayIntersection(const glm::vec3& entry, const glm::vec3& origin,
10521100 const glm::vec3& direction, float& distance) const {
10531101 float highest = _size - 1.0f;
@@ -1192,31 +1240,18 @@ void VoxelBuffer::render(bool cursor) { · 138 unmodified lines
11921240 }
11931241 }
11941242
1195− if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
1243+ if (_hermiteCount > 0) {
11961244 if (!_hermiteBuffer.isCreated()) {
11971245 _hermiteBuffer.create();
11981246 _hermiteBuffer.bind();
1199− _hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3));
1247+ _hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3));
1248+ _hermiteBuffer.release();
12001249 _hermite.clear();
1201−
1202− } else {
1203− _hermiteBuffer.bind();
12041250 }
1205−
1206− glVertexPointer(3, GL_FLOAT, 0, 0);
1207−
1208− Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind();
1209−
1210− glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
1211− glNormal3f(0.0f, 1.0f, 0.0f);
1212−
1213− glLineWidth(1.0f);
1214−
1215− glDrawArrays(GL_LINES, 0, _hermiteCount);
1216−
1217− Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().release();
1218−
1219− _hermiteBuffer.release();
1251+ HermiteBatch hermiteBatch;
1252+ hermiteBatch.vertexBuffer = &_hermiteBuffer;
1253+ hermiteBatch.vertexCount = _hermiteCount;
1254+ Application::getInstance()->getMetavoxels()->addHermiteBatch(hermiteBatch);
12201255 }
12211256 }
12221257
@@ -1880,43 +1915,6 @@ void DefaultMetavoxelRendererImplementation::simulate(MetavoxelData& data, float · 657 unmodified lines
18801915 data.guide(spannerSimulateVisitor);
18811916 }
18821917
1883−class SpannerRenderVisitor : public SpannerVisitor {
1884−public:
1885−
1886− SpannerRenderVisitor(const MetavoxelLOD& lod);
1887−
1888− virtual int visit(MetavoxelInfo& info);
1889− virtual bool visit(Spanner* spanner);
1890−
1891−private:
1892−
1893− int _containmentDepth;
1894−};
1895−
1896−SpannerRenderVisitor::SpannerRenderVisitor(const MetavoxelLOD& lod) :
1897−SpannerVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getSpannersAttribute(),
1898− QVector<AttributePointer>(), QVector<AttributePointer>(), lod,
1899− encodeOrder(Application::getInstance()->getDisplayViewFrustum()->getDirection())),
1900−_containmentDepth(INT_MAX) {
1901−}
1902−
1903−int SpannerRenderVisitor::visit(MetavoxelInfo& info) {
1904− if (_containmentDepth >= _depth) {
1905− Frustum::IntersectionType intersection = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
1906− info.getBounds());
1907− if (intersection == Frustum::NO_INTERSECTION) {
1908− return STOP_RECURSION;
1909− }
1910− _containmentDepth = (intersection == Frustum::CONTAINS_INTERSECTION) ? _depth : INT_MAX;
1911− }
1912− return SpannerVisitor::visit(info);
1913−}
1914−
1915−bool SpannerRenderVisitor::visit(Spanner* spanner) {
1916− spanner->getRenderer()->render();
1917− return true;
1918−}
1919−
19201918 class BufferRenderVisitor : public MetavoxelVisitor {
19211919 public:
19221920
@@ -1970,7 +1968,7 @@ SphereRenderer::SphereRenderer() { · 47 unmodified lines
19701968 }
19711969
19721970
1973−void SphereRenderer::render(bool cursor) {
1971+void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
19741972 Sphere* sphere = static_cast<Sphere*>(_spanner);
19751973 const QColor& color = sphere->getColor();
19761974 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
@@ -1990,7 +1988,7 @@ void SphereRenderer::render(bool cursor) { · 13 unmodified lines
19901988 CuboidRenderer::CuboidRenderer() {
19911989 }
19921990
1993−void CuboidRenderer::render(bool cursor) {
1991+void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
19941992 Cuboid* cuboid = static_cast<Cuboid*>(_spanner);
19951993 const QColor& color = cuboid->getColor();
19961994 glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF());
@@ -2041,7 +2039,7 @@ void StaticModelRenderer::simulate(float deltaTime) { · 44 unmodified lines
20412039 _model->simulate(deltaTime);
20422040 }
20432041
2044−void StaticModelRenderer::render(bool cursor) {
2042+void StaticModelRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
20452043 _model->render();
20462044 }
20472045
@@ -2073,57 +2071,66 @@ void StaticModelRenderer::applyURL(const QUrl& url) { · 25 unmodified lines
20732071 }
20742072
20752073 HeightfieldRenderer::HeightfieldRenderer() {
2076− glGenTextures(1, &_heightTextureID);
2077− glBindTexture(GL_TEXTURE_2D, _heightTextureID);
2078− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2079− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2080− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2081− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2082−
2083− glGenTextures(1, &_colorTextureID);
2084− glBindTexture(GL_TEXTURE_2D, _colorTextureID);
2085− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2086− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2087− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2088−
2089− glGenTextures(1, &_materialTextureID);
2090− glBindTexture(GL_TEXTURE_2D, _materialTextureID);
2091− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2092− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2093− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2094− glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2095−
2096− glBindTexture(GL_TEXTURE_2D, 0);
20972074 }
20982075
2099−HeightfieldRenderer::~HeightfieldRenderer() {
2100− glDeleteTextures(1, &_heightTextureID);
2101− glDeleteTextures(1, &_colorTextureID);
2102− glDeleteTextures(1, &_materialTextureID);
2076+const int X_MAXIMUM_FLAG = 1;
2077+const int Y_MAXIMUM_FLAG = 2;
2078+
2079+static void renderNode(const HeightfieldNodePointer& node, Heightfield* heightfield, const MetavoxelLOD& lod,
2080+ const glm::vec2& minimum, float size, bool contained, bool cursor) {
2081+ const glm::quat& rotation = heightfield->getRotation();
2082+ glm::vec3 scale(heightfield->getScale() * size, heightfield->getScale() * heightfield->getAspectY(),
2083+ heightfield->getScale() * heightfield->getAspectZ() * size);
2084+ glm::vec3 translation = heightfield->getTranslation() + rotation * glm::vec3(minimum.x * heightfield->getScale(),
2085+ 0.0f, minimum.y * heightfield->getScale() * heightfield->getAspectZ());
2086+ if (!contained) {
2087+ Frustum::IntersectionType type = Application::getInstance()->getMetavoxels()->getFrustum().getIntersectionType(
2088+ glm::translate(translation) * glm::mat4_cast(rotation) * Box(glm::vec3(), scale));
2089+ if (type == Frustum::NO_INTERSECTION) {
2090+ return;
2091+ }
2092+ if (type == Frustum::CONTAINS_INTERSECTION) {
2093+ contained = true;
2094+ }
2095+ }
2096+ if (!node->isLeaf() && lod.shouldSubdivide(minimum, size)) {
2097+ float nextSize = size * 0.5f;
2098+ for (int i = 0; i < HeightfieldNode::CHILD_COUNT; i++) {
2099+ renderNode(node->getChild(i), heightfield, lod, minimum + glm::vec2(i & X_MAXIMUM_FLAG ? nextSize : 0.0f,
2100+ i & Y_MAXIMUM_FLAG ? nextSize : 0.0f), nextSize, contained, cursor);
2101+ }
2102+ return;
2103+ }
2104+ HeightfieldNodeRenderer* renderer = static_cast<HeightfieldNodeRenderer*>(node->getRenderer());
2105+ if (!renderer) {
2106+ node->setRenderer(renderer = new HeightfieldNodeRenderer());
2107+ }
2108+ renderer->render(node, translation, rotation, scale, cursor);
21032109 }
21042110
2105−void HeightfieldRenderer::init(Spanner* spanner) {
2106− SpannerRenderer::init(spanner);
2107−
2108− Heightfield* heightfield = static_cast<Heightfield*>(spanner);
2109− applyHeight(heightfield->getHeight());
2110− applyColor(heightfield->getColor());
2111− applyMaterial(heightfield->getMaterial());
2112−
2113− connect(heightfield, &Heightfield::heightChanged, this, &HeightfieldRenderer::applyHeight);
2114− connect(heightfield, &Heightfield::colorChanged, this, &HeightfieldRenderer::applyColor);
2115− connect(heightfield, &Heightfield::materialChanged, this, &HeightfieldRenderer::applyMaterial);
2111+void HeightfieldRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) {
2112+ Heightfield* heightfield = static_cast<Heightfield*>(_spanner);
2113+ renderNode(heightfield->getRoot(), heightfield, heightfield->transformLOD(lod), glm::vec2(), 1.0f, contained, cursor);
21162114 }
21172115
2118−void HeightfieldRenderer::render(bool cursor) {
2119− // create the buffer objects lazily
2120− Heightfield* heightfield = static_cast<Heightfield*>(_spanner);
2121− if (!heightfield->getHeight()) {
2116+HeightfieldNodeRenderer::HeightfieldNodeRenderer() :
2117+ _heightTextureID(0),
2118+ _colorTextureID(0),
2119+ _materialTextureID(0) {
2120+}
2121+
2122+HeightfieldNodeRenderer::~HeightfieldNodeRenderer() {
2123+ QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures", Q_ARG(int, _heightTextureID),
2124+ Q_ARG(int, _colorTextureID), Q_ARG(int, _materialTextureID));
2125+}
2126+
2127+void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const glm::vec3& translation,
2128+ const glm::quat& rotation, const glm::vec3& scale, bool cursor) {
2129+ if (!node->getHeight()) {
21222130 return;
21232131 }
2124− int width = heightfield->getHeight()->getWidth();
2125− int height = heightfield->getHeight()->getContents().size() / width;
2126−
2132+ int width = node->getHeight()->getWidth();
2133+ int height = node->getHeight()->getContents().size() / width;
21272134 int innerWidth = width - 2 * HeightfieldHeight::HEIGHT_BORDER;
21282135 int innerHeight = height - 2 * HeightfieldHeight::HEIGHT_BORDER;
21292136 int vertexCount = width * height;
@@ -2180,17 +2187,76 @@ void HeightfieldRenderer::render(bool cursor) { · 50 unmodified lines
21802187 bufferPair.second.allocate(indices.constData(), indexCount * sizeof(int));
21812188 bufferPair.second.release();
21822189 }
2190+ if (_heightTextureID == 0) {
2191+ // we use non-aligned data for the various layers
2192+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2193+
2194+ glGenTextures(1, &_heightTextureID);
2195+ glBindTexture(GL_TEXTURE_2D, _heightTextureID);
2196+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2197+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2198+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2199+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2200+ const QVector<quint16>& heightContents = node->getHeight()->getContents();
2201+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, width, height, 0,
2202+ GL_RED, GL_UNSIGNED_SHORT, heightContents.constData());
2203+
2204+ glGenTextures(1, &_colorTextureID);
2205+ glBindTexture(GL_TEXTURE_2D, _colorTextureID);
2206+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2207+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2208+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2209+ if (node->getColor()) {
2210+ const QByteArray& contents = node->getColor()->getContents();
2211+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, node->getColor()->getWidth(),
2212+ contents.size() / (node->getColor()->getWidth() * DataBlock::COLOR_BYTES),
2213+ 0, GL_RGB, GL_UNSIGNED_BYTE, contents.constData());
2214+
2215+ } else {
2216+ const quint8 WHITE_COLOR[] = { 255, 255, 255 };
2217+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
2218+ }
2219+
2220+ glGenTextures(1, &_materialTextureID);
2221+ glBindTexture(GL_TEXTURE_2D, _materialTextureID);
2222+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2223+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2224+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2225+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2226+ if (node->getMaterial()) {
2227+ const QByteArray& contents = node->getMaterial()->getContents();
2228+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, node->getMaterial()->getWidth(),
2229+ contents.size() / node->getMaterial()->getWidth(),
2230+ 0, GL_RED, GL_UNSIGNED_BYTE, contents.constData());
2231+
2232+ const QVector<SharedObjectPointer>& materials = node->getMaterial()->getMaterials();
2233+ _networkTextures.resize(materials.size());
2234+ for (int i = 0; i < materials.size(); i++) {
2235+ const SharedObjectPointer& material = materials.at(i);
2236+ if (material) {
2237+ _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
2238+ static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
2239+ }
2240+ }
2241+ } else {
2242+ const quint8 ZERO_VALUE = 0;
2243+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, &ZERO_VALUE);
2244+ }
2245+ glBindTexture(GL_TEXTURE_2D, 0);
2246+
2247+ // restore the default alignment; it's what Qt uses for image storage
2248+ glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
2249+ }
21832250
2184− float xScale = heightfield->getScale(), zScale = xScale * heightfield->getAspectZ();
21852251 if (cursor) {
21862252 bufferPair.first.bind();
21872253 bufferPair.second.bind();
21882254
21892255 glPushMatrix();
2190− glTranslatef(heightfield->getTranslation().x, heightfield->getTranslation().y, heightfield->getTranslation().z);
2191− glm::vec3 axis = glm::axis(heightfield->getRotation());
2192− glRotatef(glm::degrees(glm::angle(heightfield->getRotation())), axis.x, axis.y, axis.z);
2193− glScalef(xScale, xScale * heightfield->getAspectY(), zScale);
2256+ glTranslatef(translation.x, translation.y, translation.z);
2257+ glm::vec3 axis = glm::axis(rotation);
2258+ glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
2259+ glScalef(scale.x, scale.y, scale.z);
21942260
21952261 HeightfieldPoint* point = 0;
21962262 glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex);
@@ -2208,13 +2274,12 @@ void HeightfieldRenderer::render(bool cursor) { · 11 unmodified lines
22082274 bufferPair.second.release();
22092275 return;
22102276 }
2211−
22122277 HeightfieldBaseLayerBatch baseBatch;
22132278 baseBatch.vertexBuffer = &bufferPair.first;
22142279 baseBatch.indexBuffer = &bufferPair.second;
2215− baseBatch.translation = heightfield->getTranslation();
2216− baseBatch.rotation = heightfield->getRotation();
2217− baseBatch.scale = glm::vec3(xScale, xScale * heightfield->getAspectY(), zScale);
2280+ baseBatch.translation = translation;
2281+ baseBatch.rotation = rotation;
2282+ baseBatch.scale = scale;
22182283 baseBatch.vertexCount = vertexCount;
22192284 baseBatch.indexCount = indexCount;
22202285 baseBatch.heightTextureID = _heightTextureID;
@@ -2223,13 +2288,13 @@ void HeightfieldRenderer::render(bool cursor) { · 2 unmodified lines
22232288 baseBatch.colorScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
22242289 Application::getInstance()->getMetavoxels()->addHeightfieldBaseBatch(baseBatch);
22252290
2226− if (heightfield->getMaterial() && !_networkTextures.isEmpty()) {
2291+ if (!_networkTextures.isEmpty()) {
22272292 HeightfieldSplatBatch splatBatch;
22282293 splatBatch.vertexBuffer = &bufferPair.first;
22292294 splatBatch.indexBuffer = &bufferPair.second;
2230− splatBatch.translation = heightfield->getTranslation();
2231− splatBatch.rotation = heightfield->getRotation();
2232− splatBatch.scale = glm::vec3(xScale, xScale * heightfield->getAspectY(), zScale);
2295+ splatBatch.translation = translation;
2296+ splatBatch.rotation = rotation;
2297+ splatBatch.scale = scale;
22332298 splatBatch.vertexCount = vertexCount;
22342299 splatBatch.indexCount = indexCount;
22352300 splatBatch.heightTextureID = _heightTextureID;
@@ -2237,10 +2302,10 @@ void HeightfieldRenderer::render(bool cursor) { · 1 unmodified line
22372302 splatBatch.materialTextureID = _materialTextureID;
22382303 splatBatch.textureScale = glm::vec2((float)width / innerWidth, (float)height / innerHeight);
22392304 splatBatch.splatTextureOffset = glm::vec2(
2240− glm::dot(heightfield->getTranslation(), heightfield->getRotation() * glm::vec3(1.0f, 0.0f, 0.0f)) / xScale,
2241− glm::dot(heightfield->getTranslation(), heightfield->getRotation() * glm::vec3(0.0f, 0.0f, 1.0f)) / zScale);
2305+ glm::dot(translation, rotation * glm::vec3(1.0f, 0.0f, 0.0f)) / scale.x,
2306+ glm::dot(translation, rotation * glm::vec3(0.0f, 0.0f, 1.0f)) / scale.z);
22422307
2243− const QVector<SharedObjectPointer>& materials = heightfield->getMaterial()->getMaterials();
2308+ const QVector<SharedObjectPointer>& materials = node->getMaterial()->getMaterials();
22442309 for (int i = 0; i < materials.size(); i += SPLAT_COUNT) {
22452310 for (int j = 0; j < SPLAT_COUNT; j++) {
22462311 int index = i + j;
@@ -2248,8 +2313,8 @@ void HeightfieldRenderer::render(bool cursor) { · 1 unmodified line
22482313 const NetworkTexturePointer& texture = _networkTextures.at(index);
22492314 if (texture) {
22502315 MaterialObject* material = static_cast<MaterialObject*>(materials.at(index).data());
2251− splatBatch.splatTextureScalesS[j] = xScale / material->getScaleS();
2252− splatBatch.splatTextureScalesT[j] = zScale / material->getScaleT();
2316+ splatBatch.splatTextureScalesS[j] = scale.x / material->getScaleS();
2317+ splatBatch.splatTextureScalesT[j] = scale.z / material->getScaleT();
22532318 splatBatch.splatTextureIDs[j] = texture->getID();
22542319
22552320 } else {
@@ -2265,61 +2330,4 @@ void HeightfieldRenderer::render(bool cursor) { · 9 unmodified lines
22652330 }
22662331 }
22672332
2268−void HeightfieldRenderer::applyHeight(const HeightfieldHeightPointer& height) {
2269− glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2270− glBindTexture(GL_TEXTURE_2D, _heightTextureID);
2271− if (height) {
2272− const QVector<quint16>& contents = height->getContents();
2273− glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, height->getWidth(), contents.size() / height->getWidth(), 0,
2274− GL_RED, GL_UNSIGNED_SHORT, contents.constData());
2275−
2276− } else {
2277− const quint16 ZERO_VALUE = 0;
2278− glTexImage2D(GL_TEXTURE_2D, 0, GL_R16, 1, 1, 0, GL_RED, GL_UNSIGNED_SHORT, &ZERO_VALUE);
2279− }
2280− glBindTexture(GL_TEXTURE_2D, 0);
2281−}
2282−
2283−void HeightfieldRenderer::applyColor(const HeightfieldColorPointer& color) {
2284− glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2285− glBindTexture(GL_TEXTURE_2D, _colorTextureID);
2286− if (color) {
2287− const QByteArray& contents = color->getContents();
2288− glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, color->getWidth(),
2289− contents.size() / (color->getWidth() * DataBlock::COLOR_BYTES), 0, GL_RGB, GL_UNSIGNED_BYTE, contents.constData());
2290−
2291− } else {
2292− const quint8 WHITE_COLOR[] = { 255, 255, 255 };
2293− glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, WHITE_COLOR);
2294− }
2295− glBindTexture(GL_TEXTURE_2D, 0);
2296−}
2297−
2298−void HeightfieldRenderer::applyMaterial(const HeightfieldMaterialPointer& material) {
2299− glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
2300− glBindTexture(GL_TEXTURE_2D, _materialTextureID);
2301− if (material) {
2302− const QByteArray& contents = material->getContents();
2303− glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, material->getWidth(), contents.size() / material->getWidth(), 0,
2304− GL_RED, GL_UNSIGNED_BYTE, contents.constData());
2305−
2306− const QVector<SharedObjectPointer>& materials = material->getMaterials();
2307− _networkTextures.resize(materials.size());
2308− for (int i = 0; i < materials.size(); i++) {
2309− const SharedObjectPointer& material = materials.at(i);
2310− if (material) {
2311− _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
2312− static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
2313− } else {
2314− _networkTextures[i].clear();
2315− }
2316− }
2317− } else {
2318− const quint8 ZERO_VALUE = 0;
2319− glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_UNSIGNED_BYTE, &ZERO_VALUE);
2320− _networkTextures.clear();
2321− }
2322− glBindTexture(GL_TEXTURE_2D, 0);
2323−}
2324−
2325−QHash<HeightfieldRenderer::IntPair, HeightfieldRenderer::BufferPair> HeightfieldRenderer::_bufferPairs;
2333+QHash<HeightfieldNodeRenderer::IntPair, HeightfieldNodeRenderer::BufferPair> HeightfieldNodeRenderer::_bufferPairs;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t