Working on display plugins

This commit is contained in:
Brad Davis 2015-05-11 13:08:53 -07:00
parent 6a5c7b8b42
commit abab54aed8
9 changed files with 68 additions and 33 deletions

View file

@ -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__);

View file

@ -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; }

View file

@ -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<typename F, typename FF>
static void forEachEye(F f, FF ff = []{}) {
f(_leftEye);

View file

@ -10,6 +10,7 @@
//
#include "GPULogging.h"
#include "GLBackendShared.h"
#include <glm/gtc/type_ptr.hpp>
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));
}

View file

@ -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 {

View file

@ -12,6 +12,8 @@
#ifndef hifi_RenderUtil_h
#define hifi_RenderUtil_h
#include <MatrixStack.h>
/// 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);

View file

@ -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;
}

View file

@ -26,10 +26,6 @@
#include <glm/gtc/matrix_transform.hpp>
#include <stack>
#include <gpu/GPUConfig.h>
class MatrixStack : public std::stack<glm::mat4> {
public:
@ -183,22 +179,5 @@ public:
stack2.withPush(f);
});
}
template <typename Function>
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();
});
}
};