History

Progress on rendering heightfield buffers.

Andrzej Kapolka committed 12 years ago

Commit 68244791 parent 2a7847c4 files · +50 −8Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+19−4
@@ -275,6 +275,9 @@ void HeightfieldBuffer::render() { · 274 unmodified lines
275275 if (!_heightTexture.isCreated()) {
276276 int heightSize = glm::sqrt(_height.size());
277277 _heightTexture.setSize(heightSize, heightSize);
278+ _heightTexture.setAutoMipMapGenerationEnabled(false);
279+ _heightTexture.setMinificationFilter(QOpenGLTexture::Linear);
280+ _heightTexture.setWrapMode(QOpenGLTexture::ClampToEdge);
278281 _heightTexture.setFormat(QOpenGLTexture::LuminanceFormat);
279282 _heightTexture.allocateStorage();
280283 _heightTexture.setData(QOpenGLTexture::Luminance, QOpenGLTexture::UInt8, _height.data());
@@ -284,15 +287,18 @@ void HeightfieldBuffer::render() { · 3 unmodified lines
284287 int colorSize = glm::sqrt(_color.size() / 3);
285288 _colorTexture.setSize(colorSize, colorSize);
286289 }
290+ _colorTexture.setAutoMipMapGenerationEnabled(false);
291+ _colorTexture.setMinificationFilter(QOpenGLTexture::Linear);
292+ _colorTexture.setWrapMode(QOpenGLTexture::ClampToEdge);
287293 _colorTexture.setFormat(QOpenGLTexture::RGBFormat);
288294 _colorTexture.allocateStorage();
289295 if (!_color.isEmpty()) {
290− _colorTexture.setData(QOpenGLTexture::BGR, QOpenGLTexture::UInt8, _color.data());
296+ _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, _color.data());
291297 _color.clear();
292298
293299 } else {
294300 const quint8 WHITE_COLOR[] = { 255, 255, 255 };
295− _colorTexture.setData(QOpenGLTexture::BGR, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
301+ _colorTexture.setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt8, const_cast<quint8*>(WHITE_COLOR));
296302 }
297303 }
298304 // create the buffer objects lazily
@@ -310,7 +316,7 @@ void HeightfieldBuffer::render() { · 11 unmodified lines
310316 float z = -step;
311317 for (int i = 0; i < sizeWithSkirt; i++, z += step) {
312318 float x = -step;
313− const float SKIRT_LENGTH = 1.0f;
319+ const float SKIRT_LENGTH = 0.25f;
314320 float baseY = (i == 0 || i == sizeWithSkirt - 1) ? -SKIRT_LENGTH : 0.0f;
315321 for (int j = 0; j < sizeWithSkirt; j++, point++, x += step) {
316322 point->vertex = glm::vec3(x, (j == 0 || j == sizeWithSkirt - 1) ? -SKIRT_LENGTH : baseY, z);
@@ -331,8 +337,8 @@ void HeightfieldBuffer::render() { · 14 unmodified lines
331337 for (int j = 0; j < rows; j++) {
332338 *index++ = lineIndex + j;
333339 *index++ = lineIndex + j + 1;
334− *index++ = nextLineIndex + j;
335340 *index++ = nextLineIndex + j + 1;
341+ *index++ = nextLineIndex + j;
336342 }
337343 }
338344
@@ -371,6 +377,8 @@ void HeightfieldBuffer::render() { · 32 unmodified lines
371377 QHash<int, HeightfieldBuffer::BufferPair> HeightfieldBuffer::_bufferPairs;
372378
373379 void HeightfieldPreview::render(const glm::vec3& translation, float scale) const {
380+ glColor4f(1.0f, 1.0f, 1.0f, 0.75f);
381+
374382 glEnableClientState(GL_VERTEX_ARRAY);
375383 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
376384
@@ -422,6 +430,11 @@ void DefaultMetavoxelRendererImplementation::init() { · 45 unmodified lines
422430 _heightfieldProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() +
423431 "shaders/metavoxel_heightfield.frag");
424432 _heightfieldProgram.link();
433+
434+ _heightfieldProgram.bind();
435+ _heightfieldProgram.setUniformValue("heightMap", 0);
436+ _heightfieldProgram.setUniformValue("diffuseMap", 1);
437+ _heightfieldProgram.release();
425438 }
426439 }
427440
@@ -662,6 +675,8 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 234 unmodified lines
662675
663676 _pointProgram.release();
664677
678+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
679+
665680 _heightfieldProgram.bind();
666681
667682 glEnableClientState(GL_TEXTURE_COORD_ARRAY);