Skip to content

Commit

Permalink
Bug 1036602 - Add GL support for VR rendering; r=BenWa
Browse files Browse the repository at this point in the history
From aec0bd50768482fe516111010bad2e57f01ede36 Mon Sep 17 00:00:00 2001
---
 gfx/layers/moz.build                           |   1 +
 gfx/layers/opengl/CompositingRenderTargetOGL.h |   4 +
 gfx/layers/opengl/CompositorOGL.cpp            |  14 ++
 gfx/layers/opengl/CompositorOGL.h              |  38 +++
 gfx/layers/opengl/CompositorOGLVR.cpp          | 326 +++++++++++++++++++++++++
 5 files changed, 383 insertions(+)
 create mode 100644 gfx/layers/opengl/CompositorOGLVR.cpp
  • Loading branch information
vvuk committed Jul 9, 2014
1 parent 18fcfec commit e80e04c
Show file tree
Hide file tree
Showing 5 changed files with 383 additions and 0 deletions.
1 change: 1 addition & 0 deletions gfx/layers/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ UNIFIED_SOURCES += [
'LayerSorter.cpp',
'opengl/CompositingRenderTargetOGL.cpp',
'opengl/CompositorOGL.cpp',
'opengl/CompositorOGLVR.cpp',
'opengl/GLBlitTextureImageHelper.cpp',
'opengl/OGLShaderProgram.cpp',
'opengl/TextureClientOGL.cpp',
Expand Down
4 changes: 4 additions & 0 deletions gfx/layers/opengl/CompositingRenderTargetOGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class CompositingRenderTargetOGL : public CompositingRenderTarget
virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor);
#endif

const gfx::IntSize& GetInitSize() const {
return mInitParams.mSize;
}

private:
/**
* Actually do the initialisation. Note that we leave our FBO bound, and so
Expand Down
14 changes: 14 additions & 0 deletions gfx/layers/opengl/CompositorOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ CompositorOGL::CleanupResources()
mQuadVBO = 0;
}

DestroyVR(ctx);

mGLContext->MakeCurrent();

mBlitTextureImageHelper = nullptr;
Expand Down Expand Up @@ -384,6 +386,13 @@ CompositorOGL::Initialize()
console->LogStringMessage(msg.get());
}

mVR.mInitialized = false;
if (gfxPrefs::VREnabled()) {
if (!InitializeVR()) {
NS_WARNING("Failed to initialize VR in CompositorOGL");
}
}

reporter.SetSuccessful();
return true;
}
Expand Down Expand Up @@ -889,6 +898,11 @@ CompositorOGL::DrawQuad(const Rect& aRect,
MOZ_ASSERT(mFrameInProgress, "frame not started");
MOZ_ASSERT(mCurrentRenderTarget, "No destination");

if (aEffectChain.mPrimaryEffect->mType == EffectTypes::VR_DISTORTION) {
DrawVRDistortion(aRect, aClipRect, aEffectChain, aOpacity, aTransform);
return;
}

Rect clipRect = aClipRect;
// aClipRect is in destination coordinate space (after all
// transforms and offsets have been applied) so if our
Expand Down
38 changes: 38 additions & 0 deletions gfx/layers/opengl/CompositorOGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifdef MOZ_WIDGET_GONK
#include <ui/GraphicBuffer.h>
#endif
#include "gfxVR.h"

class nsIWidget;

Expand Down Expand Up @@ -153,6 +154,32 @@ class PerFrameTexturePoolOGL : public CompositorTexturePoolOGL
nsTArray<GLuint> mUnusedTextures;
};

struct CompositorOGLVRObjects {
bool mInitialized;

gfx::VRHMDConfiguration mConfiguration;

GLuint mDistortionVertices[2];
GLuint mDistortionIndices[2];
GLuint mDistortionIndexCount[2];

GLint mAPosition;
GLint mATexCoord0;
GLint mATexCoord1;
GLint mATexCoord2;
GLint mAGenericAttribs;

// The program here implements distortion rendering for VR devices
// (in this case Oculus only). We'll need to extend this to support
// other device types in the future.

// 0 = TEXTURE_2D, 1 = TEXTURE_RECTANGLE for source
GLuint mDistortionProgram[2];
GLint mUTexture[2];
GLint mUVREyeToSource[2];
GLint mUVRDestionatinScaleAndOffset[2];
};

// If you want to make this class not MOZ_FINAL, first remove calls to virtual
// methods (Destroy) that are made in the destructor.
class CompositorOGL MOZ_FINAL : public Compositor
Expand Down Expand Up @@ -283,6 +310,15 @@ class CompositorOGL MOZ_FINAL : public Compositor
return gfx::ToIntSize(mWidgetSize);
}

bool InitializeVR();
void DestroyVR(GLContext *gl);

void DrawVRDistortion(const gfx::Rect& aRect,
const gfx::Rect& aClipRect,
const EffectChain& aEffectChain,
gfx::Float aOpacity,
const gfx::Matrix4x4& aTransform);

/** Widget associated with this compositor */
nsIWidget *mWidget;
nsIntSize mWidgetSize;
Expand Down Expand Up @@ -409,6 +445,8 @@ class CompositorOGL MOZ_FINAL : public Compositor

FenceHandle mReleaseFenceHandle;
ShaderProgramOGL *mCurrentProgram;

CompositorOGLVRObjects mVR;
};

}
Expand Down
Loading

0 comments on commit e80e04c

Please sign in to comment.