高通VR源代码分析[二] SvrApplication应用管理类

SvrApplication

找到SimpleVR可以发现jni下有个c++类叫app.点开发现这个类继承了Srv::SrvApplication类
在高通提供的 SDK 中,所有的类都在Srv命名空间下,这个类就是程序启动需要重写的基类。
需要重写的函数大概有以下几个,

        virtual void LoadConfiguration() = 0;
        virtual void Initialize();
        virtual void Shutdown();
        virtual void Update();
        virtual void Render() = 0;

Initialize()

用来对类的一些默认参数做初始化,有些参数放在构造函数中进行初始化,重写后的类一般对需要渲染的资源进行初始化创建,这个最简单的例子就对模型进行初始化。

void SimpleApp::Initialize()
{
   SvrApplication::Initialize();
   InitializeModel();//载入3D物体,初始化空间矩阵和Shader
}

Update()

/Callback function of SvrApplication, after the VR mode start,it will be called in a loop
// once each frame. Update view matrix and projection matrix here.
用于更新View和Projection的投影,通过拿到下一帧预计的时间,然后通过时间预估头移到的位置,然后再获取ViewMatrix

//update view matrix
    float predDispTime = svrGetPredictedDisplayTime();
    mPoseState = svrGetPredictedHeadPose(predDispTime);
   
    SvrGetEyeViewMatrices(mPoseState, true,
                          DEFAULT_IPD, DEFAULT_HEAD_HEIGHT, DEFAULT_HEAD_DEPTH, mViewMatrix[kLeft],
                          mViewMatrix[kRight]);

在这里处理各种事件,其中主要是控制器事件
ProcessEvents();

void FoveatedVR::ProcessEvents()
{
   svrEvent evt;
   while (svrPollEvent(&evt))
   {
       if (evt.eventType == kEventVrModeStarted)
       {
           StartController();
       }
   }
}

Render()

render for two eyes and submit the frame.
//Render代表了一系列的DrawCall操作,Submit代表了Present把从GPU呈现画面到屏幕上

void SimpleApp::Render()
{
   RenderEye(kLeft);
   RenderEye(kRight);
   SubmitFrame();
}

void SimpleApp::RenderEye(Svr::SvrEyeId eyeId)//渲染单个眼睛的函数,MVP矩阵和EyeBuffer不一样
//Submit the rendered frame
void SimpleApp::SubmitFrame()//创建提交Frame的参数,然后调用**svrSubmitFrame**函数去提交,里面主要做了各种垂直同步相关的操作
{
   svrFrameParams frameParams;
   memset(&frameParams, 0, sizeof(frameParams));
   frameParams.frameIndex = mAppContext.frameCount;

   frameParams.renderLayers[kLeft].imageHandle = mAppContext.eyeBuffers[mAppContext.eyeBufferIndex].eyeTarget[Svr::kLeft].GetColorAttachment();
   frameParams.renderLayers[kLeft].imageType = kTypeTexture;
    L_CreateLayout(0.0f, 0.0f, 1.0f, 1.0f, &frameParams.renderLayers[kLeft].imageCoords);
   frameParams.renderLayers[kLeft].eyeMask = kEyeMaskLeft;

   frameParams.renderLayers[kRight].imageHandle = mAppContext.eyeBuffers[mAppContext.eyeBufferIndex].eyeTarget[Svr::kRight].GetColorAttachment();
   frameParams.renderLayers[kRight].imageType = kTypeTexture;
   L_CreateLayout(0.0f, 0.0f, 1.0f, 1.0f, &frameParams.renderLayers[kRight].imageCoords);
   frameParams.renderLayers[kRight].eyeMask = kEyeMaskRight;

   frameParams.headPoseState = mPoseState;
   frameParams.minVsyncs = 1;
   svrSubmitFrame(&frameParams);
   mAppContext.eyeBufferIndex = (mAppContext.eyeBufferIndex + 1) % SVR_NUM_EYE_BUFFERS;
}

Shutdown()

清理场景资源

//Callback function of SvrApplication, called when VR mode stop
//Clean up the model texture
void SimpleApp::Shutdown()
{
    if (mModelTexture != 0)
    {
        GL(glDeleteTextures(1, &mModelTexture));
        mModelTexture = 0;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值