mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 23:33:48 +02:00
Working on mirror and overlay
This commit is contained in:
parent
1e90aaf9c3
commit
4282c044ef
6 changed files with 34 additions and 96 deletions
|
@ -877,6 +877,7 @@ void Application::paintGL() {
|
|||
{
|
||||
PerformanceTimer perfTimer("renderOverlay");
|
||||
_applicationOverlay.renderOverlay(&renderArgs);
|
||||
renderArgs._context->resetState();
|
||||
}
|
||||
|
||||
PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
|
||||
|
@ -3640,84 +3641,6 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) {
|
|||
return screenPoint;
|
||||
}
|
||||
|
||||
//void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) {
|
||||
// // 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;
|
||||
//
|
||||
// // bool eyeRelativeCamera = false;
|
||||
// if (billboard) {
|
||||
// fov = BILLBOARD_FIELD_OF_VIEW; // degees
|
||||
// _mirrorCamera.setPosition(_myAvatar->getPosition() +
|
||||
// _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
|
||||
//
|
||||
// } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
|
||||
// _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
|
||||
// _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
|
||||
//
|
||||
// } else { // HEAD zoom level
|
||||
// // FIXME note that the positioing of the camera relative to the avatar can suffer limited
|
||||
// // precision as the user's position moves further away from the origin. Thus at
|
||||
// // /1e7,1e7,1e7 (well outside the buildable volume) the mirror camera veers and sways
|
||||
// // wildly as you rotate your avatar because the floating point values are becoming
|
||||
// // larger, squeezing out the available digits of precision you have available at the
|
||||
// // human scale for camera positioning.
|
||||
//
|
||||
// // Previously there was a hack to correct this using the mechanism of repositioning
|
||||
// // the avatar at the origin of the world for the purposes of rendering the mirror,
|
||||
// // but it resulted in failing to render the avatar's head model in the mirror view
|
||||
// // when in first person mode. Presumably this was because of some missed culling logic
|
||||
// // that was not accounted for in the hack.
|
||||
//
|
||||
// // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
|
||||
// // investigated in order to adapt the technique while fixing the head rendering issue,
|
||||
// // but the complexity of the hack suggests that a better approach
|
||||
// _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
|
||||
// _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
|
||||
// }
|
||||
// _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
|
||||
// if (billboard) {
|
||||
// QSize size = DependencyManager::get<TextureCache>()->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());
|
||||
// } else {
|
||||
// // if not rendering the billboard, the region is in device independent coordinates; must convert to device
|
||||
// QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
|
||||
// float ratio = 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);
|
||||
// }
|
||||
// bool updateViewFrustum = false;
|
||||
// updateProjectionMatrix(_mirrorCamera, updateViewFrustum);
|
||||
// glEnable(GL_SCISSOR_TEST);
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
//
|
||||
// // render rear mirror view
|
||||
// glMatrixMode(GL_MODELVIEW);
|
||||
// glPushMatrix();
|
||||
// glLoadIdentity();
|
||||
// glLoadMatrixf(glm::value_ptr(glm::mat4_cast(_mirrorCamera.getOrientation()) * glm::translate(glm::mat4(), _mirrorCamera.getPosition())));
|
||||
// renderArgs->_context->syncCache();
|
||||
// displaySide(renderArgs, _mirrorCamera, true, billboard);
|
||||
// glMatrixMode(GL_MODELVIEW);
|
||||
// glPopMatrix();
|
||||
//
|
||||
// if (!billboard) {
|
||||
// _rearMirrorTools->render(renderArgs, false, _glWidget->mapFromGlobal(QCursor::pos()));
|
||||
// }
|
||||
//
|
||||
// // reset Viewport and projection matrix
|
||||
// glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||
// glDisable(GL_SCISSOR_TEST);
|
||||
// updateProjectionMatrix(_myCamera, updateViewFrustum);
|
||||
//}
|
||||
|
||||
void Application::resetSensors() {
|
||||
DependencyManager::get<Faceshift>()->reset();
|
||||
DependencyManager::get<DdeFaceTracker>()->reset();
|
||||
|
|
|
@ -53,6 +53,13 @@ static const float MIRROR_FIELD_OF_VIEW = 30.0f;
|
|||
static const float ORTHO_NEAR_CLIP = -10000;
|
||||
static const float ORTHO_FAR_CLIP = 10000;
|
||||
|
||||
// TODO move somewhere useful
|
||||
static void fboViewport(QOpenGLFramebufferObject* fbo) {
|
||||
auto size = fbo->size();
|
||||
glViewport(0, 0, size.width(), size.height());
|
||||
}
|
||||
|
||||
|
||||
|
||||
ApplicationOverlay::ApplicationOverlay() :
|
||||
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT))
|
||||
|
@ -94,10 +101,8 @@ void ApplicationOverlay::renderOverlay(RenderArgs* renderArgs) {
|
|||
|
||||
// Execute the batch into our framebuffer
|
||||
_overlayFramebuffer->bind();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glm::vec2 size = qApp->getCanvasSize();
|
||||
glViewport(0, 0, size.x, size.y);
|
||||
fboViewport(_overlayFramebuffer);
|
||||
|
||||
// Now render the overlay components together into a single texture
|
||||
//renderOverlays(renderArgs);
|
||||
|
@ -285,11 +290,6 @@ void ApplicationOverlay::renderAudioMeter(RenderArgs* renderArgs) {
|
|||
}
|
||||
}
|
||||
|
||||
void fboViewport(QOpenGLFramebufferObject* fbo) {
|
||||
auto size = fbo->size();
|
||||
glViewport(0, 0, size.width(), size.height());
|
||||
}
|
||||
|
||||
void ApplicationOverlay::renderRearViewToFbo(RenderArgs* renderArgs) {
|
||||
// Grab current viewport to reset it at the end
|
||||
auto mirrorSize = _mirrorFramebuffer->size();
|
||||
|
@ -342,19 +342,22 @@ void ApplicationOverlay::renderRearViewToFbo(RenderArgs* renderArgs) {
|
|||
|
||||
_mirrorFramebuffer->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glLoadMatrixf(glm::value_ptr(_mirrorCamera.getProjection()));
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glLoadMatrixf(glm::value_ptr(glm::mat4_cast(_mirrorCamera.getOrientation()) * glm::translate(glm::mat4(), _mirrorCamera.getPosition())));
|
||||
{
|
||||
auto projection = _mirrorCamera.getProjection();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(glm::value_ptr(projection));
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glLoadMatrixf(glm::value_ptr(glm::mat4_cast(_mirrorCamera.getOrientation()) * glm::translate(glm::mat4(), _mirrorCamera.getPosition())));
|
||||
renderArgs->_context->syncCache();
|
||||
qApp->displaySide(renderArgs, _mirrorCamera, true, billboard);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
}
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
_mirrorFramebuffer->release();
|
||||
|
||||
// if (!billboard) {
|
||||
|
|
|
@ -38,4 +38,8 @@ void Context::render(Batch& batch) {
|
|||
|
||||
void Context::syncCache() {
|
||||
_backend->syncCache();
|
||||
}
|
||||
|
||||
void Context::resetState() {
|
||||
_backend->resetState();
|
||||
}
|
|
@ -28,6 +28,7 @@ public:
|
|||
virtual~ Backend() {};
|
||||
virtual void render(Batch& batch) = 0;
|
||||
virtual void syncCache() = 0;
|
||||
virtual void resetState() = 0;
|
||||
|
||||
class TransformObject {
|
||||
public:
|
||||
|
@ -112,6 +113,9 @@ public:
|
|||
|
||||
void syncCache();
|
||||
|
||||
// TODO remove, make all apps set all the state they need
|
||||
void resetState();
|
||||
|
||||
protected:
|
||||
Context(const Context& context);
|
||||
|
||||
|
|
|
@ -656,4 +656,6 @@ void GLBackend::fetchMatrix(GLenum target, glm::mat4 & m) {
|
|||
glGetFloatv(target, glm::value_ptr(m));
|
||||
}
|
||||
|
||||
|
||||
void GLBackend::resetState() {
|
||||
resetPipelineState(0);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
// Let's try to avoid to do that as much as possible!
|
||||
virtual void syncCache();
|
||||
|
||||
virtual void resetState();
|
||||
|
||||
// Render Batch create a local Context and execute the batch with it
|
||||
// WARNING:
|
||||
// if syncCache is true, then the gpu::GLBackend will synchornize
|
||||
|
|
Loading…
Reference in a new issue