Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -45,6 +45,7 @@ void MetavoxelSystem::init() { · 44 unmodified lines | ||
| 45 | 45 | } |
| 46 | 46 | _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw); |
| 47 | 47 | _buffer.create(); |
| 48 | + _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new PointBufferAttribute()); | |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | MetavoxelLOD MetavoxelSystem::getLOD() const { |
| @@ -209,11 +210,66 @@ int MetavoxelSystemClient::parseData(const QByteArray& packet) { · 158 unmodified lines | ||
| 209 | 210 | return packet.size(); |
| 210 | 211 | } |
| 211 | 212 | |
| 213 | +class BufferBuilder : public MetavoxelVisitor { | |
| 214 | +public: | |
| 215 | + | |
| 216 | + BufferBuilder(const MetavoxelLOD& lod); | |
| 217 | + | |
| 218 | + virtual int visit(MetavoxelInfo& info); | |
| 219 | +}; | |
| 220 | + | |
| 221 | +BufferBuilder::BufferBuilder(const MetavoxelLOD& lod) : | |
| 222 | + MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() << | |
| 223 | + AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>(), lod) { | |
| 224 | +} | |
| 225 | + | |
| 226 | +int BufferBuilder::visit(MetavoxelInfo& info) { | |
| 227 | + if (info.isLeaf) { | |
| 228 | + | |
| 229 | + return STOP_RECURSION; | |
| 230 | + } | |
| 231 | + return DEFAULT_ORDER; | |
| 232 | +} | |
| 233 | + | |
| 234 | +void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) { | |
| 235 | + BufferBuilder builder(_remoteDataLOD); | |
| 236 | + _data.guideToDifferent(oldData, builder); | |
| 237 | +} | |
| 238 | + | |
| 212 | 239 | void MetavoxelSystemClient::sendDatagram(const QByteArray& data) { |
| 213 | 240 | NodeList::getInstance()->writeDatagram(data, _node); |
| 214 | 241 | Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size()); |
| 215 | 242 | } |
| 216 | 243 | |
| 244 | +PointBuffer::PointBuffer(const QOpenGLBuffer& buffer, const QVector<int>& offsets, int lastLeafCount) : | |
| 245 | + _buffer(buffer), | |
| 246 | + _offsets(offsets), | |
| 247 | + _lastLeafCount(lastLeafCount) { | |
| 248 | +} | |
| 249 | + | |
| 250 | +void PointBuffer::render(int level) { | |
| 251 | + _buffer.bind(); | |
| 252 | + | |
| 253 | + BufferPoint* point = 0; | |
| 254 | + glVertexPointer(4, GL_FLOAT, sizeof(BufferPoint), &point->vertex); | |
| 255 | + glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(BufferPoint), &point->color); | |
| 256 | + glNormalPointer(GL_BYTE, sizeof(BufferPoint), &point->normal); | |
| 257 | + | |
| 258 | + int nextLevel = level + 1; | |
| 259 | + if (nextLevel >= _offsets.size()) { | |
| 260 | + glDrawArrays(GL_POINTS, _offsets.last() - _lastLeafCount, _lastLeafCount); | |
| 261 | + | |
| 262 | + } else { | |
| 263 | + int first = _offsets.at(level); | |
| 264 | + glDrawArrays(GL_POINTS, first, _offsets.at(nextLevel) - first); | |
| 265 | + } | |
| 266 | + _buffer.release(); | |
| 267 | +} | |
| 268 | + | |
| 269 | +PointBufferAttribute::PointBufferAttribute() : | |
| 270 | + SharedPointerAttribute<PointBuffer>("pointBuffer") { | |
| 271 | +} | |
| 272 | + | |
| 217 | 273 | static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { |
| 218 | 274 | GLdouble coefficients[] = { x, y, z, w }; |
| 219 | 275 | glClipPlane(plane, coefficients); |