-
-
Save dpasca/dadf900df27299e47531ab0475c808b2 to your computer and use it in GitHub Desktop.
Render target blit for Gear VR SDK 1.5.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//================================================================== | |
/// DOVREyeSurface.cpp | |
/// | |
/// Created by Davide Pasca - 2017/5/28 | |
/// See the file "license.txt" that comes with this project for | |
/// copyright info. | |
//================================================================== | |
#include "DOVREyeSurface.h" | |
static const char VERTEX_SHADER[] = R"RAW( | |
in vec3 Position; | |
in vec2 TexCoord; | |
out mediump vec2 v_txc0; | |
flat out int flat_viewID; | |
uniform mediump vec2 u_scaleST; | |
void main() | |
{ | |
gl_Position = vec4( Position, 1.0 ); | |
v_txc0 = TexCoord * u_scaleST; | |
flat_viewID = VIEW_ID; | |
} | |
)RAW"; | |
static const char FRAGMENT_SHADER[] = R"RAW( | |
in mediump vec2 v_txc0; | |
flat in int flat_viewID; | |
uniform lowp sampler2D s_texture0; | |
uniform lowp sampler2D s_texture1; | |
void main() | |
{ | |
if ( flat_viewID == 0 ) | |
gl_FragColor = texture( s_texture0, v_txc0 ); | |
else | |
gl_FragColor = texture( s_texture1, v_txc0 ); | |
} | |
)RAW"; | |
//================================================================== | |
DOVREyeSurface::DOVREyeSurface() | |
{ | |
// geometry | |
OVR::VertexAttribs attribs; | |
attribs.uv0.Resize( 4 ); | |
attribs.uv0[0] = { 0, 1 }; | |
attribs.uv0[1] = { 1, 1 }; | |
attribs.uv0[2] = { 0, 0 }; | |
attribs.uv0[3] = { 1, 0 }; | |
attribs.position.Resize( 4 ); | |
attribs.position[0] = { -1, 1, 0 }; | |
attribs.position[1] = { 1, 1, 0 }; | |
attribs.position[2] = { -1, -1, 0 }; | |
attribs.position[3] = { 1, -1, 0 }; | |
OVR::Array< OVR::TriangleIndex > indices; | |
indices.Resize( 6 ); | |
indices[0] = 0; | |
indices[1] = 1; | |
indices[2] = 2; | |
indices[3] = 2; | |
indices[4] = 1; | |
indices[5] = 3; | |
mGeom.Create( attribs, indices ); | |
// program | |
static OVR::ovrProgramParm sProgParams[] = | |
{ | |
{ "s_texture0", OVR::ovrProgramParmType::TEXTURE_SAMPLED }, | |
{ "s_texture1", OVR::ovrProgramParmType::TEXTURE_SAMPLED }, | |
{ "u_scaleST", OVR::ovrProgramParmType::FLOAT_VECTOR2 }, | |
}; | |
mProgram = OVR::GlProgram::Build( VERTEX_SHADER, FRAGMENT_SHADER, sProgParams, 3 ); | |
// surface | |
mSurfaceDef.surfaceName = "DOVREyeSurface"; | |
{ | |
auto &gpuState = mSurfaceDef.graphicsCommand.GpuState; | |
gpuState.blendEnable = OVR::ovrGpuState::BLEND_DISABLE; | |
gpuState.cullEnable = false; | |
gpuState.depthEnable = false; | |
} | |
mSurfaceDef.graphicsCommand.UniformData[0].Data = &mTextures[0]; | |
mSurfaceDef.graphicsCommand.UniformData[1].Data = &mTextures[1]; | |
mSurfaceDef.graphicsCommand.UniformData[2].Data = &mTexScaleST; | |
mSurfaceDef.graphicsCommand.Program = mProgram; | |
mSurfaceDef.geo = mGeom; | |
} | |
//================================================================== | |
void DOVREyeSurface::UpdateEyeSurface( | |
const std::array<GLuint,2> &texIDs, | |
const std::array<float,2> &scaleST ) | |
{ | |
mTextures[0] = OVR::GlTexture( texIDs[0], 0, 0 ); | |
mTextures[1] = OVR::GlTexture( texIDs[1], 0, 0 ); | |
mTexScaleST[0] = scaleST[0]; | |
mTexScaleST[1] = scaleST[1]; | |
} | |
//================================================================== | |
DOVREyeSurface::~DOVREyeSurface() | |
{ | |
OVR::GlProgram::Free( mProgram ); | |
mGeom.Free(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//================================================================== | |
/// DOVREyeSurface.h | |
/// | |
/// Created by Davide Pasca - 2017/5/28 | |
/// See the file "license.txt" that comes with this project for | |
/// copyright info. | |
//================================================================== | |
#ifndef DOVREYESURFACE_H | |
#define DOVREYESURFACE_H | |
#include <array> | |
#include "SurfaceRender.h" | |
//================================================================== | |
class DOVREyeSurface | |
{ | |
OVR::ovrSurfaceDef mSurfaceDef; | |
OVR::GlProgram mProgram; | |
OVR::GlGeometry mGeom; | |
OVR::GlTexture mTextures[2]; | |
OVR::Vector2f mTexScaleST = {1,1}; | |
public: | |
DOVREyeSurface(); | |
~DOVREyeSurface(); | |
void UpdateEyeSurface( | |
const std::array<GLuint,2> &texIDs, | |
const std::array<float,2> &scaleST ); | |
const OVR::ovrSurfaceDef *GetOVRSurfaceDef() const | |
{ | |
return &mSurfaceDef; | |
} | |
}; | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment