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
608608 const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE;
609609
610610 HeightfieldBuffer::HeightfieldBuffer(const glm::vec3& translation, float scale,
611− const QByteArray& height, const QByteArray& color, const QByteArray& texture,
612− const QVector<SharedObjectPointer>& textures) :
611+ const QByteArray& height, const QByteArray& color, const QByteArray& material,
612+ const QVector<SharedObjectPointer>& materials) :
613613 _translation(translation),
614614 _scale(scale),
615615 _heightBounds(translation, translation + glm::vec3(scale, scale, scale)),
616616 _colorBounds(_heightBounds),
617617 _height(height),
618618 _color(color),
619− _texture(texture),
620− _textures(textures),
619+ _material(material),
620+ _materials(materials),
621621 _heightTextureID(0),
622622 _colorTextureID(0),
623− _textureTextureID(0),
623+ _materialTextureID(0),
624624 _heightSize(glm::sqrt(height.size())),
625625 _heightIncrement(scale / (_heightSize - HEIGHT_EXTENSION)),
626626 _colorSize(glm::sqrt(color.size() / DataBlock::COLOR_BYTES)),
@@ -639,11 +639,11 @@ HeightfieldBuffer::~HeightfieldBuffer() { · 12 unmodified lines
639639 // the textures have to be deleted on the main thread (for its opengl context)
640640 if (QThread::currentThread() != Application::getInstance()->thread()) {
641641 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));
643643 } else {
644644 glDeleteTextures(1, &_heightTextureID);
645645 glDeleteTextures(1, &_colorTextureID);
646− glDeleteTextures(1, &_textureTextureID);
646+ glDeleteTextures(1, &_materialTextureID);
647647 }
648648 }
649649
@@ -709,23 +709,23 @@ void HeightfieldBuffer::render(bool cursor) { · 59 unmodified lines
709709 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, colorSize, colorSize, 0, GL_RGB, GL_UNSIGNED_BYTE, _color.constData());
710710 }
711711
712− if (!_texture.isEmpty()) {
713− glGenTextures(1, &_textureTextureID);
714− glBindTexture(GL_TEXTURE_2D, _textureTextureID);
712+ if (!_material.isEmpty()) {
713+ glGenTextures(1, &_materialTextureID);
714+ glBindTexture(GL_TEXTURE_2D, _materialTextureID);
715715 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
716716 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
717717 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
718718 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
719− int textureSize = glm::sqrt(_texture.size());
720− glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, textureSize, textureSize, 0,
721− GL_LUMINANCE, GL_UNSIGNED_BYTE, _texture.constData());
719+ int materialSize = glm::sqrt(_material.size());
720+ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, materialSize, materialSize, 0,
721+ GL_LUMINANCE, GL_UNSIGNED_BYTE, _material.constData());
722722
723− _networkTextures.resize(_textures.size());
724− for (int i = 0; i < _textures.size(); i++) {
725− const SharedObjectPointer texture = _textures.at(i);
726− if (texture) {
723+ _networkTextures.resize(_materials.size());
724+ for (int i = 0; i < _materials.size(); i++) {
725+ const SharedObjectPointer material = _materials.at(i);
726+ if (material) {
727727 _networkTextures[i] = Application::getInstance()->getTextureCache()->getTexture(
728− static_cast<HeightfieldTexture*>(texture.data())->getURL(), SPLAT_TEXTURE);
728+ static_cast<MaterialObject*>(material.data())->getDiffuse(), SPLAT_TEXTURE);
729729 }
730730 }
731731 }
@@ -799,7 +799,7 @@ void HeightfieldBuffer::render(bool cursor) { · 67 unmodified lines
799799 if (cursor) {
800800 glDrawRangeElements(GL_TRIANGLES, 0, vertexCount - 1, indexCount, GL_UNSIGNED_INT, 0);
801801
802− } else if (!_textures.isEmpty()) {
802+ } else if (!_materials.isEmpty()) {
803803 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().bind();
804804 DefaultMetavoxelRendererImplementation::getBaseHeightfieldProgram().setUniformValue(
805805 DefaultMetavoxelRendererImplementation::getBaseHeightScaleLocation(), 1.0f / _heightSize);
@@ -826,10 +826,10 @@ void HeightfieldBuffer::render(bool cursor) { · 20 unmodified lines
826826 DefaultMetavoxelRendererImplementation::getSplatTextureOffsetLocation(),
827827 _translation.x / _scale, _translation.z / _scale);
828828
829− glBindTexture(GL_TEXTURE_2D, _textureTextureID);
829+ glBindTexture(GL_TEXTURE_2D, _materialTextureID);
830830
831831 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) {
833833 QVector4D scalesS, scalesT;
834834
835835 for (int j = 0; j < SPLAT_COUNT; j++) {
@@ -838,9 +838,9 @@ void HeightfieldBuffer::render(bool cursor) { · 2 unmodified lines
838838 if (index < _networkTextures.size()) {
839839 const NetworkTexturePointer& texture = _networkTextures.at(index);
840840 if (texture) {
841− HeightfieldTexture* heightfieldTexture = static_cast<HeightfieldTexture*>(_textures.at(index).data());
842− scalesS[j] = _scale / heightfieldTexture->getScaleS();
843− scalesT[j] = _scale / heightfieldTexture->getScaleT();
841+ MaterialObject* material = static_cast<MaterialObject*>(_materials.at(index).data());
842+ scalesS[j] = _scale / material->getScaleS();
843+ scalesT[j] = _scale / material->getScaleT();
844844 glBindTexture(GL_TEXTURE_2D, texture->getID());
845845 } else {
846846 glBindTexture(GL_TEXTURE_2D, 0);
@@ -1349,7 +1349,7 @@ private: · 502 unmodified lines
13491349 HeightfieldRegionVisitor::HeightfieldRegionVisitor(const MetavoxelLOD& lod) :
13501350 MetavoxelVisitor(QVector<AttributePointer>() << AttributeRegistry::getInstance()->getHeightfieldAttribute() <<
13511351 AttributeRegistry::getInstance()->getHeightfieldColorAttribute() <<
1352− AttributeRegistry::getInstance()->getHeightfieldTextureAttribute() <<
1352+ AttributeRegistry::getInstance()->getHeightfieldMaterialAttribute() <<
13531353 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), QVector<AttributePointer>() <<
13541354 Application::getInstance()->getMetavoxels()->getHeightfieldBufferAttribute(), lod),
13551355 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
13771377 colorContentsSize = extendedColorSize * extendedColorSize * DataBlock::COLOR_BYTES;
13781378 }
13791379
1380− HeightfieldTextureDataPointer texture = info.inputValues.at(2).getInlineValue<HeightfieldTextureDataPointer>();
1381− QByteArray textureContents;
1382− QVector<SharedObjectPointer> textures;
1383− if (texture) {
1384− textureContents = texture->getContents();
1385− textures = texture->getTextures();
1380+ HeightfieldMaterialDataPointer material = info.inputValues.at(2).getInlineValue<HeightfieldMaterialDataPointer>();
1381+ QByteArray materialContents;
1382+ QVector<SharedObjectPointer> materials;
1383+ if (material) {
1384+ materialContents = material->getContents();
1385+ materials = material->getMaterials();
13861386 }
13871387
13881388 const HeightfieldBuffer* existingBuffer = static_cast<const HeightfieldBuffer*>(
@@ -1393,12 +1393,12 @@ int HeightfieldRegionVisitor::visit(MetavoxelInfo& info) { · 4 unmodified lines
13931393 // we already have a buffer of the correct resolution
13941394 addRegion(bounds, existingBuffer->getHeightBounds());
13951395 buffer = new HeightfieldBuffer(info.minimum, info.size, existingBuffer->getHeight(),
1396− existingBuffer->getColor(), textureContents, textures);
1396+ existingBuffer->getColor(), materialContents, materials);
13971397
13981398 } else {
13991399 // we must create a new buffer and update its borders
14001400 buffer = new HeightfieldBuffer(info.minimum, info.size, QByteArray(heightContentsSize, 0),
1401− QByteArray(colorContentsSize, 0), textureContents, textures);
1401+ QByteArray(colorContentsSize, 0), materialContents, materials);
14021402 const Box& heightBounds = buffer->getHeightBounds();
14031403 addRegion(bounds, heightBounds);
14041404
@@ -1472,7 +1472,7 @@ int HeightfieldUpdateVisitor::visit(MetavoxelInfo& info) { · 67 unmodified lines
14721472 return STOP_RECURSION;
14731473 }
14741474 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());
14761476 _fetchVisitor.init(newBuffer);
14771477 _data->guide(_fetchVisitor);
14781478 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(newBuffer)));