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
45 }45 }
46 _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);46 _buffer.setUsagePattern(QOpenGLBuffer::DynamicDraw);
47 _buffer.create();47 _buffer.create();
48 _pointBufferAttribute = AttributeRegistry::getInstance()->registerAttribute(new PointBufferAttribute());
48}49}
49 50
50MetavoxelLOD MetavoxelSystem::getLOD() const {51MetavoxelLOD MetavoxelSystem::getLOD() const {
@@ -209,11 +210,66 @@ int MetavoxelSystemClient::parseData(const QByteArray& packet) { · 158 unmodified lines
209 return packet.size();210 return packet.size();
210}211}
211 212
213class BufferBuilder : public MetavoxelVisitor {
214public:
215
216 BufferBuilder(const MetavoxelLOD& lod);
217
218 virtual int visit(MetavoxelInfo& info);
219};
220
221BufferBuilder::BufferBuilder(const MetavoxelLOD& lod) :
222 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getColorAttribute() <<
223 AttributeRegistry::getInstance()->getNormalAttribute(), QVector<AttributePointer>(), lod) {
224}
225
226int BufferBuilder::visit(MetavoxelInfo& info) {
227 if (info.isLeaf) {
228
229 return STOP_RECURSION;
230 }
231 return DEFAULT_ORDER;
232}
233
234void MetavoxelSystemClient::dataChanged(const MetavoxelData& oldData) {
235 BufferBuilder builder(_remoteDataLOD);
236 _data.guideToDifferent(oldData, builder);
237}
238
212void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {239void MetavoxelSystemClient::sendDatagram(const QByteArray& data) {
213 NodeList::getInstance()->writeDatagram(data, _node);240 NodeList::getInstance()->writeDatagram(data, _node);
214 Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size());241 Application::getInstance()->getBandwidthMeter()->outputStream(BandwidthMeter::METAVOXELS).updateValue(data.size());
215}242}
216 243
244PointBuffer::PointBuffer(const QOpenGLBuffer& buffer, const QVector<int>& offsets, int lastLeafCount) :
245 _buffer(buffer),
246 _offsets(offsets),
247 _lastLeafCount(lastLeafCount) {
248}
249
250void 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
269PointBufferAttribute::PointBufferAttribute() :
270 SharedPointerAttribute<PointBuffer>("pointBuffer") {
271}
272
217static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {273static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {
218 GLdouble coefficients[] = { x, y, z, w };274 GLdouble coefficients[] = { x, y, z, w };
219 glClipPlane(plane, coefficients);275 glClipPlane(plane, coefficients);