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
29REGISTER_META_OBJECT(SphereRenderer)29REGISTER_META_OBJECT(SphereRenderer)
30REGISTER_META_OBJECT(StaticModelRenderer)30REGISTER_META_OBJECT(StaticModelRenderer)
31 31
32static int texturePointerMetaTypeId = qRegisterMetaType<TexturePointer>();
32static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();33static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>();
33 34
34void MetavoxelSystem::init() {35void MetavoxelSystem::init() {
@@ -112,6 +113,11 @@ void MetavoxelSystem::render() { · 77 unmodified lines
112 guideToAugmented(renderVisitor);113 guideToAugmented(renderVisitor);
113}114}
114 115
116void MetavoxelSystem::deleteTextures(const TexturePointer& height, const TexturePointer& color) {
117 delete height;
118 delete color;
119}
120
115MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {121MetavoxelClient* MetavoxelSystem::createClient(const SharedNodePointer& node) {
116 return new MetavoxelSystemClient(node, _updater);122 return new MetavoxelSystemClient(node, _updater);
117}123}
@@ -261,8 +267,19 @@ HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale, · 143 unmodified lines
261 _height(height),267 _height(height),
262 _color(color),268 _color(color),
263 _clearAfterLoading(clearAfterLoading),269 _clearAfterLoading(clearAfterLoading),
264 _heightTexture(QOpenGLTexture::Target2D),270 _heightTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)),
265 _colorTexture(QOpenGLTexture::Target2D) {271 _colorTexture(new QOpenGLTexture(QOpenGLTexture::Target2D)) {
272}
273
274HeightfieldBuffer::~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 }
266}283}
267 284
268class HeightfieldPoint {285class HeightfieldPoint {
@@ -273,39 +290,39 @@ public: · 4 unmodified lines
273 290
274void HeightfieldBuffer::render() {291void HeightfieldBuffer::render() {
275 // initialize textures, etc. on first render292 // initialize textures, etc. on first render
276 if (!_heightTexture.isCreated()) {293 if (!_heightTexture->isCreated()) {
277 int heightSize = glm::sqrt(_height.size());294 int heightSize = glm::sqrt(_height.size());
278 _heightTexture.setSize(heightSize, heightSize);295 _heightTexture->setSize(heightSize, heightSize);
279 _heightTexture.setAutoMipMapGenerationEnabled(false);296 _heightTexture->setAutoMipMapGenerationEnabled(false);
280 _heightTexture.setMinificationFilter(QOpenGLTexture::Linear);297 _heightTexture->setMinificationFilter(QOpenGLTexture::Linear);
281 _heightTexture.setWrapMode(QOpenGLTexture::ClampToEdge);298 _heightTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
282 _heightTexture.setFormat(QOpenGLTexture::LuminanceFormat);299 _heightTexture->setFormat(QOpenGLTexture::LuminanceFormat);
283 _heightTexture.allocateStorage();300 _heightTexture->allocateStorage();
284 _heightTexture.setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());301 _heightTexture->setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
285 if (_clearAfterLoading) {302 if (_clearAfterLoading) {
286 _height.clear();303 _height.clear();
287 }304 }
288 if (!_color.isEmpty()) {305 if (!_color.isEmpty()) {
289 int colorSize = glm::sqrt(_color.size() / 3);306 int colorSize = glm::sqrt(_color.size() / 3);
290 _colorTexture.setSize(colorSize, colorSize);307 _colorTexture->setSize(colorSize, colorSize);
291 }308 }
292 _colorTexture.setAutoMipMapGenerationEnabled(false);309 _colorTexture->setAutoMipMapGenerationEnabled(false);
293 _colorTexture.setMinificationFilter(QOpenGLTexture::Linear);310 _colorTexture->setMinificationFilter(QOpenGLTexture::Linear);
294 _colorTexture.setWrapMode(QOpenGLTexture::ClampToEdge);311 _colorTexture->setWrapMode(QOpenGLTexture::ClampToEdge);
295 _colorTexture.setFormat(QOpenGLTexture::RGBFormat);312 _colorTexture->setFormat(QOpenGLTexture::RGBFormat);
296 _colorTexture.allocateStorage();313 _colorTexture->allocateStorage();
297 if (!_color.isEmpty()) {314 if (!_color.isEmpty()) {
298 _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());315 _colorTexture->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());
299 if (_clearAfterLoading) {316 if (_clearAfterLoading) {
300 _color.clear();317 _color.clear();
301 }318 }
302 } else {319 } else {
303 const quint8 WHITE_COLOR[] = { 255, 255, 255 };320 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));
305 }322 }
306 }323 }
307 // create the buffer objects lazily324 // create the buffer objects lazily
308 int size = _heightTexture.width();325 int size = _heightTexture->width();
309 int sizeWithSkirt = size + 2;326 int sizeWithSkirt = size + 2;
310 int vertexCount = sizeWithSkirt * sizeWithSkirt;327 int vertexCount = sizeWithSkirt * sizeWithSkirt;
311 int rows = sizeWithSkirt - 1;328 int rows = sizeWithSkirt - 1;
@@ -363,13 +380,13 @@ void HeightfieldBuffer::render() { · 51 unmodified lines
363 glTranslatef(_translation.x, _translation.y, _translation.z);380 glTranslatef(_translation.x, _translation.y, _translation.z);
364 glScalef(_scale, _scale, _scale);381 glScalef(_scale, _scale, _scale);
365 382
366 _heightTexture.bind(0);383 _heightTexture->bind(0);
367 _colorTexture.bind(1);384 _colorTexture->bind(1);
368 385
369 glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);386 glDrawRangeElements(GL_QUADS, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
370 387
371 _colorTexture.release(1);388 _colorTexture->release(1);
372 _heightTexture.release(0);389 _heightTexture->release(0);
373 390
374 glPopMatrix();391 glPopMatrix();
375 392
@@ -678,7 +695,7 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 302 unmodified lines
678 695
679 _pointProgram.release();696 _pointProgram.release();
680 697
681 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);698 glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
682 699
683 _heightfieldProgram.bind();700 _heightfieldProgram.bind();
684 701