From 2d277a2abd0125a9c98ba00768ef49f722706e7b Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 17 Jul 2015 11:28:25 -0700 Subject: [PATCH 01/19] Fix https://app.asana.com/0/30233891560551/41734486809354/f --- libraries/audio/src/AudioInjector.cpp | 4 ++++ libraries/audio/src/AudioInjector.h | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index f49d51bb8b..057836fb75 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -93,6 +93,7 @@ void AudioInjector::injectAudio() { } void AudioInjector::restart() { + _isPlaying = true; connect(this, &AudioInjector::finished, this, &AudioInjector::restartPortionAfterFinished); if (!_isStarted || _isFinished) { emit finished(); @@ -270,6 +271,7 @@ void AudioInjector::injectToMixer() { } setIsFinished(true); + _isPlaying = !_isFinished; // Which can be false if a restart was requested } void AudioInjector::stop() { @@ -277,6 +279,7 @@ void AudioInjector::stop() { if (_options.localOnly) { // we're only a local injector, so we can say we are finished right away too + _isPlaying = false; setIsFinished(true); } } @@ -334,6 +337,7 @@ AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInj injectorThread->setObjectName("Audio Injector Thread"); AudioInjector* injector = new AudioInjector(buffer, options); + injector->_isPlaying = true; injector->setLocalAudioInterface(localInterface); injector->moveToThread(injectorThread); diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index 806a4ea33e..88d3f1e151 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -62,7 +62,7 @@ public slots: void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; } float getLoudness() const { return _loudness; } - bool isPlaying() const { return !_isFinished; } + bool isPlaying() const { return _isPlaying; } void restartPortionAfterFinished(); signals: @@ -78,6 +78,7 @@ private: AudioInjectorOptions _options; bool _shouldStop = false; float _loudness = 0.0f; + bool _isPlaying = false; bool _isStarted = false; bool _isFinished = false; bool _shouldDeleteAfterFinish = false; From 5ae1af0d623a5e83e93dc7be349666d42648524a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 17 Jul 2015 16:33:19 -0700 Subject: [PATCH 02/19] Update users.js to persist isMinimized value --- examples/users.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/users.js b/examples/users.js index d9fe76418d..f63184625d 100644 --- a/examples/users.js +++ b/examples/users.js @@ -286,6 +286,8 @@ var usersWindow = (function () { MENU_ITEM = "Users Online", MENU_ITEM_AFTER = "Chat...", + SETTING_USERS_WINDOW_MINIMIZED = "UsersWindow.Minimized", + isVisible = true, isMinimized = false, @@ -869,9 +871,13 @@ var usersWindow = (function () { pollUsers(); + // Set minimized at end - setup code does not handle `minimized == false` correctly + setMinimized(Settings.getValue(SETTING_USERS_WINDOW_MINIMIZED, false)); } function tearDown() { + Settings.setValue(SETTING_USERS_WINDOW_MINIMIZED, isMinimized); + Menu.removeMenuItem(MENU_NAME, MENU_ITEM); Script.clearTimeout(usersTimer); From d68618e2065310d09535f4c0551bdeb1d7e73740 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 00:46:09 -0700 Subject: [PATCH 03/19] Removing GL headers from most files, and some naked GL from application.cpp --- interface/src/Application.cpp | 93 ++--- interface/src/Application.h | 7 +- interface/src/GLCanvas.h | 1 + interface/src/Stars.cpp | 105 ++++-- interface/src/Stars.h | 26 +- interface/src/audio/AudioScope.cpp | 2 - interface/src/avatar/Avatar.cpp | 5 +- interface/src/avatar/Hand.cpp | 3 - interface/src/avatar/Hand.h | 1 - interface/src/avatar/Head.cpp | 1 - interface/src/avatar/Head.h | 1 - interface/src/avatar/MyAvatar.cpp | 1 - interface/src/devices/OculusManager.cpp | 7 +- interface/src/devices/OculusManager.h | 4 +- .../src/octree/OctreePacketProcessor.cpp | 1 - interface/src/starfield/Config.h | 62 ---- interface/src/starfield/Controller.cpp | 70 ---- interface/src/starfield/Controller.h | 44 --- interface/src/starfield/Generator.cpp | 94 ----- interface/src/starfield/Generator.h | 40 --- interface/src/starfield/data/GpuVertex.cpp | 26 -- interface/src/starfield/data/GpuVertex.h | 37 -- interface/src/starfield/data/InputVertex.cpp | 27 -- interface/src/starfield/data/InputVertex.h | 39 --- interface/src/starfield/data/Tile.h | 32 -- interface/src/starfield/renderer/Renderer.cpp | 324 ------------------ interface/src/starfield/renderer/Renderer.h | 142 -------- interface/src/starfield/renderer/Tiling.h | 48 --- .../src/starfield/renderer/VertexOrder.cpp | 20 -- .../src/starfield/renderer/VertexOrder.h | 41 --- interface/src/ui/ApplicationOverlay.cpp | 3 - interface/src/ui/Stats.cpp | 2 - interface/src/ui/Stats.h | 7 +- .../src/EntityTreeRenderer.cpp | 3 - .../src/RenderableBoxEntityItem.cpp | 1 - .../src/RenderableDebugableEntityItem.cpp | 1 - .../src/RenderableLightEntityItem.cpp | 1 - .../src/RenderableLineEntityItem.cpp | 1 - .../src/RenderableModelEntityItem.cpp | 2 - .../RenderableParticleEffectEntityItem.cpp | 2 - .../src/RenderablePolyVoxEntityItem.cpp | 2 - .../src/RenderableSphereEntityItem.cpp | 1 - .../src/RenderableTextEntityItem.cpp | 2 - .../src/RenderableWebEntityItem.cpp | 6 +- .../src/RenderableZoneEntityItem.cpp | 1 - libraries/gpu/src/gpu/Batch.cpp | 17 + libraries/gpu/src/gpu/Batch.h | 70 ++-- libraries/gpu/src/gpu/GLBackend.cpp | 1 + libraries/gpu/src/gpu/GLBackend.h | 2 + libraries/gpu/src/gpu/GLBackendOutput.cpp | 19 + libraries/gpu/src/gpu/Query.h | 1 - .../src/AmbientOcclusionEffect.cpp | 3 - .../render-utils/src/AmbientOcclusionEffect.h | 3 +- .../src/DeferredLightingEffect.cpp | 10 +- .../render-utils/src/DeferredLightingEffect.h | 2 - libraries/render-utils/src/Environment.h | 1 - libraries/render-utils/src/GeometryCache.cpp | 2 - libraries/render-utils/src/GeometryCache.h | 11 +- libraries/render-utils/src/Model.cpp | 2 - libraries/render-utils/src/Model.h | 3 - .../render-utils/src/OffscreenGlCanvas.cpp | 25 +- .../render-utils/src/OffscreenGlCanvas.h | 11 +- .../render-utils/src/OffscreenQmlSurface.cpp | 38 +- .../render-utils/src/OffscreenQmlSurface.h | 41 +-- .../render-utils/src/RenderDeferredTask.cpp | 13 +- libraries/render-utils/src/RenderUtil.cpp | 2 - libraries/render-utils/src/TextRenderer3D.cpp | 2 - libraries/render-utils/src/TextureCache.cpp | 23 -- libraries/render-utils/src/TextureCache.h | 16 +- libraries/render-utils/src/text/Font.cpp | 2 +- libraries/render/src/render/DrawStatus.cpp | 16 +- libraries/render/src/render/DrawTask.cpp | 15 +- libraries/shared/src/RenderArgs.h | 1 + libraries/shared/src/windowshacks.h | 7 + libraries/ui/src/OffscreenQmlElement.h | 82 +++++ libraries/ui/src/OffscreenUi.cpp | 2 +- libraries/ui/src/OffscreenUi.h | 65 +--- 77 files changed, 396 insertions(+), 1451 deletions(-) delete mode 100644 interface/src/starfield/Config.h delete mode 100644 interface/src/starfield/Controller.cpp delete mode 100644 interface/src/starfield/Controller.h delete mode 100644 interface/src/starfield/Generator.cpp delete mode 100644 interface/src/starfield/Generator.h delete mode 100644 interface/src/starfield/data/GpuVertex.cpp delete mode 100644 interface/src/starfield/data/GpuVertex.h delete mode 100644 interface/src/starfield/data/InputVertex.cpp delete mode 100644 interface/src/starfield/data/InputVertex.h delete mode 100644 interface/src/starfield/data/Tile.h delete mode 100644 interface/src/starfield/renderer/Renderer.cpp delete mode 100644 interface/src/starfield/renderer/Renderer.h delete mode 100644 interface/src/starfield/renderer/Tiling.h delete mode 100644 interface/src/starfield/renderer/VertexOrder.cpp delete mode 100644 interface/src/starfield/renderer/VertexOrder.h create mode 100644 libraries/ui/src/OffscreenQmlElement.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1aa9fe0427..45fd7ebc09 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -84,7 +84,6 @@ #include #include #include -#include #include #include #include @@ -100,6 +99,7 @@ #include "Application.h" #include "AudioClient.h" #include "DiscoverabilityManager.h" +#include "GLCanvas.h" #include "InterfaceVersion.h" #include "LODManager.h" #include "Menu.h" @@ -174,8 +174,6 @@ public: using namespace std; // Starfield information -static unsigned STARFIELD_NUM_STARS = 50000; -static unsigned STARFIELD_SEED = 1; static uint8_t THROTTLED_IDLE_TIMER_DELAY = 10; const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB @@ -343,7 +341,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _domainConnectionRefusals(QList()), _maxOctreePPS(maxOctreePacketsPerSecond.get()), _lastFaceTrackerUpdate(0), - _applicationOverlay() + _applicationOverlay(), + _glWidget(new GLCanvas()) { setInstance(this); #ifdef Q_OS_WIN @@ -976,39 +975,41 @@ void Application::paintGL() { } else { PROFILE_RANGE(__FUNCTION__ "/mainRender"); - auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); - GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // Viewport is assigned to the size of the framebuffer - QSize size = DependencyManager::get()->getFrameBufferSize(); - glViewport(0, 0, size.width(), size.height()); - renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + { + gpu::Batch batch; + auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + batch.setFramebuffer(primaryFbo); + // clear the normal and specular buffers + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_COLOR0 | + gpu::Framebuffer::BUFFER_COLOR1 | + gpu::Framebuffer::BUFFER_COLOR2 | + gpu::Framebuffer::BUFFER_DEPTH, + vec4(vec3(0), 1), 1.0, 0.0); + + // Viewport is assigned to the size of the framebuffer + QSize size = DependencyManager::get()->getFrameBufferSize(); + renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height()); + batch.setViewportTransform(renderArgs._viewport); + renderArgs._context->render(batch); + } + displaySide(&renderArgs, _myCamera); - glPopMatrix(); - renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { renderRearViewMirror(&renderArgs, _mirrorViewRect); } - renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; - auto finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); - - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); - glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y, - 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(), - GL_COLOR_BUFFER_BIT, GL_LINEAR); - glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); - - glBindTexture(GL_TEXTURE_2D, 0); // ??? + { + auto geometryCache = DependencyManager::get(); + auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + gpu::Batch batch; + batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y), + nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height())); + renderArgs._context->render(batch); + } _compositor.displayOverlayTexture(&renderArgs); } @@ -1078,11 +1079,7 @@ void Application::resizeGL() { if (_renderResolution != toGlm(renderSize)) { _renderResolution = toGlm(renderSize); DependencyManager::get()->setFrameBufferSize(renderSize); - - glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu??? - updateProjectionMatrix(); - glLoadIdentity(); } resetCameras(_myCamera, _renderResolution); @@ -1101,16 +1098,10 @@ void Application::updateProjectionMatrix() { void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) { _projectionMatrix = camera.getProjection(); - - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(glm::value_ptr(_projectionMatrix)); - // Tell our viewFrustum about this change, using the application camera if (updateViewFrustum) { loadViewFrustum(camera, _viewFrustum); } - - glMatrixMode(GL_MODELVIEW); } void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) { @@ -1954,7 +1945,6 @@ void Application::setEnableVRMode(bool enableVRMode) { OculusManager::connect(_glWidget->context()->contextHandle()); _glWidget->setFocus(); _glWidget->makeCurrent(); - glClear(GL_COLOR_BUFFER_BIT); } OculusManager::recalibrate(); } else { @@ -2157,12 +2147,6 @@ QVector Application::pasteEntities(float x, float y, float z) { } void Application::initDisplay() { - glEnable(GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); - glShadeModel(GL_SMOOTH); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); } void Application::init() { @@ -3322,9 +3306,6 @@ namespace render { PerformanceTimer perfTimer("stars"); PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::payloadRender() ... stars..."); - if (!background->_stars.isStarsLoaded()) { - background->_stars.generate(STARFIELD_NUM_STARS, STARFIELD_SEED); - } // should be the first rendering pass - w/o depth buffer / lighting // compute starfield alpha based on distance from atmosphere @@ -3372,7 +3353,7 @@ namespace render { // finally render the starfield if (hasStars) { - background->_stars.render(args->_viewFrustum->getFieldOfView(), args->_viewFrustum->getAspectRatio(), args->_viewFrustum->getNearClip(), alpha); + background->_stars.render(args, alpha); } // draw the sky dome @@ -3416,14 +3397,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se // load the view frustum loadViewFrustum(theCamera, _displayViewFrustum); - // transform view according to theCamera - // could be myCamera (if in normal mode) - // or could be viewFrustumOffsetCamera if in offset mode - - glm::quat rotation = theCamera.getRotation(); - glm::vec3 axis = glm::axis(rotation); - glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - // store view matrix without translation, which we'll use for precision-sensitive objects updateUntranslatedViewMatrix(-theCamera.getPosition()); @@ -3432,7 +3405,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se // this is what is used for rendering the Entities and avatars Transform viewTransform; viewTransform.setTranslation(theCamera.getPosition()); - viewTransform.setRotation(rotation); + viewTransform.setRotation(theCamera.getRotation()); if (renderArgs->_renderSide != RenderArgs::MONO) { glm::mat4 invView = glm::inverse(_untranslatedViewMatrix); @@ -3442,8 +3415,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se setViewTransform(viewTransform); - glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); - // Setup 3D lights (after the camera transform, so that they are positioned in world space) { PerformanceTimer perfTimer("lights"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 1fe1acb25a..c5445db1e8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -12,8 +12,6 @@ #ifndef hifi_Application_h #define hifi_Application_h -#include - #include #include #include @@ -47,7 +45,6 @@ #include "DatagramProcessor.h" #include "Environment.h" #include "FileLogger.h" -#include "GLCanvas.h" #include "Menu.h" #include "PacketHeaders.h" #include "Physics.h" @@ -84,10 +81,10 @@ class QSystemTrayIcon; class QTouchEvent; class QWheelEvent; +class GLCanvas; class FaceTracker; class MainWindow; class Node; -class ProgramObject; class ScriptEngine; static const QString SNAPSHOT_EXTENSION = ".jpg"; @@ -647,7 +644,7 @@ private: QThread _settingsThread; QTimer _settingsTimer; - GLCanvas* _glWidget = new GLCanvas(); // our GLCanvas has a couple extra features + GLCanvas* _glWidget{ nullptr }; void checkSkeleton(); diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 6c53a17e04..925061edd0 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -13,6 +13,7 @@ #define hifi_GLCanvas_h #include +#include #include #include diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index ab7507a228..ce43f3761d 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -13,37 +13,94 @@ #include -#include "InterfaceConfig.h" -#include "starfield/Controller.h" - -Stars::Stars() : - _controller(0l), _starsLoaded(false) { - _controller = new starfield::Controller; +Stars::Stars() { } Stars::~Stars() { - delete _controller; } -bool Stars::generate(unsigned numStars, unsigned seed) { - _starsLoaded = _controller->computeStars(numStars, seed); - return _starsLoaded; +void Stars::render(RenderArgs* args, float alpha) { } -bool Stars::setResolution(unsigned k) { - return _controller->setResolution(k); + +/* +static unsigned STARFIELD_NUM_STARS = 50000; +static unsigned STARFIELD_SEED = 1; +const float Generator::STAR_COLORIZATION = 0.1f; +const float PI_OVER_180 = 3.14159265358979f / 180.0f; + +void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) { + InputVertices* vertices = &destination; + //_limit = limit; + + QElapsedTimer startTime; + startTime.start(); + + srand(seed); + + vertices->clear(); + vertices->reserve(limit); + + const unsigned MILKY_WAY_WIDTH = 12.0; // width in degrees of one half of the Milky Way + const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees + const float MILKY_WAY_RATIO = 0.4f; + const unsigned NUM_DEGREES = 360; + + for (int star = 0; star < floor(limit * (1 - MILKY_WAY_RATIO)); ++star) { + float azimuth, altitude; + azimuth = (((float)rand() / (float)RAND_MAX) * NUM_DEGREES) - (NUM_DEGREES / 2); + altitude = (acos((2.0f * ((float)rand() / (float)RAND_MAX)) - 1.0f) / PI_OVER_180) + 90; + vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION))); + } + + for (int star = 0; star < ceil(limit * MILKY_WAY_RATIO); ++star) { + float azimuth = ((float)rand() / (float)RAND_MAX) * NUM_DEGREES; + float altitude = powf(randFloat()*0.5f, 2.0f) / 0.25f * MILKY_WAY_WIDTH; + if (randFloat() > 0.5f) { + altitude *= -1.0f; + } + + // we need to rotate the Milky Way band to the correct orientation in the sky + // convert from spherical coordinates to cartesian, rotate the point and then convert back. + // An improvement would be to convert all stars to cartesian at this point and not have to convert back. + + float tempX = sin(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180); + float tempY = sin(altitude * PI_OVER_180); + float tempZ = -cos(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180); + + float xangle = MILKY_WAY_INCLINATION * PI_OVER_180; + float newX = (tempX * cos(xangle)) - (tempY * sin(xangle)); + float newY = (tempX * sin(xangle)) + (tempY * cos(xangle)); + float newZ = tempZ; + + azimuth = (atan2(newX, -newZ) + Radians::pi()) / PI_OVER_180; + altitude = atan2(-newY, hypotf(newX, newZ)) / PI_OVER_180; + + vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION))); + } + + double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms + qDebug() << "Total time to generate stars: " << timeDiff << " msec"; } -void Stars::render(float fovY, float aspect, float nearZ, float alpha) { - // determine length of screen diagonal from quadrant height and aspect ratio - float quadrantHeight = nearZ * tanf(RADIANS_PER_DEGREE * fovY * 0.5f); - float halfDiagonal = sqrt(quadrantHeight * quadrantHeight * (1.0f + aspect * aspect)); - - // determine fov angle in respect to the diagonal - float fovDiagonal = atanf(halfDiagonal / nearZ) * 2.0f; - - // pull the modelview matrix off the GL stack - glm::mat4 view; glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(view)); - - _controller->render(fovDiagonal, aspect, glm::affineInverse(view), alpha); +// computeStarColor +// - Generate a star color. +// +// colorization can be a value between 0 and 1 specifying how colorful the resulting star color is. +// +// 0 = completely black & white +// 1 = very colorful +unsigned Generator::computeStarColor(float colorization) { + unsigned char red, green, blue; + if (randFloat() < 0.3f) { + // A few stars are colorful + red = 2 + (rand() % 254); + green = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization)); + blue = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization)); + } else { + // Most stars are dimmer and white + red = green = blue = 2 + (rand() % 128); + } + return red | (green << 8) | (blue << 16); } +*/ \ No newline at end of file diff --git a/interface/src/Stars.h b/interface/src/Stars.h index 08f218b9fa..73f04755ab 100644 --- a/interface/src/Stars.h +++ b/interface/src/Stars.h @@ -12,9 +12,7 @@ #ifndef hifi_Stars_h #define hifi_Stars_h -#include - -namespace starfield { class Controller; } +class RenderArgs; // Starfield rendering component. class Stars { @@ -22,33 +20,13 @@ public: Stars(); ~Stars(); - // Generate stars from random number - // The numStars parameter sets the number of stars to generate. - bool generate(unsigned numStars, unsigned seed); - // Renders the starfield from a local viewer's perspective. // The parameters specifiy the field of view. - void render(float fovY, float aspect, float nearZ, float alpha); - - // Sets the resolution for FOV culling. - // - // The parameter determines the number of tiles in azimuthal - // and altitudinal directions. - // - // GPU resources are updated upon change in which case 'true' - // is returned. - bool setResolution(unsigned k); - - // Returns true when stars have been loaded - bool isStarsLoaded() const { return _starsLoaded; }; + void render(RenderArgs* args, float alpha); private: // don't copy/assign Stars(Stars const&); // = delete; Stars& operator=(Stars const&); // delete; - - starfield::Controller* _controller; - - bool _starsLoaded; }; diff --git a/interface/src/audio/AudioScope.cpp b/interface/src/audio/AudioScope.cpp index 75a5137ca4..8f9d072b8e 100644 --- a/interface/src/audio/AudioScope.cpp +++ b/interface/src/audio/AudioScope.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include #include diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 239359c1cf..979995360e 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -11,8 +11,6 @@ #include -#include - #include #include @@ -708,6 +706,9 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa // Compute pixel alignment offset float clipToPix = 0.5f * windowSizeY / p1.w; // Got from clip to pixel coordinates glm::vec4 screenPos = clipToPix * p1; // in pixels coords +// WTF? +#undef round + glm::vec4 screenOffset = (glm::round(screenPos) - screenPos) / clipToPix; // in clip coords glm::vec3 worldOffset = glm::vec3(screenOffset.x, screenOffset.y, 0.0f) / (float)pixelHeight; diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 7b2968973c..63604d710d 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -8,13 +8,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include // hack to get windows to build - #include #include #include -#include #include "AvatarManager.h" #include "Hand.h" diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index f6991c5a55..a4c0265545 100644 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -30,7 +30,6 @@ class Avatar; -class ProgramObject; const float HAND_PADDLE_OFFSET = 0.1f; const float HAND_PADDLE_THICKNESS = 0.01f; diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 98126c3a22..43e68557ce 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -9,7 +9,6 @@ // #include -#include #include #include diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 3f839d53bc..2baa16f90c 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -26,7 +26,6 @@ const float EYE_EAR_GAP = 0.08f; class Avatar; -class ProgramObject; class Head : public HeadData { public: diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 93303c3536..bd0608a876 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -19,7 +19,6 @@ #include -#include #include #include #include diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index da7c7a7d2f..fd40ca592d 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -10,16 +10,16 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" #include "OculusManager.h" -#include "ui/overlays/Text3DOverlay.h" +#include -#include #include #include #include #include +#include +#include #include #include @@ -35,6 +35,7 @@ #include "InterfaceLogging.h" #include "Application.h" +#include "ui/overlays/Text3DOverlay.h" template void for_each_eye(Function function) { diff --git a/interface/src/devices/OculusManager.h b/interface/src/devices/OculusManager.h index 83ecbf0fb7..87f022a294 100644 --- a/interface/src/devices/OculusManager.h +++ b/interface/src/devices/OculusManager.h @@ -13,14 +13,16 @@ #ifndef hifi_OculusManager_h #define hifi_OculusManager_h -#include #include #include #include +#include + #include "RenderArgs.h" class QOpenGLContext; +class QGLWidget; class Camera; /// Handles interaction with the Oculus Rift. diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index 4eac1e6803..33486e3a25 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -103,4 +103,3 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode, } } } - diff --git a/interface/src/starfield/Config.h b/interface/src/starfield/Config.h deleted file mode 100644 index 00f827dad7..0000000000 --- a/interface/src/starfield/Config.h +++ /dev/null @@ -1,62 +0,0 @@ -// -// Config.h -// interface/src/starfield -// -// Created by Tobias Schwinger on 3/29/13. -// Copyright 2013 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 -// - -#ifndef hifi_Config_h -#define hifi_Config_h - -#include "InterfaceConfig.h" - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include "AngleUtil.h" -#include "Radix2InplaceSort.h" -#include "Radix2IntegerScanner.h" -#include "FloodFill.h" - -// Namespace configuration: - -namespace starfield { - - using glm::vec3; - using glm::vec4; - using glm::dot; - using glm::normalize; - using glm::mat4; - using glm::row; - - using namespace std; - - typedef uint32_t nuint; - typedef quint64 wuint; - -} - -#endif // hifi_Config_h diff --git a/interface/src/starfield/Controller.cpp b/interface/src/starfield/Controller.cpp deleted file mode 100644 index d0d46adbdc..0000000000 --- a/interface/src/starfield/Controller.cpp +++ /dev/null @@ -1,70 +0,0 @@ -// -// Controller.cpp -// interface/src/starfield -// -// Created by Chris Barnard on 10/16/13. -// Copyright 2013 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 - -#include "InterfaceLogging.h" -#include "starfield/Controller.h" - -using namespace starfield; - -bool Controller::computeStars(unsigned numStars, unsigned seed) { - QElapsedTimer startTime; - startTime.start(); - - Generator::computeStarPositions(_inputSequence, numStars, seed); - - this->retile(numStars, _tileResolution); - - double NSEC_TO_MSEC = 1.0 / 1000000.0; - double timeDiff = (double)startTime.nsecsElapsed() * NSEC_TO_MSEC; - qCDebug(interfaceapp) << "Total time to retile and generate stars: " << timeDiff << "msec"; - - return true; -} - -bool Controller::setResolution(unsigned tileResolution) { - if (tileResolution <= 3) { - return false; - } - - if (tileResolution != _tileResolution) { - - this->retile(_numStars, tileResolution); - - return true; - } else { - return false; - } -} - -void Controller::render(float perspective, float angle, mat4 const& orientation, float alpha) { - Renderer* renderer = _renderer; - - if (renderer != 0l) { - renderer->render(perspective, angle, orientation, alpha); - } -} - -void Controller::retile(unsigned numStars, unsigned tileResolution) { - Tiling tiling(tileResolution); - VertexOrder scanner(tiling); - radix2InplaceSort(_inputSequence.begin(), _inputSequence.end(), scanner); - - recreateRenderer(numStars, tileResolution); - - _tileResolution = tileResolution; -} - -void Controller::recreateRenderer(unsigned numStars, unsigned tileResolution) { - delete _renderer; - _renderer = new Renderer(_inputSequence, numStars, tileResolution); -} diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h deleted file mode 100644 index 06db5cb833..0000000000 --- a/interface/src/starfield/Controller.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// Controller.h -// interface/src/starfield -// -// Created by Tobias Schwinger on 3/29/13. -// Modified by Chris Barnard on 10/16/13. -// Copyright 2013 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 -// - -#ifndef hifi_Controller_h -#define hifi_Controller_h - -#include - -#include "starfield/Generator.h" -#include "starfield/data/InputVertex.h" -#include "starfield/renderer/Renderer.h" -#include "starfield/renderer/VertexOrder.h" - -namespace starfield { - class Controller { - public: - Controller() : _tileResolution(20), _renderer(0l) { } - - ~Controller() { delete _renderer; } - - bool computeStars(unsigned numStars, unsigned seed); - bool setResolution(unsigned tileResolution); - void render(float perspective, float angle, mat4 const& orientation, float alpha); - private: - void retile(unsigned numStars, unsigned tileResolution); - - void recreateRenderer(unsigned numStars, unsigned tileResolution); - - InputVertices _inputSequence; - unsigned _tileResolution; - unsigned _numStars; - Renderer* _renderer; - }; -} -#endif // hifi_Controller_h diff --git a/interface/src/starfield/Generator.cpp b/interface/src/starfield/Generator.cpp deleted file mode 100644 index f20521bfbf..0000000000 --- a/interface/src/starfield/Generator.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// Generator.cpp -// interface/src/starfield -// -// Created by Chris Barnard on 10/13/13. -// Copyright 2013 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 - -#include "starfield/Generator.h" - -using namespace starfield; - -const float Generator::STAR_COLORIZATION = 0.1f; -const float PI_OVER_180 = 3.14159265358979f / 180.0f; - -void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) { - InputVertices* vertices = & destination; - //_limit = limit; - - QElapsedTimer startTime; - startTime.start(); - - srand(seed); - - vertices->clear(); - vertices->reserve(limit); - - const unsigned MILKY_WAY_WIDTH = 12.0; // width in degrees of one half of the Milky Way - const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees - const float MILKY_WAY_RATIO = 0.4f; - const unsigned NUM_DEGREES = 360; - - for(int star = 0; star < floor(limit * (1 - MILKY_WAY_RATIO)); ++star) { - float azimuth, altitude; - azimuth = (((float)rand() / (float) RAND_MAX) * NUM_DEGREES) - (NUM_DEGREES / 2); - altitude = (acos((2.0f * ((float)rand() / (float)RAND_MAX)) - 1.0f) / PI_OVER_180) + 90; - vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION))); - } - - for(int star = 0; star < ceil(limit * MILKY_WAY_RATIO); ++star) { - float azimuth = ((float)rand() / (float) RAND_MAX) * NUM_DEGREES; - float altitude = powf(randFloat()*0.5f, 2.0f)/0.25f * MILKY_WAY_WIDTH; - if (randFloat() > 0.5f) { - altitude *= -1.0f; - } - - // we need to rotate the Milky Way band to the correct orientation in the sky - // convert from spherical coordinates to cartesian, rotate the point and then convert back. - // An improvement would be to convert all stars to cartesian at this point and not have to convert back. - - float tempX = sin(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180); - float tempY = sin(altitude * PI_OVER_180); - float tempZ = -cos(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180); - - float xangle = MILKY_WAY_INCLINATION * PI_OVER_180; - float newX = (tempX * cos(xangle)) - (tempY * sin(xangle)); - float newY = (tempX * sin(xangle)) + (tempY * cos(xangle)); - float newZ = tempZ; - - azimuth = (atan2(newX,-newZ) + Radians::pi()) / PI_OVER_180; - altitude = atan2(-newY, hypotf(newX, newZ)) / PI_OVER_180; - - vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION))); - } - - double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms - qDebug() << "Total time to generate stars: " << timeDiff << " msec"; -} - -// computeStarColor -// - Generate a star color. -// -// colorization can be a value between 0 and 1 specifying how colorful the resulting star color is. -// -// 0 = completely black & white -// 1 = very colorful -unsigned Generator::computeStarColor(float colorization) { - unsigned char red, green, blue; - if (randFloat() < 0.3f) { - // A few stars are colorful - red = 2 + (rand() % 254); - green = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization)); - blue = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization)); - } else { - // Most stars are dimmer and white - red = green = blue = 2 + (rand() % 128); - } - return red | (green << 8) | (blue << 16); -} diff --git a/interface/src/starfield/Generator.h b/interface/src/starfield/Generator.h deleted file mode 100644 index 5352b3daf1..0000000000 --- a/interface/src/starfield/Generator.h +++ /dev/null @@ -1,40 +0,0 @@ -// -// Generator.h -// interface/src/starfield -// -// Created by Chris Barnard on 10/13/13. -// Copyright 2013 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 -// - -#ifndef hifi_Generator_h -#define hifi_Generator_h - -#include -#include - -#include "Config.h" -#include "SharedUtil.h" - -#include "starfield/data/InputVertex.h" - -namespace starfield { - - class Generator { - - public: - Generator() {} - ~Generator() {} - - static void computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed); - static unsigned computeStarColor(float colorization); - - private: - static const float STAR_COLORIZATION; - - }; - -} -#endif // hifi_Generator_h diff --git a/interface/src/starfield/data/GpuVertex.cpp b/interface/src/starfield/data/GpuVertex.cpp deleted file mode 100644 index b7fee1f2b1..0000000000 --- a/interface/src/starfield/data/GpuVertex.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// GpuVertex.cpp -// interface/src/starfield/data -// -// Created by Chris Barnard on 10/17/13. -// Based on code by Tobias Schwinger on 3/29/13. -// Copyright 2013 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 "starfield/data/GpuVertex.h" - -using namespace starfield; - -GpuVertex::GpuVertex(InputVertex const& inputVertex) { - _color = inputVertex.getColor(); - float azimuth = inputVertex.getAzimuth(); - float altitude = inputVertex.getAltitude(); - - // compute altitude/azimuth into X/Y/Z point on a sphere - _valX = sin(azimuth) * cos(altitude); - _valY = sin(altitude); - _valZ = -cos(azimuth) * cos(altitude); -} diff --git a/interface/src/starfield/data/GpuVertex.h b/interface/src/starfield/data/GpuVertex.h deleted file mode 100644 index f3b3ccd451..0000000000 --- a/interface/src/starfield/data/GpuVertex.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// GpuVertex.h -// interface/src/starfield/data -// -// Created by Tobias Schwinger on 3/29/13. -// Modified by Chris Barnard on 10/17/13. -// Copyright 2013 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 -// - -#ifndef hifi_GpuVertex_h -#define hifi_GpuVertex_h - -#include "starfield/data/InputVertex.h" - -namespace starfield { - - class GpuVertex { - public: - GpuVertex() { } - - GpuVertex(InputVertex const& inputVertex); - - unsigned getColor() const { return _color; } - - private: - unsigned _color; - float _valX; - float _valY; - float _valZ; - }; - -} - -#endif // hifi_GpuVertex_h diff --git a/interface/src/starfield/data/InputVertex.cpp b/interface/src/starfield/data/InputVertex.cpp deleted file mode 100644 index 5dead34beb..0000000000 --- a/interface/src/starfield/data/InputVertex.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// -// InputVertex.cpp -// interface/src/starfield/data -// -// Created by Chris Barnard on 10/17/13. -// Based on code by Tobias Schwinger 3/29/13. -// Copyright 2013 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 "starfield/data/InputVertex.h" - -using namespace starfield; - -InputVertex::InputVertex(float azimuth, float altitude, unsigned color) { - _color = color | 0xff000000u; - - azimuth = angleConvert(azimuth); - altitude = angleConvert(altitude); - - angleHorizontalPolar(azimuth, altitude); - - _azimuth = azimuth; - _altitude = altitude; -} diff --git a/interface/src/starfield/data/InputVertex.h b/interface/src/starfield/data/InputVertex.h deleted file mode 100644 index 2eeda183ec..0000000000 --- a/interface/src/starfield/data/InputVertex.h +++ /dev/null @@ -1,39 +0,0 @@ -// -// InputVertex.h -// interface/src/starfield/data -// -// Created by Tobias Schwinger on 3/29/13. -// Modified by Chris Barnard on 10/17/13. -// Copyright 2013 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 -// - -#ifndef hifi_InputVertex_h -#define hifi_InputVertex_h - -#include "starfield/Config.h" - -namespace starfield { - - class InputVertex { - public: - - InputVertex(float azimuth, float altitude, unsigned color); - - float getAzimuth() const { return _azimuth; } - float getAltitude() const { return _altitude; } - unsigned getColor() const { return _color; } - - private: - unsigned _color; - float _azimuth; - float _altitude; - }; - - typedef std::vector InputVertices; - -} - -#endif // hifi_InputVertex_h diff --git a/interface/src/starfield/data/Tile.h b/interface/src/starfield/data/Tile.h deleted file mode 100644 index 7273394984..0000000000 --- a/interface/src/starfield/data/Tile.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Tile.h -// interface/src/starfield/data -// -// Created by Tobias Schwinger on 3/22/13. -// Copyright 2013 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 -// - -#ifndef hifi_Tile_h -#define hifi_Tile_h - -#include "starfield/Config.h" - -namespace starfield { - - struct Tile { - nuint offset; - nuint count; - nuint flags; - - // flags - static uint16_t const checked = 1; - static uint16_t const visited = 2; - static uint16_t const render = 4; - }; - -} - -#endif // hifi_Tile_h diff --git a/interface/src/starfield/renderer/Renderer.cpp b/interface/src/starfield/renderer/Renderer.cpp deleted file mode 100644 index 5fc858d952..0000000000 --- a/interface/src/starfield/renderer/Renderer.cpp +++ /dev/null @@ -1,324 +0,0 @@ -// -// Renderer.cpp -// interface/src/starfield/renderer -// -// Created by Chris Barnard on 10/17/13. -// Based on earlier work by Tobias Schwinger 3/22/13. -// Copyright 2013 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 "starfield/renderer/Renderer.h" -#include "Application.h" - -using namespace starfield; - -Renderer::Renderer(InputVertices const& stars, unsigned numStars, unsigned tileResolution) : _dataArray(0l), -_tileArray(0l), _tiling(tileResolution) { - this->glAlloc(); - - Tiling tiling(tileResolution); - size_t numTiles = tiling.getTileCount(); - - // REVISIT: batch arrays are probably oversized, but - hey - they - // are not very large (unless for insane tiling) and we're better - // off safe than sorry - _dataArray = new GpuVertex[numStars]; - _tileArray = new Tile[numTiles + 1]; - _batchOffs = new GLint[numTiles * 2]; - _batchCountArray = new GLsizei[numTiles * 2]; - - prepareVertexData(stars, numStars, tiling); - - this->glUpload(numStars); -} - -Renderer::~Renderer() { - delete[] _dataArray; - delete[] _tileArray; - delete[] _batchCountArray; - delete[] _batchOffs; - - this->glFree(); -} - -void Renderer::render(float perspective, float aspect, mat4 const& orientation, float alpha) { - float halfPersp = perspective * 0.5f; - - // cancel all translation - mat4 matrix = orientation; - matrix[3][0] = 0.0f; - matrix[3][1] = 0.0f; - matrix[3][2] = 0.0f; - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadMatrixf(glm::value_ptr(qApp->getDisplayViewFrustum()->getProjection())); - glMatrixMode(GL_MODELVIEW); - // extract local z vector - vec3 ahead = vec3(matrix[2]); - - float azimuth = atan2(ahead.x,-ahead.z) + Radians::pi(); - float altitude = atan2(-ahead.y, hypotf(ahead.x, ahead.z)); - angleHorizontalPolar(azimuth, altitude); - float const eps = 0.002f; - altitude = glm::clamp(altitude, -Radians::halfPi() + eps, Radians::halfPi() - eps); - - matrix = glm::affineInverse(matrix); - - this->_outIndexPos = (unsigned*) _batchOffs; - this->_wRowVec = -vec3(row(matrix, 2)); - this->_halfPerspectiveAngle = halfPersp; - - TileSelection::Cursor cursor; - cursor.current = _tileArray + _tiling.getTileIndex(azimuth, altitude); - cursor.firstInRow = _tileArray + _tiling.getTileIndex(0.0f, altitude); - - floodFill(cursor, TileSelection(*this, _tileArray, _tileArray + _tiling.getTileCount(), (TileSelection::Cursor*) _batchCountArray)); - - this->glBatch(glm::value_ptr(matrix), prepareBatch((unsigned*) _batchOffs, _outIndexPos), alpha); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - -} - -// renderer construction - -void Renderer::prepareVertexData(InputVertices const& vertices, unsigned numStars, Tiling const& tiling) { - - size_t nTiles = tiling.getTileCount(); - size_t vertexIndex = 0u, currTileIndex = 0u, count_active = 0u; - - _tileArray[0].offset = 0u; - _tileArray[0].flags = 0u; - - for (InputVertices::const_iterator i = vertices.begin(), e = vertices.end(); i != e; ++i) { - size_t tileIndex = tiling.getTileIndex(i->getAzimuth(), i->getAltitude()); - assert(tileIndex >= currTileIndex); - - // moved on to another tile? -> flush - if (tileIndex != currTileIndex) { - - Tile* tile = _tileArray + currTileIndex; - Tile* lastTile = _tileArray + tileIndex; - - // set count of active vertices (upcoming lod) - tile->count = count_active; - // generate skipped, empty tiles - for(size_t offset = vertexIndex; ++tile != lastTile ;) { - tile->offset = offset, tile->count = 0u, tile->flags = 0u; - } - - // initialize next (as far as possible here) - lastTile->offset = vertexIndex; - lastTile->flags = 0u; - - currTileIndex = tileIndex; - count_active = 0u; - } - - ++count_active; - - // write converted vertex - _dataArray[vertexIndex++] = *i; - } - assert(vertexIndex == numStars); - - // flush last tile (see above) - Tile* tile = _tileArray + currTileIndex; - tile->count = count_active; - for (Tile* e = _tileArray + nTiles + 1; ++tile != e;) { - tile->offset = vertexIndex, tile->count = 0u, tile->flags = 0; - } -} - -bool Renderer::visitTile(Tile* tile) { - unsigned index = tile - _tileArray; - *_outIndexPos++ = index; - - return isTileVisible(index); -} - -bool Renderer::isTileVisible(unsigned index) { - - float slice = _tiling.getSliceAngle(); - float halfSlice = 0.5f * slice; - unsigned stride = _tiling.getAzimuthalTiles(); - float azimuth = (index % stride) * slice; - float altitude = (index / stride) * slice - Radians::halfPi(); - float groundX = sin(azimuth); - float groundZ = -cos(azimuth); - float elevation = cos(altitude); - vec3 tileCenter = vec3(groundX * elevation, sin(altitude), groundZ * elevation); - float w = dot(_wRowVec, tileCenter); - - float daz = halfSlice * cos(std::max(0.0f, abs(altitude) - halfSlice)); - float dal = halfSlice; - float adjustedNear = cos(_halfPerspectiveAngle + sqrt(daz * daz + dal * dal)); - - return w >= adjustedNear; -} - -unsigned Renderer::prepareBatch(unsigned const* indices, unsigned const* indicesEnd) { - unsigned nRanges = 0u; - GLint* offs = _batchOffs; - GLsizei* count = _batchCountArray; - - for (unsigned* i = (unsigned*) _batchOffs; i != indicesEnd; ++i) { - Tile* t = _tileArray + *i; - if ((t->flags & Tile::render) > 0u && t->count > 0u) { - *offs++ = t->offset; - *count++ = t->count; - ++nRanges; - } - t->flags = 0; - } - return nRanges; -} - -// GL API handling - -void Renderer::glAlloc() { - GLchar const* const VERTEX_SHADER = - "#version 120\n" - "uniform float alpha;\n" - "void main(void) {\n" - " vec3 c = gl_Color.rgb * 1.22;\n" - " float s = min(max(tan((c.r + c.g + c.b) / 3), 1.0), 3.0);\n" - " gl_Position = ftransform();\n" - " gl_FrontColor= gl_Color * alpha * 1.5;\n" - " gl_PointSize = s;\n" - "}\n"; - - _program.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER); - - GLchar const* const FRAGMENT_SHADER = - "#version 120\n" - "void main(void) {\n" - " gl_FragColor = gl_Color;\n" - "}\n"; - - _program.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER); - _program.link(); - _alphaLocationHandle = _program.uniformLocation("alpha"); - - glGenBuffersARB(1, & _vertexArrayHandle); -} - -void Renderer::glFree() { - glDeleteBuffersARB(1, & _vertexArrayHandle); -} - -void Renderer::glUpload(GLsizei numStars) { - glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle); - glBufferData(GL_ARRAY_BUFFER, numStars * sizeof(GpuVertex), _dataArray, GL_STATIC_DRAW); - glBindBufferARB(GL_ARRAY_BUFFER, 0); -} - -void Renderer::glBatch(GLfloat const* matrix, GLsizei n_ranges, float alpha) { - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glEnable(GL_BLEND); - - // setup modelview matrix - glPushMatrix(); - glLoadMatrixf(matrix); - - // set point size and smoothing + shader control - glPointSize(1.0f); - glEnable(GL_POINT_SMOOTH); - glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); - - // select shader and vertex array - _program.bind(); - _program.setUniformValue(_alphaLocationHandle, alpha); - glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle); - glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); - - // render - glMultiDrawArrays(GL_POINTS, _batchOffs, _batchCountArray, n_ranges); - - // restore state - glBindBufferARB(GL_ARRAY_BUFFER, 0); - _program.release(); - glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); - glDisable(GL_POINT_SMOOTH); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - - glPopMatrix(); -} - -// flood fill strategy - -bool Renderer::TileSelection::select(Renderer::TileSelection::Cursor const& cursor) { - Tile* tile = cursor.current; - - if (tile < _tileArray || tile >= _tilesEnd || !! (tile->flags & Tile::checked)) { - // out of bounds or been here already - return false; - } - - // will check now and never again - tile->flags |= Tile::checked; - if (_rendererRef.visitTile(tile)) { - // good one -> remember (for batching) and propagate - tile->flags |= Tile::render; - return true; - } - - return false; -} - -bool Renderer::TileSelection::process(Renderer::TileSelection::Cursor const& cursor) { - Tile* tile = cursor.current; - - if (! (tile->flags & Tile::visited)) { - tile->flags |= Tile::visited; - return true; - } - - return false; -} - -void Renderer::TileSelection::right(Renderer::TileSelection::Cursor& cursor) const { - cursor.current += 1; - if (cursor.current == cursor.firstInRow + _rendererRef._tiling.getAzimuthalTiles()) { - cursor.current = cursor.firstInRow; - } -} - -void Renderer::TileSelection::left(Renderer::TileSelection::Cursor& cursor) const { - if (cursor.current == cursor.firstInRow) { - cursor.current = cursor.firstInRow + _rendererRef._tiling.getAzimuthalTiles(); - } - cursor.current -= 1; -} - -void Renderer::TileSelection::up(Renderer::TileSelection::Cursor& cursor) const { - unsigned numTiles = _rendererRef._tiling.getAzimuthalTiles(); - cursor.current += numTiles; - cursor.firstInRow += numTiles; -} - -void Renderer::TileSelection::down(Renderer::TileSelection::Cursor& cursor) const { - unsigned numTiles = _rendererRef._tiling.getAzimuthalTiles(); - cursor.current -= numTiles; - cursor.firstInRow -= numTiles; -} - -void Renderer::TileSelection::defer(Renderer::TileSelection::Cursor const& cursor) { - *_stackPos++ = cursor; -} - -bool Renderer::TileSelection::deferred(Renderer::TileSelection::Cursor& cursor) { - if (_stackPos != _stackArray) { - cursor = *--_stackPos; - return true; - } - return false; -} diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h deleted file mode 100644 index 1e271512d2..0000000000 --- a/interface/src/starfield/renderer/Renderer.h +++ /dev/null @@ -1,142 +0,0 @@ -// -// Renderer.h -// interface/src/starfield/renderer -// -// Created by Tobias Schwinger on 3/22/13. -// Modified by Chris Barnard on 10/17/13. -// Copyright 2013 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 -// - -#ifndef hifi_Renderer_h -#define hifi_Renderer_h - -#include "starfield/Config.h" -#include "starfield/data/InputVertex.h" -#include "starfield/data/Tile.h" -#include "starfield/data/GpuVertex.h" -#include "starfield/renderer/Tiling.h" - -// -// FOV culling -// =========== -// -// As stars can be thought of as at infinity distance, the field of view only -// depends on perspective and rotation: -// -// _----_ <-- visible stars -// from above +-near-+ - - -// \ / | -// near width: \ / | cos(p/2) -// 2sin(p/2) \/ _ -// center -// -// -// Now it is important to note that a change in altitude maps uniformly to a -// distance on a sphere. This is NOT the case for azimuthal angles: In this -// case a factor of 'cos(alt)' (the orbital radius) applies: -// -// -// |<-cos alt ->| | |<-|<----->|->| d_azi cos(alt) -// | -// __--* | --------- - -// __-- * | | | ^ d_alt -// __-- alt) * | | | v -// --------------*- | ------------- - -// | -// side view | tile on sphere -// -// -// This lets us find a worst-case (Eigen) angle from the center to the edge -// of a tile as -// -// hypot( 0.5 d_alt, 0.5 d_azi cos(alt_absmin) ). -// -// This angle must be added to 'p' (the perspective angle) in order to find -// an altered near plane for the culling decision. -// - -namespace starfield { - - class Renderer { - public: - - Renderer(InputVertices const& src, unsigned numStars, unsigned tileResolution); - ~Renderer(); - void render(float perspective, float aspect, mat4 const& orientation, float alpha); - - private: - // renderer construction - - void prepareVertexData(InputVertices const& vertices, unsigned numStars, Tiling const& tiling); - - // FOV culling / LOD - - class TileSelection; - friend class Renderer::TileSelection; - - class TileSelection { - - public: - struct Cursor { Tile* current, * firstInRow; }; - - private: - Renderer& _rendererRef; - Cursor* const _stackArray; - Cursor* _stackPos; - Tile const* const _tileArray; - Tile const* const _tilesEnd; - - public: - TileSelection(Renderer& renderer, Tile const* tiles, Tile const* tiles_end, Cursor* stack) : - _rendererRef(renderer), - _stackArray(stack), - _stackPos(stack), - _tileArray(tiles), - _tilesEnd(tiles_end) { } - - protected: - bool select(Cursor const& cursor); - bool process(Cursor const& cursor); - void right(Cursor& cursor) const; - void left(Cursor& cursor) const; - void up(Cursor& cursor) const; - void down(Cursor& cursor) const; - void defer(Cursor const& cursor); - bool deferred(Cursor& cursor); - }; - - bool visitTile(Tile* tile); - bool isTileVisible(unsigned index); - unsigned prepareBatch(unsigned const* indices, unsigned const* indicesEnd); - - // GL API handling - - void glAlloc(); - void glFree(); - void glUpload(GLsizei numStars); - void glBatch(GLfloat const* matrix, GLsizei n_ranges, float alpha); - - // variables - - GpuVertex* _dataArray; - Tile* _tileArray; - GLint* _batchOffs; - GLsizei* _batchCountArray; - GLuint _vertexArrayHandle; - ProgramObject _program; - int _alphaLocationHandle; - - Tiling _tiling; - - unsigned* _outIndexPos; - vec3 _wRowVec; - float _halfPerspectiveAngle; - - }; - -} - -#endif // hifi_Renderer_h diff --git a/interface/src/starfield/renderer/Tiling.h b/interface/src/starfield/renderer/Tiling.h deleted file mode 100644 index e299b0998f..0000000000 --- a/interface/src/starfield/renderer/Tiling.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Tiling.h -// interface/src/starfield/renderer -// -// Created by Tobias Schwinger on 3/22/13. -// Copyright 2013 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 -// - -#ifndef hifi_Tiling_h -#define hifi_Tiling_h - -#include "starfield/Config.h" - -namespace starfield { - const float LOG2 = 1.4426950408889634f; - - class Tiling { - public: - Tiling(unsigned tileResolution) : _tileResolution(tileResolution), _rcpSlice(tileResolution / Radians::twicePi()) { - _nBits = ceil(log((float)getTileCount()) * LOG2); } - - unsigned getAzimuthalTiles() const { return _tileResolution; } - unsigned getAltitudinalTiles() const { return _tileResolution / 2 + 1; } - unsigned getTileIndexBits() const { return _nBits; } - unsigned getTileCount() const { return getAzimuthalTiles() * getAltitudinalTiles(); } - unsigned getTileIndex(float azimuth, float altitude) const { return discreteAzimuth(azimuth) + - _tileResolution * discreteAltitude(altitude); } - float getSliceAngle() const { return 1.0f / _rcpSlice; } - - private: - - unsigned discreteAngle(float unsigned_angle) const { return unsigned(floor(unsigned_angle * _rcpSlice + 0.5f)); } - unsigned discreteAzimuth(float angle) const { return discreteAngle(angle) % _tileResolution; } - unsigned discreteAltitude(float angle) const { return min( getAltitudinalTiles() - 1, - discreteAngle(angle + Radians::halfPi()) ); } - - // variables - - unsigned _tileResolution; - float _rcpSlice; - unsigned _nBits; - }; -} - -#endif // hifi_Tiling_h diff --git a/interface/src/starfield/renderer/VertexOrder.cpp b/interface/src/starfield/renderer/VertexOrder.cpp deleted file mode 100644 index ec36f1eea2..0000000000 --- a/interface/src/starfield/renderer/VertexOrder.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// VertexOrder.cpp -// interface/src/starfield/renderer -// -// Created by Chris Barnard on 10/17/13. -// Based on code by Tobias Schwinger on 3/22/13. -// Copyright 2013 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 "starfield/renderer/VertexOrder.h" - -using namespace starfield; - -bool VertexOrder::bit(InputVertex const& vertex, state_type const& state) const { - unsigned key = _tiling.getTileIndex(vertex.getAzimuth(), vertex.getAltitude()); - return base::bit(key, state); -} diff --git a/interface/src/starfield/renderer/VertexOrder.h b/interface/src/starfield/renderer/VertexOrder.h deleted file mode 100644 index e45ccdedb0..0000000000 --- a/interface/src/starfield/renderer/VertexOrder.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// VertexOrder.h -// interface/src/starfield/renderer -// -// Created by Tobias Schwinger on 3/22/13. -// Copyright 2013 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 -// - -#ifndef hifi_VertexOrder_h -#define hifi_VertexOrder_h - -#include "starfield/Config.h" -#include "starfield/data/InputVertex.h" -#include "starfield/renderer/Tiling.h" - -namespace starfield { - - // Defines the vertex order for the renderer as a bit extractor for - //binary in-place Radix Sort. - - class VertexOrder : public Radix2IntegerScanner - { - public: - explicit VertexOrder(Tiling const& tiling) : - - base(tiling.getTileIndexBits()), _tiling(tiling) { } - - bool bit(InputVertex const& vertex, state_type const& state) const; - - private: - Tiling _tiling; - - typedef Radix2IntegerScanner base; - }; - -} // anonymous namespace - -#endif // hifi_VertexOrder_h diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index da76e9c032..f1bf8265ef 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -11,9 +11,6 @@ #include "InterfaceConfig.h" -#include -#include - #include #include diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 49e93739a6..3993c48b36 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -6,8 +6,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "Stats.h" #include diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index a897e0422e..af6824d1a3 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -9,12 +9,9 @@ #ifndef hifi_Stats_h #define hifi_Stats_h -#include -#include -#include - -#include +#include #include +#include #define STATS_PROPERTY(type, name, initialValue) \ Q_PROPERTY(type name READ name NOTIFY name##Changed) \ diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 43f3492091..150b4cb8b8 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -9,9 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include -#include - #include #include diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 23b93250bc..bb51dd1aad 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -13,7 +13,6 @@ #include -#include #include #include diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp index 6a511e0d30..2770c4edc2 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp @@ -14,7 +14,6 @@ #include -#include #include #include #include diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 819989d5ec..d07d7f99fd 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -11,7 +11,6 @@ #include -#include #include #include diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index 6eb575814a..893e8a5f39 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -11,7 +11,6 @@ #include -#include #include #include diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 09411c53d5..38fa67003f 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -11,8 +11,6 @@ #include -#include - #include #include diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 2eb95d1bef..dec4e4644c 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -10,8 +10,6 @@ #include -#include - #include #include #include diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 46cfcefa40..a9f6d52622 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -23,8 +23,6 @@ #pragma GCC diagnostic pop #endif -#include - #include #include #include diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 6d9cb525d6..cf44efc42e 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -13,7 +13,6 @@ #include -#include #include #include diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 0c9b36dd87..d3e8e99e6e 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -11,8 +11,6 @@ #include -#include - #include #include #include diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 219d066611..e4d9d40bf4 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -8,12 +8,14 @@ #include "RenderableWebEntityItem.h" +#include #include +#include +#include +#include #include -#include - #include #include #include diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 8c147cac05..c0ebc64ea6 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -11,7 +11,6 @@ #include "RenderableZoneEntityItem.h" -#include #include #include diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index 9f75f9a94f..e3e9088afa 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -9,6 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "Batch.h" +#include "GPUConfig.h" #include @@ -254,6 +255,22 @@ void Batch::setFramebuffer(const FramebufferPointer& framebuffer) { } +void Batch::blit(const FramebufferPointer& src, const Vec4i& srcViewport, + const FramebufferPointer& dst, const Vec4i& dstViewport) { + ADD_COMMAND(blit); + + _params.push_back(_framebuffers.cache(src)); + _params.push_back(srcViewport.x); + _params.push_back(srcViewport.y); + _params.push_back(srcViewport.z); + _params.push_back(srcViewport.w); + _params.push_back(_framebuffers.cache(dst)); + _params.push_back(dstViewport.x); + _params.push_back(dstViewport.y); + _params.push_back(dstViewport.z); + _params.push_back(dstViewport.w); +} + void Batch::beginQuery(const QueryPointer& query) { ADD_COMMAND(beginQuery); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index ac4f624bda..2f1d2e8ece 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -11,20 +11,14 @@ #ifndef hifi_gpu_Batch_h #define hifi_gpu_Batch_h -#include -#include "GPUConfig.h" - -#include "Transform.h" - #include +#include "Framebuffer.h" +#include "Pipeline.h" #include "Query.h" #include "Stream.h" #include "Texture.h" - -#include "Pipeline.h" - -#include "Framebuffer.h" +#include "Transform.h" #if defined(NSIGHT_FOUND) class ProfileRange { @@ -111,6 +105,9 @@ public: // Framebuffer Stage void setFramebuffer(const FramebufferPointer& framebuffer); + void blit(const FramebufferPointer& src, const Vec4i& srcViewport, + const FramebufferPointer& dst, const Vec4i& dstViewport); + // Query Section void beginQuery(const QueryPointer& query); @@ -123,42 +120,42 @@ public: // For now, instead of calling the raw gl Call, use the equivalent call on the batch so the call is beeing recorded // THe implementation of these functions is in GLBackend.cpp - void _glEnable(GLenum cap); - void _glDisable(GLenum cap); + void _glEnable(unsigned int cap); + void _glDisable(unsigned int cap); - void _glEnableClientState(GLenum array); - void _glDisableClientState(GLenum array); + void _glEnableClientState(unsigned int array); + void _glDisableClientState(unsigned int array); - void _glCullFace(GLenum mode); - void _glAlphaFunc(GLenum func, GLclampf ref); + void _glCullFace(unsigned int mode); + void _glAlphaFunc(unsigned int func, float ref); - void _glDepthFunc(GLenum func); - void _glDepthMask(GLboolean flag); - void _glDepthRange(GLfloat zNear, GLfloat zFar); + void _glDepthFunc(unsigned int func); + void _glDepthMask(unsigned char flag); + void _glDepthRange(float zNear, float zFar); - void _glBindBuffer(GLenum target, GLuint buffer); + void _glBindBuffer(unsigned int target, unsigned int buffer); - void _glBindTexture(GLenum target, GLuint texture); - void _glActiveTexture(GLenum texture); - void _glTexParameteri(GLenum target, GLenum pname, GLint param); + void _glBindTexture(unsigned int target, unsigned int texture); + void _glActiveTexture(unsigned int texture); + void _glTexParameteri(unsigned int target, unsigned int pname, int param); - void _glDrawBuffers(GLsizei n, const GLenum* bufs); + void _glDrawBuffers(int n, const unsigned int* bufs); - void _glUseProgram(GLuint program); - void _glUniform1i(GLint location, GLint v0); - void _glUniform1f(GLint location, GLfloat v0); - void _glUniform2f(GLint location, GLfloat v0, GLfloat v1); - void _glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); - void _glUniform3fv(GLint location, GLsizei count, const GLfloat* value); - void _glUniform4fv(GLint location, GLsizei count, const GLfloat* value); - void _glUniform4iv(GLint location, GLsizei count, const GLint* value); - void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); + void _glUseProgram(unsigned int program); + void _glUniform1i(int location, int v0); + void _glUniform1f(int location, float v0); + void _glUniform2f(int location, float v0, float v1); + void _glUniform3f(int location, float v0, float v1, float v2); + void _glUniform3fv(int location, int count, const float* value); + void _glUniform4fv(int location, int count, const float* value); + void _glUniform4iv(int location, int count, const int* value); + void _glUniformMatrix4fv(int location, int count, unsigned char transpose, const float* value); - void _glEnableVertexAttribArray(GLint location); - void _glDisableVertexAttribArray(GLint location); + void _glEnableVertexAttribArray(int location); + void _glDisableVertexAttribArray(int location); - void _glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); - void _glLineWidth(GLfloat width); + void _glColor4f(float red, float green, float blue, float alpha); + void _glLineWidth(float width); enum Command { COMMAND_draw = 0, @@ -185,6 +182,7 @@ public: COMMAND_setResourceTexture, COMMAND_setFramebuffer, + COMMAND_blit, COMMAND_beginQuery, COMMAND_endQuery, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index ea7dca09b5..29f432e498 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -39,6 +39,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setResourceTexture), (&::gpu::GLBackend::do_setFramebuffer), + (&::gpu::GLBackend::do_blit), (&::gpu::GLBackend::do_beginQuery), (&::gpu::GLBackend::do_endQuery), diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index aedf058c82..2cdab49f29 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -394,6 +394,8 @@ protected: // Output stage void do_setFramebuffer(Batch& batch, uint32 paramOffset); + void do_blit(Batch& batch, uint32 paramOffset); + struct OutputStageState { diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index 1a7c5d2281..8876db95ac 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -166,3 +166,22 @@ void GLBackend::do_setFramebuffer(Batch& batch, uint32 paramOffset) { _output._framebuffer = framebuffer; } } + +void GLBackend::do_blit(Batch& batch, uint32 paramOffset) { + auto srcframebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint); + Vec4i srcvp; + for (size_t i = 0; i < 4; ++i) { + srcvp[i] = batch._params[paramOffset + 1 + i]._int; + } + + auto dstframebuffer = batch._framebuffers.get(batch._params[paramOffset + 5]._uint); + Vec4i dstvp; + for (size_t i = 0; i < 4; ++i) { + dstvp[i] = batch._params[paramOffset + 6 + i]._int; + } + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, getFramebufferID(dstframebuffer)); + glBindFramebuffer(GL_READ_FRAMEBUFFER, getFramebufferID(srcframebuffer)); + glBlitFramebuffer(srcvp.x, srcvp.y, srcvp.z, srcvp.w, + dstvp.x, dstvp.y, dstvp.z, dstvp.w, + GL_COLOR_BUFFER_BIT, GL_LINEAR); +} diff --git a/libraries/gpu/src/gpu/Query.h b/libraries/gpu/src/gpu/Query.h index 0a4d554e77..d9c3185d9e 100644 --- a/libraries/gpu/src/gpu/Query.h +++ b/libraries/gpu/src/gpu/Query.h @@ -14,7 +14,6 @@ #include #include #include -#include "GPUConfig.h" #include "Format.h" diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index 8a77d4090a..1b0b5aeebc 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -9,9 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL -#include - #include #include diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index c7acb90133..a397a6e3d0 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -12,6 +12,7 @@ #ifndef hifi_AmbientOcclusionEffect_h #define hifi_AmbientOcclusionEffect_h +#include #include class AbstractViewStateInterface; @@ -43,7 +44,7 @@ private: ProgramObject* _blurProgram; int _blurScaleLocation; - GLuint _rotationTextureID; + uint32_t _rotationTextureID; AbstractViewStateInterface* _viewState; }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 72c3f72fa1..582864991a 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -9,21 +9,21 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include "DeferredLightingEffect.h" #include +#include +#include +#include +#include #include #include #include "AbstractViewStateInterface.h" -#include "DeferredLightingEffect.h" #include "GeometryCache.h" #include "RenderUtil.h" #include "TextureCache.h" -#include "gpu/Batch.h" -#include "gpu/Context.h" -#include "gpu/StandardShaderLib.h" #include "simple_vert.h" #include "simple_textured_frag.h" diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 2c5ef6bb83..ba4fbd6d69 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -17,8 +17,6 @@ #include #include -#include "ProgramObject.h" - #include "model/Light.h" #include "model/Stage.h" #include "model/Geometry.h" diff --git a/libraries/render-utils/src/Environment.h b/libraries/render-utils/src/Environment.h index 65e0df4b36..6fa5a1a782 100644 --- a/libraries/render-utils/src/Environment.h +++ b/libraries/render-utils/src/Environment.h @@ -21,7 +21,6 @@ #include class ViewFrustum; -class ProgramObject; class Environment { public: diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index b8a6fd939d..d566265982 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -10,8 +10,6 @@ // // include this before QOpenGLBuffer, which includes an earlier version of OpenGL -#include - #include #include diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 47490bca0d..147b4f8093 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -12,11 +12,7 @@ #ifndef hifi_GeometryCache_h #define hifi_GeometryCache_h -// include this before QOpenGLBuffer, which includes an earlier version of OpenGL -#include - #include -#include #include #include @@ -264,12 +260,7 @@ private: virtual ~GeometryCache(); typedef QPair IntPair; - typedef QPair VerticesIndices; - struct BufferDetails { - QOpenGLBuffer buffer; - int vertices; - int vertexSize; - }; + typedef QPair VerticesIndices; gpu::PipelinePointer _standardDrawPipeline; QHash _cubeVerticies; diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 07df7fbda4..285daec247 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include #include #include diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index b3a62b8da7..8c792c8a3b 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -12,8 +12,6 @@ #ifndef hifi_Model_h #define hifi_Model_h -#include - #include #include #include @@ -36,7 +34,6 @@ #include "AnimationHandle.h" #include "GeometryCache.h" #include "JointState.h" -#include "ProgramObject.h" #include "TextureCache.h" class AbstractViewStateInterface; diff --git a/libraries/render-utils/src/OffscreenGlCanvas.cpp b/libraries/render-utils/src/OffscreenGlCanvas.cpp index e41209a40c..9154149809 100644 --- a/libraries/render-utils/src/OffscreenGlCanvas.cpp +++ b/libraries/render-utils/src/OffscreenGlCanvas.cpp @@ -11,9 +11,12 @@ #include "OffscreenGlCanvas.h" -#include -OffscreenGlCanvas::OffscreenGlCanvas() { +#include +#include +#include + +OffscreenGlCanvas::OffscreenGlCanvas() : _context(new QOpenGLContext), _offscreenSurface(new QOffscreenSurface){ } OffscreenGlCanvas::~OffscreenGlCanvas() { @@ -24,14 +27,14 @@ OffscreenGlCanvas::~OffscreenGlCanvas() { _logger = nullptr; } #endif - _context.doneCurrent(); + _context->doneCurrent(); } void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) { if (nullptr != sharedContext) { sharedContext->doneCurrent(); - _context.setFormat(sharedContext->format()); - _context.setShareContext(sharedContext); + _context->setFormat(sharedContext->format()); + _context->setShareContext(sharedContext); } else { QSurfaceFormat format; format.setDepthBufferSize(16); @@ -42,17 +45,17 @@ void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) { #ifdef DEBUG format.setOption(QSurfaceFormat::DebugContext); #endif - _context.setFormat(format); + _context->setFormat(format); } - _context.create(); + _context->create(); - _offscreenSurface.setFormat(_context.format()); - _offscreenSurface.create(); + _offscreenSurface->setFormat(_context->format()); + _offscreenSurface->create(); } bool OffscreenGlCanvas::makeCurrent() { - bool result = _context.makeCurrent(&_offscreenSurface); + bool result = _context->makeCurrent(_offscreenSurface); #ifdef DEBUG if (result && !_logger) { @@ -71,6 +74,6 @@ bool OffscreenGlCanvas::makeCurrent() { } void OffscreenGlCanvas::doneCurrent() { - _context.doneCurrent(); + _context->doneCurrent(); } diff --git a/libraries/render-utils/src/OffscreenGlCanvas.h b/libraries/render-utils/src/OffscreenGlCanvas.h index 7a69e276e4..0fa226a30d 100644 --- a/libraries/render-utils/src/OffscreenGlCanvas.h +++ b/libraries/render-utils/src/OffscreenGlCanvas.h @@ -12,9 +12,10 @@ #ifndef hifi_OffscreenGlCanvas_h #define hifi_OffscreenGlCanvas_h -#include -#include +#include +class QOpenGLContext; +class QOffscreenSurface; class QOpenGLDebugLogger; class OffscreenGlCanvas : public QObject { @@ -25,12 +26,12 @@ public: bool makeCurrent(); void doneCurrent(); QOpenGLContext* getContext() { - return &_context; + return _context; } protected: - QOpenGLContext _context; - QOffscreenSurface _offscreenSurface; + QOpenGLContext* _context; + QOffscreenSurface* _offscreenSurface; #ifdef DEBUG QOpenGLDebugLogger* _logger{ nullptr }; #endif diff --git a/libraries/render-utils/src/OffscreenQmlSurface.cpp b/libraries/render-utils/src/OffscreenQmlSurface.cpp index b6bc6b721e..3ebc7704a8 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.cpp +++ b/libraries/render-utils/src/OffscreenQmlSurface.cpp @@ -11,9 +11,31 @@ #include #include #include +#include +#include +#include +#include +#include +#include "FboCache.h" #include +class QMyQuickRenderControl : public QQuickRenderControl { +protected: + QWindow* renderWindow(QPoint* offset) Q_DECL_OVERRIDE{ + if (nullptr == _renderWindow) { + return QQuickRenderControl::renderWindow(offset); + } + if (nullptr != offset) { + offset->rx() = offset->ry() = 0; + } + return _renderWindow; + } + +private: + QWindow* _renderWindow{ nullptr }; + friend class OffscreenQmlSurface; +}; #include "AbstractViewStateInterface.h" Q_DECLARE_LOGGING_CATEGORY(offscreenFocus) @@ -24,7 +46,8 @@ Q_LOGGING_CATEGORY(offscreenFocus, "hifi.offscreen.focus") // achieve. static const int SMALL_INTERVAL = 5; -OffscreenQmlSurface::OffscreenQmlSurface() { +OffscreenQmlSurface::OffscreenQmlSurface() : + _renderControl(new QMyQuickRenderControl), _fboCache(new FboCache) { } OffscreenQmlSurface::~OffscreenQmlSurface() { @@ -43,6 +66,7 @@ OffscreenQmlSurface::~OffscreenQmlSurface() { delete _qmlEngine; doneCurrent(); + delete _fboCache; } void OffscreenQmlSurface::create(QOpenGLContext* shareContext) { @@ -87,7 +111,7 @@ void OffscreenQmlSurface::create(QOpenGLContext* shareContext) { _qmlComponent = new QQmlComponent(_qmlEngine); // Initialize the render control and our OpenGL resources. makeCurrent(); - _renderControl->initialize(&_context); + _renderControl->initialize(_context); } void OffscreenQmlSurface::resize(const QSize& newSize) { @@ -101,14 +125,14 @@ void OffscreenQmlSurface::resize(const QSize& newSize) { pixelRatio = AbstractViewStateInterface::instance()->getDevicePixelRatio(); } QSize newOffscreenSize = newSize * pixelRatio; - if (newOffscreenSize == _fboCache.getSize()) { + if (newOffscreenSize == _fboCache->getSize()) { return; } // Clear out any fbos with the old size makeCurrent(); qDebug() << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height() << " with pixel ratio " << pixelRatio; - _fboCache.setSize(newSize * pixelRatio); + _fboCache->setSize(newSize * pixelRatio); if (_quickWindow) { _quickWindow->setGeometry(QRect(QPoint(), newSize)); @@ -233,7 +257,7 @@ void OffscreenQmlSurface::updateQuick() { _polish = false; } - QOpenGLFramebufferObject* fbo = _fboCache.getReadyFbo(); + QOpenGLFramebufferObject* fbo = _fboCache->getReadyFbo(); _quickWindow->setRenderTarget(fbo); fbo->bind(); @@ -354,11 +378,11 @@ bool OffscreenQmlSurface::eventFilter(QObject* originalDestination, QEvent* even } void OffscreenQmlSurface::lockTexture(int texture) { - _fboCache.lockTexture(texture); + _fboCache->lockTexture(texture); } void OffscreenQmlSurface::releaseTexture(int texture) { - _fboCache.releaseTexture(texture); + _fboCache->releaseTexture(texture); } void OffscreenQmlSurface::pause() { diff --git a/libraries/render-utils/src/OffscreenQmlSurface.h b/libraries/render-utils/src/OffscreenQmlSurface.h index a1b66b48ad..b892806c44 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.h +++ b/libraries/render-utils/src/OffscreenQmlSurface.h @@ -9,15 +9,8 @@ #ifndef hifi_OffscreenQmlSurface_h #define hifi_OffscreenQmlSurface_h -#include -#include -#include -#include -#include -#include #include -#include - +#include #include #include @@ -25,27 +18,19 @@ #include #include "OffscreenGlCanvas.h" -#include "FboCache.h" + +class QWindow; +class QMyQuickRenderControl; +class QQmlEngine; +class QQmlContext; +class QQmlComponent; +class QQuickWindow; +class QQuickItem; +class FboCache; class OffscreenQmlSurface : public OffscreenGlCanvas { Q_OBJECT -protected: - class QMyQuickRenderControl : public QQuickRenderControl { - protected: - QWindow* renderWindow(QPoint* offset) Q_DECL_OVERRIDE{ - if (nullptr == _renderWindow) { - return QQuickRenderControl::renderWindow(offset); - } - if (nullptr != offset) { - offset->rx() = offset->ry() = 0; - } - return _renderWindow; - } - private: - QWindow* _renderWindow{ nullptr }; - friend class OffscreenQmlSurface; - }; public: OffscreenQmlSurface(); virtual ~OffscreenQmlSurface(); @@ -76,7 +61,7 @@ public: virtual bool eventFilter(QObject* originalDestination, QEvent* event); signals: - void textureUpdated(GLuint texture); + void textureUpdated(unsigned int texture); public slots: void requestUpdate(); @@ -95,12 +80,12 @@ protected: QQuickWindow* _quickWindow{ nullptr }; private: - QMyQuickRenderControl* _renderControl{ new QMyQuickRenderControl }; + QMyQuickRenderControl* _renderControl{ nullptr }; QQmlEngine* _qmlEngine{ nullptr }; QQmlComponent* _qmlComponent{ nullptr }; QQuickItem* _rootItem{ nullptr }; QTimer _updateTimer; - FboCache _fboCache; + FboCache* _fboCache; bool _polish{ true }; bool _paused{ true }; MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p; } }; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index fab134913d..3069e7b556 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -10,17 +10,18 @@ // #include "RenderDeferredTask.h" -#include "gpu/Batch.h" -#include "gpu/Context.h" +#include +#include +#include +#include +#include +#include + #include "DeferredLightingEffect.h" -#include "ViewFrustum.h" -#include "RenderArgs.h" #include "TextureCache.h" #include "render/DrawStatus.h" -#include - #include "overlay3D_vert.h" #include "overlay3D_frag.h" diff --git a/libraries/render-utils/src/RenderUtil.cpp b/libraries/render-utils/src/RenderUtil.cpp index 7744817625..44733418ff 100644 --- a/libraries/render-utils/src/RenderUtil.cpp +++ b/libraries/render-utils/src/RenderUtil.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include #include "GeometryCache.h" diff --git a/libraries/render-utils/src/TextRenderer3D.cpp b/libraries/render-utils/src/TextRenderer3D.cpp index a93ba1daec..5519300a2e 100644 --- a/libraries/render-utils/src/TextRenderer3D.cpp +++ b/libraries/render-utils/src/TextRenderer3D.cpp @@ -12,8 +12,6 @@ #include "TextRenderer3D.h" #include -#include -#include #include #include diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 953cfda910..910cf3386b 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -237,18 +237,6 @@ GLuint TextureCache::getPrimaryDepthTextureID() { return gpu::GLBackend::getTextureID(getPrimaryDepthTexture()); } -GLuint TextureCache::getPrimaryColorTextureID() { - return gpu::GLBackend::getTextureID(getPrimaryColorTexture()); -} - -GLuint TextureCache::getPrimaryNormalTextureID() { - return gpu::GLBackend::getTextureID(getPrimaryNormalTexture()); -} - -GLuint TextureCache::getPrimarySpecularTextureID() { - return gpu::GLBackend::getTextureID(getPrimarySpecularTexture()); -} - void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) { gpu::Batch batch; setPrimaryDrawBuffers(batch, color, normal, specular); @@ -284,7 +272,6 @@ gpu::FramebufferPointer TextureCache::getTertiaryFramebuffer() { return _tertiaryFramebuffer; } - gpu::FramebufferPointer TextureCache::getShadowFramebuffer() { if (!_shadowFramebuffer) { const int SHADOW_MAP_SIZE = 2048; @@ -295,12 +282,6 @@ gpu::FramebufferPointer TextureCache::getShadowFramebuffer() { return _shadowFramebuffer; } -GLuint TextureCache::getShadowDepthTextureID() { - // ensure that the shadow framebuffer object is initialized before returning the depth texture id - getShadowFramebuffer(); - return gpu::GLBackend::getTextureID(_shadowTexture); -} - /// Returns a texture version of an image file gpu::TexturePointer TextureCache::getImageTexture(const QString& path) { QImage image = QImage(path).mirrored(false, true); @@ -331,10 +312,6 @@ Texture::Texture() { Texture::~Texture() { } -GLuint Texture::getID() const { - return gpu::GLBackend::getTextureID(_gpuTexture); -} - NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArray& content) : Resource(url, !content.isEmpty()), _type(type), diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index fc02438c84..6b4fff4f6b 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -12,7 +12,6 @@ #ifndef hifi_TextureCache_h #define hifi_TextureCache_h -#include #include #include @@ -78,14 +77,7 @@ public: gpu::TexturePointer getPrimarySpecularTexture(); /// Returns the ID of the primary framebuffer object's depth texture. This contains the Z buffer used in rendering. - GLuint getPrimaryDepthTextureID(); - GLuint getPrimaryColorTextureID(); - - /// Returns the ID of the primary framebuffer object's normal texture. - GLuint getPrimaryNormalTextureID(); - - /// Returns the ID of the primary framebuffer object's specular texture. - GLuint getPrimarySpecularTextureID(); + uint32_t getPrimaryDepthTextureID(); /// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound. void setPrimaryDrawBuffers(bool color, bool normal = false, bool specular = false); @@ -102,10 +94,6 @@ public: /// Returns the framebuffer object used to render shadow maps; gpu::FramebufferPointer getShadowFramebuffer(); - - /// Returns the ID of the shadow framebuffer object's depth texture. - GLuint getShadowDepthTextureID(); - protected: virtual QSharedPointer createResource(const QUrl& url, @@ -149,8 +137,6 @@ public: Texture(); ~Texture(); - GLuint getID() const; - const gpu::TexturePointer& getGPUTexture() const { return _gpuTexture; } protected: diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index 6aae7ae81a..99a96b45f3 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -314,7 +314,7 @@ void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, c batch.setPipeline(_pipeline); batch.setResourceTexture(_fontLoc, _texture); batch._glUniform1i(_outlineLoc, (effectType == OUTLINE_EFFECT)); - batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)color); + batch._glUniform4fv(_colorLoc, 1, (const float*)color); batch.setInputFormat(_format); batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); diff --git a/libraries/render/src/render/DrawStatus.cpp b/libraries/render/src/render/DrawStatus.cpp index 90d167cc2a..5a34b3dc03 100644 --- a/libraries/render/src/render/DrawStatus.cpp +++ b/libraries/render/src/render/DrawStatus.cpp @@ -9,20 +9,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "DrawStatus.h" + #include #include -#include "DrawStatus.h" - #include -#include "gpu/GPULogging.h" +#include +#include +#include +#include -#include "gpu/Batch.h" -#include "gpu/Context.h" - -#include "ViewFrustum.h" -#include "RenderArgs.h" +#include +#include #include "drawItemBounds_vert.h" #include "drawItemBounds_frag.h" diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index 6b028e6c4b..0e3eba0b53 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -9,18 +9,17 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "DrawTask.h" + #include #include -#include "DrawTask.h" - +#include +#include +#include #include - -#include "gpu/Batch.h" -#include "gpu/Context.h" - -#include "ViewFrustum.h" -#include "RenderArgs.h" +#include +#include using namespace render; diff --git a/libraries/shared/src/RenderArgs.h b/libraries/shared/src/RenderArgs.h index 5507072b2c..604cb46731 100644 --- a/libraries/shared/src/RenderArgs.h +++ b/libraries/shared/src/RenderArgs.h @@ -14,6 +14,7 @@ #include #include +#include "GLMHelpers.h" class AABox; diff --git a/libraries/shared/src/windowshacks.h b/libraries/shared/src/windowshacks.h index 67c6f8be0c..60ad650c24 100644 --- a/libraries/shared/src/windowshacks.h +++ b/libraries/shared/src/windowshacks.h @@ -54,6 +54,13 @@ inline int c99_snprintf(char* str, size_t size, const char* format, ...) { #endif // SNPRINTF_FIX #endif // _MSC_VER +#include +#include + +#else // WIN32 + +#include #endif // WIN32 + #endif // hifi_windowshacks_h diff --git a/libraries/ui/src/OffscreenQmlElement.h b/libraries/ui/src/OffscreenQmlElement.h new file mode 100644 index 0000000000..87b404a4bd --- /dev/null +++ b/libraries/ui/src/OffscreenQmlElement.h @@ -0,0 +1,82 @@ +// +// OffscreenUi.h +// interface/src/entities +// +// Created by Bradley Austin Davis on 2015-07-17 +// 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 +// +#pragma once +#ifndef hifi_OffscreenQmlElement_h +#define hifi_OffscreenQmlElement_h + +#include +class QQmlContext; + +#define HIFI_QML_DECL \ +private: \ + static const QString NAME; \ + static const QUrl QML; \ +public: \ + static void registerType(); \ + static void show(std::function f = [](QQmlContext*, QObject*) {}); \ + static void toggle(std::function f = [](QQmlContext*, QObject*) {}); \ + static void load(std::function f = [](QQmlContext*, QObject*) {}); \ +private: + +#define HIFI_QML_DECL_LAMBDA \ +protected: \ + static const QString NAME; \ + static const QUrl QML; \ +public: \ + static void registerType(); \ + static void show(); \ + static void toggle(); \ + static void load(); \ +private: + +#define HIFI_QML_DEF(x) \ + const QUrl x::QML = QUrl(#x ".qml"); \ + const QString x::NAME = #x; \ + \ + void x::registerType() { \ + qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ + } \ + \ + void x::show(std::function f) { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->show(QML, NAME, f); \ + } \ + \ + void x::toggle(std::function f) { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->toggle(QML, NAME, f); \ + } \ + void x::load(std::function f) { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->load(QML, f); \ + } + +#define HIFI_QML_DEF_LAMBDA(x, f) \ + const QUrl x::QML = QUrl(#x ".qml"); \ + const QString x::NAME = #x; \ + \ + void x::registerType() { \ + qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ + } \ + void x::show() { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->show(QML, NAME, f); \ + } \ + void x::toggle() { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->toggle(QML, NAME, f); \ + } \ + void x::load() { \ + auto offscreenUi = DependencyManager::get(); \ + offscreenUi->load(QML, f); \ + } + +#endif diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index d94cad20d2..916cdf8659 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -11,12 +11,12 @@ #include "OffscreenUi.h" #include #include +#include #include #include #include "ErrorDialog.h" #include "MessageDialog.h" - class OffscreenUiRoot : public QQuickItem { Q_OBJECT public: diff --git a/libraries/ui/src/OffscreenUi.h b/libraries/ui/src/OffscreenUi.h index c7fd205236..4c8b4a8304 100644 --- a/libraries/ui/src/OffscreenUi.h +++ b/libraries/ui/src/OffscreenUi.h @@ -14,72 +14,11 @@ #include "OffscreenQmlSurface.h" +#include #include +#include "OffscreenQmlElement.h" -#define HIFI_QML_DECL \ -private: \ - static const QString NAME; \ - static const QUrl QML; \ -public: \ - static void registerType(); \ - static void show(std::function f = [](QQmlContext*, QObject*) {}); \ - static void toggle(std::function f = [](QQmlContext*, QObject*) {}); \ - static void load(std::function f = [](QQmlContext*, QObject*) {}); \ -private: - -#define HIFI_QML_DECL_LAMBDA \ -protected: \ - static const QString NAME; \ - static const QUrl QML; \ -public: \ - static void registerType(); \ - static void show(); \ - static void toggle(); \ - static void load(); \ -private: - -#define HIFI_QML_DEF(x) \ - const QUrl x::QML = QUrl(#x ".qml"); \ - const QString x::NAME = #x; \ - \ - void x::registerType() { \ - qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ - } \ - \ - void x::show(std::function f) { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->show(QML, NAME, f); \ - } \ - \ - void x::toggle(std::function f) { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->toggle(QML, NAME, f); \ - } \ - void x::load(std::function f) { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->load(QML, f); \ - } - -#define HIFI_QML_DEF_LAMBDA(x, f) \ - const QUrl x::QML = QUrl(#x ".qml"); \ - const QString x::NAME = #x; \ - \ - void x::registerType() { \ - qmlRegisterType("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \ - } \ - void x::show() { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->show(QML, NAME, f); \ - } \ - void x::toggle() { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->toggle(QML, NAME, f); \ - } \ - void x::load() { \ - auto offscreenUi = DependencyManager::get(); \ - offscreenUi->load(QML, f); \ - } class OffscreenUi : public OffscreenQmlSurface, public Dependency { Q_OBJECT From b7fdfd8663a9e0fd5111d79fd61b8e1c70308961 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 10:55:53 -0700 Subject: [PATCH 04/19] Working on lighting --- interface/src/Application.cpp | 34 +++++++----------- interface/src/Application.h | 2 +- libraries/gpu/src/gpu/Batch.cpp | 23 +++++++++++++ libraries/gpu/src/gpu/Batch.h | 5 +++ libraries/gpu/src/gpu/GLBackend.cpp | 44 ++---------------------- libraries/gpu/src/gpu/GLBackend.h | 6 ++-- libraries/gpu/src/gpu/GLBackendInput.cpp | 28 +++++++++++++++ libraries/gpu/src/gpu/GLBackendShared.h | 2 -- libraries/gpu/src/gpu/Light.h | 31 +++++++++++++++++ 9 files changed, 105 insertions(+), 70 deletions(-) create mode 100644 libraries/gpu/src/gpu/Light.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 45fd7ebc09..185191b8ce 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3130,27 +3130,19 @@ void Application::updateShadowMap(RenderArgs* renderArgs) { activeRenderingThread = nullptr; } -const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f }; -const GLfloat WORLD_DIFFUSE_COLOR[] = { 0.6f, 0.525f, 0.525f }; -const GLfloat WORLD_SPECULAR_COLOR[] = { 0.08f, 0.08f, 0.08f, 1.0f }; - -const glm::vec3 GLOBAL_LIGHT_COLOR = { 0.6f, 0.525f, 0.525f }; - -void Application::setupWorldLight() { - - // Setup 3D lights (after the camera transform, so that they are positioned in world space) - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - - glm::vec3 sunDirection = getSunDirection(); - GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 }; - glLightfv(GL_LIGHT0, GL_POSITION, light_position0); - glLightfv(GL_LIGHT0, GL_AMBIENT, WORLD_AMBIENT_COLOR); - glLightfv(GL_LIGHT0, GL_DIFFUSE, WORLD_DIFFUSE_COLOR); - glLightfv(GL_LIGHT0, GL_SPECULAR, WORLD_SPECULAR_COLOR); - glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR); - glMateriali(GL_FRONT, GL_SHININESS, 96); +static gpu::Light defaultLight{ + vec3( 0.525f, 0.525f, 0.6f), // ambient + vec3( 0.6f, 0.525f, 0.525f), // diffuse + vec4(0.08f, 0.08f, 0.08f, 1.0f), // specular + vec4( 0, 0, 0, 0 ), // position + 96 // shininess +}; +void Application::setupWorldLight(RenderArgs* renderArgs) { + gpu::Batch batch; + defaultLight._position = vec4(getSunDirection(), 0); + batch.setLight(0, defaultLight); + renderArgs->_context->render(batch); } bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { @@ -3418,7 +3410,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se // Setup 3D lights (after the camera transform, so that they are positioned in world space) { PerformanceTimer perfTimer("lights"); - setupWorldLight(); + setupWorldLight(renderArgs); } // setup shadow matrices (again, after the camera transform) diff --git a/interface/src/Application.h b/interface/src/Application.h index c5445db1e8..3cdf6e729a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -262,7 +262,7 @@ public: void controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes); - virtual void setupWorldLight(); + virtual void setupWorldLight(RenderArgs* renderArgs); virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera); QImage renderAvatarBillboard(RenderArgs* renderArgs); diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index e3e9088afa..f8d530bb74 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -288,3 +288,26 @@ void Batch::getQuery(const QueryPointer& query) { _params.push_back(_queries.cache(query)); } + +void push_back(Batch::Params& params, const vec3& v) { + params.push_back(v.x); + params.push_back(v.y); + params.push_back(v.z); +} + +void push_back(Batch::Params& params, const vec4& v) { + params.push_back(v.x); + params.push_back(v.y); + params.push_back(v.z); + params.push_back(v.a); +} + +void Batch::setLight(uint8_t index, const Light& light) { + ADD_COMMAND(setLight); + _params.push_back(index); + push_back(_params, light._ambientColor); + push_back(_params, light._diffuseColor); + push_back(_params, light._position); + push_back(_params, light._specularColor); + _params.push_back(light._shininess); +} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 2f1d2e8ece..3954127783 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -14,6 +14,7 @@ #include #include "Framebuffer.h" +#include "Light.h" #include "Pipeline.h" #include "Query.h" #include "Stream.h" @@ -76,6 +77,8 @@ public: void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset); void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView + void setLight(uint8_t index, const Light& light); + // Transform Stage // Vertex position is transformed by ModelTransform from object space to world space // Then by the inverse of the ViewTransform from world space to eye space @@ -169,6 +172,8 @@ public: COMMAND_setInputBuffer, COMMAND_setIndexBuffer, + COMMAND_setLight, + COMMAND_setModelTransform, COMMAND_setViewTransform, COMMAND_setProjectionTransform, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 29f432e498..f6b9bb8706 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -26,6 +26,8 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setInputBuffer), (&::gpu::GLBackend::do_setIndexBuffer), + (&::gpu::GLBackend::do_setLight), + (&::gpu::GLBackend::do_setModelTransform), (&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setProjectionTransform), @@ -747,45 +749,3 @@ void GLBackend::do_glLineWidth(Batch& batch, uint32 paramOffset) { glLineWidth(batch._params[paramOffset]._float); (void) CHECK_GL_ERROR(); } - -void GLBackend::loadMatrix(GLenum target, const glm::mat4 & m) { - glMatrixMode(target); - glLoadMatrixf(glm::value_ptr(m)); -} - -void GLBackend::fetchMatrix(GLenum target, glm::mat4 & m) { - switch (target) { - case GL_MODELVIEW_MATRIX: - case GL_PROJECTION_MATRIX: - break; - - // Lazy cheating - case GL_MODELVIEW: - target = GL_MODELVIEW_MATRIX; - break; - case GL_PROJECTION: - target = GL_PROJECTION_MATRIX; - break; - default: - Q_ASSERT_X(false, "GLBackend::fetchMatrix", "Bad matrix target"); - } - glGetFloatv(target, glm::value_ptr(m)); -} - -void GLBackend::checkGLStackStable(std::function f) { -#ifdef DEBUG - GLint mvDepth, prDepth; - glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &mvDepth); - glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &prDepth); -#endif - - f(); - -#ifdef DEBUG - GLint mvDepthFinal, prDepthFinal; - glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &mvDepthFinal); - glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &prDepthFinal); - Q_ASSERT(mvDepth == mvDepthFinal); - Q_ASSERT(prDepth == prDepthFinal); -#endif -} diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 2cdab49f29..eab880f14d 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -107,10 +107,6 @@ public: static GLShader* syncGPUObject(const Shader& shader); static GLuint getShaderID(const ShaderPointer& shader); - // FIXME: Please remove these 2 calls once the text renderer doesn't use naked gl calls anymore - static void loadMatrix(GLenum target, const glm::mat4 & m); - static void fetchMatrix(GLenum target, glm::mat4 & m); - class GLState : public GPUObject { public: class Command { @@ -257,6 +253,8 @@ protected: void do_setInputBuffer(Batch& batch, uint32 paramOffset); void do_setIndexBuffer(Batch& batch, uint32 paramOffset); + void do_setLight(Batch& batch, uint32 paramOffset); + void initInput(); void killInput(); void syncInputStateCache(); diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 34b1b1761f..e356dbcb9a 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -298,3 +298,31 @@ void GLBackend::do_setIndexBuffer(Batch& batch, uint32 paramOffset) { } (void) CHECK_GL_ERROR(); } + +template +void popParam(Batch::Params& params, uint32& paramOffset, V& v) { + for (size_t i = 0; i < v.length(); ++i) { + v[i] = params[paramOffset++]._float; + } +} + +void GLBackend::do_setLight(Batch& batch, uint32 paramOffset) { + int index = batch._params[paramOffset++]._uint; + gpu::Light light; + popParam(batch._params, paramOffset, light._ambientColor); + popParam(batch._params, paramOffset, light._diffuseColor); + popParam(batch._params, paramOffset, light._position); + popParam(batch._params, paramOffset, light._specularColor); + light._shininess = batch._params[paramOffset++]._int; + + // Setup 3D lights (after the camera transform, so that they are positioned in world space) + glEnable(GL_COLOR_MATERIAL); + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + glLightfv(GL_LIGHT0 + index, GL_POSITION, &light._position.x); + glLightfv(GL_LIGHT0 + index, GL_AMBIENT, &light._ambientColor.r); + glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, &light._diffuseColor.r); + glLightfv(GL_LIGHT0 + index, GL_SPECULAR, &light._specularColor.r); + glMaterialfv(GL_FRONT + index, GL_SPECULAR, &light._specularColor.r); + glMateriali(GL_FRONT + index, GL_SHININESS, light._shininess); +} + diff --git a/libraries/gpu/src/gpu/GLBackendShared.h b/libraries/gpu/src/gpu/GLBackendShared.h index 365934379f..27f58fcbe3 100644 --- a/libraries/gpu/src/gpu/GLBackendShared.h +++ b/libraries/gpu/src/gpu/GLBackendShared.h @@ -53,6 +53,4 @@ static const GLenum _elementTypeToGLType[gpu::NUM_TYPES] = { // #define CHECK_GL_ERROR() gpu::GLBackend::checkGLErrorDebug(__FUNCTION__ ":" CHECK_GL_ERROR_HELPER(__LINE__)) #define CHECK_GL_ERROR() gpu::GLBackend::checkGLErrorDebug(__FUNCTION__) -#define CHECK_GL_STACK_STABLE(f) gpu::GLBackend::checkGLStackStable(f) - #endif diff --git a/libraries/gpu/src/gpu/Light.h b/libraries/gpu/src/gpu/Light.h new file mode 100644 index 0000000000..080a117405 --- /dev/null +++ b/libraries/gpu/src/gpu/Light.h @@ -0,0 +1,31 @@ +// +// Created by Bradley Austin Davis 2015/07/18 +// Copyright 2014 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_gpu_Light_h +#define hifi_gpu_Light_h + +#include + +namespace gpu { + +struct Light { + Light() {} + Light(const vec3& ambient, const vec3& diffuse, const vec4& position, const vec4& specular = vec4(), int shininess = 0) : + _ambientColor(ambient), _diffuseColor(diffuse), _specularColor(specular), _position(position), _shininess(shininess) { + + } + vec3 _ambientColor; + vec3 _diffuseColor; + vec4 _position; + vec4 _specularColor; + int _shininess{0}; +}; + +} + +#endif From 5e0a0409bfa9f7955342047aab1198a5fe1c79f0 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Sat, 18 Jul 2015 12:16:51 -0700 Subject: [PATCH 05/19] Removing setupWorldLight from viewstateinterface --- libraries/gpu/src/gpu/Light.h | 2 +- libraries/render-utils/src/AbstractViewStateInterface.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/gpu/src/gpu/Light.h b/libraries/gpu/src/gpu/Light.h index 080a117405..6ce8eb637f 100644 --- a/libraries/gpu/src/gpu/Light.h +++ b/libraries/gpu/src/gpu/Light.h @@ -16,7 +16,7 @@ namespace gpu { struct Light { Light() {} Light(const vec3& ambient, const vec3& diffuse, const vec4& position, const vec4& specular = vec4(), int shininess = 0) : - _ambientColor(ambient), _diffuseColor(diffuse), _specularColor(specular), _position(position), _shininess(shininess) { + _ambientColor(ambient), _diffuseColor(diffuse), _position(position), _specularColor(specular), _shininess(shininess) { } vec3 _ambientColor; diff --git a/libraries/render-utils/src/AbstractViewStateInterface.h b/libraries/render-utils/src/AbstractViewStateInterface.h index ff417da85e..b6783f7455 100644 --- a/libraries/render-utils/src/AbstractViewStateInterface.h +++ b/libraries/render-utils/src/AbstractViewStateInterface.h @@ -52,7 +52,6 @@ public: virtual QThread* getMainThread() = 0; virtual const Transform& getViewTransform() const = 0; - virtual void setupWorldLight() = 0; virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera) = 0; virtual float getSizeScale() const = 0; virtual int getBoundaryLevelAdjust() const = 0; From e4f6586c3c50b71577098980fbeb3671ababe9a8 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 16:40:54 -0700 Subject: [PATCH 06/19] Working on star rendering, removal of naked GL --- interface/src/Application.cpp | 60 +++----- interface/src/Stars.cpp | 176 ++++++++++++++++-------- interface/src/ui/ApplicationOverlay.cpp | 1 - 3 files changed, 135 insertions(+), 102 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 185191b8ce..9cecae2854 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2991,15 +2991,26 @@ glm::vec3 Application::getSunDirection() { static QThread * activeRenderingThread = nullptr; void Application::updateShadowMap(RenderArgs* renderArgs) { + // TODO fix shadows and make them use the GPU library +#if 0 activeRenderingThread = QThread::currentThread(); PerformanceTimer perfTimer("shadowMap"); auto shadowFramebuffer = DependencyManager::get()->getShadowFramebuffer(); - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(shadowFramebuffer)); - - glEnable(GL_DEPTH_TEST); - glClear(GL_DEPTH_BUFFER_BIT); + { + gpu::Batch batch; + auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); + batch.setFramebuffer(shadowFramebuffer); + // clear the normal and specular buffers + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_DEPTH, + vec4(vec3(0), 1), 1.0, 0.0); + // Viewport is assigned to the size of the framebuffer + QSize size = DependencyManager::get()->getFrameBufferSize(); + renderArgs->_context->render(batch); + } + glm::vec3 lightDirection = getSunDirection(); glm::quat rotation = rotationBetween(IDENTITY_FRONT, lightDirection); glm::quat inverseRotation = glm::inverse(rotation); @@ -3079,30 +3090,13 @@ void Application::updateShadowMap(RenderArgs* renderArgs) { _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z)); _shadowViewFrustum.calculate(); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z); - - glm::mat4 projAgain; - glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&projAgain); - - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - glm::vec3 axis = glm::axis(inverseRotation); - glRotatef(glm::degrees(glm::angle(inverseRotation)), axis.x, axis.y, axis.z); - // store view matrix without translation, which we'll use for precision-sensitive objects updateUntranslatedViewMatrix(); - // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation // the viewTransofmr object is updatded with the correct values and saved, // this is what is used for rendering the Entities and avatars Transform viewTransform; viewTransform.setRotation(rotation); - // viewTransform.postTranslate(shadowFrustumCenter); setViewTransform(viewTransform); @@ -3115,19 +3109,11 @@ void Application::updateShadowMap(RenderArgs* renderArgs) { } glDisable(GL_POLYGON_OFFSET_FILL); - - glPopMatrix(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - - glMatrixMode(GL_MODELVIEW); } - // fbo->release(); - glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); activeRenderingThread = nullptr; +#endif } static gpu::Light defaultLight{ @@ -3412,7 +3398,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se PerformanceTimer perfTimer("lights"); setupWorldLight(renderArgs); } - + + // TODO fix shadows and make them use the GPU library +#if 0 // setup shadow matrices (again, after the camera transform) int shadowMatrixCount = 0; if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { @@ -3426,7 +3414,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][1]); glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][2]); } - +#endif // The pending changes collecting the changes here render::PendingChanges pendingChanges; @@ -3444,11 +3432,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } - glEnable(GL_LIGHTING); - glEnable(GL_DEPTH_TEST); - // Assuming nothing get's rendered through that - if (!selfAvatarOnly) { if (DependencyManager::get()->shouldRenderEntities()) { // render models... @@ -3574,7 +3558,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se } void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) { - glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); _viewMatrixTranslation = viewMatrixTranslation; } @@ -3583,9 +3566,6 @@ void Application::setViewTransform(const Transform& view) { } void Application::loadTranslatedViewMatrix(const glm::vec3& translation) { - glLoadMatrixf((const GLfloat*)&_untranslatedViewMatrix); - glTranslatef(translation.x + _viewMatrixTranslation.x, translation.y + _viewMatrixTranslation.y, - translation.z + _viewMatrixTranslation.z); } void Application::getModelViewMatrix(glm::dmat4* modelViewMatrix) { diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index ce43f3761d..8ac49da78f 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -11,7 +11,37 @@ #include "Stars.h" +#include + +#include + +#include +#include #include +#include +#include +#include +#include +#include + +static const unsigned int STARFIELD_NUM_STARS = 50000; +static const unsigned int STARFIELD_SEED = 1; +static const float STAR_COLORIZATION = 0.1f; + +static const float TAU = 6.28318530717958f; +static const float HALF_TAU = TAU / 2.0f; +static const float QUARTER_TAU = TAU / 4.0f; +static const float MILKY_WAY_WIDTH = TAU / 30.0f; // width in radians of one half of the Milky Way +static const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees +static const float MILKY_WAY_RATIO = 0.4f; + +#include "../../libraries/render-utils/standardTransformPNTC_vert.h" + +const char stars_frag[] = R"SCRIBE(#version 430 compatibility +void main(void) { + gl_FragColor = vec4( 1.0 ); +} +)SCRIBE"; Stars::Stars() { } @@ -19,70 +49,43 @@ Stars::Stars() { Stars::~Stars() { } -void Stars::render(RenderArgs* args, float alpha) { +// Produce a random float value between 0 and 1 +static float frand() { + return (float)rand() / (float)RAND_MAX; +} + +// Produce a random radian value between 0 and 2 PI (TAU) +static float rrand() { + return frand() * TAU; +} + +// http://mathworld.wolfram.com/SpherePointPicking.html +static vec2 randPolar() { + vec2 result(frand(), frand()); + result.x *= TAU; + result.y = powf(result.y, 2.0) / 2.0f; + if (frand() > 0.5f) { + result.y = 0.5f - result.y; + } else { + result.y += 0.5f; + } + result.y = acos((2.0f * result.y) - 1.0f); + return result; } -/* -static unsigned STARFIELD_NUM_STARS = 50000; -static unsigned STARFIELD_SEED = 1; -const float Generator::STAR_COLORIZATION = 0.1f; -const float PI_OVER_180 = 3.14159265358979f / 180.0f; - -void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) { - InputVertices* vertices = &destination; - //_limit = limit; - - QElapsedTimer startTime; - startTime.start(); - - srand(seed); - - vertices->clear(); - vertices->reserve(limit); - - const unsigned MILKY_WAY_WIDTH = 12.0; // width in degrees of one half of the Milky Way - const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees - const float MILKY_WAY_RATIO = 0.4f; - const unsigned NUM_DEGREES = 360; - - for (int star = 0; star < floor(limit * (1 - MILKY_WAY_RATIO)); ++star) { - float azimuth, altitude; - azimuth = (((float)rand() / (float)RAND_MAX) * NUM_DEGREES) - (NUM_DEGREES / 2); - altitude = (acos((2.0f * ((float)rand() / (float)RAND_MAX)) - 1.0f) / PI_OVER_180) + 90; - vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION))); - } - - for (int star = 0; star < ceil(limit * MILKY_WAY_RATIO); ++star) { - float azimuth = ((float)rand() / (float)RAND_MAX) * NUM_DEGREES; - float altitude = powf(randFloat()*0.5f, 2.0f) / 0.25f * MILKY_WAY_WIDTH; - if (randFloat() > 0.5f) { - altitude *= -1.0f; - } - - // we need to rotate the Milky Way band to the correct orientation in the sky - // convert from spherical coordinates to cartesian, rotate the point and then convert back. - // An improvement would be to convert all stars to cartesian at this point and not have to convert back. - - float tempX = sin(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180); - float tempY = sin(altitude * PI_OVER_180); - float tempZ = -cos(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180); - - float xangle = MILKY_WAY_INCLINATION * PI_OVER_180; - float newX = (tempX * cos(xangle)) - (tempY * sin(xangle)); - float newY = (tempX * sin(xangle)) + (tempY * cos(xangle)); - float newZ = tempZ; - - azimuth = (atan2(newX, -newZ) + Radians::pi()) / PI_OVER_180; - altitude = atan2(-newY, hypotf(newX, newZ)) / PI_OVER_180; - - vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION))); - } - - double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms - qDebug() << "Total time to generate stars: " << timeDiff << " msec"; +static vec3 fromPolar(const vec2& polar) { + float sinTheta = sin(polar.x); + float cosTheta = cos(polar.x); + float sinPhi = sin(polar.y); + float cosPhi = cos(polar.y); + return vec3( + cosTheta * sinPhi, + cosPhi, + sinTheta * sinPhi); } + // computeStarColor // - Generate a star color. // @@ -90,7 +93,7 @@ void Generator::computeStarPositions(InputVertices& destination, unsigned limit, // // 0 = completely black & white // 1 = very colorful -unsigned Generator::computeStarColor(float colorization) { +unsigned computeStarColor(float colorization) { unsigned char red, green, blue; if (randFloat() < 0.3f) { // A few stars are colorful @@ -103,4 +106,55 @@ unsigned Generator::computeStarColor(float colorization) { } return red | (green << 8) | (blue << 16); } -*/ \ No newline at end of file + +// FIXME star colors +void Stars::render(RenderArgs* renderArgs, float alpha) { + static gpu::BufferPointer vertexBuffer; + static gpu::Stream::FormatPointer streamFormat; + static gpu::Element positionElement, colorElement; + + const int VERTICES_SLOT = 0; + const int COLOR_SLOT = 2; + + static std::once_flag once; + + std::call_once(once, [&] { + QElapsedTimer startTime; + startTime.start(); + + vertexBuffer.reset(new gpu::Buffer); + + srand(STARFIELD_SEED); + unsigned limit = STARFIELD_NUM_STARS; + std::vector points; + points.reserve(limit); + for (size_t star = 0; star < limit; ++star) { + points[star] = fromPolar(randPolar()); + //auto color = computeStarColor(STAR_COLORIZATION); + //vertexBuffer->append(sizeof(color), (const gpu::Byte*)&color); + } + vertexBuffer->append(sizeof(vec3) * limit, (const gpu::Byte*)&points[0]); + streamFormat.reset(new gpu::Stream::Format()); // 1 for everyone + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + positionElement = streamFormat->getAttributes().at(gpu::Stream::POSITION)._element; + double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms + qDebug() << "Total time to generate stars: " << timeDiff << " msec"; + }); + + gpu::Batch batch; + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, gpu::BufferView(vertexBuffer, positionElement)); + Transform tr; +// tr.setTranslation(renderArgs->_viewFrustum->getPosition()); + tr.setRotation(glm::inverse(renderArgs->_viewFrustum->getOrientation())); + batch.setViewTransform(Transform()); + batch.setModelTransform(tr); + batch.setProjectionTransform(renderArgs->_viewFrustum->getProjection()); + auto geometryCache = DependencyManager::get(); + auto textureCache = DependencyManager::get(); + geometryCache->useSimpleDrawPipeline(batch); + batch.setResourceTexture(0, textureCache->getWhiteTexture()); + batch.draw(gpu::Primitive::POINTS, STARFIELD_NUM_STARS); + renderArgs->_context->syncCache(); + renderArgs->_context->render(batch); +} diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f1bf8265ef..1ab1210881 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -51,7 +51,6 @@ ApplicationOverlay::ApplicationOverlay() connect(offscreenUi.data(), &OffscreenUi::textureUpdated, this, [&](GLuint textureId) { auto offscreenUi = DependencyManager::get(); offscreenUi->lockTexture(textureId); - assert(!glGetError()); std::swap(_uiTexture, textureId); if (textureId) { offscreenUi->releaseTexture(textureId); From c446bb307d279fd049d24e72f111fb9c570ab4f3 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 16:56:32 -0700 Subject: [PATCH 07/19] Adding convenience return *this to many transform methods --- interface/src/Stars.cpp | 6 +- libraries/shared/src/Transform.h | 119 +++++++++++++++++-------------- 2 files changed, 67 insertions(+), 58 deletions(-) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 8ac49da78f..3ef909786d 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -144,17 +144,13 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { gpu::Batch batch; batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, gpu::BufferView(vertexBuffer, positionElement)); - Transform tr; -// tr.setTranslation(renderArgs->_viewFrustum->getPosition()); - tr.setRotation(glm::inverse(renderArgs->_viewFrustum->getOrientation())); batch.setViewTransform(Transform()); - batch.setModelTransform(tr); batch.setProjectionTransform(renderArgs->_viewFrustum->getProjection()); + batch.setModelTransform(Transform().setRotation(glm::inverse(renderArgs->_viewFrustum->getOrientation()))); auto geometryCache = DependencyManager::get(); auto textureCache = DependencyManager::get(); geometryCache->useSimpleDrawPipeline(batch); batch.setResourceTexture(0, textureCache->getWhiteTexture()); batch.draw(gpu::Primitive::POINTS, STARFIELD_NUM_STARS); - renderArgs->_context->syncCache(); renderArgs->_context->render(batch); } diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index 3b66bcd814..1ec81fbc43 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -82,25 +82,25 @@ public: return (*this); } - void setIdentity(); + Transform& setIdentity(); const Vec3& getTranslation() const; - void setTranslation(const Vec3& translation); // [new this] = [translation] * [this.rotation] * [this.scale] - void preTranslate(const Vec3& translation); // [new this] = [translation] * [this] - void postTranslate(const Vec3& translation); // [new this] = [this] * [translation] equivalent to:glTranslate + Transform& setTranslation(const Vec3& translation); // [new this] = [translation] * [this.rotation] * [this.scale] + Transform& preTranslate(const Vec3& translation); // [new this] = [translation] * [this] + Transform& postTranslate(const Vec3& translation); // [new this] = [this] * [translation] equivalent to:glTranslate const Quat& getRotation() const; - void setRotation(const Quat& rotation); // [new this] = [this.translation] * [rotation] * [this.scale] - void preRotate(const Quat& rotation); // [new this] = [rotation] * [this] - void postRotate(const Quat& rotation); // [new this] = [this] * [rotation] equivalent to:glRotate + Transform& setRotation(const Quat& rotation); // [new this] = [this.translation] * [rotation] * [this.scale] + Transform& preRotate(const Quat& rotation); // [new this] = [rotation] * [this] + Transform& postRotate(const Quat& rotation); // [new this] = [this] * [rotation] equivalent to:glRotate const Vec3& getScale() const; - void setScale(float scale); - void setScale(const Vec3& scale); // [new this] = [this.translation] * [this.rotation] * [scale] - void preScale(float scale); - void preScale(const Vec3& scale); - void postScale(float scale); // [new this] = [this] * [scale] equivalent to:glScale - void postScale(const Vec3& scale); // [new this] = [this] * [scale] equivalent to:glScale + Transform& setScale(float scale); + Transform& setScale(const Vec3& scale); // [new this] = [this.translation] * [this.rotation] * [scale] + Transform& preScale(float scale); + Transform& preScale(const Vec3& scale); + Transform& postScale(float scale); // [new this] = [this] * [scale] equivalent to:glScale + Transform& postScale(const Vec3& scale); // [new this] = [this] * [scale] equivalent to:glScale bool isIdentity() const { return (_flags & ~Flags(FLAG_CACHE_INVALID_BITSET)).none(); } bool isTranslating() const { return _flags[FLAG_TRANSLATION]; } @@ -109,8 +109,8 @@ public: bool isUniform() const { return !isNonUniform(); } bool isNonUniform() const { return _flags[FLAG_NON_UNIFORM]; } - void evalFromRawMatrix(const Mat4& matrix); - void evalFromRawMatrix(const Mat3& rotationScalematrix); + Transform& evalFromRawMatrix(const Mat4& matrix); + Transform& evalFromRawMatrix(const Mat3& rotationScalematrix); Mat4& getMatrix(Mat4& result) const; Mat4& getInverseMatrix(Mat4& result) const; @@ -182,18 +182,19 @@ protected: Mat4& getCachedMatrix(Mat4& result) const; }; -inline void Transform::setIdentity() { +inline Transform& Transform::setIdentity() { _translation = Vec3(0.0f); _rotation = Quat(1.0f, 0.0f, 0.0f, 0.0f); _scale = Vec3(1.0f); _flags = Flags(FLAG_CACHE_INVALID_BITSET); + return *this; } inline const Transform::Vec3& Transform::getTranslation() const { return _translation; } -inline void Transform::setTranslation(const Vec3& translation) { +inline Transform& Transform::setTranslation(const Vec3& translation) { invalidCache(); if (translation == Vec3()) { unflagTranslation(); @@ -201,20 +202,22 @@ inline void Transform::setTranslation(const Vec3& translation) { flagTranslation(); } _translation = translation; + return *this; } -inline void Transform::preTranslate(const Vec3& translation) { +inline Transform& Transform::preTranslate(const Vec3& translation) { if (translation == Vec3()) { - return; + return *this; } invalidCache(); flagTranslation(); _translation += translation; + return *this; } -inline void Transform::postTranslate(const Vec3& translation) { +inline Transform& Transform::postTranslate(const Vec3& translation) { if (translation == Vec3()) { - return; + return *this; } invalidCache(); flagTranslation(); @@ -229,13 +232,14 @@ inline void Transform::postTranslate(const Vec3& translation) { } else { _translation += scaledT; } + return *this; } inline const Transform::Quat& Transform::getRotation() const { return _rotation; } -inline void Transform::setRotation(const Quat& rotation) { +inline Transform& Transform::setRotation(const Quat& rotation) { invalidCache(); if (rotation == Quat()) { unflagRotation(); @@ -243,11 +247,12 @@ inline void Transform::setRotation(const Quat& rotation) { flagRotation(); } _rotation = rotation; + return *this; } -inline void Transform::preRotate(const Quat& rotation) { +inline Transform& Transform::preRotate(const Quat& rotation) { if (rotation == Quat()) { - return; + return *this; } invalidCache(); if (isRotating()) { @@ -258,11 +263,12 @@ inline void Transform::preRotate(const Quat& rotation) { flagRotation(); _translation = glm::rotate(rotation, _translation); + return *this; } -inline void Transform::postRotate(const Quat& rotation) { +inline Transform& Transform::postRotate(const Quat& rotation) { if (rotation == Quat()) { - return; + return *this; } invalidCache(); @@ -289,15 +295,16 @@ inline void Transform::postRotate(const Quat& rotation) { } } flagRotation(); + return *this; } inline const Transform::Vec3& Transform::getScale() const { return _scale; } -inline void Transform::setScale(float scale) { +inline Transform& Transform::setScale(float scale) { if (!isValidScale(scale)) { - return; + return *this; } invalidCache(); flagUniform(); @@ -308,46 +315,49 @@ inline void Transform::setScale(float scale) { flagScaling(); } _scale = Vec3(scale); + return *this; } -inline void Transform::setScale(const Vec3& scale) { +inline Transform& Transform::setScale(const Vec3& scale) { if (!isValidScale(scale)) { - return; + return *this; } + if ((scale.x == scale.y) && (scale.x == scale.z)) { - setScale(scale.x); - } else { - invalidCache(); - flagScaling(); - flagNonUniform(); - _scale = scale; - } + return setScale(scale.x); + } + + invalidCache(); + flagScaling(); + flagNonUniform(); + _scale = scale; + return *this; } -inline void Transform::preScale(float scale) { - setScale(getScale() * scale); +inline Transform& Transform::preScale(float scale) { + return setScale(getScale() * scale); } -inline void Transform::preScale(const Vec3& scale) { - setScale(getScale() * scale); +inline Transform& Transform::preScale(const Vec3& scale) { + return setScale(getScale() * scale); } -inline void Transform::postScale(float scale) { +inline Transform& Transform::postScale(float scale) { if (!isValidScale(scale) || scale == 1.0f) { - return; + return *this; } - if (isScaling()) { - // if already scaling, just invalid cache and apply uniform scale - invalidCache(); - _scale *= scale; - } else { - setScale(scale); + if (!isScaling()) { + return setScale(scale); } + // if already scaling, just invalid cache and apply uniform scale + invalidCache(); + _scale *= scale; + return *this; } -inline void Transform::postScale(const Vec3& scale) { +inline Transform& Transform::postScale(const Vec3& scale) { if (!isValidScale(scale)) { - return; + return *this; } invalidCache(); if (isScaling()) { @@ -356,6 +366,7 @@ inline void Transform::postScale(const Vec3& scale) { _scale = scale; } flagScaling(); + return *this; } inline Transform::Mat4& Transform::getMatrix(Transform::Mat4& result) const { @@ -405,20 +416,22 @@ inline Transform::Mat4& Transform::getRotationScaleMatrixInverse(Mat4& result) c return result; } -inline void Transform::evalFromRawMatrix(const Mat4& matrix) { +inline Transform& Transform::evalFromRawMatrix(const Mat4& matrix) { // for now works only in the case of TRS transformation if ((matrix[0][3] == 0.0f) && (matrix[1][3] == 0.0f) && (matrix[2][3] == 0.0f) && (matrix[3][3] == 1.0f)) { setTranslation(Vec3(matrix[3])); evalFromRawMatrix(Mat3(matrix)); } + return *this; } -inline void Transform::evalFromRawMatrix(const Mat3& rotationScaleMatrix) { +inline Transform& Transform::evalFromRawMatrix(const Mat3& rotationScaleMatrix) { Quat rotation; Vec3 scale; evalRotationScale(rotation, scale, rotationScaleMatrix); setRotation(rotation); setScale(scale); + return *this; } inline Transform& Transform::evalInverse(Transform& inverse) const { From 005620856526bcf0f5a7a552a8f23795e7a0f8fc Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 17:04:44 -0700 Subject: [PATCH 08/19] Another whack at GL headers --- interface/InterfaceConfig.h.in | 3 +-- interface/src/ui/ApplicationCompositor.h | 2 +- interface/src/ui/ApplicationOverlay.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interface/InterfaceConfig.h.in b/interface/InterfaceConfig.h.in index b2b1881d67..c44fc6b8a8 100644 --- a/interface/InterfaceConfig.h.in +++ b/interface/InterfaceConfig.h.in @@ -12,7 +12,6 @@ #ifndef interface__InterfaceConfig__ #define interface__InterfaceConfig__ -#define GL_GLEXT_PROTOTYPES 1 -@GL_HEADERS@ +#include #endif diff --git a/interface/src/ui/ApplicationCompositor.h b/interface/src/ui/ApplicationCompositor.h index 5df145afa2..8ae6f0930e 100644 --- a/interface/src/ui/ApplicationCompositor.h +++ b/interface/src/ui/ApplicationCompositor.h @@ -62,7 +62,7 @@ public: glm::vec2 screenToOverlay(const glm::vec2 & screenPos) const; glm::vec2 overlayToScreen(const glm::vec2 & overlayPos) const; void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const; - GLuint getOverlayTexture() const; + uint32_t getOverlayTexture() const; static glm::vec2 directionToSpherical(const glm::vec3 & direction); static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos); diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 6aa5d2a9e8..92485fba82 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -40,7 +40,7 @@ private: float _alpha{ 1.0f }; float _trailingAudioLoudness{ 0.0f }; - GLuint _uiTexture{ 0 }; + uint32_t _uiTexture{ 0 }; int _domainStatusBorder; int _magnifierBorder; From 35f7307f30c72c7c9249d017c6dc13828ec35176 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 22:15:50 -0700 Subject: [PATCH 09/19] More header cleanup --- interface/InterfaceConfig.h.in | 2 - interface/src/Application.cpp | 2 - interface/src/Menu.cpp | 3 - interface/src/Util.cpp | 1 - interface/src/avatar/Avatar.h | 1 - interface/src/avatar/Hand.h | 2 - interface/src/avatar/Head.h | 1 - interface/src/devices/OculusManager.cpp | 17 --- interface/src/devices/TV3DManager.cpp | 15 -- interface/src/ui/LogDialog.cpp | 1 - interface/src/ui/LogDialog.h | 2 - interface/src/ui/OctreeStatsDialog.cpp | 4 +- interface/src/ui/Stats.cpp | 1 - interface/src/ui/overlays/Base3DOverlay.cpp | 3 - .../src/ui/overlays/BillboardOverlay.cpp | 6 + interface/src/ui/overlays/Circle3DOverlay.h | 2 - interface/src/ui/overlays/Grid3DOverlay.cpp | 9 +- interface/src/ui/overlays/Grid3DOverlay.h | 7 - interface/src/ui/overlays/ImageOverlay.h | 2 - interface/src/ui/overlays/Overlay.h | 2 - interface/src/ui/overlays/Overlay2D.h | 3 - interface/src/ui/overlays/Planar3DOverlay.h | 3 - interface/src/ui/overlays/Text3DOverlay.h | 3 - interface/src/ui/overlays/TextOverlay.h | 3 - interface/src/ui/overlays/Volume3DOverlay.h | 3 - libraries/gpu/src/gpu/GLBackendInput.cpp | 2 +- libraries/gpu/src/gpu/GPUConfig.h | 1 - .../src/AmbientOcclusionEffect.cpp | 128 +++++++++++------- .../render-utils/src/AmbientOcclusionEffect.h | 6 +- libraries/render-utils/src/ProgramObject.cpp | 56 -------- libraries/render-utils/src/ProgramObject.h | 42 ------ 31 files changed, 91 insertions(+), 242 deletions(-) delete mode 100644 libraries/render-utils/src/ProgramObject.cpp delete mode 100644 libraries/render-utils/src/ProgramObject.h diff --git a/interface/InterfaceConfig.h.in b/interface/InterfaceConfig.h.in index c44fc6b8a8..fba2b7e4d6 100644 --- a/interface/InterfaceConfig.h.in +++ b/interface/InterfaceConfig.h.in @@ -12,6 +12,4 @@ #ifndef interface__InterfaceConfig__ #define interface__InterfaceConfig__ -#include - #endif diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9cecae2854..404193aa3a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3688,9 +3688,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render rear mirror view - glPushMatrix(); displaySide(renderArgs, _mirrorCamera, true, billboard); - glPopMatrix(); // reset Viewport and projection matrix renderArgs->_viewport = glm::ivec4(viewport[0], viewport[1], viewport[2], viewport[3]); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7213d4eb79..75ae88e296 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -9,9 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include #include diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 5d625ba3a3..cb3865d336 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -24,7 +24,6 @@ #include #include -#include "InterfaceConfig.h" #include "world.h" #include "Application.h" #include "InterfaceLogging.h" diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index b67caa1641..a694a82ac7 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -24,7 +24,6 @@ #include "Hand.h" #include "Head.h" -#include "InterfaceConfig.h" #include "SkeletonModel.h" #include "world.h" diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index a4c0265545..ddc9d13489 100644 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -11,8 +11,6 @@ #ifndef hifi_Hand_h #define hifi_Hand_h -#include "InterfaceConfig.h" - #include #include diff --git a/interface/src/avatar/Head.h b/interface/src/avatar/Head.h index 2baa16f90c..d7a8462693 100644 --- a/interface/src/avatar/Head.h +++ b/interface/src/avatar/Head.h @@ -19,7 +19,6 @@ #include #include "FaceModel.h" -#include "InterfaceConfig.h" #include "world.h" diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index fd40ca592d..9395584a66 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -648,12 +648,6 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFBO)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glm::quat orientation; glm::vec3 trackerPosition; auto deviceSize = qApp->getDeviceSize(); @@ -697,12 +691,6 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const configureCamera(*_camera); _camera->update(1.0f / Application::getInstance()->getFps()); - glMatrixMode(GL_PROJECTION); - glLoadMatrixf(glm::value_ptr(_camera->getProjection())); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - ovrRecti & vp = _eyeViewports[eye]; vp.Size.h = _recommendedTexSize.h * _offscreenRenderScale; vp.Size.w = _recommendedTexSize.w * _offscreenRenderScale; @@ -715,15 +703,10 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const }); _activeEye = ovrEye_Count; - glPopMatrix(); - gpu::FramebufferPointer finalFbo; finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); glBindFramebuffer(GL_FRAMEBUFFER, 0); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - // restore our normal viewport glViewport(0, 0, deviceSize.width(), deviceSize.height()); diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index 24cf529a33..fefaf060bd 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" - #include #include @@ -74,10 +72,6 @@ void TV3DManager::configureCamera(Camera& whichCamera, int screenWidth, int scre setFrustum(whichCamera); glViewport (0, 0, _screenWidth, _screenHeight); // sets drawing viewport - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); } void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { @@ -105,7 +99,6 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { eyeCamera.setPosition(whichCamera.getPosition()); glEnable(GL_SCISSOR_TEST); - glPushMatrix(); forEachEye([&](eyeFrustum& eye){ _activeEye = &eye; glViewport(portalX, portalY, portalW, portalH); @@ -115,14 +108,7 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { glm::mat4 projection = glm::frustum(eye.left, eye.right, eye.bottom, eye.top, nearZ, farZ); projection = glm::translate(projection, vec3(eye.modelTranslation, 0, 0)); eyeCamera.setProjection(projection); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); // reset projection matrix - glLoadMatrixf(glm::value_ptr(projection)); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); renderArgs->_renderSide = RenderArgs::MONO; - qApp->displaySide(renderArgs, eyeCamera, false); qApp->getApplicationCompositor().displayOverlayTexture(renderArgs); _activeEye = NULL; @@ -130,7 +116,6 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { // render right side view portalX = deviceSize.width() / 2; }); - glPopMatrix(); glDisable(GL_SCISSOR_TEST); // FIXME - glow effect is removed, 3D TV mode broken until we get display plugins working diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index d7d1eef74a..0d2d0d11f6 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -18,7 +18,6 @@ #include #include -#include #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop diff --git a/interface/src/ui/LogDialog.h b/interface/src/ui/LogDialog.h index 914e1b4949..999a8394cc 100644 --- a/interface/src/ui/LogDialog.h +++ b/interface/src/ui/LogDialog.h @@ -12,8 +12,6 @@ #ifndef hifi_LogDialog_h #define hifi_LogDialog_h -#include "InterfaceConfig.h" - #include #include #include diff --git a/interface/src/ui/OctreeStatsDialog.cpp b/interface/src/ui/OctreeStatsDialog.cpp index fbfc3ea662..89e5899acd 100644 --- a/interface/src/ui/OctreeStatsDialog.cpp +++ b/interface/src/ui/OctreeStatsDialog.cpp @@ -94,7 +94,6 @@ void OctreeStatsDialog::moreless(const QString& link) { int OctreeStatsDialog::AddStatItem(const char* caption, unsigned colorRGBA) { - char strBuf[64]; const int STATS_LABEL_WIDTH = 600; _statCount++; // increment our current stat count @@ -115,8 +114,7 @@ int OctreeStatsDialog::AddStatItem(const char* caption, unsigned colorRGBA) { rgb = ((rgb & colorpart1) >> 1) + ((rgb & colorpart2) >> 3); palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb)); label->setPalette(palette); - snprintf(strBuf, sizeof(strBuf), " %s:", caption); - _form->addRow(strBuf, label); + _form->addRow(QString(" %1:").arg(caption), label); label->setFixedWidth(STATS_LABEL_WIDTH); return _statCount; diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 3993c48b36..db140e53e2 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -24,7 +24,6 @@ #include #include "BandwidthRecorder.h" -#include "InterfaceConfig.h" #include "Menu.h" #include "Util.h" #include "SequenceNumberStats.h" diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 06e26e0781..108f092465 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -8,9 +8,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include "Application.h" diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index 90ef5989fc..b2843230f3 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -11,6 +11,12 @@ #include "BillboardOverlay.h" +#include + +#include +#include +#include + #include "Application.h" #include "GeometryUtil.h" diff --git a/interface/src/ui/overlays/Circle3DOverlay.h b/interface/src/ui/overlays/Circle3DOverlay.h index 0a2352148a..d83703fcd0 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.h +++ b/interface/src/ui/overlays/Circle3DOverlay.h @@ -12,8 +12,6 @@ #define hifi_Circle3DOverlay_h // include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include "Planar3DOverlay.h" class Circle3DOverlay : public Planar3DOverlay { diff --git a/interface/src/ui/overlays/Grid3DOverlay.cpp b/interface/src/ui/overlays/Grid3DOverlay.cpp index baf7b42ac5..ad64c6091b 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.cpp +++ b/interface/src/ui/overlays/Grid3DOverlay.cpp @@ -9,17 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include "Grid3DOverlay.h" #include - #include "Application.h" -ProgramObject Grid3DOverlay::_gridProgram; - Grid3DOverlay::Grid3DOverlay() : _minorGridWidth(1.0), _majorGridEvery(5) { @@ -42,7 +36,7 @@ void Grid3DOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; // center the grid around the camera position on the plane - glm::vec3 rotated = glm::inverse(getRotation()) * Application::getInstance()->getCamera()->getPosition(); + glm::vec3 rotated = glm::inverse(getRotation()) * args->_viewFrustum->getPosition(); float spacing = _minorGridWidth; @@ -118,3 +112,4 @@ QScriptValue Grid3DOverlay::getProperty(const QString& property) { Grid3DOverlay* Grid3DOverlay::createClone() const { return new Grid3DOverlay(this); } + diff --git a/interface/src/ui/overlays/Grid3DOverlay.h b/interface/src/ui/overlays/Grid3DOverlay.h index ac0f2834fe..80ec4b84b9 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.h +++ b/interface/src/ui/overlays/Grid3DOverlay.h @@ -12,11 +12,6 @@ #ifndef hifi_Grid3DOverlay_h #define hifi_Grid3DOverlay_h -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - -#include - #include "Planar3DOverlay.h" class Grid3DOverlay : public Planar3DOverlay { @@ -35,8 +30,6 @@ public: private: float _minorGridWidth; int _majorGridEvery; - - static ProgramObject _gridProgram; }; #endif // hifi_Grid3DOverlay_h diff --git a/interface/src/ui/overlays/ImageOverlay.h b/interface/src/ui/overlays/ImageOverlay.h index b7924bdb71..59d4102933 100644 --- a/interface/src/ui/overlays/ImageOverlay.h +++ b/interface/src/ui/overlays/ImageOverlay.h @@ -12,8 +12,6 @@ #define hifi_ImageOverlay_h // include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include #include diff --git a/interface/src/ui/overlays/Overlay.h b/interface/src/ui/overlays/Overlay.h index 375a1c3bb9..1698d71fc3 100644 --- a/interface/src/ui/overlays/Overlay.h +++ b/interface/src/ui/overlays/Overlay.h @@ -12,8 +12,6 @@ #define hifi_Overlay_h // include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include // for xColor #include diff --git a/interface/src/ui/overlays/Overlay2D.h b/interface/src/ui/overlays/Overlay2D.h index d91a20b070..382105c047 100644 --- a/interface/src/ui/overlays/Overlay2D.h +++ b/interface/src/ui/overlays/Overlay2D.h @@ -11,9 +11,6 @@ #ifndef hifi_Overlay2D_h #define hifi_Overlay2D_h -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include "Overlay.h" diff --git a/interface/src/ui/overlays/Planar3DOverlay.h b/interface/src/ui/overlays/Planar3DOverlay.h index 9683cb3357..fe8c513efd 100644 --- a/interface/src/ui/overlays/Planar3DOverlay.h +++ b/interface/src/ui/overlays/Planar3DOverlay.h @@ -11,9 +11,6 @@ #ifndef hifi_Planar3DOverlay_h #define hifi_Planar3DOverlay_h -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include "Base3DOverlay.h" class Planar3DOverlay : public Base3DOverlay { diff --git a/interface/src/ui/overlays/Text3DOverlay.h b/interface/src/ui/overlays/Text3DOverlay.h index 93d4106708..666b43d8b1 100644 --- a/interface/src/ui/overlays/Text3DOverlay.h +++ b/interface/src/ui/overlays/Text3DOverlay.h @@ -11,9 +11,6 @@ #ifndef hifi_Text3DOverlay_h #define hifi_Text3DOverlay_h -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include "Planar3DOverlay.h" diff --git a/interface/src/ui/overlays/TextOverlay.h b/interface/src/ui/overlays/TextOverlay.h index 7ada26f892..b70b95ca3b 100644 --- a/interface/src/ui/overlays/TextOverlay.h +++ b/interface/src/ui/overlays/TextOverlay.h @@ -11,9 +11,6 @@ #ifndef hifi_TextOverlay_h #define hifi_TextOverlay_h -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include diff --git a/interface/src/ui/overlays/Volume3DOverlay.h b/interface/src/ui/overlays/Volume3DOverlay.h index 51f63dc580..ada485a663 100644 --- a/interface/src/ui/overlays/Volume3DOverlay.h +++ b/interface/src/ui/overlays/Volume3DOverlay.h @@ -11,9 +11,6 @@ #ifndef hifi_Volume3DOverlay_h #define hifi_Volume3DOverlay_h -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include "Base3DOverlay.h" class Volume3DOverlay : public Base3DOverlay { diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index e356dbcb9a..59719bd000 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -101,7 +101,7 @@ void GLBackend::syncInputStateCache() { //_input._defaultVAO glBindVertexArray(_input._defaultVAO); #else - int i = 0; + size_t i = 0; #if defined(SUPPORT_LEGACY_OPENGL) for (; i < NUM_CLASSIC_ATTRIBS; i++) { _input._attributeActivation[i] = glIsEnabled(attributeSlotToClassicAttribName[i]); diff --git a/libraries/gpu/src/gpu/GPUConfig.h b/libraries/gpu/src/gpu/GPUConfig.h index 0b2d93b18d..1d092dbc6a 100644 --- a/libraries/gpu/src/gpu/GPUConfig.h +++ b/libraries/gpu/src/gpu/GPUConfig.h @@ -25,7 +25,6 @@ #define GPU_TRANSFORM_PROFILE GPU_LEGACY #elif defined(WIN32) -#include #include #include diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index 1b0b5aeebc..ee1af18494 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -9,32 +9,50 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "AmbientOcclusionEffect.h" + +#include +#include + #include - #include - #include #include #include "AbstractViewStateInterface.h" -#include "AmbientOcclusionEffect.h" -#include "ProgramObject.h" #include "RenderUtil.h" #include "TextureCache.h" const int ROTATION_WIDTH = 4; const int ROTATION_HEIGHT = 4; +static QString readFile(const QString& path) { + QFile file(path); + QString result; + if (file.open(QFile::ReadOnly | QFile::Text)) { + QTextStream in(&file); + result = in.readAll(); + } + return result; +} + void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) { +#if 0 _viewState = viewState; // we will use this for view state services - - _occlusionProgram = new ProgramObject(); - _occlusionProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() - + "shaders/ambient_occlusion.vert"); - _occlusionProgram->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() - + "shaders/ambient_occlusion.frag"); - _occlusionProgram->link(); - + + { + gpu::Shader::Source vertexSource = std::string(readFile(PathUtils::resourcesPath() + + "shaders/ambient_occlusion.vert").toLocal8Bit().data()); + gpu::Shader::Source fragmentSource = std::string(readFile(PathUtils::resourcesPath() + + "shaders/ambient_occlusion.frag").toLocal8Bit().data()); + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vertexSource)); + auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentSource)); + _occlusionProgram = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); + } + foreach(auto uniform, _occlusionProgram->getUniforms()) { + qDebug() << uniform._location; + } + // create the sample kernel: an array of hemispherically distributed offset vectors const int SAMPLE_KERNEL_SIZE = 16; QVector3D sampleKernel[SAMPLE_KERNEL_SIZE]; @@ -48,20 +66,20 @@ void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) { sampleKernel[i] = QVector3D(vector.x, vector.y, vector.z); } - _occlusionProgram->bind(); - _occlusionProgram->setUniformValue("depthTexture", 0); - _occlusionProgram->setUniformValue("rotationTexture", 1); - _occlusionProgram->setUniformValueArray("sampleKernel", sampleKernel, SAMPLE_KERNEL_SIZE); - _occlusionProgram->setUniformValue("radius", 0.1f); - _occlusionProgram->release(); - - _nearLocation = _occlusionProgram->uniformLocation("near"); - _farLocation = _occlusionProgram->uniformLocation("far"); - _leftBottomLocation = _occlusionProgram->uniformLocation("leftBottom"); - _rightTopLocation = _occlusionProgram->uniformLocation("rightTop"); - _noiseScaleLocation = _occlusionProgram->uniformLocation("noiseScale"); - _texCoordOffsetLocation = _occlusionProgram->uniformLocation("texCoordOffset"); - _texCoordScaleLocation = _occlusionProgram->uniformLocation("texCoordScale"); + glUseProgram(gpu::GLBackend::getShaderID(_occlusionProgram)); + glUniform1i(_occlusionProgram->getUniforms().findLocation("depthTexture"), 0); + glUniform1i(_occlusionProgram->getUniforms().findLocation("rotationTexture"), 1); + glUniform1f(_occlusionProgram->getUniforms().findLocation("radius"), 0.1f); + //_occlusionProgram->setUniformValueArray("sampleKernel", sampleKernel, SAMPLE_KERNEL_SIZE); + glUseProgram(0); + + _nearLocation = _occlusionProgram->getUniforms().findLocation("near"); + _farLocation = _occlusionProgram->getUniforms().findLocation("far"); + _leftBottomLocation = _occlusionProgram->getUniforms().findLocation("leftBottom"); + _rightTopLocation = _occlusionProgram->getUniforms().findLocation("rightTop"); + _noiseScaleLocation = _occlusionProgram->getUniforms().findLocation("noiseScale"); + _texCoordOffsetLocation = _occlusionProgram->getUniforms().findLocation("texCoordOffset"); + _texCoordScaleLocation = _occlusionProgram->getUniforms().findLocation("texCoordScale"); // generate the random rotation texture glGenTextures(1, &_rotationTextureID); @@ -79,20 +97,29 @@ void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); - - _blurProgram = new ProgramObject(); - _blurProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/ambient_occlusion.vert"); - _blurProgram->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/occlusion_blur.frag"); - _blurProgram->link(); - - _blurProgram->bind(); - _blurProgram->setUniformValue("originalTexture", 0); - _blurProgram->release(); - - _blurScaleLocation = _blurProgram->uniformLocation("blurScale"); + + { + gpu::Shader::Source vertexSource = std::string(readFile(PathUtils::resourcesPath() + + "shaders/ambient_occlusion.vert").toLocal8Bit().data()); + gpu::Shader::Source fragmentSource = std::string(readFile(PathUtils::resourcesPath() + + "shaders/occlusion_blur.frag").toLocal8Bit().data()); + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vertexSource)); + auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentSource)); + _blurProgram = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs)); + } + + glUseProgram(gpu::GLBackend::getShaderID(_blurProgram)); + foreach(auto uniform, _blurProgram->getUniforms()) { + qDebug() << uniform._location; + } + glUniform1f(_blurProgram->getUniforms().findLocation("originalTexture"), 0); + glUseProgram(0); + _blurScaleLocation = _blurProgram->getUniforms().findLocation("blurScale"); +#endif } void AmbientOcclusionEffect::render() { +#if 0 glDisable(GL_BLEND); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); @@ -119,19 +146,19 @@ void AmbientOcclusionEffect::render() { float sMin = viewport[VIEWPORT_X_INDEX] / (float)framebufferSize.width(); float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)framebufferSize.width(); - _occlusionProgram->bind(); - _occlusionProgram->setUniformValue(_nearLocation, nearVal); - _occlusionProgram->setUniformValue(_farLocation, farVal); - _occlusionProgram->setUniformValue(_leftBottomLocation, left, bottom); - _occlusionProgram->setUniformValue(_rightTopLocation, right, top); - _occlusionProgram->setUniformValue(_noiseScaleLocation, viewport[VIEWPORT_WIDTH_INDEX] / (float)ROTATION_WIDTH, + glUseProgram(gpu::GLBackend::getShaderID(_occlusionProgram)); + glUniform1f(_nearLocation, nearVal); + glUniform1f(_farLocation, farVal); + glUniform2f(_leftBottomLocation, left, bottom); + glUniform2f(_rightTopLocation, right, top); + glUniform2f(_noiseScaleLocation, viewport[VIEWPORT_WIDTH_INDEX] / (float)ROTATION_WIDTH, framebufferSize.height() / (float)ROTATION_HEIGHT); - _occlusionProgram->setUniformValue(_texCoordOffsetLocation, sMin, 0.0f); - _occlusionProgram->setUniformValue(_texCoordScaleLocation, sWidth, 1.0f); + glUniform2f(_texCoordOffsetLocation, sMin, 0.0f); + glUniform2f(_texCoordScaleLocation, sWidth, 1.0f); renderFullscreenQuad(); - _occlusionProgram->release(); + glUseProgram(0); glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -149,16 +176,17 @@ void AmbientOcclusionEffect::render() { auto freeFramebufferTexture = nullptr; // freeFramebuffer->getRenderBuffer(0); // FIXME glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(freeFramebufferTexture)); - _blurProgram->bind(); - _blurProgram->setUniformValue(_blurScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height()); + glUseProgram(gpu::GLBackend::getShaderID(_occlusionProgram)); + glUniform2f(_blurScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height()); renderFullscreenQuad(sMin, sMin + sWidth); - _blurProgram->release(); - + glUseProgram(0); + glBindTexture(GL_TEXTURE_2D, 0); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); +#endif } diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index a397a6e3d0..e8d49cd3a3 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -14,9 +14,9 @@ #include #include +#include class AbstractViewStateInterface; -class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at /// http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html for reference. @@ -32,7 +32,7 @@ private: AmbientOcclusionEffect() {} virtual ~AmbientOcclusionEffect() {} - ProgramObject* _occlusionProgram; + gpu::ShaderPointer _occlusionProgram; int _nearLocation; int _farLocation; int _leftBottomLocation; @@ -41,7 +41,7 @@ private: int _texCoordOffsetLocation; int _texCoordScaleLocation; - ProgramObject* _blurProgram; + gpu::ShaderPointer _blurProgram; int _blurScaleLocation; uint32_t _rotationTextureID; diff --git a/libraries/render-utils/src/ProgramObject.cpp b/libraries/render-utils/src/ProgramObject.cpp deleted file mode 100644 index 56fd48bff7..0000000000 --- a/libraries/render-utils/src/ProgramObject.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// ProgramObject.cpp -// interface/src/renderer -// -// Created by Andrzej Kapolka on 5/7/13. -// Copyright 2013 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 - -#include "ProgramObject.h" - -ProgramObject::ProgramObject(QObject* parent) : QGLShaderProgram(parent) { -} - -void ProgramObject::setUniform(int location, const glm::vec2& value) { - setUniformValue(location, value.x, value.y); -} - -void ProgramObject::setUniform(const char* name, const glm::vec2& value) { - setUniformValue(name, value.x, value.y); -} - -void ProgramObject::setUniform(int location, const glm::vec3& value) { - setUniformValue(location, value.x, value.y, value.z); -} - -void ProgramObject::setUniform(const char* name, const glm::vec3& value) { - setUniformValue(name, value.x, value.y, value.z); -} - -void ProgramObject::setUniform(int location, const glm::vec4& value) { - setUniformValue(location, value.x, value.y, value.z, value.w); -} - -void ProgramObject::setUniform(const char* name, const glm::vec4& value) { - setUniformValue(name, value.x, value.y, value.z, value.w); -} - -void ProgramObject::setUniformArray(const char* name, const glm::vec3* values, int count) { - GLfloat* floatVal = new GLfloat[count*3]; - int index = 0; - for (int i = 0; i < count; i++) { - assert(index < count*3); - const float* valPtr = glm::value_ptr(values[i]); - floatVal[index++] = valPtr[0]; - floatVal[index++] = valPtr[1]; - floatVal[index++] = valPtr[2]; - } - - setUniformValueArray(name, floatVal, count, 3); - delete[] floatVal; -} diff --git a/libraries/render-utils/src/ProgramObject.h b/libraries/render-utils/src/ProgramObject.h deleted file mode 100644 index 2b7dad71a5..0000000000 --- a/libraries/render-utils/src/ProgramObject.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// ProgramObject.h -// interface/src/renderer -// -// Created by Andrzej Kapolka on 5/7/13. -// Copyright 2013 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 -// - -#ifndef hifi_ProgramObject_h -#define hifi_ProgramObject_h - -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdouble-promotion" -#endif - -#include - -#if defined(__GNUC__) && !defined(__clang__) -#pragma GCC diagnostic pop -#endif - -#include - -class ProgramObject : public QGLShaderProgram { -public: - - ProgramObject(QObject* parent = 0); - - void setUniform(int location, const glm::vec2& value); - void setUniform(const char* name, const glm::vec2& value); - void setUniform(int location, const glm::vec3& value); - void setUniform(const char* name, const glm::vec3& value); - void setUniform(int location, const glm::vec4& value); - void setUniform(const char* name, const glm::vec4& value); - void setUniformArray(const char* name, const glm::vec3* values, int count); -}; - -#endif // hifi_ProgramObject_h From 5b494c23fd4a59217eea123cb976265ea62bfde4 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 22:38:26 -0700 Subject: [PATCH 10/19] More header cleanup --- interface/src/Application.cpp | 3 --- interface/src/ui/ApplicationCompositor.cpp | 2 -- interface/src/ui/ApplicationOverlay.cpp | 2 -- interface/src/ui/AudioStatsDialog.cpp | 5 ++--- interface/src/ui/LogDialog.cpp | 2 -- interface/src/ui/overlays/Base3DOverlay.cpp | 8 ++++++-- interface/src/ui/overlays/Cube3DOverlay.cpp | 9 +++++---- interface/src/ui/overlays/Grid3DOverlay.cpp | 6 +++++- interface/src/ui/overlays/ImageOverlay.cpp | 7 ++----- interface/src/ui/overlays/Line3DOverlay.cpp | 6 +----- .../src/ui/overlays/LocalModelsOverlay.cpp | 11 +++++------ interface/src/ui/overlays/ModelOverlay.cpp | 2 +- interface/src/ui/overlays/Overlays.cpp | 3 ++- .../src/ui/overlays/Rectangle3DOverlay.cpp | 3 --- interface/src/ui/overlays/Sphere3DOverlay.cpp | 10 ++++------ interface/src/ui/overlays/Text3DOverlay.cpp | 3 --- interface/src/ui/overlays/TextOverlay.cpp | 17 +++++++++-------- 17 files changed, 42 insertions(+), 57 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 404193aa3a..0ce7698afe 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -21,9 +21,6 @@ #include #include -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include #include #include diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index cd28ca0732..dad626ae44 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" - #include "ApplicationCompositor.h" #include diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 1ab1210881..ed2c68aba5 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" - #include #include diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp index 1d6d84a15b..116cc60b5e 100644 --- a/interface/src/ui/AudioStatsDialog.cpp +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -9,9 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include "AudioStatsDialog.h" -#include "InterfaceConfig.h" +#include #include #include @@ -22,7 +22,6 @@ #include -#include "AudioStatsDialog.h" const unsigned COLOR0 = 0x33cc99ff; const unsigned COLOR1 = 0xffef40c0; diff --git a/interface/src/ui/LogDialog.cpp b/interface/src/ui/LogDialog.cpp index 0d2d0d11f6..c9a303461f 100644 --- a/interface/src/ui/LogDialog.cpp +++ b/interface/src/ui/LogDialog.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "InterfaceConfig.h" - #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdouble-promotion" diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 108f092465..e1252836d7 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -8,10 +8,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + +#include "Base3DOverlay.h" + +#include + +#include #include -#include "Application.h" -#include "Base3DOverlay.h" const float DEFAULT_LINE_WIDTH = 1.0f; const bool DEFAULT_IS_SOLID = false; diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 7f6fd5f971..961d7f765b 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -9,14 +9,15 @@ // // include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include "Cube3DOverlay.h" + +#include #include #include #include - -#include "Application.h" -#include "Cube3DOverlay.h" +#include +#include Cube3DOverlay::Cube3DOverlay(const Cube3DOverlay* cube3DOverlay) : Volume3DOverlay(cube3DOverlay) diff --git a/interface/src/ui/overlays/Grid3DOverlay.cpp b/interface/src/ui/overlays/Grid3DOverlay.cpp index ad64c6091b..956eae35ff 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.cpp +++ b/interface/src/ui/overlays/Grid3DOverlay.cpp @@ -11,8 +11,12 @@ #include "Grid3DOverlay.h" +#include + +#include +#include #include -#include "Application.h" +#include Grid3DOverlay::Grid3DOverlay() : _minorGridWidth(1.0), diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 73a3f7e39c..cad9010531 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -12,13 +12,10 @@ #include #include +#include +#include #include -#include "qapplication.h" - -#include "gpu/Context.h" -#include "gpu/StandardShaderLib.h" - ImageOverlay::ImageOverlay() : _imageURL(), _renderImage(false), diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 4e2763d260..d026e5f56e 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -8,15 +8,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" +#include "Line3DOverlay.h" #include #include -#include "Line3DOverlay.h" - - Line3DOverlay::Line3DOverlay() : _geometryCacheID(DependencyManager::get()->allocateID()) { diff --git a/interface/src/ui/overlays/LocalModelsOverlay.cpp b/interface/src/ui/overlays/LocalModelsOverlay.cpp index 06b27f8f22..9a2733c739 100644 --- a/interface/src/ui/overlays/LocalModelsOverlay.cpp +++ b/interface/src/ui/overlays/LocalModelsOverlay.cpp @@ -9,10 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "Application.h" - #include "LocalModelsOverlay.h" +#include +#include + LocalModelsOverlay::LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer) : Volume3DOverlay(), _entityTreeRenderer(entityTreeRenderer) { @@ -33,13 +34,11 @@ void LocalModelsOverlay::render(RenderArgs* args) { float glowLevel = getGlowLevel(); // FIXME, glowing removed for now auto batch = args ->_batch; - Application* app = Application::getInstance(); - glm::vec3 oldTranslation = app->getViewMatrixTranslation(); Transform transform = Transform(); - transform.setTranslation(oldTranslation + getPosition()); + transform.setTranslation(args->_viewFrustum->getPosition() + getPosition()); batch->setViewTransform(transform); _entityTreeRenderer->render(args); - transform.setTranslation(oldTranslation); + transform.setTranslation(args->_viewFrustum->getPosition()); batch->setViewTransform(transform); } } diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index 5a399aef76..ed15e57d43 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -11,7 +11,7 @@ #include "ModelOverlay.h" -#include +#include "Application.h" ModelOverlay::ModelOverlay() : _model(), diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 63b87a30ae..6f28cf8352 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -14,10 +14,11 @@ #include -#include #include #include +#include +#include "Application.h" #include "BillboardOverlay.h" #include "Circle3DOverlay.h" #include "Cube3DOverlay.h" diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 0ab9174da8..1d5183b833 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -8,9 +8,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include "Rectangle3DOverlay.h" #include diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 8d751c73c5..307b60b2ce 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -8,14 +8,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - -#include - #include "Sphere3DOverlay.h" -#include "Application.h" +#include +#include +#include +#include Sphere3DOverlay::Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay) : Volume3DOverlay(Sphere3DOverlay) diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 17dc8d03a8..737b2d0bc5 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -8,9 +8,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - #include "Text3DOverlay.h" #include diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 597a630e3c..467014427d 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -8,21 +8,22 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" -#include "Application.h" #include "TextOverlay.h" -#include "OffscreenUi.h" -#include "text/FontFamilies.h" -#include + +#include + #include #include -#include #include +#include +#include #include #include +#include #include -#include + +#include "Application.h" +#include "text/FontFamilies.h" #define TEXT_OVERLAY_PROPERTY(type, name, initialValue) \ Q_PROPERTY(type name READ name WRITE set##name NOTIFY name##Changed) \ From 0da8b27fcf67006d8be1d188d0acc6a5e500067f Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 22:53:43 -0700 Subject: [PATCH 11/19] Removing unused files --- interface/CMakeLists.txt | 15 -- interface/InterfaceConfig.h.in | 15 -- interface/src/ui/FlowLayout.cpp | 222 ------------------------ interface/src/ui/FlowLayout.h | 78 --------- interface/src/ui/ScriptEditorWindow.cpp | 1 - 5 files changed, 331 deletions(-) delete mode 100644 interface/InterfaceConfig.h.in delete mode 100644 interface/src/ui/FlowLayout.cpp delete mode 100644 interface/src/ui/FlowLayout.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 017a9d3c5f..beeaab8567 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -22,23 +22,8 @@ else () set(BUILD_SEQ "dev") endif () -if (APPLE) - set(GL_HEADERS "#include ") -elseif (UNIX) - # include the right GL headers for UNIX - set(GL_HEADERS "#include \n#include ") -elseif (WIN32) - add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h - add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines - - set(GL_HEADERS "#include \n#include \n#include ") -endif () - -# create the InterfaceConfig.h file based on GL_HEADERS above -configure_file(InterfaceConfig.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h") configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h") - macro(GroupSources curdir) file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*) foreach(child ${children}) diff --git a/interface/InterfaceConfig.h.in b/interface/InterfaceConfig.h.in deleted file mode 100644 index fba2b7e4d6..0000000000 --- a/interface/InterfaceConfig.h.in +++ /dev/null @@ -1,15 +0,0 @@ -// -// InterfaceConfig.h -// interface/src -// -// Created by Stephen Birarda on 2/8/13. -// Copyright 2013 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 -// - -#ifndef interface__InterfaceConfig__ -#define interface__InterfaceConfig__ - -#endif diff --git a/interface/src/ui/FlowLayout.cpp b/interface/src/ui/FlowLayout.cpp deleted file mode 100644 index ed68204d90..0000000000 --- a/interface/src/ui/FlowLayout.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdouble-promotion" -#endif - -#include - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -#include "FlowLayout.h" -//! [1] -FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) - : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) -{ - setContentsMargins(margin, margin, margin, margin); -} - -FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) - : m_hSpace(hSpacing), m_vSpace(vSpacing) -{ - setContentsMargins(margin, margin, margin, margin); -} -//! [1] - -//! [2] -FlowLayout::~FlowLayout() -{ - QLayoutItem *item; - while ((item = takeAt(0))) - delete item; -} -//! [2] - -//! [3] -void FlowLayout::addItem(QLayoutItem *item) -{ - itemList.append(item); -} -//! [3] - -//! [4] -int FlowLayout::horizontalSpacing() const -{ - if (m_hSpace >= 0) { - return m_hSpace; - } else { - return smartSpacing(QStyle::PM_LayoutHorizontalSpacing); - } -} - -int FlowLayout::verticalSpacing() const -{ - if (m_vSpace >= 0) { - return m_vSpace; - } else { - return smartSpacing(QStyle::PM_LayoutVerticalSpacing); - } -} -//! [4] - -//! [5] -int FlowLayout::count() const -{ - return itemList.size(); -} - -QLayoutItem *FlowLayout::itemAt(int index) const -{ - return itemList.value(index); -} - -QLayoutItem *FlowLayout::takeAt(int index) -{ - if (index >= 0 && index < itemList.size()) - return itemList.takeAt(index); - else - return 0; -} -//! [5] - -//! [6] -Qt::Orientations FlowLayout::expandingDirections() const -{ - return 0; -} -//! [6] - -//! [7] -bool FlowLayout::hasHeightForWidth() const -{ - return true; -} - -int FlowLayout::heightForWidth(int width) const -{ - int height = doLayout(QRect(0, 0, width, 0), true); - return height; -} -//! [7] - -//! [8] -void FlowLayout::setGeometry(const QRect &rect) -{ - QLayout::setGeometry(rect); - doLayout(rect, false); -} - -QSize FlowLayout::sizeHint() const -{ - return minimumSize(); -} - -QSize FlowLayout::minimumSize() const -{ - QSize size; - QLayoutItem *item; - foreach (item, itemList) - size = size.expandedTo(item->minimumSize()); - - size += QSize(2*margin(), 2*margin()); - return size; -} -//! [8] - -//! [9] -int FlowLayout::doLayout(const QRect &rect, bool testOnly) const -{ - int left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); - QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); - int x = effectiveRect.x(); - int y = effectiveRect.y(); - int lineHeight = 0; -//! [9] - -//! [10] - QLayoutItem *item; - foreach (item, itemList) { - QWidget *wid = item->widget(); - int spaceX = horizontalSpacing(); - if (spaceX == -1) - spaceX = wid->style()->layoutSpacing( - QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal); - int spaceY = verticalSpacing(); - if (spaceY == -1) - spaceY = wid->style()->layoutSpacing( - QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical); -//! [10] -//! [11] - int nextX = x + item->sizeHint().width() + spaceX; - if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { - x = effectiveRect.x(); - y = y + lineHeight + spaceY; - nextX = x + item->sizeHint().width() + spaceX; - lineHeight = 0; - } - - if (!testOnly) - item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); - - x = nextX; - lineHeight = qMax(lineHeight, item->sizeHint().height()); - } - return y + lineHeight - rect.y() + bottom; -} -//! [11] -//! [12] -int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const -{ - QObject *parent = this->parent(); - if (!parent) { - return -1; - } else if (parent->isWidgetType()) { - QWidget *pw = static_cast(parent); - return pw->style()->pixelMetric(pm, 0, pw); - } else { - return static_cast(parent)->spacing(); - } -} -//! [12] diff --git a/interface/src/ui/FlowLayout.h b/interface/src/ui/FlowLayout.h deleted file mode 100644 index f7107be6b2..0000000000 --- a/interface/src/ui/FlowLayout.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef FLOWLAYOUT_H -#define FLOWLAYOUT_H - -#include -#include -#include -//! [0] -class FlowLayout : public QLayout -{ -public: - explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1); - explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1); - ~FlowLayout(); - - void addItem(QLayoutItem *item); - int horizontalSpacing() const; - int verticalSpacing() const; - Qt::Orientations expandingDirections() const; - bool hasHeightForWidth() const; - int heightForWidth(int) const; - int count() const; - QLayoutItem *itemAt(int index) const; - QSize minimumSize() const; - void setGeometry(const QRect &rect); - QSize sizeHint() const; - QLayoutItem *takeAt(int index); - -private: - int doLayout(const QRect &rect, bool testOnly) const; - int smartSpacing(QStyle::PixelMetric pm) const; - - QList itemList; - int m_hSpace; - int m_vSpace; -}; -//! [0] - -#endif // FLOWLAYOUT_H diff --git a/interface/src/ui/ScriptEditorWindow.cpp b/interface/src/ui/ScriptEditorWindow.cpp index 424b649b02..41d172cf48 100644 --- a/interface/src/ui/ScriptEditorWindow.cpp +++ b/interface/src/ui/ScriptEditorWindow.cpp @@ -28,7 +28,6 @@ #include #include "Application.h" -#include "FlowLayout.h" #include "JSConsole.h" #include "PathUtils.h" From f13152b2b4d5142fc2572d7de0cb298dc83bbe6c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 18 Jul 2015 23:04:16 -0700 Subject: [PATCH 12/19] Fixing reference to PI/2 --- interface/src/devices/SixenseManager.cpp | 5 +++-- interface/src/ui/ApplicationCompositor.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index c82027cb38..19763ee3bf 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "Application.h" #include "SixenseManager.h" @@ -527,8 +528,8 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { glm::vec3 direction = glm::inverse(avatar->getOrientation()) * palm->getFingerDirection(); // Get the angles, scaled between (-0.5,0.5) - float xAngle = (atan2(direction.z, direction.x) + M_PI_2); - float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2)); + float xAngle = (atan2(direction.z, direction.x) + PI_OVER_TWO); + float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)PI_OVER_TWO)); auto canvasSize = qApp->getCanvasSize(); // Get the pixel range over which the xAngle and yAngle are scaled float cursorRange = canvasSize.x * getCursorPixelRangeMult(); diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index dad626ae44..c7308674fe 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "CursorManager.h" #include "Tooltip.h" @@ -499,8 +500,8 @@ void ApplicationCompositor::renderControllerPointers(gpu::Batch& batch) { glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection(); // Get the angles, scaled between (-0.5,0.5) - float xAngle = (atan2(direction.z, direction.x) + M_PI_2); - float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2)); + float xAngle = (atan2(direction.z, direction.x) + PI_OVER_TWO); + float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)PI_OVER_TWO)); // Get the pixel range over which the xAngle and yAngle are scaled float cursorRange = canvasSize.x * SixenseManager::getInstance().getCursorPixelRangeMult(); From 81543d918554ba26b6823b1ca8362ddbb426f3a7 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 19 Jul 2015 19:06:21 -0700 Subject: [PATCH 13/19] Removing unneeded undef --- interface/src/avatar/Avatar.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 979995360e..5b6e53be53 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -706,9 +706,6 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa // Compute pixel alignment offset float clipToPix = 0.5f * windowSizeY / p1.w; // Got from clip to pixel coordinates glm::vec4 screenPos = clipToPix * p1; // in pixels coords -// WTF? -#undef round - glm::vec4 screenOffset = (glm::round(screenPos) - screenPos) / clipToPix; // in clip coords glm::vec3 worldOffset = glm::vec3(screenOffset.x, screenOffset.y, 0.0f) / (float)pixelHeight; From 4c3cfe1e82f2d8c79ec8f86a361542dd99581837 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 19 Jul 2015 20:53:50 -0700 Subject: [PATCH 14/19] Starfield jazz hands --- interface/src/Stars.cpp | 58 ++++++++++++----- libraries/render-utils/src/stars.slf | 93 ++++++++++++---------------- 2 files changed, 82 insertions(+), 69 deletions(-) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 3ef909786d..02c4ffd32f 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -24,6 +24,10 @@ #include #include +#include "../../libraries/render-utils/standardTransformPNTC_vert.h" +#include "../../libraries/render-utils/stars_frag.h" + +static const float TILT = 0.23f; static const unsigned int STARFIELD_NUM_STARS = 50000; static const unsigned int STARFIELD_SEED = 1; static const float STAR_COLORIZATION = 0.1f; @@ -34,14 +38,9 @@ static const float QUARTER_TAU = TAU / 4.0f; static const float MILKY_WAY_WIDTH = TAU / 30.0f; // width in radians of one half of the Milky Way static const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees static const float MILKY_WAY_RATIO = 0.4f; +static const char* UNIFORM_TIME_NAME = "iGlobalTime"; -#include "../../libraries/render-utils/standardTransformPNTC_vert.h" -const char stars_frag[] = R"SCRIBE(#version 430 compatibility -void main(void) { - gl_FragColor = vec4( 1.0 ); -} -)SCRIBE"; Stars::Stars() { } @@ -112,16 +111,16 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { static gpu::BufferPointer vertexBuffer; static gpu::Stream::FormatPointer streamFormat; static gpu::Element positionElement, colorElement; + static gpu::PipelinePointer _pipeline; + static int32_t _timeSlot{ -1 }; + static std::once_flag once; const int VERTICES_SLOT = 0; const int COLOR_SLOT = 2; - static std::once_flag once; - std::call_once(once, [&] { QElapsedTimer startTime; startTime.start(); - vertexBuffer.reset(new gpu::Buffer); srand(STARFIELD_SEED); @@ -139,18 +138,45 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { positionElement = streamFormat->getAttributes().at(gpu::Stream::POSITION)._element; double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms qDebug() << "Total time to generate stars: " << timeDiff << " msec"; + + auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(standardTransformPNTC_vert))); + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(stars_frag))); + auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + gpu::Shader::makeProgram((*program)); + _timeSlot = program->getBuffers().findLocation(UNIFORM_TIME_NAME); + if (_timeSlot == gpu::Shader::INVALID_LOCATION) { + _timeSlot = program->getUniforms().findLocation(UNIFORM_TIME_NAME); + } + auto state = gpu::StatePointer(new gpu::State()); + // enable decal blend + state->setDepthTest(gpu::State::DepthTest(false)); + state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + _pipeline.reset(gpu::Pipeline::create(program, state)); }); - gpu::Batch batch; - batch.setInputFormat(streamFormat); - batch.setInputBuffer(VERTICES_SLOT, gpu::BufferView(vertexBuffer, positionElement)); - batch.setViewTransform(Transform()); - batch.setProjectionTransform(renderArgs->_viewFrustum->getProjection()); - batch.setModelTransform(Transform().setRotation(glm::inverse(renderArgs->_viewFrustum->getOrientation()))); auto geometryCache = DependencyManager::get(); auto textureCache = DependencyManager::get(); - geometryCache->useSimpleDrawPipeline(batch); + + gpu::Batch batch; + batch.setViewTransform(Transform()); + batch.setProjectionTransform(renderArgs->_viewFrustum->getProjection()); + batch.setModelTransform(Transform().setRotation(glm::inverse(renderArgs->_viewFrustum->getOrientation()) * + quat(vec3(TILT, 0, 0)))); batch.setResourceTexture(0, textureCache->getWhiteTexture()); + + // Render the world lines + batch.setPipeline(_pipeline); + static auto start = usecTimestampNow(); + float msecs = (float)(usecTimestampNow() - start) / (float)USECS_PER_MSEC; + float secs = msecs / (float)MSECS_PER_SECOND; + batch._glUniform1f(_timeSlot, secs); + geometryCache->renderUnitCube(batch); + + + // Render the stars + geometryCache->useSimpleDrawPipeline(batch); + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, gpu::BufferView(vertexBuffer, positionElement)); batch.draw(gpu::Primitive::POINTS, STARFIELD_NUM_STARS); renderArgs->_context->render(batch); } diff --git a/libraries/render-utils/src/stars.slf b/libraries/render-utils/src/stars.slf index f0f81cb5f4..344d196230 100644 --- a/libraries/render-utils/src/stars.slf +++ b/libraries/render-utils/src/stars.slf @@ -1,5 +1,6 @@ <@include gpu/Config.slh@> <$VERSION_HEADER$> +#line __LINE__ // Generated on <$_SCRIBE_DATE$> // stars.frag // fragment shader @@ -10,67 +11,53 @@ varying vec2 varTexcoord; varying vec3 varNomral; varying vec3 varPosition; +uniform float iGlobalTime; -const int star_iterations = 14; -const float time_scale = 0.2; -const vec3 col_star = vec3( 1.0, 0.7, 0.5 ); +const float PI = 3.14159; +const float TAU = 3.14159 * 2.0; +const int latitudeCount = 5; +const float latitudeDist = PI / 2.0 / float(latitudeCount); +const int meridianCount = 4; +const float merdianDist = PI / float(meridianCount); -float hash( float n ) { return fract(sin(n)*123.456789); } -vec2 rotate( in vec2 uv, float a) -{ - float c = cos( a ); - float s = sin( a ); - return vec2( c * uv.x - s * uv.y, s * uv.x + c * uv.y ); +float clampLine(float val, float target) { + return clamp((1.0 - abs((val - target)) - 0.998) * 500.0, 0.0, 1.0); } -float noise( in vec3 p ) -{ - vec3 fl = floor( p ); - vec3 fr = fract( p ); - fr = fr * fr * ( 3.0 - 2.0 * fr ); - - float n = fl.x + fl.y * 157.0 + 113.0 * fl.z; - return mix( mix( mix( hash( n + 0.0), hash( n + 1.0 ), fr.x ), - mix( hash( n + 157.0), hash( n + 158.0 ), fr.x ), fr.y ), - mix( mix( hash( n + 113.0), hash( n + 114.0 ), fr.x ), - mix( hash( n + 270.0), hash( n + 271.0 ), fr.x ), fr.y ), fr.z ); -} - -float fbm( in vec2 p, float t ) -{ - float f; - f = 0.5000 * noise( vec3( p, t ) ); p *= 2.1; - f += 0.2500 * noise( vec3( p, t ) ); p *= 2.2; - f += 0.1250 * noise( vec3( p, t ) ); p *= 2.3; - f += 0.0625 * noise( vec3( p, t ) ); - return f; -} - -vec3 doBackgroundStars( in vec3 dir ) -{ - vec3 n = abs( dir ); - vec2 uv = ( n.x > n.y && n.x > n.z ) ? dir.yz / dir.x: - ( n.y > n.x && n.y > n.z ) ? dir.zx / dir.y: - dir.xy / dir.z; - - float f = 0.0; - - for( int i = 0 ; i < star_iterations; ++i ) - { - uv = rotate( 1.07 * uv + vec2( 0.7 ), 0.5 ); - - float t = 10. * uv.x * uv.y; - vec2 u = cos( 100. * uv ) * fbm( 10. * uv, 0.0 ); - f += smoothstep( 0.5, 0.55, u.x * u.y ) * ( 0.25 * sin( t ) + 0.75 ); +float latitude(vec2 pos, float angle) { + float result = clampLine(pos.y, angle); + if (angle != 0.0) { + result += clampLine(pos.y, -angle); } - - return f * col_star; + return result; +} + +float meridian(vec2 pos, float angle) { + return clampLine(pos.x, angle) + clampLine(pos.x + PI, angle); +} + +vec2 toPolar(in vec3 dir) { + vec2 polar = vec2(atan(dir.z, dir.x), asin(dir.y)); + return polar; +} + +void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 fragRayDir ) +{ + vec2 polar = toPolar(fragRayDir); + polar.x += mod(iGlobalTime / 12.0, PI / 4.0) - PI / 4.0; + float c = 0.0; + for (int i = 0; i < latitudeCount - 1; ++i) { + c += latitude(polar, float(i) * latitudeDist); + } + for (int i = 0; i < meridianCount; ++i) { + c += meridian(polar, float(i) * merdianDist); + } + const vec3 col_lines = vec3(102.0 / 255.0, 136.0 / 255.0, 221.0 / 255.0); + fragColor = vec4(c * col_lines, 1.0); } void main(void) { - vec3 c = doBackgroundStars( normalize(varPosition) ); - c = pow( c, vec3( 0.4545 ) ); - gl_FragColor = vec4( c, 1.0 ); + mainVR(gl_FragColor, gl_FragCoord.xy, vec3(0.0), normalize(varPosition)); } From 5159452335487f8d2150df416af32acc71f04e4c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 19 Jul 2015 23:03:46 -0700 Subject: [PATCH 15/19] Fixing invalid vector usage and strange picking crash --- interface/src/Stars.cpp | 2 +- libraries/shared/src/RegisteredMetaTypes.cpp | 22 ++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 02c4ffd32f..87000b40a4 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -126,7 +126,7 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { srand(STARFIELD_SEED); unsigned limit = STARFIELD_NUM_STARS; std::vector points; - points.reserve(limit); + points.resize(limit); for (size_t star = 0; star < limit; ++star) { points[star] = fromPolar(randPolar()); //auto color = computeStarColor(STAR_COLORIZATION); diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index dce31b2971..de684dced1 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -210,15 +210,25 @@ QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay) void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay) { QScriptValue originValue = object.property("origin"); if (originValue.isValid()) { - pickRay.origin.x = originValue.property("x").toVariant().toFloat(); - pickRay.origin.y = originValue.property("y").toVariant().toFloat(); - pickRay.origin.z = originValue.property("z").toVariant().toFloat(); + auto x = originValue.property("x"); + auto y = originValue.property("y"); + auto z = originValue.property("z"); + if (x.isValid() && y.isValid() && z.isValid()) { + pickRay.origin.x = x.toVariant().toFloat(); + pickRay.origin.y = y.toVariant().toFloat(); + pickRay.origin.z = z.toVariant().toFloat(); + } } QScriptValue directionValue = object.property("direction"); if (directionValue.isValid()) { - pickRay.direction.x = directionValue.property("x").toVariant().toFloat(); - pickRay.direction.y = directionValue.property("y").toVariant().toFloat(); - pickRay.direction.z = directionValue.property("z").toVariant().toFloat(); + auto x = directionValue.property("x"); + auto y = directionValue.property("y"); + auto z = directionValue.property("z"); + if (x.isValid() && y.isValid() && z.isValid()) { + pickRay.direction.x = x.toVariant().toFloat(); + pickRay.direction.y = y.toVariant().toFloat(); + pickRay.direction.z = z.toVariant().toFloat(); + } } } From d4e637c5b8cedc0cadcde4fbf0c65b942a0c3464 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 09:36:05 -0700 Subject: [PATCH 16/19] Removing superfluous lighting and naked GL in mirror --- interface/CMakeLists.txt | 5 ++ interface/src/Application.cpp | 64 ++++++++++---------- libraries/gpu/src/gpu/Batch.cpp | 13 +--- libraries/gpu/src/gpu/Batch.h | 5 -- libraries/gpu/src/gpu/GLBackend.cpp | 2 - libraries/gpu/src/gpu/GLBackend.h | 2 - libraries/gpu/src/gpu/GLBackendInput.cpp | 21 ------- libraries/gpu/src/gpu/GLBackendTransform.cpp | 1 + libraries/gpu/src/gpu/Light.h | 31 ---------- 9 files changed, 40 insertions(+), 104 deletions(-) delete mode 100644 libraries/gpu/src/gpu/Light.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index beeaab8567..1dd9d35b66 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -22,6 +22,11 @@ else () set(BUILD_SEQ "dev") endif () +if (WIN32) + add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h + add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines +endif() + configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h") macro(GroupSources curdir) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0ce7698afe..192db1afd4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -993,11 +993,12 @@ void Application::paintGL() { } displaySide(&renderArgs, _myCamera); - renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; - if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { + + if (_myCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) { + renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; renderRearViewMirror(&renderArgs, _mirrorViewRect); + renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; } - renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; { auto geometryCache = DependencyManager::get(); @@ -3113,19 +3114,7 @@ void Application::updateShadowMap(RenderArgs* renderArgs) { #endif } -static gpu::Light defaultLight{ - vec3( 0.525f, 0.525f, 0.6f), // ambient - vec3( 0.6f, 0.525f, 0.525f), // diffuse - vec4(0.08f, 0.08f, 0.08f, 1.0f), // specular - vec4( 0, 0, 0, 0 ), // position - 96 // shininess -}; - void Application::setupWorldLight(RenderArgs* renderArgs) { - gpu::Batch batch; - defaultLight._position = vec4(getSunDirection(), 0); - batch.setLight(0, defaultLight); - renderArgs->_context->render(batch); } bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { @@ -3624,9 +3613,8 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { } void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) { + auto originalViewport = renderArgs->_viewport; // Grab current viewport to reset it at the end - int viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); float aspect = (float)region.width() / region.height(); float fov = MIRROR_FIELD_OF_VIEW; @@ -3663,35 +3651,45 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)); _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f))); + // set the bounds of rear mirror view + gpu::Vec4i viewport; if (billboard) { QSize size = DependencyManager::get()->getFrameBufferSize(); - glViewport(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); - glScissor(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); - renderArgs->_viewport = glm::ivec4(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); + viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height()); } else { // if not rendering the billboard, the region is in device independent coordinates; must convert to device QSize size = DependencyManager::get()->getFrameBufferSize(); float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale(); int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio; - glViewport(x, size.height() - y - height, width, height); - glScissor(x, size.height() - y - height, width, height); - - renderArgs->_viewport = glm::ivec4(x, size.height() - y - height, width, height); + viewport = gpu::Vec4i(x, size.height() - y - height, width, height); } + renderArgs->_viewport = viewport; + + { + gpu::Batch batch; + batch.setViewportTransform(viewport); + batch.setStateScissorRect(viewport); + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_COLOR0 | + gpu::Framebuffer::BUFFER_COLOR1 | + gpu::Framebuffer::BUFFER_COLOR2 | + gpu::Framebuffer::BUFFER_DEPTH, + vec4(vec3(0), 1), 1.0, 0.0, true); + // Viewport is assigned to the size of the framebuffer + renderArgs->_context->render(batch); + } + bool updateViewFrustum = false; updateProjectionMatrix(_mirrorCamera, updateViewFrustum); - glEnable(GL_SCISSOR_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - // render rear mirror view displaySide(renderArgs, _mirrorCamera, true, billboard); - - // reset Viewport and projection matrix - renderArgs->_viewport = glm::ivec4(viewport[0], viewport[1], viewport[2], viewport[3]); - glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); - glDisable(GL_SCISSOR_TEST); - updateProjectionMatrix(_myCamera, updateViewFrustum); + //{ + // gpu::Batch batch; + // renderArgs->_viewport = originalViewport; + // batch.setViewportTransform(originalViewport); + // renderArgs->_context->render(batch); + //} } void Application::resetSensors() { diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index f8d530bb74..01c3c4ade7 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -13,6 +13,9 @@ #include +#include + + #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" @@ -301,13 +304,3 @@ void push_back(Batch::Params& params, const vec4& v) { params.push_back(v.z); params.push_back(v.a); } - -void Batch::setLight(uint8_t index, const Light& light) { - ADD_COMMAND(setLight); - _params.push_back(index); - push_back(_params, light._ambientColor); - push_back(_params, light._diffuseColor); - push_back(_params, light._position); - push_back(_params, light._specularColor); - _params.push_back(light._shininess); -} \ No newline at end of file diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 3954127783..2f1d2e8ece 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -14,7 +14,6 @@ #include #include "Framebuffer.h" -#include "Light.h" #include "Pipeline.h" #include "Query.h" #include "Stream.h" @@ -77,8 +76,6 @@ public: void setIndexBuffer(Type type, const BufferPointer& buffer, Offset offset); void setIndexBuffer(const BufferView& buffer); // not a command, just a shortcut from a BufferView - void setLight(uint8_t index, const Light& light); - // Transform Stage // Vertex position is transformed by ModelTransform from object space to world space // Then by the inverse of the ViewTransform from world space to eye space @@ -172,8 +169,6 @@ public: COMMAND_setInputBuffer, COMMAND_setIndexBuffer, - COMMAND_setLight, - COMMAND_setModelTransform, COMMAND_setViewTransform, COMMAND_setProjectionTransform, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index f6b9bb8706..adebee2f20 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -26,8 +26,6 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_setInputBuffer), (&::gpu::GLBackend::do_setIndexBuffer), - (&::gpu::GLBackend::do_setLight), - (&::gpu::GLBackend::do_setModelTransform), (&::gpu::GLBackend::do_setViewTransform), (&::gpu::GLBackend::do_setProjectionTransform), diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index eab880f14d..60c01a815c 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -253,8 +253,6 @@ protected: void do_setInputBuffer(Batch& batch, uint32 paramOffset); void do_setIndexBuffer(Batch& batch, uint32 paramOffset); - void do_setLight(Batch& batch, uint32 paramOffset); - void initInput(); void killInput(); void syncInputStateCache(); diff --git a/libraries/gpu/src/gpu/GLBackendInput.cpp b/libraries/gpu/src/gpu/GLBackendInput.cpp index 59719bd000..229b29cd43 100755 --- a/libraries/gpu/src/gpu/GLBackendInput.cpp +++ b/libraries/gpu/src/gpu/GLBackendInput.cpp @@ -305,24 +305,3 @@ void popParam(Batch::Params& params, uint32& paramOffset, V& v) { v[i] = params[paramOffset++]._float; } } - -void GLBackend::do_setLight(Batch& batch, uint32 paramOffset) { - int index = batch._params[paramOffset++]._uint; - gpu::Light light; - popParam(batch._params, paramOffset, light._ambientColor); - popParam(batch._params, paramOffset, light._diffuseColor); - popParam(batch._params, paramOffset, light._position); - popParam(batch._params, paramOffset, light._specularColor); - light._shininess = batch._params[paramOffset++]._int; - - // Setup 3D lights (after the camera transform, so that they are positioned in world space) - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - glLightfv(GL_LIGHT0 + index, GL_POSITION, &light._position.x); - glLightfv(GL_LIGHT0 + index, GL_AMBIENT, &light._ambientColor.r); - glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, &light._diffuseColor.r); - glLightfv(GL_LIGHT0 + index, GL_SPECULAR, &light._specularColor.r); - glMaterialfv(GL_FRONT + index, GL_SPECULAR, &light._specularColor.r); - glMateriali(GL_FRONT + index, GL_SHININESS, light._shininess); -} - diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu/src/gpu/GLBackendTransform.cpp index 01229cb317..2378edb095 100755 --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu/src/gpu/GLBackendTransform.cpp @@ -32,6 +32,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) { void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) { memcpy(&_transform._viewport, batch.editData(batch._params[paramOffset]._uint), sizeof(Vec4i)); + glViewport(_transform._viewport.x, _transform._viewport.y, _transform._viewport.z, _transform._viewport.w); _transform._invalidViewport = true; } diff --git a/libraries/gpu/src/gpu/Light.h b/libraries/gpu/src/gpu/Light.h deleted file mode 100644 index 6ce8eb637f..0000000000 --- a/libraries/gpu/src/gpu/Light.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Created by Bradley Austin Davis 2015/07/18 -// Copyright 2014 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_gpu_Light_h -#define hifi_gpu_Light_h - -#include - -namespace gpu { - -struct Light { - Light() {} - Light(const vec3& ambient, const vec3& diffuse, const vec4& position, const vec4& specular = vec4(), int shininess = 0) : - _ambientColor(ambient), _diffuseColor(diffuse), _position(position), _specularColor(specular), _shininess(shininess) { - - } - vec3 _ambientColor; - vec3 _diffuseColor; - vec4 _position; - vec4 _specularColor; - int _shininess{0}; -}; - -} - -#endif From de92e66635ecbb20687ac46a36cf3eb889e2c2e0 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 09:59:22 -0700 Subject: [PATCH 17/19] Removing shadows code --- interface/src/Application.cpp | 138 +--------------------------------- 1 file changed, 1 insertion(+), 137 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 192db1afd4..9557d982a2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2990,128 +2990,6 @@ static QThread * activeRenderingThread = nullptr; void Application::updateShadowMap(RenderArgs* renderArgs) { // TODO fix shadows and make them use the GPU library -#if 0 - activeRenderingThread = QThread::currentThread(); - - PerformanceTimer perfTimer("shadowMap"); - auto shadowFramebuffer = DependencyManager::get()->getShadowFramebuffer(); - - { - gpu::Batch batch; - auto primaryFbo = DependencyManager::get()->getPrimaryFramebuffer(); - batch.setFramebuffer(shadowFramebuffer); - // clear the normal and specular buffers - batch.clearFramebuffer( - gpu::Framebuffer::BUFFER_DEPTH, - vec4(vec3(0), 1), 1.0, 0.0); - // Viewport is assigned to the size of the framebuffer - QSize size = DependencyManager::get()->getFrameBufferSize(); - renderArgs->_context->render(batch); - } - - glm::vec3 lightDirection = getSunDirection(); - glm::quat rotation = rotationBetween(IDENTITY_FRONT, lightDirection); - glm::quat inverseRotation = glm::inverse(rotation); - - const float SHADOW_MATRIX_DISTANCES[] = { 0.0f, 2.0f, 6.0f, 14.0f, 30.0f }; - const glm::vec2 MAP_COORDS[] = { glm::vec2(0.0f, 0.0f), glm::vec2(0.5f, 0.0f), - glm::vec2(0.0f, 0.5f), glm::vec2(0.5f, 0.5f) }; - - float frustumScale = 1.0f / (_viewFrustum.getFarClip() - _viewFrustum.getNearClip()); - loadViewFrustum(_myCamera, _viewFrustum); - - int matrixCount = 1; - //int targetSize = fbo->width(); - int sourceSize = shadowFramebuffer->getWidth(); - int targetSize = shadowFramebuffer->getWidth(); - float targetScale = 1.0f; - if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { - matrixCount = CASCADED_SHADOW_MATRIX_COUNT; - targetSize = sourceSize / 2; - targetScale = 0.5f; - } - for (int i = 0; i < matrixCount; i++) { - const glm::vec2& coord = MAP_COORDS[i]; - glViewport(coord.s * sourceSize, coord.t * sourceSize, targetSize, targetSize); - - // if simple shadow then since the resolution is twice as much as with cascaded, cover 2 regions with the map, not just one - int regionIncrement = (matrixCount == 1 ? 2 : 1); - float nearScale = SHADOW_MATRIX_DISTANCES[i] * frustumScale; - float farScale = SHADOW_MATRIX_DISTANCES[i + regionIncrement] * frustumScale; - glm::vec3 points[] = { - glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale), - glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale), - glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale), - glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale), - glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale), - glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale), - glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale), - glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) }; - glm::vec3 center; - for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { - center += points[j]; - } - center /= (float)(sizeof(points) / sizeof(points[0])); - float radius = 0.0f; - for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) { - radius = qMax(radius, glm::distance(points[j], center)); - } - if (i < 3) { - const float RADIUS_SCALE = 0.5f; - _shadowDistances[i] = -glm::distance(_viewFrustum.getPosition(), center) - radius * RADIUS_SCALE; - } - center = inverseRotation * center; - - // to reduce texture "shimmer," move in texel increments - float texelSize = (2.0f * radius) / targetSize; - center = glm::vec3(roundf(center.x / texelSize) * texelSize, roundf(center.y / texelSize) * texelSize, - roundf(center.z / texelSize) * texelSize); - - glm::vec3 minima(center.x - radius, center.y - radius, center.z - radius); - glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius); - - // stretch out our extents in z so that we get all of the avatars - minima.z -= _viewFrustum.getFarClip() * 0.5f; - maxima.z += _viewFrustum.getFarClip() * 0.5f; - - // save the combined matrix for rendering - _shadowMatrices[i] = glm::transpose(glm::translate(glm::vec3(coord, 0.0f)) * - glm::scale(glm::vec3(targetScale, targetScale, 1.0f)) * - glm::translate(glm::vec3(0.5f, 0.5f, 0.5f)) * glm::scale(glm::vec3(0.5f, 0.5f, 0.5f)) * - glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation)); - - // update the shadow view frustum - // glm::vec3 shadowFrustumCenter = glm::vec3((minima.x + maxima.x) * 0.5f, (minima.y + maxima.y) * 0.5f, (minima.z + maxima.z) * 0.5f); - glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f); - _shadowViewFrustum.setPosition(shadowFrustumCenter); - _shadowViewFrustum.setOrientation(rotation); - _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z)); - _shadowViewFrustum.calculate(); - - // store view matrix without translation, which we'll use for precision-sensitive objects - updateUntranslatedViewMatrix(); - // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation - // the viewTransofmr object is updatded with the correct values and saved, - // this is what is used for rendering the Entities and avatars - Transform viewTransform; - viewTransform.setRotation(rotation); - setViewTransform(viewTransform); - - - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt - - { - PerformanceTimer perfTimer("entities"); - _entities.render(renderArgs); - } - - glDisable(GL_POLYGON_OFFSET_FILL); - } - - glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); - activeRenderingThread = nullptr; -#endif } void Application::setupWorldLight(RenderArgs* renderArgs) { @@ -3386,21 +3264,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se } // TODO fix shadows and make them use the GPU library -#if 0 - // setup shadow matrices (again, after the camera transform) - int shadowMatrixCount = 0; - if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) { - shadowMatrixCount = 1; - } else if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) { - shadowMatrixCount = CASCADED_SHADOW_MATRIX_COUNT; - } - for (int i = shadowMatrixCount - 1; i >= 0; i--) { - glActiveTexture(GL_TEXTURE0 + i); - glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][0]); - glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][1]); - glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][2]); - } -#endif + // The pending changes collecting the changes here render::PendingChanges pendingChanges; From cd677ccb18049dbb3fef2195b5633b5045dfb891 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 10:18:14 -0700 Subject: [PATCH 18/19] Removing animation from star grid --- libraries/render-utils/src/stars.slf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/stars.slf b/libraries/render-utils/src/stars.slf index 344d196230..0f3070581c 100644 --- a/libraries/render-utils/src/stars.slf +++ b/libraries/render-utils/src/stars.slf @@ -45,7 +45,7 @@ vec2 toPolar(in vec3 dir) { void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 fragRayDir ) { vec2 polar = toPolar(fragRayDir); - polar.x += mod(iGlobalTime / 12.0, PI / 4.0) - PI / 4.0; + //polar.x += mod(iGlobalTime / 12.0, PI / 4.0) - PI / 4.0; float c = 0.0; for (int i = 0; i < latitudeCount - 1; ++i) { c += latitude(polar, float(i) * latitudeDist); From 23b058e4eb7d9aac31f587bcd1d2bfce6fa4528f Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 20 Jul 2015 11:40:12 -0700 Subject: [PATCH 19/19] Removing starfield tilt and reducing grid alpha --- interface/src/Stars.cpp | 3 ++- libraries/render-utils/src/stars.slf | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 87000b40a4..e6c96d9b4b 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -27,7 +27,8 @@ #include "../../libraries/render-utils/standardTransformPNTC_vert.h" #include "../../libraries/render-utils/stars_frag.h" -static const float TILT = 0.23f; +//static const float TILT = 0.23f; +static const float TILT = 0.0f; static const unsigned int STARFIELD_NUM_STARS = 50000; static const unsigned int STARFIELD_SEED = 1; static const float STAR_COLORIZATION = 0.1f; diff --git a/libraries/render-utils/src/stars.slf b/libraries/render-utils/src/stars.slf index 0f3070581c..ed338deaef 100644 --- a/libraries/render-utils/src/stars.slf +++ b/libraries/render-utils/src/stars.slf @@ -54,7 +54,7 @@ void mainVR( out vec4 fragColor, in vec2 fragCoord, in vec3 fragRayOri, in vec3 c += meridian(polar, float(i) * merdianDist); } const vec3 col_lines = vec3(102.0 / 255.0, 136.0 / 255.0, 221.0 / 255.0); - fragColor = vec4(c * col_lines, 1.0); + fragColor = vec4(c * col_lines, 0.2); } void main(void) {