# 4. Function and API Reference

# 4.1 Data Structure

struct qiyu_SdkVersion
{
	int versionProduct;
	int versionMajor;
	int versionMinor;
};
enum class qiyu_GraphicsApi
{
	GA_OpenGLES,
};
struct qiyu_ViewFrustum
{
	float left;					//left plane
	float right;				//right plane
	float top;					//top plane
	float bottom;				//bottom plane
	float near;				//near plane
	float far;					//far plane
	qiyu_Vector3    position;	//frustum position
	qiyu_Quaternion rotation;	//frustum rotation
};
enum qiyu_FoveationLevel
{
	FL_None = 0,						//Default value. Not use foveation.
	FL_Low,								//use foveationLow from qiyu_DeviceInfo.
	FL_Medium,							//use foveationMedium from qiyu_DeviceInfo.
	FL_High,							//use foveationHigh from qiyu_DeviceInfo.
	FL_COUNT_DeviceLevel,

	FL_Custom = FL_COUNT_DeviceLevel,	//use customFoveation.

	FL_COUNT
};
struct qiyu_FoveationParam
{
	qiyu_Vector2	gainRate;		//Foveation Gain Rate [1, ...]
	float			areaSize;		//Foveation Area Size [0, ...]
	float			minResolution;	//Foveation Minimum Resolution [1, 1/2, 1/4, ..., 1/16, 0]
};
struct qiyu_DeviceInfo
{
	qiyu_ViewFrustum 	frustumLeftEye;		//frustum information for left eye
	qiyu_ViewFrustum 	frustumRightEye;	//frustum information for right eye
	int32_t 			iEyeTargetWidth;		//eye buffer width
	int32_t 			iEyeTargetHeight;		//eye buffer height
    qiyu_FoveationParam	foveationLow;		//foveation low level values
	qiyu_FoveationParam	foveationMedium;	//foveation medium level values
	qiyu_FoveationParam	foveationHigh;		//foveation high level values

};
enum qiyu_EyeType
{
	EYE_Left = 0,		//left eye
	EYE_Right,		//right eye
	EYE_COUNT		//eye count
};
struct qiyu_ControllerData

{
    int 			isConnect;			//connection state
    int 			button;		//button state. refer to qiyu_ButtonType
    int 			buttonTouch;//touch state. refer to qiyu_ButtonType
    int 			batteryLevel;		//[0, 1] battery level
    float 			triggerForce;		//[0.0f, 1.0f] trigger force
    float 			gripForce;			//[0.0f, 1.0f] grip force
    int 			isShow;				//whether show controller
    qiyu_Vector2 	joyStickPos;		//[-1.0f, 1.0f] joystick position
    qiyu_Vector3 	position;			//controller position (meter)
    qiyu_Quaternion rotation;			//controller quaternion
    qiyu_Vector3 	velocity;			//linear velocity
    qiyu_Vector3 	acceleration;		//linear acceleration
    qiyu_Vector3 	angVelocity;		//angular velocity
    qiyu_Vector3 	angAcceleration;	//angular acceleration

};
enum qiyu_ButtonType
{
	BT_None			= 0,
	BT_Trigger		= 0x01,
	BT_Grip			= 0x02,
	BT_A_X			= 0x10,
	BT_B_Y			= 0x20,
	BT_Home_Menu	= 0x40,
	BT_JoyStick 	= 0x80
};
enum class qiyu_ControllerMask
{
	CM_Left = 0x01,		//left controller
	CM_Right  = 0x02,	//right controller
	CM_Both = 0x03		//left and right controllers
};
enum class qiyu_ControllerIndex

{
	CI_Left = 0,
	CI_Right,
	CI_COUNT
};
enum qiyu_PerfLevel
{
	PL_System 	= 0,		//default system level
	PL_Minimum 	= 1,		//min level
	PL_Medium 	= 2,		//medium level
	PL_Maximum 	= 3,		//max level
	PL_COUNT
};
struct qiyu_HeadPose
{
	qiyu_Quaternion	rotation;		//rotation quaternion
	qiyu_Vector3      	position;		//position
};
struct qiyu_HeadPoseState
{
    qiyu_HeadPose 	pose;				//head pose
    int32_t 	poseStatus;	            //Bit field (sxrTrackingMode) //indicating pose status
    uint64_t 	poseTimeStampNs;       //Time stamp in which the head pose //was generated (nanoseconds)
    uint64_t 	poseFetchTimeNs;       //Time stamp when this pose was //retrieved
    uint64_t 	expectedDisplayTimeNs;	//Expected time when this pose //should be on screen (nanoseconds)
};
enum class qiyu_TrackingOriginMode

{
    TM_Device,	//device mode. default mode.
    TM_Ground	//ground mode. 
};
enum qiyu_TextureType
{
	TT_Texture = 0,			//Standard texture
	TT_TextureArray,		//Standard texture array (Left eye is first layer, right eye is second layer)
	TT_Image,				//EGL Image texture
	TT_EquiRectTexture,		//Equirectangular texture
	TT_EquiRectImage,		//Equirectangular Image texture
	TT_CubemapTexture,		//Cubemap texture (Not supporting cubemap image)
};
struct qiyu_RenderLayer_ScreenPosUV
{
	float LowerLeftPos[4];		//0 = X-Position; 1 = Y-Position; 2 = Z-Position; 3 = W-Component
	float LowerRightPos[4];		//0 = X-Position; 1 = Y-Position; 2 = Z-Position; 3 = W-Component
	float UpperLeftPos[4];		//0 = X-Position; 1 = Y-Position; 2 = Z-Position; 3 = W-Component
	float UpperRightPos[4];		//0 = X-Position; 1 = Y-Position; 2 = Z-Position; 3 = W-Component
	float LowerUVs[4];			//[0,1] = Lower Left UV values; [2,3] = Lower Right UV values
	float UpperUVs[4];			//[0,1] = Upper Left UV values; [2,3] = Upper Right UV values
};
enum qiyu_RenderLayer_EyeMask
{
	RL_EyeMask_Left		= 0x00000001,
	RL_EyeMask_Right		= 0x00000002,
	RL_EyeMask_Both		= 0x00000003
};
struct qiyu_RenderLayer
{
	int32_t						imageHandle;	//Handle to the texture/image to be rendered
	qiyu_TextureType				imageType;	//Type of texture: Standard Texture or EGL Image
	qiyu_RenderLayer_ScreenPosUV	imageCoords;	//Layout of this layer on the screen
	qiyu_RenderLayer_EyeMask		eyeMask;		//Determines which eye[s] receive this render layer
};
static const int qiyu_RenderLayerMaxCount = 16;

struct qiyu_FrameParam
{
	int32_t minVsyncs; //Minimum number of vysnc events before displaying the frame (1=display refresh, 2=half refresh, etc...)
	qiyu_RenderLayer renderLayers[qiyu_RenderLayerMaxCount]; //Description of each render layer
	qiyu_HeadPoseState headPoseState; //Head pose state used to generate the frame
};

# 4.2 Basic Functions

@brief Function description
@param[in] Input parameter
@param[inout] Output parameters
@return  Return value
qiyu_SdkVersion qiyu_GetSdkVersion();

@brief //获取SDK版本。
@return //qiyu_SdkVersion.
bool qiyu_Init(jobject clazz,  
               JavaVM* vm, 
               qiyu_GraphicsApi graphicsApi = qiyu_GraphicsApi::GA_OpenGLES,
               qiyu_TrackingOriginMode trackMode = qiyu_TrackingOriginMode::TM_Device,
               bool bLogVerbose = false);

- brief //Init QiyuNativeSDK. 'void android_main(struct android_app* app)' is the main entry point of a native application that is using android_native_app_glue.  It runs in its own thread, with its own event loop for receiving input events and doing other things.
- @param[in] clazz // The object handle of activity which is 'ANativeActivity' object instance that this 'android_app' is running in. eg.'android_app->activity->clazz;''
- @param[in] vm // The global handle on the process's Java VM in 'ANativeActivity' in 'android_app'. eg.'android_app->activity->vm;'
- @param[in] graphicsApi - the graphics API。please refer to 'enum class qiyu_GraphicsApi'.
- @param[in] trackMode - the tracking mode for device or ground, please refer to 'enum class qiyu_TrackingOriginMode'.
- @param[in] bLogVerbose // Output the verbose log. Note this will output many unuseful log, just open this to fix bug while debug.
- @return //True if succeed, False if fail.
bool qiyu_Release();

- brief //Release QiyuNativeSDK, normally called while APP_CMD_DESTROY/APP_CMD_TERM_WINDOW, etc. Please refer to the Samples.
- @return //True if succeed, False if fail.
bool qiyu_StartVR(ANativeWindow* nativeWindow, qiyu_PerfLevel cpuPerfLevel, qiyu_PerfLevel gpuPerfLevel);

- @brief //Start VR service, normally called in the main loop while APP_CMD_START/APP_CMD_RESUME/APP_CMD_INIT_WINDOW, etc. Please refer to the Samples.
- @param[in] nativeWindow // The window surface that the 'android_app' can draw in. eg.'android_app->window;' 
 - @param[in] cpuPerfLevel // CPU performance level.
 - @param[in] gpuPerfLevel // GPU performance level.
- @return //True if succeed, False if fail.
bool qiyu_EndVR();

- brief //Terminate VR service, normally called while APP_CMD_PAUSE, etc. Please refer to the Samples.
- @return //True if succeed; False if fail.
bool bool qiyu_StartEye(bool isMultiView, qiyu_Eye eyeType, qiyu_TextureType imageType);

- @brief //Prepare rendering for one eye, called AFTER eye buffer is Bind but BEFORE rendering, normally called after renderState is set.
- @param[in] isMultiView // When the value is set true, the MultiView is used, otherwise the MultiPass is used.
- @param[in] imageType // Setting the image type, please refer to'enum qiyu_TextureType'.
- @param[in] eyeType // Specify left/right eye buffer to be rendered on.
- @return //True if succeed; False if fail.
bool bool qiyu_EndEye(bool isMultiView, qiyu_Eye eyeType, qiyu_TextureType imageType);

- @brief //Finish rendering for one eye, called AFTER eye buffer is rendered but BEFORE eye buffer is Unbind and submit frame.
- @param[in] isMultiView // When the value is set true, the MultiView is used, otherwise the MultiPass is used.
- @param[in] imageType // Setting the image type, please refer to'enum qiyu_TextureType'.
- @param[in] eyeType // Specify left/right eye buffer was rendered on.
- @return //True if succeed; False if fail.
bool bool qiyu_SubmitFrame(const qiyu_FrameParam& frameParam);

- @brief //Submit one frame, by default submit to ATW(asynchronous time warp), called after render finished.
- @param[in] frameParam // Please refer to qiyu_FrameParam.
- @return //True if succeed; False if fail.
qiyu_Update(float deltaTime);

- @brief //Update, normally called before render or in another thread other rendering-thread.
- @param[in] deltaTime //(in seconds) time between two frames.
qiyu_DeviceInfo qiyu_GetDeviceInfo();

- @brief //Get the device information.
- @return qiyu_DeviceInfo // Please check 'struct qiyu_DeviceInfo'.
bool qiyu_SetFoveation(qiyu_FoveationLevel foveatLevel, const qiyu_FoveationParam* customFoveatParam = nullptr);

- @brief //set foveation
- @param[in] foveatLevel // please refer to'enum qiyu_FoveationLevel'。
- @param[in] customFoveatParam // only set when foveatLevel==FL_Custom. Please refer to'struct qiyu_FoveationParam'。
- @return //True if succeed; False if fail.
bool qiyu_GetFoveation(qiyu_FoveationLevel& foveatLevel, qiyu_FoveationParam& foveatParam);

- @brief // Get foveation
- @param[out] foveatLevel // please refer to 'enum qiyu_FoveationLevel'。
- @param[out] foveatParam // please refer to 'struct qiyu_FoveationParam'。
- @return //True if succeed; False if fail.
bool qiyu_GetViewMatrix(qiyu_Matrix4& outLeftEyeViewMatrix, qiyu_Matrix4& outRightEyeViewMatrix, float& outDistanceToGround, const qiyu_HeadPoseState& poseState, const qiyu_Quaternion& eyeRotationLeft, const qiyu_Quaternion& eyeRotationRight);

- @brief //Get updated view matrix for both eyes, called before rendering and submitFrame which means before qiyu_StartEye. Use the updated lastes IPD inside.
- @param[inout] outLeftEyeViewMatrix // Return the view matrix for left eye.
- @param[inout] outRightEyeViewMatrix // Return the view matrix for right eye.
- @param[inout] outTrackingOffset(in meters) // Return value of TrackingOffset which take care of HeadsetToGround and the height of recenter. HeadsetToGround is the distance from headset down to the ground so the value is minus. NOTE this value should be used to adjust the position of controllers.
- @param[in] poseState // Head pose state, normally use the value get from qiyu_PredictHeadPose.
- @param[in] eyeRotationLeft // Rotation offset for left eye.
- @param[in] eyeRotationRight // Rotation offset for right eye.
- @return //True if succeed; False if fail.
float qiyu_PredictDisplayTime();

- @brief //Get the predicted time when current frame be displayed.
- @return //Predicted display time(in milliseconds).
qiyu_HeadPoseState qiyu_PredictHeadPose(float predicteDisplayTime);

- @brief //Predicte head pose based on the predicteDisplayTime pass in, normally called before qiyu_GetViewMatrix.
- @param[in] predicteDisplayTime(in milliseconds) // Time ahead of current time to predict the head pose.
- @return qiyu_HeadPoseState // Predicted head pose. Please check 'struct qiyu_HeadPoseState'.
void qiyu_PostSetEyeBufferSize(int width, int height)
    
- @brief //Please call this API after setting the size of EyeBuffer everytime, otherwise, the data of QIYU perfromance Tool will be shown errors.Please note! The EyeBuffer is managed by developer compeletly, this API is for QIYU performance tool to collect the data.
- @param[in] width // EyeBuffer's Width.
- @param[in] height // EyeBuffer's Height.
qiyu_GraphicsApi qiyu_GetGraphicsApi();

- @brief //Get graphic API,which need to be set in qiyu_Init, and the value can be gained by using qiyu_GetGraphicsApi after initialization.
- @return qiyu_GraphicsApi // return the graphic API. Please refer to 'enum class qiyu_GraphicsApi'.

# 4.3 Additional Function

# 4.3.1 Tracking Origin Mode

void qiyu_SetTrackingOriginMode(qiyu_TrackingOriginMode trackMode);

- @brief //Set trackingOrigin mode, mode is pass in qiyu_Init then can be changed by this function.
- @param[in] trackMode // Specify the mode to be device or ground. Please check 'enum class qiyu_TrackingOriginMode'.
qiyu_TrackingOriginMode qiyu_GetTrackingOriginMode();

- @brief //Get trackingOrigin mode, mode is pass in qiyu_Init then can be changed by qiyu_SetTrackingOriginMode.
- @return qiyu_TrackingOriginMode // Return the mode of device or ground. Please check 'enum class qiyu_TrackingOriginMode'.

# 4.3.2 Eye Resolution Scale Factor

A value of 0.7(recommended) will use the default eye texture resolution specified by the device. The lower scale value, the lower resolution eye textures, which can improve performance at the expense of a less sharp image. The higher scale value, the higher resolution eye textures, resulting in a potentially sharper image at a cost to performance and increased memory usage. Please not exceed 1.0.

qiyu_DeviceInfo.iEyeTargetWidth * Scale

qiyu_DeviceInfo.iEyeTargetHeight * Scale

Please refer to the qiyu_GetDeviceInfo and QYApp_InitEyeBuffers of QYApp_Init in the QiyuVR_NativeActivity Sample code, there are two different scale of EyeBuffer which can be switched by pressing X or Y button.

# 4.4 QIYU Controller

bool qiyu_IsControllerInit();

- @brief //Is controller module initialized, called and check the return value before all other controller related api was called.
- @return //True if initialized, False if not initialized.
void qiyu_GetControllerData(qiyu_ControllerData* left, qiyu_ControllerData* right);

- @brief //Get updated controller data. Please check 'struct qiyu_ControllerData'.
- @param[inout] left // Return data for left controller.
- @param[inout] right // Return data for right controller.
void qiyu_StartControllerVibration(qiyu_ControllerMask whichController, float amplitude, float duration);

- @brief //Start vibration for specified controller.
- @param[in] whichController // Start vibration for which controller. Please check 'enum class qiyu_ControllerMask'.
- @param[in] amplitude // [0.0f, 1.0f] Vibration amplitude.
- @param[in] duration//(in seconds)  [[0.0f, 9999.0f] Vibration duration.
void qiyu_StopControllerVibration(qiyu_ControllerMask whichController);

- @brief //Stop vibration for specified controller.
- @param[in] whichController // Start vibration for which controller. Please check 'enum class qiyu_ControllerMask'.

# 4.5 Boundary

qiyu_GetBoundaryGeometry(void* points, int& pointsCount);

- @brief //Get geometry for vitual boundary.
- @param[inout] points // Return geometry points data.
- @param[inout] pointsCount // Return geometry points count.
- @return //True if succeed, False if fail.
qiyu_Vector3 qiyu_GetBoundaryDimensions();

- @brief //Get dimensions for vitual boundary.
- @return qiyu_Vector3 // the size for x/y/z dimensions.
bool qiyu_IsBoundaryVisible();

- @brief //Is boundary visible.
- @return //True if visible; False if not visible.
bool qiyu_IsBoundaryBelowHeadVisible();

- @brief //Is the boundary below head visible.
- @return //True if visible; False if not visible.

# 4.6 Advanced Rendering

# 4.6.1 Foveation

Please refer to the code of QYApp_testFoveation, InitFunction_Foveation, IsSupport_Foveation, FoveationLevel in the QiyuVR_NativeActivity sample.

  • How to use:
  1. Check if the foveation extension is supported, load the foveation functions.
  2. Set GL_TEXTURE_FOVEATED_FEATURE_BITS_QCOM while create framebuffer.
  3. Use glTextureFoveationParametersQCOM and set its params such as focalPoint, focalX, focalY, gainX, gainY, foveaArea.
  • Reference:

[1] https://www.khronos.org/registry/OpenGL/extensions/QCOM/QCOM_framebuffer_foveated.txt (opens new window)

[2] https://www.khronos.org/registry/OpenGL/extensions/QCOM/QCOM_texture_foveated.txt (opens new window)

[3] https://www.khronos.org/registry/OpenGL/extensions/QCOM/QCOM_texture_foveated2.txt (opens new window)

[4] https://www.khronos.org/registry/OpenGL/extensions/QCOM/QCOM_texture_foveated_subsampled_layout.txt (opens new window)

# 4.6.2 MultiView

Please refer to the function QYApp_testMultiView in QiyuVR_NativeActivity Sample. For example, the Shader, which the suffix is MultiView.

How to use:

  1. Check if the multiview extension is supported, load the multiview functions.

  2. Create Texture array and bind it with framebuffer.

  3. Passing view matrix array to vertex shader, use gl_ViewID_OVR index to access view matrix, it will calculate twice and render in one draw call.

  4. Pass param 'isMultiView' to these functions: qiyu_StartEye;qiyu_EndEye;qiyu_SubmitFrame.

# 4.7 Platform Solution

# 4.7.1 Initialization

void qiyu_Platform_Init(const char* app_id, const char* app_secret, PCallback_Init callback);

- @brief // Init platform APIs, which should be called before all other Platform APIs.
- @param[in] app_id // Application ID.
- @param[in] app_secret // Application secret key.
- @param[in] callback // Callback.
  • app_id, app_secret

    Please log in to the QIYU developer Platform (opens new window) and click "Manage - My Apps - +New" to create your app. The system will generate an unique app_id and app_secret for each application. Click「API」to view the App information.

Return Code Reason
S0000 Success
S9000 System Error
B1009 Fail to get Token
B3021 App ID or App Secret is wrong

# 4.7.2 Account Linking

  • Get the status of account login
bool qiyu_Platform_IsAccountLogin();

- @brief //Is account login.
- @return //success to login return true, otherwise, return false.
  • Get QIYU account information
void qiyu_Platform_GetQiyuAccountInfo(PCallback_GetAccountInfo callback);

- @brief //Get QIYU account information.
- @param[in] callback // call back.

# 4.7.3 Deep Linking

void qiyu_Platform_LaunchOtherApp(const char* app_id, const char* key, const char* value);	

- @brief //Deep Linking.
- @param[in] app_id // App ID.
- @param[in] key // Deep linking Key.
- @param[in] value // Deep linking value.
void qiyu_Platform_GetDeepLink(PCallback_GetDeepLink callback);

- @brief //Get DeepLink.
- @param[in] callback // call back.

# 4.7.4 Qiyu PlayerPrefs (A requirement to pass our QA Review)

void qiyu_Prefs_Init();

- @brief //it will prompt storage permission window before calling the archive API. 
    	//it should be called before using other APIs.
    	//The external storage permission is needed.
void float qiyu_Prefs_GetFloat(const char* key, float defaultValue);

- @brief //Get Float Playerprefs, if not exist, return defaultValue.
- @param[in] key // Key word.
- @param[in] defaultValue // Default value. 
- @return //Return float value.
int qiyu_Prefs_GetInt(const char* key, int defaultValue);

- @brief //Get Int Playerprefs, if not exist, return defaultValue.
- @param[in] key // Key word.
- @param[in] defaultValue // Default value.  
- @return //Return int value.
const char* qiyu_Prefs_GetString(const char* key, const char* defaultValue);

- @brief //Get String Playerprefs, if not exist, return defaultValue.
- @param[in] key // Key word.
- @param[in] defaultValue // Default value.  
- @return //Return String value.
bool qiyu_Prefs_HasKey(const char* key);

- @brief //If the Key exist in PlayerPrefs, return True, otherwise, return False
- @param[in] key // Key word.
- @return //return true or false.
void qiyu_Prefs_Save();

- @brief //Save, which write the PlayerPrefs to disk, should be called after all modifications.
void qiyu_Prefs_DeleteAll();

- @brief //Delete all the PlayerPrefs.
void qiyu_Prefs_DeleteKey(const char* key);
- @brief //Delete the Key in PlayerPrefs.
- @param[in] key // Key word.
void qiyu_Prefs_SetFloat(const char* key, float value);

- @brief // Set float PlayerPrefs for specific Key.
- @param[in] key // Key word.
- @param[in] value // Value.
void qiyu_Prefs_SetInt(const char* key, int value);

- @brief //Set int PlayerPrefs for specific Key.
- @param[in] key // Key word.
- @param[in] value // Value.
void qiyu_Prefs_SetString(const char* key, const char* value);

- @brief // Set String PlayerPrefs for specific Key.
- @param[in] key // Key word.
- @param[in] value // Value.