本文将介绍SvrPluginAndroid脚本中的Submit方法,该方法的作用是渲染左右眼图像,是SvrPlugin中VR模式实现的核心代码。
public override void SubmitFrame(int frameIndex, float fieldOfView, int frameType)
{
int i;
int eyeCount = 0;
if (eyes != null) for (i = 0; i < eyes.Length; i++)
{
var eye = eyes;
if (eyes.isActiveAndEnabled == false || eye.TextureId == 0 || eye.Side == 0) continue;
if (eye.imageTransform != null && eye.imageTransform.gameObject.activeSelf == false) continue;
SvrSetupLayerData(0, eyeCount, (int)eye.Side, eye.TextureId, eye.ImageType == SvrEye.eType.EglTexture ? 1 : 0);
float[] lowerLeft = { eye.clipLowerLeft.x, eye.clipLowerLeft.y, eye.clipLowerLeft.z, eye.clipLowerLeft.w, eye.uvLowerLeft.x, eye.uvLowerLeft.y };
float[] upperLeft = { eye.clipUpperLeft.x, eye.clipUpperLeft.y, eye.clipUpperLeft.z, eye.clipUpperLeft.w, eye.uvUpperLeft.x, eye.uvUpperLeft.y };
float[] upperRight = { eye.clipUpperRight.x, eye.clipUpperRight.y, eye.clipUpperRight.z, eye.clipUpperRight.w, eye.uvUpperRight.x, eye.uvUpperRight.y };
float[] lowerRight = { eye.clipLowerRight.x, eye.clipLowerRight.y, eye.clipLowerRight.z, eye.clipLowerRight.w, eye.uvLowerRight.x, eye.uvLowerRight.y };
SvrSetupLayerCoords(0, eyeCount, lowerLeft, lowerRight, upperLeft, upperRight);
eyeCount++;
}
for (i = eyeCount; i < SvrManager.EyeLayerMax; i++)
{
SvrSetupLayerData(0, i, 0, 0, 0);
}
int overlayCount = 0;
if (overlays != null) for (i = 0; i < overlays.Length; i++)
{
var overlay = overlays;
if (overlay.isActiveAndEnabled == false || overlay.TextureId == 0 || overlay.Side == 0) continue;
if (overlay.imageTransform != null && overlay.imageTransform.gameObject.activeSelf == false) continue;
SvrSetupLayerData(1, overlayCount, (int)overlay.Side, overlay.TextureId, overlay.ImageType == SvrOverlay.eType.EglTexture ? 1 : 0);
float[] lowerLeft = { overlay.clipLowerLeft.x, overlay.clipLowerLeft.y, overlay.clipLowerLeft.z, overlay.clipLowerLeft.w, overlay.uvLowerLeft.x, overlay.uvLowerLeft.y };
float[] upperLeft = { overlay.clipUpperLeft.x, overlay.clipUpperLeft.y, overlay.clipUpperLeft.z, overlay.clipUpperLeft.w, overlay.uvUpperLeft.x, overlay.uvUpperLeft.y };
float[] upperRight = { overlay.clipUpperRight.x, overlay.clipUpperRight.y, overlay.clipUpperRight.z, overlay.clipUpperRight.w, overlay.uvUpperRight.x, overlay.uvUpperRight.y };
float[] lowerRight = { overlay.clipLowerRight.x, overlay.clipLowerRight.y, overlay.clipLowerRight.z, overlay.clipLowerRight.w, overlay.uvLowerRight.x, overlay.uvLowerRight.y };
SvrSetupLayerCoords(1, overlayCount, lowerLeft, lowerRight, upperLeft, upperRight); overlayCount++;
}
for (i = overlayCount; i < SvrManager.OverlayLayerMax; i++)
{
SvrSetupLayerData(1, i, 0, 0, 0);
}
SvrSubmitFrameEventData(frameIndex, fieldOfView, frameType);
IssueEvent (RenderEvent.SubmitFrame);
}
首先先看该方法传入的参数。
frameIndex表示当前程序运行的帧数。
fieldOfView表示当前左右眼Camera的fov参数。
frameType表示当前帧类型。
在这个方法中首先遍历了eyes数据。
eyes数组在前几篇文章中已经提到的,表示的是当前场景中的SvrEye数组。
并依次设置左右眼的屏幕坐标。
|