History

HeightfieldTexture -> MaterialObject (we want to use it for voxels, too, and eventually include components other than diffuse color).

Andrzej Kapolka committed 12 years ago

Commit e454a081 parent 0aefa378 files · +281 −213Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+34−34
@@ -608,19 +608,19 @@ const int HeightfieldBuffer::SHARED_EDGE = 1; · 607 unmodified lines
608const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE;608const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE;
609 609
610HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale,610HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale,
611 const QByteArray& height, const QByteArray& color, const QByteArray& texture,611 const QByteArray& height, const QByteArray& color, const QByteArray& material,
612 const QVector<SharedObjectPointer>& textures) :612 const QVector<SharedObjectPointer>& materials) :
613 _translation(translation),613 _translation(translation),
614 _scale(scale),614 _scale(scale),
615 _heightBounds(translation, translation + glm::vec3(scale, scale, scale)),615 _heightBounds(translation, translation + glm::vec3(scale, scale, scale)),
616 _colorBounds(_heightBounds),616 _colorBounds(_heightBounds),
617 _height(height),617 _height(height),
618 _color(color),618 _color(color),
619 _texture(texture),619 _material(material),
620 _textures(textures),620 _materials(materials),
621 _heightTextureID(0),621 _heightTextureID(0),
622 _colorTextureID(0),622 _colorTextureID(0),
623 _textureTextureID(0),623 _materialTextureID(0),
624 _heightSize(glm::sqrt(height.size())),624 _heightSize(glm::sqrt(height.size())),
625 _heightIncrement(scale / (_heightSize - HEIGHT_EXTENSION)),625 _heightIncrement(scale / (_heightSize - HEIGHT_EXTENSION)),
626 _colorSize(glm::sqrt(color.size() / DataBlock::COLOR_BYTES)),626 _colorSize(glm::sqrt(color.size() / DataBlock::COLOR_BYTES)),
@@ -639,11 +639,11 @@ HeightfieldBuffer::~HeightfieldBuffer() { · 12 unmodified lines
639 // the textures have to be deleted on the main thread (for its opengl context)639 // the textures have to be deleted on the main thread (for its opengl context)
640 if (QThread::currentThread() != Application::getInstance()->thread()) {640 if (QThread::currentThread() != Application::getInstance()->thread()) {
641 QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",641 QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteTextures",
642 Q_ARG(int, _heightTextureID), Q_ARG(int, _colorTextureID), Q_ARG(int, _textureTextureID));642 Q_ARG(int, _heightTextureID), Q_ARG(int, _colorTextureID), Q_ARG(int, _materialTextureID));
643 } else {643 } else {
644 glDeleteTextures(1, &_heightTextureID);644 glDeleteTextures(1, &_heightTextureID);
645 glDeleteTextures(1, &_colorTextureID);645 glDeleteTextures(1, &_colorTextureID);
646 glDeleteTextures(1, &_textureTextureID);646 glDeleteTextures(1, &_materialTextureID);
647 }647 }
648}648}
649 649
@@ -709,23 +709,23 @@ void HeightfieldBuffer::render(bool cursor) { · 59 unmodified lines
709 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());709 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());
710 }710 }
711 711
712 if (!_texture.isEmpty()) {712 if (!_material.isEmpty()) {
713 glGenTextures(1, &_textureTextureID);713 glGenTextures(1, &_materialTextureID);
714 glBindTexture(GL_TEXTURE_2D, _textureTextureID);714 glBindTexture(GL_TEXTURE_2D, _materialTextureID);
715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
719 int textureSize = glm::sqrt(_texture.size()); 719 int materialSize = glm::sqrt(_material.size());
720 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, textureSize, textureSize, 0,720 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, materialSize, materialSize, 0,
721 GL_LUMINANCE, GL_UNSIGNED_BYTE, _texture.constData());721 GL_LUMINANCE, GL_UNSIGNED_BYTE, _material.constData());
722 722
723 _networkTextures.resize(_textures.size());723 _networkTextures.resize(_materials.size());
724 for (int i = 0; i < _textures.size(); i++) {724 for (int i = 0; i < _materials.size(); i++) {
725 const SharedObjectPointer texture = _textures.at(i);725 const SharedObjectPointer material = _materials.at(i);
726 if (texture) {726 if (material) {
727 _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(727 _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
728 static_cast<HeightfieldTexture*>(texture.data())->getURL(), SPLAT_TEXTURE);728 static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
729 }729 }
730 }730 }
731 }731 }
@@ -799,7 +799,7 @@ void HeightfieldBuffer::render(bool cursor) { · 67 unmodified lines
799 if (cursor) {799 if (cursor) {
800 glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);800 glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
801 801
802 } else if (!_textures.isEmpty()) {802 } else if (!_materials.isEmpty()) {
803 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind();803 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind();
804 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(804 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
805 DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / _heightSize);805 DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / _heightSize);
@@ -826,10 +826,10 @@ void HeightfieldBuffer::render(bool cursor) { · 20 unmodified lines
826 DefaultMetavoxelRendererImplementation::getSplatTextureOffsetLocation(),826 DefaultMetavoxelRendererImplementation::getSplatTextureOffsetLocation(),
827 _translation.x / _scale, _translation.z / _scale);827 _translation.x / _scale, _translation.z / _scale);
828 828
829 glBindTexture(GL_TEXTURE_2D, _textureTextureID);829 glBindTexture(GL_TEXTURE_2D, _materialTextureID);
830 830
831 const int TEXTURES_PER_SPLAT = 4;831 const int TEXTURES_PER_SPLAT = 4;
832 for (int i = 0; i < _textures.size(); i += TEXTURES_PER_SPLAT) {832 for (int i = 0; i < _materials.size(); i += TEXTURES_PER_SPLAT) {
833 QVector4D scalesS, scalesT;833 QVector4D scalesS, scalesT;
834 834
835 for (int j = 0; j < SPLAT_COUNT; j++) {835 for (int j = 0; j < SPLAT_COUNT; j++) {
@@ -838,9 +838,9 @@ void HeightfieldBuffer::render(bool cursor) { · 2 unmodified lines
838 if (index < _networkTextures.size()) {838 if (index < _networkTextures.size()) {
839 const NetworkTexturePointer& texture = _networkTextures.at(index);839 const NetworkTexturePointer& texture = _networkTextures.at(index);
840 if (texture) {840 if (texture) {
841 HeightfieldTexture* heightfieldTexture = static_cast<HeightfieldTexture*>(_textures.at(index).data());841 MaterialObject* material = static_cast<MaterialObject*>(_materials.at(index).data());
842 scalesS[j] = _scale / heightfieldTexture->getScaleS();842 scalesS[j] = _scale / material->getScaleS();
843 scalesT[j] = _scale / heightfieldTexture->getScaleT();843 scalesT[j] = _scale / material->getScaleT();
844 glBindTexture(GL_TEXTURE_2D, texture->getID()); 844 glBindTexture(GL_TEXTURE_2D, texture->getID());
845 } else {845 } else {
846 glBindTexture(GL_TEXTURE_2D, 0);846 glBindTexture(GL_TEXTURE_2D, 0);
@@ -1349,7 +1349,7 @@ private: · 502 unmodified lines
1349HeightfieldRegionVisitor::HeightfieldRegionVisitor(const MetavoxelLOD& lod) :1349HeightfieldRegionVisitor::HeightfieldRegionVisitor(const MetavoxelLOD& lod) :
1350 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getHeightfieldAttribute() <<1350 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getHeightfieldAttribute() <<
1351 AttributeRegistry::getInstance()->getHeightfieldColorAttribute() <<1351 AttributeRegistry::getInstance()->getHeightfieldColorAttribute() <<
1352 AttributeRegistry::getInstance()->getHeightfieldTextureAttribute() <<1352 AttributeRegistry::getInstance()->getHeightfieldMaterialAttribute() <<
1353 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), QVector<AttributePointer>() <<1353 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), QVector<AttributePointer>() <<
1354 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), lod),1354 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), lod),
1355 regionBounds(glm::vec3(FLT_MAX, FLT_MAX, FLT_MAX), glm::vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX)),1355 regionBounds(glm::vec3(FLT_MAX, FLT_MAX, FLT_MAX), glm::vec3(-FLT_MAX, -FLT_MAX, -FLT_MAX)),
@@ -1377,12 +1377,12 @@ int HeightfieldRegionVisitor::visit(MetavoxelInfo& info) { · 21 unmodified lines
1377 colorContentsSize = extendedColorSize * extendedColorSize * DataBlock::COLOR_BYTES;1377 colorContentsSize = extendedColorSize * extendedColorSize * DataBlock::COLOR_BYTES;
1378 }1378 }
1379 1379
1380 HeightfieldTextureDataPointer texture = info.inputValues.at(2).getInlineValue<HeightfieldTextureDataPointer>();1380 HeightfieldMaterialDataPointer material = info.inputValues.at(2).getInlineValue<HeightfieldMaterialDataPointer>();
1381 QByteArray textureContents;1381 QByteArray materialContents;
1382 QVector<SharedObjectPointer> textures;1382 QVector<SharedObjectPointer> materials;
1383 if (texture) {1383 if (material) {
1384 textureContents = texture->getContents();1384 materialContents = material->getContents();
1385 textures = texture->getTextures();1385 materials = material->getMaterials();
1386 }1386 }
1387 1387
1388 const HeightfieldBuffer* existingBuffer = static_cast<const HeightfieldBuffer*>(1388 const HeightfieldBuffer* existingBuffer = static_cast<const HeightfieldBuffer*>(
@@ -1393,12 +1393,12 @@ int HeightfieldRegionVisitor::visit(MetavoxelInfo& info) { · 4 unmodified lines
1393 // we already have a buffer of the correct resolution 1393 // we already have a buffer of the correct resolution
1394 addRegion(bounds, existingBuffer->getHeightBounds());1394 addRegion(bounds, existingBuffer->getHeightBounds());
1395 buffer = new HeightfieldBuffer(info.minimum, info.size, existingBuffer->getHeight(),1395 buffer = new HeightfieldBuffer(info.minimum, info.size, existingBuffer->getHeight(),
1396 existingBuffer->getColor(), textureContents, textures);1396 existingBuffer->getColor(), materialContents, materials);
1397 1397
1398 } else {1398 } else {
1399 // we must create a new buffer and update its borders1399 // we must create a new buffer and update its borders
1400 buffer = new HeightfieldBuffer(info.minimum, info.size, QByteArray(heightContentsSize, 0),1400 buffer = new HeightfieldBuffer(info.minimum, info.size, QByteArray(heightContentsSize, 0),
1401 QByteArray(colorContentsSize, 0), textureContents, textures);1401 QByteArray(colorContentsSize, 0), materialContents, materials);
1402 const Box& heightBounds = buffer->getHeightBounds();1402 const Box& heightBounds = buffer->getHeightBounds();
1403 addRegion(bounds, heightBounds);1403 addRegion(bounds, heightBounds);
1404 1404
@@ -1472,7 +1472,7 @@ int HeightfieldUpdateVisitor::visit(MetavoxelInfo& info) { · 67 unmodified lines
1472 return STOP_RECURSION;1472 return STOP_RECURSION;
1473 }1473 }
1474 HeightfieldBuffer* newBuffer = new HeightfieldBuffer(info.minimum, info.size,1474 HeightfieldBuffer* newBuffer = new HeightfieldBuffer(info.minimum, info.size,
1475 buffer->getHeight(), buffer->getColor(), buffer->getTexture(), buffer->getTextures());1475 buffer->getHeight(), buffer->getColor(), buffer->getMaterial(), buffer->getMaterials());
1476 _fetchVisitor.init(newBuffer);1476 _fetchVisitor.init(newBuffer);
1477 _data->guide(_fetchVisitor);1477 _data->guide(_fetchVisitor);
1478 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(newBuffer)));1478 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(newBuffer)));