WVR_RenderMask¶
-
WVR_EXPORT void WVR_RenderMask(WVR_Eye eye, WVR_TextureTarget target = WVR_TextureTarget_2D)
Renders a mask to cover the pixels that will be hidden after distortion.
The mask will be drawn into the depth buffer setting near clipping distance in the z-direction. This will improve performance by letting the GPU early-reject pixels the user will never see. Called before rendering the scene texture of each eye.
This function must be called after WVR_RenderInit.
- Version
- API Level 1
- Parameters
eye
: WVR_Eye, eye id to specify the side of scene.target
: WVR_TextureTarget, Specifies the target texture.
Struct and enumeration¶
How to use¶
Here is an example for the function:
#include <wvr/wvr_render.h>
#include <VertexArrayObject.h>
#include <Shader.h>
#include <Texture.h>
#include <GLES3/gl31.h>
#include <GLES2/gl2ext.h>
RenderTarget::RenderTarget() {
loadShaderFromAsset("shader/vertex/vertex.glsl", "shader/fragment/fragment.glsl");
mMatrixLocation = mShader->getUniformLocation("matrix");
mNormalMatrixLocation = mShader->getUniformLocation("normal");
mLightDirLocation = mShader->getUniformLocation("light_dir");
mVAO = new VertexArrayObject(true, true);
mTexture = Texture::loadTexture("textures/texture.jpg");
initObjects();
initTexture();
}
void RenderTarget::draw(const Matrix4& projection, const Matrix4& eye, const Matrix4& view, const Vector4& lightDir) {
// Draw scene in single eye.
}
void RenderTarget::drawMultiView(const Matrix4 projection[2], const Matrix4 eye[2], const Matrix4& view, const Vector4& lightDir) {
// Draw scene in multi-view mode.
}
bool MainApplication::initGL() {
RenderTarget * mRenderTarget;
mRenderTarget = new RenderTarget();
}
void MainApplication::renderScene(WVR_Eye nEye) {
// Specify the RenderMask before drawing the render target via OpenGL.
WVR_RenderMask(nEye);
// Render target
if (nEye == WVR_Eye_Left)
mRenderTarget->draw(mProjectionLeft, mEyePosLeft, mHMDPose, mLightDir);
else if (nEye == WVR_Eye_Right)
mRenderTarget->draw(mProjectionRight, mEyePosRight, mHMDPose, mLightDir);
}
void MainApplication::renderSceneMultiView() {
// Activate RenderMask in multi-view mode.
WVR_RenderMask(WVR_Eye_Left, WVR_TextureTarget_2D_ARRAY);
// Render target
mRenderTarget->drawMultiView(mProjectionMultiView, mEyePosMultiView, mHMDPose, mLightDir);
}