// I appreciate this is not an idea place for this function, but it didn't seem to be // being linked properly when in OVR_CAPI.cpp. // Please relocate if you know of a better place ovrBool ovrHmd_CreateDistortionMeshInternal( ovrHmdStruct * hmd, ovrEyeType eyeType, ovrFovPort fov, unsigned int distortionCaps, ovrDistortionMesh *meshData, float overrideEyeReliefIfNonZero ) { if (!meshData) return 0; HMDState* hmds = (HMDState*)hmd; // Not used now, but Chromatic flag or others could possibly be checked for in the future. OVR_UNUSED1(distortionCaps); #if defined (OVR_CC_MSVC) static_assert(sizeof(DistortionMeshVertexData) == sizeof(ovrDistortionVertex), "DistortionMeshVertexData size mismatch"); #endif // *** Calculate a part of "StereoParams" needed for mesh generation // Note that mesh distortion generation is invariant of RenderTarget UVs, allowing // render target size and location to be changed after the fact dynamically. // eyeToSourceUV is computed here for convenience, so that users don't need // to call ovrHmd_GetRenderScaleAndOffset unless changing RT dynamically. const HmdRenderInfo& hmdri = hmds->RenderState.RenderInfo; StereoEye stereoEye = (eyeType == ovrEye_Left) ? StereoEye_Left : StereoEye_Right; DistortionRenderDesc& distortion = hmds->RenderState.Distortion[eyeType]; if (overrideEyeReliefIfNonZero) { distortion.Lens = GenerateLensConfigFromEyeRelief(overrideEyeReliefIfNonZero,hmdri); } // Find the mapping from TanAngle space to target NDC space. ScaleAndOffset2D eyeToSourceNDC = CreateNDCScaleAndOffsetFromFov(fov); int triangleCount = 0; int vertexCount = 0; DistortionMeshCreate((DistortionMeshVertexData**)&meshData->pVertexData, (uint16_t**)&meshData->pIndexData, &vertexCount, &triangleCount, (stereoEye == StereoEye_Right), hmdri, distortion, eyeToSourceNDC); if (meshData->pVertexData) { // Convert to index meshData->IndexCount = triangleCount * 3; meshData->VertexCount = vertexCount; return 1; } return 0; }
bool HMDState::CreateDistortionMesh(ovrEyeType eyeType, ovrFovPort fov, unsigned int distortionCaps, ovrDistortionMesh *meshData, float overrideEyeReliefIfNonZero) { const HmdRenderInfo& hmdri = RenderState.RenderInfo; DistortionRenderDesc& distortion = RenderState.Distortion[eyeType]; if (overrideEyeReliefIfNonZero) { distortion.Lens = GenerateLensConfigFromEyeRelief(overrideEyeReliefIfNonZero, hmdri); } if (CalculateDistortionMeshFromFOV( hmdri, distortion, (eyeType == ovrEye_Left ? StereoEye_Left : StereoEye_Right), fov, distortionCaps, meshData)) { return 1; } return 0; }