WVR_RenderMask¶
- WVR_EXPORT void WVR_RenderMask(WVR_Eye eye)
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.
- Parameters
- eye -
WVR_Eye, eye id to specify the side of scene.
- eye -
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/vtn_vertex.glsl", "shader/fragment/ti_fragment.glsl");
mMatrixLocation = mShader->getUniformLocation("matrix");
mNormalMatrixLocation = mShader->getUniformLocation("normalm");
mLightDirLocation = mShader->getUniformLocation("l_dir");
mVAO = new VertexArrayObject(true, true);
mTexture = Texture::loadTexture("textures/cube_texture.jpg");
initCubes();
initTexture();
}
void RenderTarget::draw(const Matrix4& projection, const Matrix4& eye, const Matrix4& view, const Vector4& lightDir) {
if (!mEnable || mHasError)
return;
Matrix4 matrix = projection * eye * view * getTransforms();
Matrix3 normal = makeNormalMatrix(getTransforms());
mShader->useProgram();
glUniformMatrix4fv(mMatrixLocation, 1, false, matrix.get());
glUniformMatrix3fv(mNormalMatrixLocation, 1, false, normal.get());
glUniform4f(mLightDirLocation, lightDir.x, lightDir.y, lightDir.z, lightDir.w);
mVAO->bindVAO();
glActiveTexture(GL_TEXTURE0);
mTexture->bindTexture();
glDrawElements(GL_TRIANGLES, mTrianglesX3, GL_UNSIGNED_INT, 0);
mShader->unuseProgram();
mTexture->unbindTexture();
mVAO->unbindVAO();
}
bool MainApplication::initGL() {
RenderTarget * mRenderTarget;
mRenderTarget = new RenderTarget();
}
void MainApplication::renderScene(WVR_Eye nEye) {
//Specify the render mask 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);
}