From de5e95f7dcdae2e11482c9d106d215b72af7c8fd Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 28 Sep 2015 09:59:18 -0700 Subject: [PATCH 01/15] Improved procedural surfaces, textures and more standard uniforms --- .../src/RenderableBoxEntityItem.cpp | 2 +- .../src/RenderableSphereEntityItem.cpp | 2 +- libraries/gpu/src/gpu/Batch.h | 54 ++-- .../procedural/src/procedural/Procedural.cpp | 246 +++++++++++++----- .../procedural/src/procedural/Procedural.h | 35 ++- .../src/procedural/ProceduralShaders.h | 38 ++- .../src/procedural/ProceduralSkybox.cpp | 36 +-- 7 files changed, 305 insertions(+), 108 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 187b25e75a..077f28350b 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -56,7 +56,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { if (_procedural->ready()) { batch.setModelTransform(getTransformToCenter()); // we want to include the scale as well - _procedural->prepare(batch, this->getDimensions()); + _procedural->prepare(batch, getPosition(), getDimensions()); auto color = _procedural->getColor(cubeColor); batch._glColor4f(color.r, color.g, color.b, color.a); DependencyManager::get()->renderCube(batch); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 3cfc18046a..246cd2fea7 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -62,7 +62,7 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { modelTransform.postScale(SPHERE_ENTITY_SCALE); if (_procedural->ready()) { batch.setModelTransform(modelTransform); // use a transform with scale, rotation, registration point and translation - _procedural->prepare(batch, getDimensions()); + _procedural->prepare(batch, getPosition(), getDimensions()); auto color = _procedural->getColor(sphereColor); batch._glColor4f(color.r, color.g, color.b, color.a); DependencyManager::get()->renderSphere(batch); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 2a35d04aac..e1b76e2e81 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -156,24 +156,24 @@ public: // Indirect buffer is used by the multiDrawXXXIndirect calls // The indirect buffer contains the command descriptions to execute multiple drawcalls in a single call void setIndirectBuffer(const BufferPointer& buffer, Offset offset = 0, Offset stride = 0); - - // multi command desctription for multiDrawIndexedIndirect - class DrawIndirectCommand { - public: - uint _count{ 0 }; - uint _instanceCount{ 0 }; - uint _firstIndex{ 0 }; - uint _baseInstance{ 0 }; + + // multi command desctription for multiDrawIndexedIndirect + class DrawIndirectCommand { + public: + uint _count{ 0 }; + uint _instanceCount{ 0 }; + uint _firstIndex{ 0 }; + uint _baseInstance{ 0 }; }; - - // multi command desctription for multiDrawIndexedIndirect - class DrawIndexedIndirectCommand { - public: - uint _count{ 0 }; - uint _instanceCount{ 0 }; - uint _firstIndex{ 0 }; - uint _baseVertex{ 0 }; - uint _baseInstance{ 0 }; + + // multi command desctription for multiDrawIndexedIndirect + class DrawIndexedIndirectCommand { + public: + uint _count{ 0 }; + uint _instanceCount{ 0 }; + uint _firstIndex{ 0 }; + uint _baseVertex{ 0 }; + uint _baseInstance{ 0 }; }; // Transform Stage @@ -246,6 +246,26 @@ public: void _glUniform4iv(int location, int count, const int* value); void _glUniformMatrix4fv(int location, int count, unsigned char transpose, const float* value); + void _glUniform(int location, int v0) { + _glUniform1i(location, v0); + } + + void _glUniform(int location, float v0) { + _glUniform1f(location, v0); + } + + void _glUniform(int location, const glm::vec2& v) { + _glUniform2f(location, v.x, v.y); + } + + void _glUniform(int location, const glm::vec3& v) { + _glUniform3f(location, v.x, v.y, v.z); + } + + void _glUniform(int location, const glm::vec4& v) { + _glUniform4f(location, v.x, v.y, v.z, v.w); + } + void _glColor4f(float red, float green, float blue, float alpha); enum Command { diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index aa8946f62b..334aaca741 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -17,20 +17,30 @@ #include #include #include +#include #include "ProceduralShaders.h" -static const char* const UNIFORM_TIME_NAME= "iGlobalTime"; -static const char* const UNIFORM_SCALE_NAME = "iWorldScale"; +// Userdata parsing constants static const QString PROCEDURAL_USER_DATA_KEY = "ProceduralEntity"; - static const QString URL_KEY = "shaderUrl"; static const QString VERSION_KEY = "version"; static const QString UNIFORMS_KEY = "uniforms"; +static const QString CHANNELS_KEY = "channels"; + +// Shader replace strings static const std::string PROCEDURAL_BLOCK = "//PROCEDURAL_BLOCK"; static const std::string PROCEDURAL_COMMON_BLOCK = "//PROCEDURAL_COMMON_BLOCK"; static const std::string PROCEDURAL_VERSION = "//PROCEDURAL_VERSION"; +static const std::string STANDARD_UNIFORM_NAMES[Procedural::NUM_STANDARD_UNIFORMS] = { + "iDate", + "iGlobalTime", + "iFrameCount", + "iWorldScale", + "iWorldPosition", + "iChannelResolution" +}; // Example //{ @@ -100,7 +110,21 @@ void Procedural::parse(const QJsonObject& proceduralData) { { auto uniforms = proceduralData[UNIFORMS_KEY]; if (uniforms.isObject()) { - _uniforms = uniforms.toObject();; + _parsedUniforms = uniforms.toObject(); + } + } + + // Grab any textures + { + auto channels = proceduralData[CHANNELS_KEY]; + if (channels.isArray()) { + auto textureCache = DependencyManager::get(); + _parsedChannels = channels.toArray(); + size_t channelCount = std::min(MAX_PROCEDURAL_TEXTURE_CHANNELS, (size_t)_parsedChannels.size()); + for (size_t i = 0; i < channelCount; ++i) { + QString url = _parsedChannels.at(i).toString(); + _channels[i] = textureCache->getTexture(QUrl(url)); + } } } _enabled = true; @@ -111,20 +135,26 @@ bool Procedural::ready() { return false; } - if (!_shaderPath.isEmpty()) { - return true; + // Do we have a network or local shader + if (_shaderPath.isEmpty() && (!_networkShader || !_networkShader->isLoaded())) { + return false; } - if (_networkShader) { - return _networkShader->isLoaded(); + // Do we have textures, and if so, are they loaded? + for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { + if (_channels[i] && !_channels[i]->isLoaded()) { + return false; + } } - return false; + return true; } -void Procedural::prepare(gpu::Batch& batch, const glm::vec3& size) { +void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size) { + _entityDimensions = size; + _entityPosition = position; if (_shaderUrl.isLocalFile()) { - auto lastModified = (quint64) QFileInfo(_shaderPath).lastModified().toMSecsSinceEpoch(); + auto lastModified = (quint64)QFileInfo(_shaderPath).lastModified().toMSecsSinceEpoch(); if (lastModified > _shaderModified) { QFile file(_shaderPath); file.open(QIODevice::ReadOnly); @@ -164,69 +194,169 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& size) { //qDebug() << "FragmentShader:\n" << fragmentShaderSource.c_str(); _fragmentShader = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentShaderSource)); _shader = gpu::ShaderPointer(gpu::Shader::createProgram(_vertexShader, _fragmentShader)); - gpu::Shader::makeProgram(*_shader); + + gpu::Shader::BindingSet slotBindings; + slotBindings.insert(gpu::Shader::Binding(std::string("iChannel0"), 0)); + slotBindings.insert(gpu::Shader::Binding(std::string("iChannel1"), 1)); + slotBindings.insert(gpu::Shader::Binding(std::string("iChannel2"), 2)); + slotBindings.insert(gpu::Shader::Binding(std::string("iChannel3"), 3)); + gpu::Shader::makeProgram(*_shader, slotBindings); + _pipeline = gpu::PipelinePointer(gpu::Pipeline::create(_shader, _state)); - _timeSlot = _shader->getUniforms().findLocation(UNIFORM_TIME_NAME); - _scaleSlot = _shader->getUniforms().findLocation(UNIFORM_SCALE_NAME); + for (size_t i = 0; i < NUM_STANDARD_UNIFORMS; ++i) { + const std::string& name = STANDARD_UNIFORM_NAMES[i]; + _standardUniformSlots[i] = _shader->getUniforms().findLocation(name); + } _start = usecTimestampNow(); + _frameCount = 0; } batch.setPipeline(_pipeline); if (_pipelineDirty) { _pipelineDirty = false; - // Set any userdata specified uniforms - foreach(QString key, _uniforms.keys()) { - std::string uniformName = key.toLocal8Bit().data(); - int32_t slot = _shader->getUniforms().findLocation(uniformName); - if (gpu::Shader::INVALID_LOCATION == slot) { - continue; - } - QJsonValue value = _uniforms[key]; - if (value.isDouble()) { - batch._glUniform1f(slot, value.toDouble()); - } else if (value.isArray()) { - auto valueArray = value.toArray(); - switch (valueArray.size()) { - case 0: - break; + setupUniforms(); + } - case 1: - batch._glUniform1f(slot, valueArray[0].toDouble()); - break; - case 2: - batch._glUniform2f(slot, - valueArray[0].toDouble(), - valueArray[1].toDouble()); - break; - case 3: - batch._glUniform3f(slot, - valueArray[0].toDouble(), - valueArray[1].toDouble(), - valueArray[2].toDouble()); - break; - case 4: - default: - batch._glUniform4f(slot, - valueArray[0].toDouble(), - valueArray[1].toDouble(), - valueArray[2].toDouble(), - valueArray[3].toDouble()); - break; + for (auto lambda : _uniforms) { + lambda(batch); + } + + for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { + if (_channels[i] && _channels[i]->isLoaded()) { + batch.setResourceTexture(i, _channels[i]->getGPUTexture()); + } + } +} + +void Procedural::setupUniforms() { + _uniforms.clear(); + // Set any userdata specified uniforms + foreach(QString key, _parsedUniforms.keys()) { + std::string uniformName = key.toLocal8Bit().data(); + int32_t slot = _shader->getUniforms().findLocation(uniformName); + if (gpu::Shader::INVALID_LOCATION == slot) { + continue; + } + QJsonValue value = _parsedUniforms[key]; + if (value.isDouble()) { + float v = value.toDouble(); + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform1f(slot, v); + }); + } else if (value.isArray()) { + auto valueArray = value.toArray(); + switch (valueArray.size()) { + case 0: + break; + + case 1: { + float v = valueArray[0].toDouble(); + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform1f(slot, v); + }); + break; + } + case 2: { + glm::vec2 v{ valueArray[0].toDouble(), valueArray[1].toDouble() }; + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform2f(slot, v.x, v.y); + }); + break; + } + case 3: { + glm::vec3 v{ + valueArray[0].toDouble(), + valueArray[1].toDouble(), + valueArray[2].toDouble(), + }; + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform3f(slot, v.x, v.y, v.z); + }); + break; + } + + default: + case 4: { + glm::vec4 v{ + valueArray[0].toDouble(), + valueArray[1].toDouble(), + valueArray[2].toDouble(), + valueArray[3].toDouble(), + }; + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform4f(slot, v.x, v.y, v.z, v.w); + }); + break; } - valueArray.size(); } } } - // Minimize floating point error by doing an integer division to milliseconds, before the floating point division to seconds - float time = (float)((usecTimestampNow() - _start) / USECS_PER_MSEC) / MSECS_PER_SECOND; - batch._glUniform1f(_timeSlot, time); - // FIXME move into the 'set once' section, since this doesn't change over time - batch._glUniform3f(_scaleSlot, size.x, size.y, size.z); -} + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[TIME]) { + _uniforms.push_back([=](gpu::Batch& batch) { + // Minimize floating point error by doing an integer division to milliseconds, before the floating point division to seconds + float time = (float)((usecTimestampNow() - _start) / USECS_PER_MSEC) / MSECS_PER_SECOND; + batch._glUniform(_standardUniformSlots[TIME], time); + }); + } + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[DATE]) { + _uniforms.push_back([=](gpu::Batch& batch) { + QDateTime now = QDateTime::currentDateTimeUtc(); + QDate date = now.date(); + QTime time = now.time(); + vec4 v; + v.x = date.year(); + // Shadertoy month is 0 based + v.y = date.month() - 1; + // But not the day... go figure + v.z = date.day(); + v.w = (time.hour() * 3600) + (time.minute() * 60) + time.second(); + batch._glUniform(_standardUniformSlots[DATE], v); + }); + } + + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[FRAME_COUNT]) { + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform(_standardUniformSlots[FRAME_COUNT], ++_frameCount); + }); + } + + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[SCALE]) { + // FIXME move into the 'set once' section, since this doesn't change over time + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform(_standardUniformSlots[SCALE], _entityDimensions); + }); + } + + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[SCALE]) { + // FIXME move into the 'set once' section, since this doesn't change over time + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform(_standardUniformSlots[SCALE], _entityDimensions); + }); + } + + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[POSITION]) { + // FIXME move into the 'set once' section, since this doesn't change over time + _uniforms.push_back([=](gpu::Batch& batch) { + batch._glUniform(_standardUniformSlots[POSITION], _entityPosition); + }); + } + + if (gpu::Shader::INVALID_LOCATION != _standardUniformSlots[CHANNEL_RESOLUTION]) { + _uniforms.push_back([=](gpu::Batch& batch) { + vec3 channelSizes[MAX_PROCEDURAL_TEXTURE_CHANNELS]; + for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { + if (_channels[i]) { + channelSizes[i] = vec3(_channels[i]->getWidth(), _channels[i]->getHeight(), 1.0); + } + } + batch._glUniform3fv(_standardUniformSlots[CHANNEL_RESOLUTION], MAX_PROCEDURAL_TEXTURE_CHANNELS, &channelSizes[0].x); + }); + } +} glm::vec4 Procedural::getColor(const glm::vec4& entityColor) { if (_version == 1) { diff --git a/libraries/procedural/src/procedural/Procedural.h b/libraries/procedural/src/procedural/Procedural.h index 5b3f2b4742..1b02fbd435 100644 --- a/libraries/procedural/src/procedural/Procedural.h +++ b/libraries/procedural/src/procedural/Procedural.h @@ -14,11 +14,16 @@ #include #include #include +#include #include #include #include #include +#include + +using UniformLambdas = std::list>; +const size_t MAX_PROCEDURAL_TEXTURE_CHANNELS{ 4 }; // FIXME better encapsulation // FIXME better mechanism for extending to things rendered using shaders other than simple.slv @@ -29,7 +34,8 @@ struct Procedural { void parse(const QString& userDataJson); void parse(const QJsonObject&); bool ready(); - void prepare(gpu::Batch& batch, const glm::vec3& size); + void prepare(gpu::Batch& batch, const glm::vec3& position, const glm::vec3& size); + void setupUniforms(); glm::vec4 getColor(const glm::vec4& entityColor); bool _enabled{ false }; @@ -43,17 +49,34 @@ struct Procedural { QUrl _shaderUrl; quint64 _shaderModified{ 0 }; bool _pipelineDirty{ true }; - int32_t _timeSlot{ gpu::Shader::INVALID_LOCATION }; - int32_t _scaleSlot{ gpu::Shader::INVALID_LOCATION }; - uint64_t _start{ 0 }; - NetworkShaderPointer _networkShader; - QJsonObject _uniforms; + enum StandardUniforms { + DATE, + TIME, + FRAME_COUNT, + SCALE, + POSITION, + CHANNEL_RESOLUTION, + NUM_STANDARD_UNIFORMS + }; + + int32_t _standardUniformSlots[NUM_STANDARD_UNIFORMS]; + + uint64_t _start{ 0 }; + int32_t _frameCount{ 0 }; + NetworkShaderPointer _networkShader; + QJsonObject _parsedUniforms; + QJsonArray _parsedChannels; + + UniformLambdas _uniforms; + NetworkTexturePointer _channels[MAX_PROCEDURAL_TEXTURE_CHANNELS]; gpu::PipelinePointer _pipeline; gpu::ShaderPointer _vertexShader; gpu::ShaderPointer _fragmentShader; gpu::ShaderPointer _shader; gpu::StatePointer _state; + glm::vec3 _entityDimensions; + glm::vec3 _entityPosition; }; #endif diff --git a/libraries/procedural/src/procedural/ProceduralShaders.h b/libraries/procedural/src/procedural/ProceduralShaders.h index 9943a322cc..eddf53cb09 100644 --- a/libraries/procedural/src/procedural/ProceduralShaders.h +++ b/libraries/procedural/src/procedural/ProceduralShaders.h @@ -262,15 +262,39 @@ float snoise(vec2 v) { return 130.0 * dot(m, g); } -// TODO add more uniforms -uniform float iGlobalTime; // shader playback time (in seconds) -uniform vec3 iWorldScale; // the dimensions of the object being rendered - -// TODO add support for textures -// TODO document available inputs other than the uniforms -// TODO provide world scale in addition to the untransformed position +// shader playback time (in seconds) +uniform float iGlobalTime; +// the dimensions of the object being rendered +uniform vec3 iWorldScale; #define PROCEDURAL 1 //PROCEDURAL_VERSION + +#ifdef PROCEDURAL_V1 + +#else + +// Unimplemented uniforms +// Resolution doesn't make sense in the VR context +const vec3 iResolution = vec3(1.0); +// Mouse functions not enabled currently +const vec4 iMouse = vec4(0.0); +// No support for audio input +const float iSampleRate = 1.0; +// No support for video input +const vec4 iChannelTime = vec4(0.0); + + +uniform vec4 iDate; +uniform int iFrameCount; +uniform vec3 iWorldPosition; +uniform vec3 iChannelResolution[4]; +uniform sampler2D iChannel0; +uniform sampler2D iChannel1; +uniform sampler2D iChannel2; +uniform sampler2D iChannel3; + +#endif + )SHADER"; diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 1c7e7e457c..022bf7898a 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -1,20 +1,20 @@ -// -// ProceduralSkybox.cpp -// libraries/procedural/src/procedural -// -// Created by Sam Gateau on 9/21/2015. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// -#include "ProceduralSkybox.h" - - -#include -#include -#include - +// +// ProceduralSkybox.cpp +// libraries/procedural/src/procedural +// +// Created by Sam Gateau on 9/21/2015. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "ProceduralSkybox.h" + + +#include +#include +#include + #include "ProceduralSkybox_vert.h" #include "ProceduralSkybox_frag.h" @@ -74,7 +74,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setResourceTexture(0, skybox.getCubemap()); } - skybox._procedural->prepare(batch, glm::vec3(1)); + skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); batch.draw(gpu::TRIANGLE_STRIP, 4); } } From 7d4b6802559e5043f71e05fffbb8befa24a9c3f4 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 30 Sep 2015 09:48:08 -0700 Subject: [PATCH 02/15] PR comments --- .../procedural/src/procedural/Procedural.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 334aaca741..18b6765d89 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -248,24 +248,26 @@ void Procedural::setupUniforms() { } else if (value.isArray()) { auto valueArray = value.toArray(); switch (valueArray.size()) { - case 0: - break; + case 0: + break; - case 1: { + case 1: { float v = valueArray[0].toDouble(); _uniforms.push_back([=](gpu::Batch& batch) { batch._glUniform1f(slot, v); }); break; } - case 2: { + + case 2: { glm::vec2 v{ valueArray[0].toDouble(), valueArray[1].toDouble() }; _uniforms.push_back([=](gpu::Batch& batch) { batch._glUniform2f(slot, v.x, v.y); }); break; } - case 3: { + + case 3: { glm::vec3 v{ valueArray[0].toDouble(), valueArray[1].toDouble(), @@ -277,8 +279,8 @@ void Procedural::setupUniforms() { break; } - default: - case 4: { + default: + case 4: { glm::vec4 v{ valueArray[0].toDouble(), valueArray[1].toDouble(), From 83c9ebf06cfe00e3a0226484dfd594263a40e318 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 2 Oct 2015 11:38:19 -0700 Subject: [PATCH 03/15] Fixing Linux build failure --- libraries/model-networking/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/model-networking/CMakeLists.txt b/libraries/model-networking/CMakeLists.txt index 3613f76cff..f014885794 100644 --- a/libraries/model-networking/CMakeLists.txt +++ b/libraries/model-networking/CMakeLists.txt @@ -7,5 +7,5 @@ add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) -link_hifi_libraries(shared networking gpu model) +link_hifi_libraries(shared networking gpu model fbx) From c8aea675057a0ed74193a1673ca054eda58ea394 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 2 Oct 2015 19:09:43 -0700 Subject: [PATCH 04/15] Working on texture compatibility with Shadertoy --- libraries/gpu/src/gpu/Texture.cpp | 19 ++++++++++++++++--- .../procedural/src/procedural/Procedural.cpp | 14 +++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index d358b6431d..ae6f3b740d 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -343,9 +343,22 @@ bool Texture::assignStoredMipFace(uint16 level, const Element& format, Size size } uint16 Texture::autoGenerateMips(uint16 maxMip) { - _autoGenerateMips = true; - _maxMip = std::min((uint16) (evalNumMips() - 1), maxMip); - _stamp++; + bool changed = false; + if (!_autoGenerateMips) { + changed = true; + _autoGenerateMips = true; + } + + auto newMaxMip = std::min((uint16)(evalNumMips() - 1), maxMip); + if (newMaxMip != _maxMip) { + changed = true; + _maxMip = newMaxMip;; + } + + if (changed) { + _stamp++; + } + return _maxMip; } diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 18b6765d89..f5448bda5c 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -223,9 +223,21 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm lambda(batch); } + static gpu::Sampler sampler; + static std::once_flag once; + std::call_once(once, [&] { + gpu::Sampler::Desc desc; + desc._filter = gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR; + }); + for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { if (_channels[i] && _channels[i]->isLoaded()) { - batch.setResourceTexture(i, _channels[i]->getGPUTexture()); + auto gpuTexture = _channels[i]->getGPUTexture(); + if (gpuTexture) { + gpuTexture->setSampler(sampler); + gpuTexture->autoGenerateMips(-1); + } + batch.setResourceTexture(i, gpuTexture); } } } From 725ed26ac2e72bf59f320151c93a226dcc039c19 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 4 Oct 2015 16:26:06 -0700 Subject: [PATCH 05/15] Enabling programmatic access to the IPD scale --- examples/example/hmd/ipdScalingTest.js | 42 ++++++++++++ interface/src/Application.cpp | 47 +++++++++---- interface/src/PluginContainerProxy.cpp | 7 ++ interface/src/PluginContainerProxy.h | 3 + interface/src/avatar/MyAvatar.cpp | 10 +-- .../src/scripting/HMDScriptingInterface.cpp | 68 ++++++++++--------- .../src/scripting/HMDScriptingInterface.h | 23 +++---- .../AbstractHMDScriptingInterface.cpp | 52 ++++++++++++++ .../AbstractHMDScriptingInterface.h | 39 +++++++++++ .../src/display-plugins/DisplayPlugin.h | 17 +++-- .../oculus/OculusBaseDisplayPlugin.cpp | 16 +++-- .../oculus/OculusBaseDisplayPlugin.h | 11 +-- .../display-plugins/oculus/OculusHelpers.h | 8 +++ .../oculus/OculusLegacyDisplayPlugin.cpp | 4 +- .../oculus/OculusLegacyDisplayPlugin.h | 2 +- .../openvr/OpenVrDisplayPlugin.cpp | 4 +- .../openvr/OpenVrDisplayPlugin.h | 2 +- .../stereo/StereoDisplayPlugin.cpp | 4 -- .../stereo/StereoDisplayPlugin.h | 9 ++- .../plugins/src/plugins/PluginContainer.cpp | 10 +++ .../plugins/src/plugins/PluginContainer.h | 4 ++ 21 files changed, 291 insertions(+), 91 deletions(-) create mode 100644 examples/example/hmd/ipdScalingTest.js create mode 100644 libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.cpp create mode 100644 libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.h diff --git a/examples/example/hmd/ipdScalingTest.js b/examples/example/hmd/ipdScalingTest.js new file mode 100644 index 0000000000..daa11170e4 --- /dev/null +++ b/examples/example/hmd/ipdScalingTest.js @@ -0,0 +1,42 @@ +// +// Created by Bradley Austin Davis on 2015/10/04 +// Copyright 2013-2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +IPDScalingTest = function() { + // Switch every 5 seconds between normal IPD and 0 IPD (in seconds) + this.UPDATE_INTERVAL = 10.0; + this.lastUpdateInterval = 0; + this.scaled = false; + + var that = this; + Script.scriptEnding.connect(function() { + that.onCleanup(); + }); + + Script.update.connect(function(deltaTime) { + that.lastUpdateInterval += deltaTime; + if (that.lastUpdateInterval >= that.UPDATE_INTERVAL) { + that.onUpdate(that.lastUpdateInterval); + that.lastUpdateInterval = 0; + } + }); +} + +IPDScalingTest.prototype.onCleanup = function() { + HMD.setIPDScale(1.0); +} + +IPDScalingTest.prototype.onUpdate = function(deltaTime) { + this.scaled = !this.scaled; + if (this.scaled) { + HMD.ipdScale = 0.0; + } else { + HMD.ipdScale = 1.0; + } +} + +new IPDScalingTest(); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b25f3aa6a5..025e448e29 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -300,6 +300,7 @@ bool setupEssentials(int& argc, char** argv) { auto desktopScriptingInterface = DependencyManager::set(); auto entityScriptingInterface = DependencyManager::set(); auto windowScriptingInterface = DependencyManager::set(); + auto hmdScriptingInterface = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) auto speechRecognizer = DependencyManager::set(); #endif @@ -1203,9 +1204,11 @@ void Application::paintGL() { // right eye. There are FIXMEs in the relevant plugins _myCamera.setProjection(displayPlugin->getProjection(Mono, _myCamera.getProjection())); renderArgs._context->enableStereo(true); - mat4 eyeViews[2]; + mat4 eyeOffsets[2]; mat4 eyeProjections[2]; auto baseProjection = renderArgs._viewFrustum->getProjection(); + auto hmdInterface = DependencyManager::get(); + float IPDScale = hmdInterface->getIPDScale(); // FIXME we probably don't need to set the projection matrix every frame, // only when the display plugin changes (or in non-HMD modes when the user // changes the FOV manually, which right now I don't think they can. @@ -1214,14 +1217,24 @@ void Application::paintGL() { // applied to the avatar, so we need to get the difference between the head // pose applied to the avatar and the per eye pose, and use THAT as // the per-eye stereo matrix adjustment. - mat4 eyePose = displayPlugin->getEyePose(eye); + mat4 eyeToHead = displayPlugin->getEyeToHeadTransform(eye); + // Grab the translation + vec3 eyeOffset = glm::vec3(eyeToHead[3]); + // Apply IPD scaling + mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale); + eyeOffsets[eye] = eyeOffsetTransform; + + // Tell the plugin what pose we're using to render. In this case we're just using the + // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it + // for rotational timewarp. If we move to support positonal timewarp, we need to + // ensure this contains the full pose composed with the eye offsets. mat4 headPose = displayPlugin->getHeadPose(); - mat4 eyeView = glm::inverse(eyePose) * headPose; - eyeViews[eye] = eyeView; + displayPlugin->setEyeRenderPose(eye, headPose); + eyeProjections[eye] = displayPlugin->getProjection(eye, baseProjection); }); renderArgs._context->setStereoProjections(eyeProjections); - renderArgs._context->setStereoViews(eyeViews); + renderArgs._context->setStereoViews(eyeOffsets); } displaySide(&renderArgs, _myCamera); renderArgs._context->enableStereo(false); @@ -4130,7 +4143,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("Paths", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance()); + scriptEngine->registerGlobalObject("HMD", DependencyManager::get().data()); scriptEngine->registerFunction("HMD", "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0); scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); @@ -4980,19 +4993,25 @@ mat4 Application::getEyeProjection(int eye) const { mat4 Application::getEyePose(int eye) const { if (isHMDMode()) { - return getActiveDisplayPlugin()->getEyePose((Eye)eye); + auto hmdInterface = DependencyManager::get(); + float IPDScale = hmdInterface->getIPDScale(); + auto displayPlugin = getActiveDisplayPlugin(); + mat4 headPose = displayPlugin->getHeadPose(); + mat4 eyeToHead = displayPlugin->getEyeToHeadTransform((Eye)eye); + { + vec3 eyeOffset = glm::vec3(eyeToHead[3]); + // Apply IPD scaling + mat4 eyeOffsetTransform = glm::translate(mat4(), eyeOffset * -1.0f * IPDScale); + eyeToHead[3] = vec4(eyeOffset, 1.0); + } + return eyeToHead * headPose; } - return mat4(); } mat4 Application::getEyeOffset(int eye) const { - if (isHMDMode()) { - mat4 identity; - return getActiveDisplayPlugin()->getView((Eye)eye, identity); - } - - return mat4(); + // FIXME invert? + return getActiveDisplayPlugin()->getEyeToHeadTransform((Eye)eye); } mat4 Application::getHMDSensorPose() const { diff --git a/interface/src/PluginContainerProxy.cpp b/interface/src/PluginContainerProxy.cpp index 4ef755bd1b..fd57b388fc 100644 --- a/interface/src/PluginContainerProxy.cpp +++ b/interface/src/PluginContainerProxy.cpp @@ -16,6 +16,9 @@ PluginContainerProxy::PluginContainerProxy() { Plugin::setContainer(this); } +PluginContainerProxy::~PluginContainerProxy() { +} + bool PluginContainerProxy::isForeground() { return qApp->_isForeground && !qApp->getWindow()->isMinimized(); } @@ -147,3 +150,7 @@ void PluginContainerProxy::showDisplayPluginsTools() { QGLWidget* PluginContainerProxy::getPrimarySurface() { return qApp->_glWidget; } + +const DisplayPlugin* PluginContainerProxy::getActiveDisplayPlugin() const { + return qApp->getActiveDisplayPlugin(); +} diff --git a/interface/src/PluginContainerProxy.h b/interface/src/PluginContainerProxy.h index e01cabc3b8..e3be5441b9 100644 --- a/interface/src/PluginContainerProxy.h +++ b/interface/src/PluginContainerProxy.h @@ -11,6 +11,7 @@ class PluginContainerProxy : public QObject, PluginContainer { Q_OBJECT PluginContainerProxy(); + virtual ~PluginContainerProxy(); virtual void addMenu(const QString& menuName) override; virtual void removeMenu(const QString& menuName) override; virtual QAction* addMenuItem(const QString& path, const QString& name, std::function onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") override; @@ -22,6 +23,8 @@ class PluginContainerProxy : public QObject, PluginContainer { virtual void showDisplayPluginsTools() override; virtual QGLWidget* getPrimarySurface() override; virtual bool isForeground() override; + virtual const DisplayPlugin* getActiveDisplayPlugin() const override; + QRect _savedGeometry{ 10, 120, 800, 600 }; friend class Application; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 9654305d70..71698fa4ea 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1341,11 +1341,13 @@ void MyAvatar::renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, fl if (qApp->isHMDMode()) { glm::vec3 cameraPosition = Application::getInstance()->getCamera()->getPosition(); - glm::mat4 leftEyePose = Application::getInstance()->getActiveDisplayPlugin()->getEyePose(Eye::Left); - glm::vec3 leftEyePosition = glm::vec3(leftEyePose[3]); - glm::mat4 rightEyePose = Application::getInstance()->getActiveDisplayPlugin()->getEyePose(Eye::Right); - glm::vec3 rightEyePosition = glm::vec3(rightEyePose[3]); glm::mat4 headPose = Application::getInstance()->getActiveDisplayPlugin()->getHeadPose(); + glm::mat4 leftEyePose = Application::getInstance()->getActiveDisplayPlugin()->getEyeToHeadTransform(Eye::Left); + leftEyePose = leftEyePose * headPose; + glm::vec3 leftEyePosition = glm::vec3(leftEyePose[3]); + glm::mat4 rightEyePose = Application::getInstance()->getActiveDisplayPlugin()->getEyeToHeadTransform(Eye::Right); + rightEyePose = rightEyePose * headPose; + glm::vec3 rightEyePosition = glm::vec3(rightEyePose[3]); glm::vec3 headPosition = glm::vec3(headPose[3]); getHead()->renderLookAts(renderArgs, diff --git a/interface/src/scripting/HMDScriptingInterface.cpp b/interface/src/scripting/HMDScriptingInterface.cpp index 68ac511eaf..f6bf7f8b3c 100644 --- a/interface/src/scripting/HMDScriptingInterface.cpp +++ b/interface/src/scripting/HMDScriptingInterface.cpp @@ -10,12 +10,46 @@ // #include "HMDScriptingInterface.h" + +#include + #include "display-plugins/DisplayPlugin.h" #include +#include "Application.h" -HMDScriptingInterface& HMDScriptingInterface::getInstance() { - static HMDScriptingInterface sharedInstance; - return sharedInstance; +HMDScriptingInterface::HMDScriptingInterface() { +} + +QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { + glm::vec3 hudIntersection; + auto instance = DependencyManager::get(); + if (instance->getHUDLookAtPosition3D(hudIntersection)) { + MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); + glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); + glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); + glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); + glm::vec3 eulers = ::safeEulerAngles(rotation); + return qScriptValueFromValue(engine, Application::getInstance()->getApplicationCompositor() + .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); + } + return QScriptValue::NullValue; +} + +QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { + glm::vec3 result; + auto instance = DependencyManager::get(); + if (instance->getHUDLookAtPosition3D(result)) { + return qScriptValueFromValue(engine, result); + } + return QScriptValue::NullValue; +} + +void HMDScriptingInterface::toggleMagnifier() { + qApp->getApplicationCompositor().toggleMagnifier(); +} + +bool HMDScriptingInterface::getMagnifier() const { + return Application::getInstance()->getApplicationCompositor().hasMagnifier(); } bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { @@ -29,31 +63,3 @@ bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const { return compositor.calculateRayUICollisionPoint(position, direction, result); } - -QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) { - - glm::vec3 hudIntersection; - - if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(hudIntersection)) { - MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition(); - glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter); - glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction); - glm::vec3 eulers = ::safeEulerAngles(rotation); - return qScriptValueFromValue(engine, Application::getInstance()->getApplicationCompositor() - .sphericalToOverlay(glm::vec2(eulers.y, -eulers.x))); - } - return QScriptValue::NullValue; -} - -QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) { - glm::vec3 result; - if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(result)) { - return qScriptValueFromValue(engine, result); - } - return QScriptValue::NullValue; -} - -float HMDScriptingInterface::getIPD() const { - return Application::getInstance()->getActiveDisplayPlugin()->getIPD(); -} diff --git a/interface/src/scripting/HMDScriptingInterface.h b/interface/src/scripting/HMDScriptingInterface.h index 82b444abaa..c097cde5e3 100644 --- a/interface/src/scripting/HMDScriptingInterface.h +++ b/interface/src/scripting/HMDScriptingInterface.h @@ -12,32 +12,29 @@ #ifndef hifi_HMDScriptingInterface_h #define hifi_HMDScriptingInterface_h +#include +class QScriptContext; +class QScriptEngine; + #include +#include +#include -#include "Application.h" -class HMDScriptingInterface : public QObject { +class HMDScriptingInterface : public AbstractHMDScriptingInterface, public Dependency { Q_OBJECT Q_PROPERTY(bool magnifier READ getMagnifier) - Q_PROPERTY(bool active READ isHMDMode) - Q_PROPERTY(float ipd READ getIPD) public: - static HMDScriptingInterface& getInstance(); - + HMDScriptingInterface(); static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine); static QScriptValue getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine); public slots: - void toggleMagnifier() { Application::getInstance()->getApplicationCompositor().toggleMagnifier(); }; + void toggleMagnifier(); private: - HMDScriptingInterface() {}; - bool getMagnifier() const { return Application::getInstance()->getApplicationCompositor().hasMagnifier(); }; - bool isHMDMode() const { return Application::getInstance()->isHMDMode(); } - float getIPD() const; - + bool getMagnifier() const; bool getHUDLookAtPosition3D(glm::vec3& result) const; - }; #endif // hifi_HMDScriptingInterface_h diff --git a/libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.cpp b/libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.cpp new file mode 100644 index 0000000000..9987ae345c --- /dev/null +++ b/libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.cpp @@ -0,0 +1,52 @@ +// +// Created by Bradley Austin Davis on 2015/10/04 +// Copyright 2013-2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include "AbstractHMDScriptingInterface.h" + +#include + +#include "DisplayPlugin.h" +#include +#include + +static Setting::Handle IPD_SCALE_HANDLE("hmd.ipdScale", 1.0f); + +AbstractHMDScriptingInterface::AbstractHMDScriptingInterface() { + _IPDScale = IPD_SCALE_HANDLE.get(); +} + +float AbstractHMDScriptingInterface::getIPD() const { + return PluginContainer::getInstance().getActiveDisplayPlugin()->getIPD(); +} + +float AbstractHMDScriptingInterface::getEyeHeight() const { + // FIXME update the display plugin interface to expose per-plugin settings + return OVR_DEFAULT_EYE_HEIGHT; +} + +float AbstractHMDScriptingInterface::getPlayerHeight() const { + // FIXME update the display plugin interface to expose per-plugin settings + return OVR_DEFAULT_PLAYER_HEIGHT; +} + +float AbstractHMDScriptingInterface::getIPDScale() const { + return _IPDScale; +} + +void AbstractHMDScriptingInterface::setIPDScale(float IPDScale) { + IPDScale = glm::clamp(IPDScale, -1.0f, 3.0f); + if (IPDScale != _IPDScale) { + _IPDScale = IPDScale; + IPD_SCALE_HANDLE.set(IPDScale); + emit IPDScaleChanged(); + } +} + +bool AbstractHMDScriptingInterface::isHMDMode() const { + return PluginContainer::getInstance().getActiveDisplayPlugin()->isHmd(); +} diff --git a/libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.h b/libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.h new file mode 100644 index 0000000000..5df58ce677 --- /dev/null +++ b/libraries/display-plugins/src/display-plugins/AbstractHMDScriptingInterface.h @@ -0,0 +1,39 @@ +// +// Created by Bradley Austin Davis on 2015/10/04 +// Copyright 2013-2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once +#ifndef hifi_AbstractHMDScriptingInterface_h +#define hifi_AbstractHMDScriptingInterface_h + +#include + +class AbstractHMDScriptingInterface : public QObject { + Q_OBJECT + Q_PROPERTY(bool active READ isHMDMode) + Q_PROPERTY(float ipd READ getIPD) + Q_PROPERTY(float eyeHeight READ getEyeHeight) + Q_PROPERTY(float playerHeight READ getPlayerHeight) + Q_PROPERTY(float ipdScale READ getIPDScale WRITE setIPDScale NOTIFY IPDScaleChanged) + +public: + AbstractHMDScriptingInterface(); + float getIPD() const; + float getEyeHeight() const; + float getPlayerHeight() const; + float getIPDScale() const; + void setIPDScale(float ipdScale); + bool isHMDMode() const; + +signals: + void IPDScaleChanged(); + +private: + float _IPDScale{ 1.0 }; +}; + +#endif // hifi_AbstractHMDScriptingInterface_h diff --git a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h index 8b9d249bd4..b4ae6be97f 100644 --- a/libraries/display-plugins/src/display-plugins/DisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/DisplayPlugin.h @@ -46,6 +46,8 @@ void for_each_eye(F f, FF ff) { class QWindow; +#define AVERAGE_HUMAN_IPD 0.064f + class DisplayPlugin : public Plugin { Q_OBJECT public: @@ -107,21 +109,22 @@ public: return baseProjection; } - virtual glm::mat4 getView(Eye eye, const glm::mat4& baseView) const { - return glm::inverse(getEyePose(eye)) * baseView; - } - // HMD specific methods // TODO move these into another class? - virtual glm::mat4 getEyePose(Eye eye) const { - static const glm::mat4 pose; return pose; + virtual glm::mat4 getEyeToHeadTransform(Eye eye) const { + static const glm::mat4 transform; return transform; } virtual glm::mat4 getHeadPose() const { static const glm::mat4 pose; return pose; } - virtual float getIPD() const { return 0.0f; } + // Needed for timewarp style features + virtual void setEyeRenderPose(Eye eye, const glm::mat4& pose) { + // NOOP + } + + virtual float getIPD() const { return AVERAGE_HUMAN_IPD; } virtual void abandonCalibration() {} virtual void resetSensors() {} diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp index f2a7b06510..859a4a810a 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.cpp @@ -19,7 +19,6 @@ void OculusBaseDisplayPlugin::preRender() { #if (OVR_MAJOR_VERSION >= 6) ovrFrameTiming ftiming = ovr_GetFrameTiming(_hmd, _frameIndex); _trackingState = ovr_GetTrackingState(_hmd, ftiming.DisplayMidpointSeconds); - ovr_CalcEyePoses(_trackingState.HeadPose.ThePose, _eyeOffsets, _eyePoses); #endif } @@ -33,14 +32,19 @@ void OculusBaseDisplayPlugin::resetSensors() { #endif } -glm::mat4 OculusBaseDisplayPlugin::getEyePose(Eye eye) const { - return toGlm(_eyePoses[eye]); +glm::mat4 OculusBaseDisplayPlugin::getEyeToHeadTransform(Eye eye) const { + return glm::translate(mat4(), toGlm(_eyeOffsets[eye])); } glm::mat4 OculusBaseDisplayPlugin::getHeadPose() const { return toGlm(_trackingState.HeadPose.ThePose); } +void OculusBaseDisplayPlugin::setEyeRenderPose(Eye eye, const glm::mat4& pose) { + _eyePoses[eye] = ovrPoseFromGlm(pose); +} + + bool OculusBaseDisplayPlugin::isSupported() const { #if (OVR_MAJOR_VERSION >= 6) if (!OVR_SUCCESS(ovr_Initialize(nullptr))) { @@ -151,9 +155,9 @@ void OculusBaseDisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sce } float OculusBaseDisplayPlugin::getIPD() const { - float result = 0.0f; + float result = OVR_DEFAULT_IPD; #if (OVR_MAJOR_VERSION >= 6) - result = ovr_GetFloat(_hmd, OVR_KEY_IPD, OVR_DEFAULT_IPD); + result = ovr_GetFloat(_hmd, OVR_KEY_IPD, result); #endif return result; -} \ No newline at end of file +} diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h index d879085b8f..6307f6bbf9 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusBaseDisplayPlugin.h @@ -29,8 +29,9 @@ public: virtual glm::uvec2 getRecommendedRenderSize() const override final; virtual glm::uvec2 getRecommendedUiSize() const override final { return uvec2(1920, 1080); } virtual void resetSensors() override final; - virtual glm::mat4 getEyePose(Eye eye) const override final; + virtual glm::mat4 getEyeToHeadTransform(Eye eye) const override final; virtual glm::mat4 getHeadPose() const override final; + virtual void setEyeRenderPose(Eye eye, const glm::mat4& pose) override final; virtual float getIPD() const override final; protected: @@ -39,6 +40,7 @@ protected: protected: ovrPosef _eyePoses[2]; + ovrVector3f _eyeOffsets[2]; mat4 _eyeProjections[3]; mat4 _compositeEyeProjections[2]; @@ -50,13 +52,12 @@ protected: ovrHmd _hmd; float _ipd{ OVR_DEFAULT_IPD }; ovrEyeRenderDesc _eyeRenderDescs[2]; - ovrVector3f _eyeOffsets[2]; ovrFovPort _eyeFovs[2]; - ovrHmdDesc _hmdDesc; - ovrLayerEyeFov _sceneLayer; + ovrHmdDesc _hmdDesc; + ovrLayerEyeFov _sceneLayer; #endif #if (OVR_MAJOR_VERSION == 7) - ovrGraphicsLuid _luid; + ovrGraphicsLuid _luid; #endif }; diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusHelpers.h b/libraries/display-plugins/src/display-plugins/oculus/OculusHelpers.h index df0a6c5228..5a6999075b 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusHelpers.h +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusHelpers.h @@ -79,3 +79,11 @@ inline ovrQuatf ovrFromGlm(const glm::quat & q) { return{ q.x, q.y, q.z, q.w }; } +inline ovrPosef ovrPoseFromGlm(const glm::mat4 & m) { + glm::vec3 translation = glm::vec3(m[3]) / m[3].w; + glm::quat orientation = glm::quat_cast(m); + ovrPosef result; + result.Orientation = ovrFromGlm(orientation); + result.Position = ovrFromGlm(translation); + return result; +} diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.cpp index ade34afcae..1ad61513d6 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.cpp @@ -59,11 +59,11 @@ void OculusLegacyDisplayPlugin::resetSensors() { #endif } -glm::mat4 OculusLegacyDisplayPlugin::getEyePose(Eye eye) const { +glm::mat4 OculusLegacyDisplayPlugin::getEyeToHeadTransform(Eye eye) const { #if (OVR_MAJOR_VERSION == 5) return toGlm(_eyePoses[eye]); #else - return WindowOpenGLDisplayPlugin::getEyePose(eye); + return WindowOpenGLDisplayPlugin::getEyeToHeadTransform(eye); #endif } diff --git a/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.h index 5bce032948..9e2e47f434 100644 --- a/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/oculus/OculusLegacyDisplayPlugin.h @@ -31,7 +31,7 @@ public: virtual glm::uvec2 getRecommendedRenderSize() const override; virtual glm::uvec2 getRecommendedUiSize() const override { return uvec2(1920, 1080); } virtual void resetSensors() override; - virtual glm::mat4 getEyePose(Eye eye) const override; + virtual glm::mat4 getEyeToHeadTransform(Eye eye) const override; virtual glm::mat4 getHeadPose() const override; protected: diff --git a/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.cpp index fab9cc5dd4..faf5a7b781 100644 --- a/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.cpp @@ -160,8 +160,8 @@ void OpenVrDisplayPlugin::resetSensors() { _sensorResetMat = glm::inverse(cancelOutRollAndPitch(_trackedDevicePoseMat4[0])); } -glm::mat4 OpenVrDisplayPlugin::getEyePose(Eye eye) const { - return getHeadPose() * _eyesData[eye]._eyeOffset; +glm::mat4 OpenVrDisplayPlugin::getEyeToHeadTransform(Eye eye) const { + return _eyesData[eye]._eyeOffset; } glm::mat4 OpenVrDisplayPlugin::getHeadPose() const { diff --git a/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.h index afe024e72b..7849623552 100644 --- a/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/openvr/OpenVrDisplayPlugin.h @@ -29,7 +29,7 @@ public: virtual glm::mat4 getProjection(Eye eye, const glm::mat4& baseProjection) const override; virtual void resetSensors() override; - virtual glm::mat4 getEyePose(Eye eye) const override; + virtual glm::mat4 getEyeToHeadTransform(Eye eye) const override; virtual glm::mat4 getHeadPose() const override; protected: diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp index 77906d1857..2ea79ed2e0 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp @@ -61,10 +61,6 @@ glm::mat4 StereoDisplayPlugin::getProjection(Eye eye, const glm::mat4& baseProje return eyeProjection; } -glm::mat4 StereoDisplayPlugin::getEyePose(Eye eye) const { - return mat4(); -} - std::vector _screenActions; void StereoDisplayPlugin::activate() { auto screens = qApp->screens(); diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h index 86f35c1260..33b0b09b0d 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h @@ -21,7 +21,14 @@ public: virtual float getRecommendedAspectRatio() const override; virtual glm::mat4 getProjection(Eye eye, const glm::mat4& baseProjection) const override; - virtual glm::mat4 getEyePose(Eye eye) const override; + + // NOTE, because Stereo displays don't include head tracking, and therefore + // can't include roll or pitch, the eye separation is embedded into the projection + // matrix. However, this eliminates the possibility of easily mainpulating + // the IPD at the Application level, the way we now allow with HMDs. + // If that becomes an issue then we'll need to break up the functionality similar + // to the HMD plugins. + // virtual glm::mat4 getEyeToHeadTransform(Eye eye) const override; protected: void updateScreen(); diff --git a/libraries/plugins/src/plugins/PluginContainer.cpp b/libraries/plugins/src/plugins/PluginContainer.cpp index b27f076eb6..8afac745f3 100644 --- a/libraries/plugins/src/plugins/PluginContainer.cpp +++ b/libraries/plugins/src/plugins/PluginContainer.cpp @@ -9,7 +9,17 @@ static PluginContainer* INSTANCE{ nullptr }; +PluginContainer& PluginContainer::getInstance() { + Q_ASSERT(INSTANCE); + return *INSTANCE; +} + PluginContainer::PluginContainer() { Q_ASSERT(!INSTANCE); INSTANCE = this; }; + +PluginContainer::~PluginContainer() { + Q_ASSERT(INSTANCE == this); + INSTANCE = nullptr; +}; diff --git a/libraries/plugins/src/plugins/PluginContainer.h b/libraries/plugins/src/plugins/PluginContainer.h index c2cba23392..f52799adb3 100644 --- a/libraries/plugins/src/plugins/PluginContainer.h +++ b/libraries/plugins/src/plugins/PluginContainer.h @@ -13,10 +13,13 @@ class QAction; class QGLWidget; class QScreen; +class DisplayPlugin; class PluginContainer { public: + static PluginContainer& getInstance(); PluginContainer(); + virtual ~PluginContainer(); virtual void addMenu(const QString& menuName) = 0; virtual void removeMenu(const QString& menuName) = 0; virtual QAction* addMenuItem(const QString& path, const QString& name, std::function onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") = 0; @@ -28,4 +31,5 @@ public: virtual void showDisplayPluginsTools() = 0; virtual QGLWidget* getPrimarySurface() = 0; virtual bool isForeground() = 0; + virtual const DisplayPlugin* getActiveDisplayPlugin() const = 0; }; From 8cd549c958186b568f71b18d0bd9ad5f22268d61 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 5 Oct 2015 14:02:24 -0700 Subject: [PATCH 06/15] adjust chair and plant starting positions --- unpublishedScripts/masterReset.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index d6759e2b48..1bca00a6f3 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -71,13 +71,13 @@ function createAllToys() { createCombinedArmChair({ x: 549.29, - y: 495.05, + y: 494.9, z: 508.22 }); createPottedPlant({ x: 554.26, - y: 495.23, + y: 495.2, z: 504.53 }); @@ -98,7 +98,7 @@ function createAllToys() { function deleteAllToys() { var entities = Entities.findEntities(MyAvatar.position, 100); - entities.forEach(function (entity) { + entities.forEach(function(entity) { //params: customKey, id, defaultValue var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; if (shouldReset === true) { @@ -831,4 +831,4 @@ function cleanup() { if (shouldDeleteOnEndScript) { Script.scriptEnding.connect(cleanup); -} +} \ No newline at end of file From 9bc95a0fc120f142b821afe33777dae978a5fba3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:17:10 -0700 Subject: [PATCH 07/15] fix override warnings in assignment-client --- assignment-client/src/entities/EntityServer.h | 26 +++++++++---------- libraries/octree/src/OctreeHeadlessViewer.h | 6 ++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/assignment-client/src/entities/EntityServer.h b/assignment-client/src/entities/EntityServer.h index 114e0e1726..065834cbc2 100644 --- a/assignment-client/src/entities/EntityServer.h +++ b/assignment-client/src/entities/EntityServer.h @@ -26,28 +26,28 @@ public: ~EntityServer(); // Subclasses must implement these methods - virtual OctreeQueryNode* createOctreeQueryNode(); - virtual char getMyNodeType() const { return NodeType::EntityServer; } - virtual PacketType getMyQueryMessageType() const { return PacketType::EntityQuery; } - virtual const char* getMyServerName() const { return MODEL_SERVER_NAME; } - virtual const char* getMyLoggingServerTargetName() const { return MODEL_SERVER_LOGGING_TARGET_NAME; } - virtual const char* getMyDefaultPersistFilename() const { return LOCAL_MODELS_PERSIST_FILE; } - virtual PacketType getMyEditNackType() const { return PacketType::EntityEditNack; } - virtual QString getMyDomainSettingsKey() const { return QString("entity_server_settings"); } + virtual OctreeQueryNode* createOctreeQueryNode() override ; + virtual char getMyNodeType() const override { return NodeType::EntityServer; } + virtual PacketType getMyQueryMessageType() const override { return PacketType::EntityQuery; } + virtual const char* getMyServerName() const override { return MODEL_SERVER_NAME; } + virtual const char* getMyLoggingServerTargetName() const override { return MODEL_SERVER_LOGGING_TARGET_NAME; } + virtual const char* getMyDefaultPersistFilename() const override { return LOCAL_MODELS_PERSIST_FILE; } + virtual PacketType getMyEditNackType() const override { return PacketType::EntityEditNack; } + virtual QString getMyDomainSettingsKey() const override { return QString("entity_server_settings"); } // subclass may implement these method - virtual void beforeRun(); - virtual bool hasSpecialPacketsToSend(const SharedNodePointer& node); - virtual int sendSpecialPackets(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent); + virtual void beforeRun() override; + virtual bool hasSpecialPacketsToSend(const SharedNodePointer& node) override; + virtual int sendSpecialPackets(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent) override; - virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode); + virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) override; virtual bool readAdditionalConfiguration(const QJsonObject& settingsSectionObject) override; public slots: void pruneDeletedEntities(); protected: - virtual OctreePointer createTree(); + virtual OctreePointer createTree() override; private slots: void handleEntityPacket(QSharedPointer packet, SharedNodePointer senderNode); diff --git a/libraries/octree/src/OctreeHeadlessViewer.h b/libraries/octree/src/OctreeHeadlessViewer.h index 5a17f48a19..605db15cd2 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.h +++ b/libraries/octree/src/OctreeHeadlessViewer.h @@ -30,9 +30,9 @@ class OctreeHeadlessViewer : public OctreeRenderer { public: OctreeHeadlessViewer(); virtual ~OctreeHeadlessViewer() {}; - virtual void renderElement(OctreeElementPointer element, RenderArgs* args) { /* swallow these */ } + virtual void renderElement(OctreeElementPointer element, RenderArgs* args) override { /* swallow these */ } - virtual void init(); + virtual void init() override ; virtual void render(RenderArgs* renderArgs) override { /* swallow these */ } void setJurisdictionListener(JurisdictionListener* jurisdictionListener) { _jurisdictionListener = jurisdictionListener; } @@ -58,7 +58,7 @@ public slots: // getters for LOD and PPS float getVoxelSizeScale() const { return _voxelSizeScale; } - int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; } + int getBoundaryLevelAdjust() const override { return _boundaryLevelAdjust; } int getMaxPacketsPerSecond() const { return _maxPacketsPerSecond; } unsigned getOctreeElementsCount() const { return _tree->getOctreeElementsCount(); } From e835b5ccf397729f0c120700c7d50121a76c723e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:30:26 -0700 Subject: [PATCH 08/15] remove old gnutls code from domain-server --- domain-server/src/DomainServer.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 614b0a1528..48bb9bed62 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -133,33 +133,14 @@ bool DomainServer::optionallyReadX509KeyAndCertificate() { QString keyPath = _settingsManager.getSettingsMap().value(X509_PRIVATE_KEY_OPTION).toString(); if (!certPath.isEmpty() && !keyPath.isEmpty()) { - // the user wants to use DTLS to encrypt communication with nodes + // the user wants to use the following cert and key for HTTPS + // this is used for Oauth callbacks when authorizing users against a data server // let's make sure we can load the key and certificate -// _x509Credentials = new gnutls_certificate_credentials_t; -// gnutls_certificate_allocate_credentials(_x509Credentials); QString keyPassphraseString = QProcessEnvironment::systemEnvironment().value(X509_KEY_PASSPHRASE_ENV); - qDebug() << "Reading certificate file at" << certPath << "for DTLS."; - qDebug() << "Reading key file at" << keyPath << "for DTLS."; - -// int gnutlsReturn = gnutls_certificate_set_x509_key_file2(*_x509Credentials, -// certPath.toLocal8Bit().constData(), -// keyPath.toLocal8Bit().constData(), -// GNUTLS_X509_FMT_PEM, -// keyPassphraseString.toLocal8Bit().constData(), -// 0); -// -// if (gnutlsReturn < 0) { -// qDebug() << "Unable to load certificate or key file." << "Error" << gnutlsReturn << "- domain-server will now quit."; -// QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); -// return false; -// } - -// qDebug() << "Successfully read certificate and private key."; - - // we need to also pass this certificate and private key to the HTTPS manager - // this is used for Oauth callbacks when authorizing users against a data server + qDebug() << "Reading certificate file at" << certPath << "for HTTPS."; + qDebug() << "Reading key file at" << keyPath << "for HTTPS."; QFile certFile(certPath); certFile.open(QIODevice::ReadOnly); From 1e01d6bd8f0f16e0015278c9dec3a0366a6f808b Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Mon, 5 Oct 2015 15:30:53 -0700 Subject: [PATCH 09/15] Add the ability to switch between mono and stereo in HMD Add the ability to switch between mono and stereo in HMD --- examples/utilities/tools/MonoHMD.js | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/utilities/tools/MonoHMD.js diff --git a/examples/utilities/tools/MonoHMD.js b/examples/utilities/tools/MonoHMD.js new file mode 100644 index 0000000000..5ab0ea4d64 --- /dev/null +++ b/examples/utilities/tools/MonoHMD.js @@ -0,0 +1,68 @@ +// +// MonoHMD.js +// +// Created by Chris Collins on 10/5/15 +// Copyright 2015 High Fidelity, Inc. +// +// This script allows you to switch between mono and stereo mode within the HMD. +// It will add adition menu to Tools called "IPD". +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + + + +function setupipdMenu() { + if (!Menu.menuExists("Tools > IPD")) { + Menu.addMenu("Tools > IPD"); + } + if (!Menu.menuItemExists("Tools > IPD", "Stereo")) { + Menu.addMenuItem({ + menuName: "Tools > IPD", + menuItemName: "Stereo", + isCheckable: true, + isChecked: true + }); + } + if (!Menu.menuItemExists("Tools > IPD", "Mono")) { + Menu.addMenuItem({ + menuName: "Tools > IPD", + menuItemName: "Mono", + isCheckable: true, + isChecked: false + }); + } + +} + + +function menuItemEvent(menuItem) { + if (menuItem == "Stereo") { + Menu.setIsOptionChecked("Mono", false); + HMD.setIPDScale(1.0); + + } + if (menuItem == "Mono") { + Menu.setIsOptionChecked("Stereo", false); + HMD.setIPDScale(0.0); + } + +} + + + +function scriptEnding() { + + Menu.removeMenuItem("Tools > IPD", "Stereo"); + Menu.removeMenuItem("Tools > IPD", "Mono"); + Menu.removeMenu("Tools > IPD"); + //reset the HMD to stereo mode + HMD.setIPDScale(1.0); + +} + + +setupipdMenu(); +Menu.menuItemEvent.connect(menuItemEvent); +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file From c0a881ec52321f8a339d8e4951dd865ba67d19da Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Mon, 5 Oct 2015 15:37:04 -0700 Subject: [PATCH 10/15] added the correct call added the correct call --- examples/utilities/tools/MonoHMD.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/utilities/tools/MonoHMD.js b/examples/utilities/tools/MonoHMD.js index 5ab0ea4d64..4565ebd7bf 100644 --- a/examples/utilities/tools/MonoHMD.js +++ b/examples/utilities/tools/MonoHMD.js @@ -40,12 +40,12 @@ function setupipdMenu() { function menuItemEvent(menuItem) { if (menuItem == "Stereo") { Menu.setIsOptionChecked("Mono", false); - HMD.setIPDScale(1.0); + HMD.ipdScale = 1.0; } if (menuItem == "Mono") { Menu.setIsOptionChecked("Stereo", false); - HMD.setIPDScale(0.0); + HMD.ipdScale = 0.0; } } From 3ddfcc10c2dcf591038f8d8af9d7dadaeac89deb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:50:35 -0700 Subject: [PATCH 11/15] override additions to input-plugins --- libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h | 2 +- libraries/input-plugins/src/input-plugins/SDL2Manager.h | 2 +- libraries/input-plugins/src/input-plugins/SixenseManager.h | 2 +- .../input-plugins/src/input-plugins/ViveControllerManager.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h index 70e2ee5d34..6f703bc6f9 100644 --- a/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h +++ b/libraries/input-plugins/src/input-plugins/KeyboardMouseDevice.h @@ -59,7 +59,7 @@ public: // Plugin functions virtual bool isSupported() const override { return true; } virtual bool isJointController() const override { return false; } - const QString& getName() const { return NAME; } + const QString& getName() const override { return NAME; } virtual void activate() override {}; virtual void deactivate() override {}; diff --git a/libraries/input-plugins/src/input-plugins/SDL2Manager.h b/libraries/input-plugins/src/input-plugins/SDL2Manager.h index f017e2cc65..52d39597ef 100644 --- a/libraries/input-plugins/src/input-plugins/SDL2Manager.h +++ b/libraries/input-plugins/src/input-plugins/SDL2Manager.h @@ -30,7 +30,7 @@ public: // Plugin functions virtual bool isSupported() const override; virtual bool isJointController() const override { return false; } - const QString& getName() const { return NAME; } + const QString& getName() const override { return NAME; } virtual void init() override; virtual void deinit() override; diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.h b/libraries/input-plugins/src/input-plugins/SixenseManager.h index 22340cfc95..5e3815cd20 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.h +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.h @@ -63,7 +63,7 @@ public: // Plugin functions virtual bool isSupported() const override; virtual bool isJointController() const override { return true; } - const QString& getName() const { return NAME; } + const QString& getName() const override { return NAME; } virtual void activate() override; virtual void deactivate() override; diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.h b/libraries/input-plugins/src/input-plugins/ViveControllerManager.h index 98f32b9f35..5cae8daaf4 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.h +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.h @@ -53,7 +53,7 @@ public: // Plugin functions virtual bool isSupported() const override; virtual bool isJointController() const override { return true; } - const QString& getName() const { return NAME; } + const QString& getName() const override { return NAME; } virtual void activate() override; virtual void deactivate() override; From a2c9d7a4b2502837918512529896a7b28b2dad2c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:52:47 -0700 Subject: [PATCH 12/15] add overrides for Avatar classes in Interface --- interface/src/avatar/MyAvatar.h | 32 ++++++++++++++-------------- interface/src/avatar/SkeletonModel.h | 6 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 96c9f37c39..5d87737dd7 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -139,19 +139,19 @@ public: void updateLookAtTargetAvatar(); void clearLookAtTargetAvatar(); - virtual void setJointRotations(QVector jointRotations); - virtual void setJointTranslations(QVector jointTranslations); - virtual void setJointData(int index, const glm::quat& rotation, const glm::vec3& translation); - virtual void setJointRotation(int index, const glm::quat& rotation); - virtual void setJointTranslation(int index, const glm::vec3& translation); - virtual void clearJointData(int index); - virtual void clearJointsData(); + virtual void setJointRotations(QVector jointRotations) override; + virtual void setJointTranslations(QVector jointTranslations) override; + virtual void setJointData(int index, const glm::quat& rotation, const glm::vec3& translation) override; + virtual void setJointRotation(int index, const glm::quat& rotation) override; + virtual void setJointTranslation(int index, const glm::vec3& translation) override; + virtual void clearJointData(int index) override; + virtual void clearJointsData() override; Q_INVOKABLE void useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelName = QString()); Q_INVOKABLE const QUrl& getFullAvatarURLFromPreferences() const { return _fullAvatarURLFromPreferences; } Q_INVOKABLE const QString& getFullAvatarModelName() const { return _fullAvatarModelName; } - virtual void setAttachmentData(const QVector& attachmentData); + virtual void setAttachmentData(const QVector& attachmentData) override; DynamicCharacterController* getCharacterController() { return &_characterController; } @@ -218,7 +218,7 @@ public slots: void saveRecording(QString filename); void loadLastRecording(); - virtual void rebuildSkeletonBody(); + virtual void rebuildSkeletonBody() override; bool getEnableRigAnimations() const { return _rig->getEnableRig(); } void setEnableRigAnimations(bool isEnabled); @@ -243,7 +243,7 @@ private: glm::vec3 getWorldBodyPosition() const; glm::quat getWorldBodyOrientation() const; - QByteArray toByteArray(bool cullSmallChanges, bool sendAll); + QByteArray toByteArray(bool cullSmallChanges, bool sendAll) override; void simulate(float deltaTime); void updateFromTrackers(float deltaTime); virtual void render(RenderArgs* renderArgs, const glm::vec3& cameraPositio) override; @@ -252,9 +252,9 @@ private: void setShouldRenderLocally(bool shouldRender) { _shouldRender = shouldRender; } bool getShouldRenderLocally() const { return _shouldRender; } bool getDriveKeys(int key) { return _driveKeys[key] != 0.0f; }; - bool isMyAvatar() const { return true; } - virtual int parseDataFromBuffer(const QByteArray& buffer); - virtual glm::vec3 getSkeletonPosition() const; + bool isMyAvatar() const override { return true; } + virtual int parseDataFromBuffer(const QByteArray& buffer) override; + virtual glm::vec3 getSkeletonPosition() const override; glm::vec3 getScriptedMotorVelocity() const { return _scriptedMotorVelocity; } float getScriptedMotorTimescale() const { return _scriptedMotorTimescale; } @@ -264,7 +264,7 @@ private: void setScriptedMotorFrame(QString frame); virtual void attach(const QString& modelURL, const QString& jointName = QString(), const glm::vec3& translation = glm::vec3(), const glm::quat& rotation = glm::quat(), float scale = 1.0f, - bool allowDuplicates = false, bool useSaved = true); + bool allowDuplicates = false, bool useSaved = true) override; void renderLaserPointers(gpu::Batch& batch); const RecorderPointer getRecorder() const { return _recorder; } @@ -273,8 +273,8 @@ private: bool cameraInsideHead() const; // These are made private for MyAvatar so that you will use the "use" methods instead - virtual void setFaceModelURL(const QUrl& faceModelURL); - virtual void setSkeletonModelURL(const QUrl& skeletonModelURL); + virtual void setFaceModelURL(const QUrl& faceModelURL) override; + virtual void setSkeletonModelURL(const QUrl& skeletonModelURL) override; void setVisibleInSceneIfReady(Model* model, render::ScenePointer scene, bool visiblity); diff --git a/interface/src/avatar/SkeletonModel.h b/interface/src/avatar/SkeletonModel.h index e2c3ab8f83..d655d6e01f 100644 --- a/interface/src/avatar/SkeletonModel.h +++ b/interface/src/avatar/SkeletonModel.h @@ -27,10 +27,10 @@ public: SkeletonModel(Avatar* owningAvatar, QObject* parent = nullptr, RigPointer rig = nullptr); ~SkeletonModel(); - virtual void initJointStates(QVector states); + virtual void initJointStates(QVector states) override; - virtual void simulate(float deltaTime, bool fullUpdate = true); - virtual void updateRig(float deltaTime, glm::mat4 parentTransform); + virtual void simulate(float deltaTime, bool fullUpdate = true) override; + virtual void updateRig(float deltaTime, glm::mat4 parentTransform) override; void updateAttitude(); void renderIKConstraints(gpu::Batch& batch); From 25a1f2dd11a855c544f6c2d8b79e21a9c9d2d9c2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:53:37 -0700 Subject: [PATCH 13/15] add override to suppress warning for PluginContainerProxy --- interface/src/PluginContainerProxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/PluginContainerProxy.h b/interface/src/PluginContainerProxy.h index e01cabc3b8..16e9b951fe 100644 --- a/interface/src/PluginContainerProxy.h +++ b/interface/src/PluginContainerProxy.h @@ -16,7 +16,7 @@ class PluginContainerProxy : public QObject, PluginContainer { virtual QAction* addMenuItem(const QString& path, const QString& name, std::function onClicked, bool checkable = false, bool checked = false, const QString& groupName = "") override; virtual void removeMenuItem(const QString& menuName, const QString& menuItem) override; virtual bool isOptionChecked(const QString& name) override; - virtual void setIsOptionChecked(const QString& path, bool checked); + virtual void setIsOptionChecked(const QString& path, bool checked) override; virtual void setFullscreen(const QScreen* targetScreen, bool hideMenu = true) override; virtual void unsetFullscreen(const QScreen* avoidScreen = nullptr) override; virtual void showDisplayPluginsTools() override; From 7bd98354d819219aa6557337a0ca6a2cd3891e9a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:53:52 -0700 Subject: [PATCH 14/15] add override to supress warnings in ui-test --- tests/ui/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ui/src/main.cpp b/tests/ui/src/main.cpp index 6611e8f343..3879d0b029 100644 --- a/tests/ui/src/main.cpp +++ b/tests/ui/src/main.cpp @@ -260,7 +260,7 @@ protected: } - void keyPressEvent(QKeyEvent* event) { + void keyPressEvent(QKeyEvent* event) override { _altPressed = Qt::Key_Alt == event->key(); switch (event->key()) { case Qt::Key_B: @@ -292,13 +292,13 @@ protected: QWindow::keyPressEvent(event); } QQmlContext* menuContext{ nullptr }; - void keyReleaseEvent(QKeyEvent *event) { + void keyReleaseEvent(QKeyEvent *event) override { if (_altPressed && Qt::Key_Alt == event->key()) { VrMenu::toggle(); } } - void moveEvent(QMoveEvent* event) { + void moveEvent(QMoveEvent* event) override { static qreal oldPixelRatio = 0.0; if (devicePixelRatio() != oldPixelRatio) { oldPixelRatio = devicePixelRatio(); From 5989cad054410eb64d0fc23d671245b6fc41597c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 5 Oct 2015 15:55:05 -0700 Subject: [PATCH 15/15] add override qualifier to suppress warnings in entities-renderer --- .../src/RenderableParticleEffectEntityItem.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h index 9581c43ca5..5d69d19026 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h @@ -25,8 +25,8 @@ public: void updateRenderItem(); - virtual bool addToScene(EntityItemPointer self, render::ScenePointer scene, render::PendingChanges& pendingChanges); - virtual void removeFromScene(EntityItemPointer self, render::ScenePointer scene, render::PendingChanges& pendingChanges); + virtual bool addToScene(EntityItemPointer self, render::ScenePointer scene, render::PendingChanges& pendingChanges) override; + virtual void removeFromScene(EntityItemPointer self, render::ScenePointer scene, render::PendingChanges& pendingChanges) override; protected: render::ItemID _renderItemId;