History

Working on heightfield transmission, merging.

Andrzej Kapolka committed 12 years ago

Commit 82e442c1 parent ff01d4b6 files · +220 −32Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+41−24
@@ -29,6 +29,7 @@ REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) · 28 unmodified lines
2929 REGISTER_META_OBJECT(SphereRenderer)
3030 REGISTER_META_OBJECT(StaticModelRenderer)
3131
32+static int texturePointerMetaTypeId = qRegisterMetaType<TexturePointer>();
3233 static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
3334
3435 void MetavoxelSystem::init() {
@@ -112,6 +113,11 @@ void MetavoxelSystem::render() { · 77 unmodified lines
112113 guideToAugmented(renderVisitor);
113114 }
114115
116+void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) {
117+ delete height;
118+ delete color;
119+}
120+
115121 MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
116122 return new MetavoxelSystemClient(node, _updater);
117123 }
@@ -261,8 +267,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, · 143 unmodified lines
261267 _height(height),
262268 _color(color),
263269 _clearAfterLoading(clearAfterLoading),
264− _heightTexture(QOpenGLTexture::Target2D),
265− _colorTexture(QOpenGLTexture::Target2D) {
270+ _heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)),
271+ _colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) {
272+}
273+
274+HeightfieldBuffer::~HeightfieldBuffer() {
275+ // the textures have to be deleted on the main thread (for its opengl context)
276+ if (QThread::currentThread() != Application::getInstance()->thread()) {
277+ QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",
278+ Q_ARG(const TexturePointer&, _heightTexture), Q_ARG(const TexturePointer&, _colorTexture));
279+ } else {
280+ delete _heightTexture;
281+ delete _colorTexture;
282+ }
266283 }
267284
268285 class HeightfieldPoint {
@@ -273,39 +290,39 @@ public: · 4 unmodified lines
273290
274291 void HeightfieldBuffer::render() {
275292 // initialize textures, etc. on first render
276− if (!_heightTexture.isCreated()) {
293+ if (!_heightTexture->isCreated()) {
277294 int heightSize = glm::sqrt(_height.size());
278− _heightTexture.setSize(heightSize, heightSize);
279− _heightTexture.setAutoMipMapGenerationEnabled(false);
280− _heightTexture.setMinificationFilter(QOpenGLTexture::Linear);
281− _heightTexture.setWrapMode(QOpenGLTexture::ClampToEdge);
282− _heightTexture.setFormat(QOpenGLTexture::LuminanceFormat);
283− _heightTexture.allocateStorage();
284− _heightTexture.setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
295+ _heightTexture->setSize(heightSize, heightSize);
296+ _heightTexture->setAutoMipMapGenerationEnabled(false);
297+ _heightTexture->setMinificationFilter(QOpenGLTexture::Linear);
298+ _heightTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
299+ _heightTexture->setFormat(QOpenGLTexture::LuminanceFormat);
300+ _heightTexture->allocateStorage();
301+ _heightTexture->setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
285302 if (_clearAfterLoading) {
286303 _height.clear();
287304 }
288305 if (!_color.isEmpty()) {
289306 int colorSize = glm::sqrt(_color.size() / 3);
290− _colorTexture.setSize(colorSize, colorSize);
307+ _colorTexture->setSize(colorSize, colorSize);
291308 }
292− _colorTexture.setAutoMipMapGenerationEnabled(false);
293− _colorTexture.setMinificationFilter(QOpenGLTexture::Linear);
294− _colorTexture.setWrapMode(QOpenGLTexture::ClampToEdge);
295− _colorTexture.setFormat(QOpenGLTexture::RGBFormat);
296− _colorTexture.allocateStorage();
309+ _colorTexture->setAutoMipMapGenerationEnabled(false);
310+ _colorTexture->setMinificationFilter(QOpenGLTexture::Linear);
311+ _colorTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
312+ _colorTexture->setFormat(QOpenGLTexture::RGBFormat);
313+ _colorTexture->allocateStorage();
297314 if (!_color.isEmpty()) {
298− _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());
315+ _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());
299316 if (_clearAfterLoading) {
300317 _color.clear();
301318 }
302319 } else {
303320 const quint8 WHITE_COLOR[] = { 255, 255, 255 };
304− _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
321+ _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
305322 }
306323 }
307324 // create the buffer objects lazily
308− int size = _heightTexture.width();
325+ int size = _heightTexture->width();
309326 int sizeWithSkirt = size + 2;
310327 int vertexCount = sizeWithSkirt * sizeWithSkirt;
311328 int rows = sizeWithSkirt - 1;
@@ -363,13 +380,13 @@ void HeightfieldBuffer::render() { · 51 unmodified lines
363380 glTranslatef(_translation.x, _translation.y, _translation.z);
364381 glScalef(_scale, _scale, _scale);
365382
366− _heightTexture.bind(0);
367− _colorTexture.bind(1);
383+ _heightTexture->bind(0);
384+ _colorTexture->bind(1);
368385
369386 glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
370387
371− _colorTexture.release(1);
372− _heightTexture.release(0);
388+ _colorTexture->release(1);
389+ _heightTexture->release(0);
373390
374391 glPopMatrix();
375392
@@ -678,7 +695,7 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 302 unmodified lines
678695
679696 _pointProgram.release();
680697
681− glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
698+ glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
682699
683700 _heightfieldProgram.bind();
684701