Skip to content

Commit

Permalink
Stereo 3D|Client: Oculus Rift mode projects composited UI as smaller
Browse files Browse the repository at this point in the history
The window can now tell the UI compositor how to project the composited
view. The default is the entire view area.
  • Loading branch information
skyjake committed Nov 10, 2013
1 parent 946887b commit 09853c3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
14 changes: 14 additions & 0 deletions doomsday/client/include/ui/widgets/compositorwidget.h
Expand Up @@ -39,6 +39,20 @@ class CompositorWidget : public GuiWidget

de::GLTexture &composite() const;

/**
* Sets the matrix that is used when drawing the composited contents
* back to the normal render target.
*
* @param projMatrix Projection matrix.
*/
void setCompositeProjection(de::Matrix4f const &projMatrix);

/**
* Sets the projection used for displaying the composited content to the
* default matrix (covering the full view).
*/
void useDefaultCompositeProjection();

// Events.
void viewResized();
void preDrawChildren();
Expand Down
17 changes: 17 additions & 0 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -51,6 +51,7 @@
#include "dd_main.h"
#include "con_main.h"
#include "ui/vrcontenttransform.h"
#include "render/vr.h"

using namespace de;

Expand Down Expand Up @@ -439,6 +440,21 @@ DENG2_OBSERVES(App, GameChange)
root.setViewSize(size);
busyRoot.setViewSize(size);
}

void updateCompositor()
{
if(!compositor) return;

if(VR::mode() == VR::MODE_OCULUS_RIFT)
{
compositor->setCompositeProjection(Matrix4f::ortho(-1, 2, -1, 2));
}
else
{
// We'll simply cover the entire view.
compositor->useDefaultCompositeProjection();
}
}
};

ClientWindow::ClientWindow(String const &id)
Expand Down Expand Up @@ -554,6 +570,7 @@ void ClientWindow::canvasGLDraw(Canvas &canvas)
{
d->updateRootSize();
}
d->updateCompositor();

d->contentXf.drawTransformed();

Expand Down
23 changes: 14 additions & 9 deletions doomsday/client/src/ui/widgets/compositorwidget.cpp
Expand Up @@ -38,16 +38,16 @@ DENG_GUI_PIMPL(CompositorWidget)
int nextBufIndex;
QList<Buffer *> buffers; ///< Stack of buffers to allow nested compositing.
GLUniform uMvpMatrix;
//GLUniform uColor;
GLUniform uTex;
GLUniform uTex;

Instance(Public *i)
: Base(i),
nextBufIndex(0),
uMvpMatrix("uMvpMatrix", GLUniform::Mat4),
//uColor ("uColor", GLUniform::Vec4),
uTex ("uTex", GLUniform::Sampler2D)
{}
{
uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);
}

/*void updateSize()
{
Expand Down Expand Up @@ -93,11 +93,6 @@ DENG_GUI_PIMPL(CompositorWidget)

void glInit()
{
// We'll simply cover the entire view.
uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);

//updateSize();

DefaultVertexBuf *buf = new DefaultVertexBuf;
buf->setVertices(gl::TriangleStrip,
DefaultVertexBuf::Builder()
Expand Down Expand Up @@ -135,6 +130,16 @@ GLTexture &CompositorWidget::composite() const
return d->buffers.first()->texture;
}

void CompositorWidget::setCompositeProjection(const Matrix4f &projMatrix)
{
d->uMvpMatrix = projMatrix;
}

void CompositorWidget::useDefaultCompositeProjection()
{
d->uMvpMatrix = Matrix4f::ortho(0, 1, 0, 1);
}

void CompositorWidget::viewResized()
{
GuiWidget::viewResized();
Expand Down

3 comments on commit 09853c3

@cmbruns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beautiful. I see the menus at appropriate scale in the Rift for the first time. The menus, intermission screen, and console taskbar are all centered in the display. But the crosshair, weapon sprite and status HUD remain in their original locations on the larger canvas.
It looks like I will be able to fuss with the updateCompositor/setCompositeProjection methods to adjust the apparent depth of the menus.

@skyjake
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see if there is a single place (on game-side) where we can adjust the remaining HUD elements.

@skyjake
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, you can use "menu-fog 0" to get rid of the menu background effect since that assumes an additive blending mode and thus can't be drawn with the compositor we're currently using.

Please sign in to comment.