History

Working on point buffer building.

Andrzej Kapolka committed 12 years ago

Commit 64c3a621 parent 7355fb65 files · +126 −2Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+56−0
@@ -45,6 +45,7 @@ void MetavoxelSystem::init() { · 44 unmodified lines
4545 }
4646 _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
4747 _buffer.create();
48+ _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new PointBufferAttribute());
4849 }
4950
5051 MetavoxelLOD MetavoxelSystem::getLOD() const {
@@ -209,11 +210,66 @@ int MetavoxelSystemClient::parseData(const QByteArray& packet) { · 158 unmodified lines
209210 return packet.size();
210211 }
211212
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+
212239 void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {
213240 NodeList::getInstance()->writeDatagram(data, _node);
214241 Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size());
215242 }
216243
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+
217273 static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {
218274 GLdouble coefficients[] = { x, y, z, w };
219275 glClipPlane(plane, coefficients);