From abab54aed8ccc8c94fd2b02cb1ef7fb0da1bf7f4 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 11 May 2015 13:08:53 -0700 Subject: [PATCH] Working on display plugins --- interface/src/Application.cpp | 16 ++++++++++- interface/src/Application.h | 1 + interface/src/devices/TV3DManager.h | 4 +++ libraries/gpu/src/gpu/GLBackend.cpp | 27 +++++++++++++++++++ libraries/gpu/src/gpu/GLBackend.h | 3 +++ libraries/render-utils/src/RenderUtil.h | 2 ++ libraries/render-utils/src/TextRenderer.cpp | 27 +++++++++++-------- .../src/MatrixStack.cpp | 0 .../src/MatrixStack.h | 21 --------------- 9 files changed, 68 insertions(+), 33 deletions(-) rename libraries/{render-utils => shared}/src/MatrixStack.cpp (100%) rename libraries/{render-utils => shared}/src/MatrixStack.h (88%) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 67af262595..ba90086017 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3069,7 +3069,11 @@ PickRay Application::computePickRay(float x, float y) const { if (isHMDMode()) { ApplicationOverlay::computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction); } else { - getViewFrustum()->computePickRay(x, y, result.origin, result.direction); + if (activeRenderingThread) { + getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction); + } else { + getViewFrustum()->computePickRay(x, y, result.origin, result.direction); + } } return result; } @@ -3124,6 +3128,16 @@ ViewFrustum* Application::getDisplayViewFrustum() { return &_displayViewFrustum; } +const ViewFrustum* Application::getDisplayViewFrustum() const { +#ifdef DEBUG + if (QThread::currentThread() != activeRenderingThread) { + // FIXME, should this be an assert? + qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; + } +#endif + return &_displayViewFrustum; +} + void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs::RenderSide renderSide) { activeRenderingThread = QThread::currentThread(); PROFILE_RANGE(__FUNCTION__); diff --git a/interface/src/Application.h b/interface/src/Application.h index 5a3756e768..3edc968c24 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -205,6 +205,7 @@ public: // which might be different from the viewFrustum, i.e. shadowmap // passes, mirror window passes, etc ViewFrustum* getDisplayViewFrustum(); + const ViewFrustum* getDisplayViewFrustum() const; ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; } const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; } EntityTreeRenderer* getEntities() { return &_entities; } diff --git a/interface/src/devices/TV3DManager.h b/interface/src/devices/TV3DManager.h index dfe5b28e87..0424eeecb4 100644 --- a/interface/src/devices/TV3DManager.h +++ b/interface/src/devices/TV3DManager.h @@ -45,6 +45,10 @@ private: static eyeFrustum _rightEye; static eyeFrustum* _activeEye; + // The first function is the code executed for each eye + // while the second is code to be executed between the two eyes. + // The use case here is to modify the output viewport coordinates + // for the new eye. template static void forEachEye(F f, FF ff = []{}) { f(_leftEye); diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 3c0ff4b309..08a9a39d68 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -10,6 +10,7 @@ // #include "GPULogging.h" #include "GLBackendShared.h" +#include GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = { @@ -521,3 +522,29 @@ void GLBackend::do_glColor4f(Batch& batch, uint32 paramOffset) { (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)); +} + + + diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index 9943af1679..3551953998 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -79,6 +79,9 @@ public: static GLShader* syncGPUObject(const Shader& shader); static GLuint getShaderID(const ShaderPointer& shader); + static void loadMatrix(GLenum target, const glm::mat4 & m); + static void fetchMatrix(GLenum target, glm::mat4 & m); + class GLState : public GPUObject { public: class Command { diff --git a/libraries/render-utils/src/RenderUtil.h b/libraries/render-utils/src/RenderUtil.h index 8c1b1e12e7..cc823dc177 100644 --- a/libraries/render-utils/src/RenderUtil.h +++ b/libraries/render-utils/src/RenderUtil.h @@ -12,6 +12,8 @@ #ifndef hifi_RenderUtil_h #define hifi_RenderUtil_h +#include + /// Renders a quad from (-1, -1, 0) to (1, 1, 0) with texture coordinates from (sMin, tMin) to (sMax, tMax). void renderFullscreenQuad(float sMin = 0.0f, float sMax = 1.0f, float tMin = 0.0f, float tMax = 1.0f); diff --git a/libraries/render-utils/src/TextRenderer.cpp b/libraries/render-utils/src/TextRenderer.cpp index f459d466f4..87cf9b2728 100644 --- a/libraries/render-utils/src/TextRenderer.cpp +++ b/libraries/render-utils/src/TextRenderer.cpp @@ -548,18 +548,23 @@ float TextRenderer::draw(float x, float y, const QString & str, float scale = (_pointSize / DEFAULT_POINT_SIZE) * 0.25f; glm::vec2 result; - MatrixStack::withGlMatrices([&] { + + MatrixStack::withPushAll([&] { MatrixStack & mv = MatrixStack::modelview(); - // scale the modelview into font units - // FIXME migrate the constant scale factor into the geometry of the - // fonts so we don't have to flip the Y axis here and don't have to - // scale at all. - mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale)); - // The font does all the OpenGL work - if (_font) { - result = _font->drawString(x, y, str, actualColor, _effectType, bounds / scale); - } - }); + MatrixStack & pr = MatrixStack::projection(); + gpu::GLBackend::fetchMatrix(GL_MODELVIEW_MATRIX, mv.top()); + gpu::GLBackend::fetchMatrix(GL_PROJECTION_MATRIX, pr.top()); + + // scale the modelview into font units + // FIXME migrate the constant scale factor into the geometry of the + // fonts so we don't have to flip the Y axis here and don't have to + // scale at all. + mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale)); + // The font does all the OpenGL work + if (_font) { + result = _font->drawString(x, y, str, actualColor, _effectType, bounds / scale); + } + }); return result.x; } diff --git a/libraries/render-utils/src/MatrixStack.cpp b/libraries/shared/src/MatrixStack.cpp similarity index 100% rename from libraries/render-utils/src/MatrixStack.cpp rename to libraries/shared/src/MatrixStack.cpp diff --git a/libraries/render-utils/src/MatrixStack.h b/libraries/shared/src/MatrixStack.h similarity index 88% rename from libraries/render-utils/src/MatrixStack.h rename to libraries/shared/src/MatrixStack.h index feeda44058..7850af76f2 100644 --- a/libraries/render-utils/src/MatrixStack.h +++ b/libraries/shared/src/MatrixStack.h @@ -26,10 +26,6 @@ #include #include -#include - - - class MatrixStack : public std::stack { public: @@ -183,22 +179,5 @@ public: stack2.withPush(f); }); } - - template - static void withGlMatrices(Function f) { - // Push the current stack, and then copy the values out of OpenGL - withPushAll([&] { - // Fetch the current matrices out of GL stack - // FIXME, eliminate the usage of deprecated GL - MatrixStack & mv = MatrixStack::modelview(); - MatrixStack & pr = MatrixStack::projection(); - glm::mat4 & mvm = mv.top(); - glGetFloatv(GL_MODELVIEW_MATRIX, &(mvm[0][0])); - - glm::mat4 & prm = pr.top(); - glGetFloatv(GL_PROJECTION_MATRIX, &(prm[0][0])); - f(); - }); - } };