Merge pull request #3363 from ey6es/metavoxels

Metavoxel fixes: added wireframe option, fixed shadow menu group, make sure edit colors are either 100% opaque or 100% transparent, fix deferred lighting/ambient occlusion when glow effect disabled, save metavoxels.dat regularly.
This commit is contained in:
Philip Rosedale 2014-09-05 15:33:20 -07:00
commit 220e79a6a9
7 changed files with 61 additions and 24 deletions

View file

@ -23,7 +23,8 @@
MetavoxelServer::MetavoxelServer(const QByteArray& packet) :
ThreadedAssignment(packet),
_nextSender(0) {
_nextSender(0),
_savedDataInitialized(false) {
}
void MetavoxelServer::applyEdit(const MetavoxelEditMessage& edit) {
@ -33,8 +34,20 @@ void MetavoxelServer::applyEdit(const MetavoxelEditMessage& edit) {
}
void MetavoxelServer::setData(const MetavoxelData& data) {
if (_data != data) {
emit dataChanged(_data = data);
if (_data == data) {
return;
}
emit dataChanged(_data = data);
if (!_savedDataInitialized) {
_savedData = data;
_savedDataInitialized = true;
// start the save timer
QTimer* saveTimer = new QTimer(this);
connect(saveTimer, &QTimer::timeout, this, &MetavoxelServer::maybeSaveData);
const int SAVE_INTERVAL = 1000 * 30;
saveTimer->start(SAVE_INTERVAL);
}
}
@ -135,6 +148,12 @@ void MetavoxelServer::maybeDeleteSession(const SharedNodePointer& node) {
}
}
void MetavoxelServer::maybeSaveData() {
if (_savedData != _data) {
QMetaObject::invokeMethod(_persister, "save", Q_ARG(const MetavoxelData&, _savedData = _data));
}
}
MetavoxelSender::MetavoxelSender(MetavoxelServer* server) :
_server(server),
_sendTimer(this) {

View file

@ -52,6 +52,7 @@ private slots:
void maybeAttachSession(const SharedNodePointer& node);
void maybeDeleteSession(const SharedNodePointer& node);
void maybeSaveData();
private:
@ -61,6 +62,8 @@ private:
MetavoxelPersister* _persister;
MetavoxelData _data;
MetavoxelData _savedData;
bool _savedDataInitialized;
};
/// Handles update sending for one thread.

View file

@ -589,8 +589,6 @@ void Application::paintGL() {
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::paintGL()");
const bool glowEnabled = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect);
// Set the desired FBO texture size. If it hasn't changed, this does nothing.
// Otherwise, it must rebuild the FBOs
if (OculusManager::isConnected()) {
@ -665,16 +663,11 @@ void Application::paintGL() {
updateShadowMap();
}
//If we aren't using the glow shader, we have to clear the color and depth buffer
if (!glowEnabled) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
} else if (OculusManager::isConnected()) {
if (OculusManager::isConnected()) {
//Clear the color buffer to ensure that there isnt any residual color
//Left over from when OR was not connected.
glClear(GL_COLOR_BUFFER_BIT);
}
if (OculusManager::isConnected()) {
//When in mirror mode, use camera rotation. Otherwise, use body rotation
if (whichCamera.getMode() == CAMERA_MODE_MIRROR) {
OculusManager::display(whichCamera.getRotation(), whichCamera.getPosition(), whichCamera);
@ -687,9 +680,7 @@ void Application::paintGL() {
TV3DManager::display(whichCamera);
} else {
if (glowEnabled) {
_glowEffect.prepare();
}
_glowEffect.prepare();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
@ -697,9 +688,7 @@ void Application::paintGL() {
displaySide(whichCamera);
glPopMatrix();
if (glowEnabled) {
_glowEffect.render();
}
_glowEffect.render();
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
renderRearViewMirror(_mirrorViewRect);
@ -2809,6 +2798,10 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
_stars.render(whichCamera.getFieldOfView(), whichCamera.getAspectRatio(), whichCamera.getNearClip(), alpha);
}
if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
// draw the sky dome
if (!selfAvatarOnly && Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
PerformanceTimer perfTimer("atmosphere");
@ -2947,6 +2940,10 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) {
_overlays.render3D();
}
}
if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
}
void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) {

View file

@ -370,7 +370,7 @@ Menu::Menu() :
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, "None", 0, true));
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, MenuOption::SimpleShadows, 0, false));
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, MenuOption::CascadedShadows, 0, false));
shadowGroup->addAction(addCheckableActionToQMenuAndActionHash(shadowMenu, MenuOption::AvatarsReceiveShadows, 0, true));
addCheckableActionToQMenuAndActionHash(shadowMenu, MenuOption::AvatarsReceiveShadows, 0, true);
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Stars, Qt::Key_Asterisk, true);
@ -386,6 +386,7 @@ Menu::Menu() :
0,
appInstance->getGlowEffect(),
SLOT(cycleRenderMode()));
addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, 0, false);
addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools()));
QMenu* avatarDebugMenu = developerMenu->addMenu("Avatar");

View file

@ -471,6 +471,7 @@ namespace MenuOption {
const QString Voxels = "Voxels";
const QString VoxelTextures = "Voxel Textures";
const QString WalletPrivateKey = "Wallet Private Key...";
const QString Wireframe = "Wireframe";
}
void sendFakeEnterEvent();

View file

@ -140,7 +140,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) {
QOpenGLFramebufferObject* destFBO = toTexture ?
Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject() : NULL;
if (_isEmpty && _renderMode != DIFFUSE_ADD_MODE) {
if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || (_isEmpty && _renderMode != DIFFUSE_ADD_MODE)) {
// copy the primary to the screen
if (QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) {
QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO);

View file

@ -1251,8 +1251,11 @@ QColor VoxelColorBoxTool::getColor() {
}
void VoxelColorBoxTool::applyValue(const glm::vec3& minimum, const glm::vec3& maximum) {
// ensure that color is either 100% transparent or 100% opaque
QColor color = _color->getColor();
color.setAlphaF(color.alphaF() > 0.5f ? 1.0f : 0.0f);
MetavoxelEditMessage message = { QVariant::fromValue(VoxelColorBoxEdit(Box(minimum, maximum),
_editor->getGridSpacing(), _color->getColor())) };
_editor->getGridSpacing(), color)) };
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
}
@ -1279,8 +1282,13 @@ QColor VoxelMaterialBoxTool::getColor() {
void VoxelMaterialBoxTool::applyValue(const glm::vec3& minimum, const glm::vec3& maximum) {
SharedObjectPointer material = _materialEditor->getObject();
_materialEditor->detachObject();
QColor color;
if (_texture) {
color = _texture->getAverageColor();
color.setAlphaF(1.0f);
}
MetavoxelEditMessage message = { QVariant::fromValue(VoxelMaterialBoxEdit(Box(minimum, maximum),
_editor->getGridSpacing(), material, _texture ? _texture->getAverageColor() : QColor())) };
_editor->getGridSpacing(), material, color)) };
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
}
@ -1363,8 +1371,11 @@ QColor VoxelColorSphereTool::getColor() {
}
void VoxelColorSphereTool::applyValue(const glm::vec3& position, float radius) {
// ensure that color is either 100% transparent or 100% opaque
QColor color = _color->getColor();
color.setAlphaF(color.alphaF() > 0.5f ? 1.0f : 0.0f);
MetavoxelEditMessage message = { QVariant::fromValue(VoxelColorSphereEdit(position, radius,
_editor->getGridSpacing(), _color->getColor())) };
_editor->getGridSpacing(), color)) };
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
}
@ -1386,8 +1397,13 @@ QColor VoxelMaterialSphereTool::getColor() {
void VoxelMaterialSphereTool::applyValue(const glm::vec3& position, float radius) {
SharedObjectPointer material = _materialEditor->getObject();
_materialEditor->detachObject();
QColor color;
if (_texture) {
color = _texture->getAverageColor();
color.setAlphaF(1.0f);
}
MetavoxelEditMessage message = { QVariant::fromValue(VoxelMaterialSphereEdit(position, radius,
_editor->getGridSpacing(), material, _texture ? _texture->getAverageColor() : QColor())) };
_editor->getGridSpacing(), material, color)) };
Application::getInstance()->getMetavoxels()->applyEdit(message, true);
}