diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index d1dd5cce8e..7defe347ca 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -1139,8 +1139,8 @@ void RenderablePolyVoxEntityItem::getMesh() { auto indexBuffer = std::make_shared(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data()); auto indexBufferPtr = gpu::BufferPointer(indexBuffer); - auto indexBufferView = new gpu::BufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW)); - mesh->setIndexBuffer(*indexBufferView); + gpu::BufferView indexBufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW)); + mesh->setIndexBuffer(indexBufferView); const std::vector& vecVertices = polyVoxMesh.getVertices(); auto vertexBuffer = std::make_shared(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal), @@ -1150,10 +1150,10 @@ void RenderablePolyVoxEntityItem::getMesh() { if (vertexBufferPtr->getSize() > sizeof(float) * 3) { vertexBufferSize = vertexBufferPtr->getSize() - sizeof(float) * 3; } - auto vertexBufferView = new gpu::BufferView(vertexBufferPtr, 0, vertexBufferSize, - sizeof(PolyVox::PositionMaterialNormal), - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)); - mesh->setVertexBuffer(*vertexBufferView); + gpu::BufferView vertexBufferView(vertexBufferPtr, 0, vertexBufferSize, + sizeof(PolyVox::PositionMaterialNormal), + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW)); + mesh->setVertexBuffer(vertexBufferView); mesh->addAttribute(gpu::Stream::NORMAL, gpu::BufferView(vertexBufferPtr, sizeof(float) * 3, @@ -1323,14 +1323,14 @@ void RenderablePolyVoxEntityItem::setCollisionPoints(ShapeInfo::PointCollection // include the registrationPoint in the shape key, because the offset is already // included in the points and the shapeManager wont know that the shape has changed. withWriteLock([&] { - QString shapeKey = QString(_voxelData.toBase64()) + "," + - QString::number(_registrationPoint.x) + "," + - QString::number(_registrationPoint.y) + "," + - QString::number(_registrationPoint.z); - _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey); - _shapeInfo.setPointCollection(pointCollection); - _meshDirty = false; - }); + QString shapeKey = QString(_voxelData.toBase64()) + "," + + QString::number(_registrationPoint.x) + "," + + QString::number(_registrationPoint.y) + "," + + QString::number(_registrationPoint.z); + _shapeInfo.setParams(SHAPE_TYPE_COMPOUND, collisionModelDimensions, shapeKey); + _shapeInfo.setPointCollection(pointCollection); + _meshDirty = false; + }); } void RenderablePolyVoxEntityItem::setXNNeighborID(const EntityItemID& xNNeighborID) { @@ -1439,3 +1439,16 @@ void RenderablePolyVoxEntityItem::bonkNeighbors() { currentZNNeighbor->setVolDataDirty(); } } + + +void RenderablePolyVoxEntityItem::locationChanged(bool tellPhysics) { + EntityItem::locationChanged(tellPhysics); + if (!_pipeline || !render::Item::isValidID(_myItem)) { + return; + } + render::ScenePointer scene = AbstractViewStateInterface::instance()->getMain3DScene(); + render::PendingChanges pendingChanges; + pendingChanges.updateItem(_myItem, [](PolyVoxPayload& payload) {}); + + scene->enqueuePendingChanges(pendingChanges); +} diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index f84637ec95..1b6ea34bda 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -141,6 +141,9 @@ public: // Transparent polyvox didn't seem to be working so disable for now bool isTransparent() override { return false; } +protected: + virtual void locationChanged(bool tellPhysics = true) override; + private: // The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions // may not match _voxelVolumeSize. diff --git a/libraries/gpu/src/gpu/Buffer.cpp b/libraries/gpu/src/gpu/Buffer.cpp index ff425d1f6b..54533b3263 100644 --- a/libraries/gpu/src/gpu/Buffer.cpp +++ b/libraries/gpu/src/gpu/Buffer.cpp @@ -25,6 +25,14 @@ void Buffer::updateBufferCPUMemoryUsage(Size prevObjectSize, Size newObjectSize) } } +void Buffer::incrementBufferCPUCount() { + _bufferCPUCount++; +} + +void Buffer::decrementBufferCPUCount() { + _bufferCPUCount--; +} + uint32_t Buffer::getBufferCPUCount() { return _bufferCPUCount.load(); } @@ -43,7 +51,7 @@ Buffer::Size Buffer::getBufferGPUMemoryUsage() { Buffer::Buffer(Size pageSize) : _renderPages(pageSize), _pages(pageSize) { - _bufferCPUCount++; + Buffer::incrementBufferCPUCount(); } Buffer::Buffer(Size size, const Byte* bytes, Size pageSize) : Buffer(pageSize) { @@ -61,7 +69,7 @@ Buffer& Buffer::operator=(const Buffer& buf) { } Buffer::~Buffer() { - _bufferCPUCount--; + Buffer::decrementBufferCPUCount(); Buffer::updateBufferCPUMemoryUsage(_sysmem.getSize(), 0); } diff --git a/libraries/gpu/src/gpu/Buffer.h b/libraries/gpu/src/gpu/Buffer.h index 981424de2f..9e85868a01 100644 --- a/libraries/gpu/src/gpu/Buffer.h +++ b/libraries/gpu/src/gpu/Buffer.h @@ -27,6 +27,8 @@ class Buffer : public Resource { static std::atomic _bufferCPUCount; static std::atomic _bufferCPUMemoryUsage; static void updateBufferCPUMemoryUsage(Size prevObjectSize, Size newObjectSize); + static void incrementBufferCPUCount(); + static void decrementBufferCPUCount(); public: using Flag = PageManager::Flag;