Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.88 KB | None | 0 0
  1. /************************************************************************************
  2.  
  3. Filename    :   VrApi_Types.h
  4. Content     :   Types for minimum necessary API for mobile VR
  5. Created     :   April 30, 2015
  6. Authors     :   J.M.P. van Waveren
  7.  
  8. Copyright   :   Copyright 2015 Oculus VR, LLC. All Rights reserved.
  9.  
  10. *************************************************************************************/
  11. #ifndef OVR_VrApi_Types_h
  12. #define OVR_VrApi_Types_h
  13.  
  14. #include <stdbool.h>
  15.  
  16. //-----------------------------------------------------------------
  17. // Java
  18. //-----------------------------------------------------------------
  19.  
  20. #if defined( ANDROID )
  21. #include <jni.h>
  22. #elif defined( __cplusplus )
  23. typedef struct _JNIEnv JNIEnv;
  24. typedef struct _JavaVM JavaVM;
  25. typedef class _jobject * jobject;
  26. #else
  27. typedef const struct JNINativeInterface * JNIEnv;
  28. typedef const struct JNIInvokeInterface * JavaVM;
  29. void * jobject;
  30. #endif
  31.  
  32. typedef struct
  33. {
  34.     JavaVM *    Vm;                 // Java Virtual Machine
  35.     JNIEnv *    Env;                // Thread specific environment
  36.     jobject     ActivityObject;     // Java activity object
  37. } ovrJava;
  38.  
  39. //-----------------------------------------------------------------
  40. // HMD information.
  41. //-----------------------------------------------------------------
  42.  
  43. typedef struct
  44. {
  45.     // Resolution of the display in pixels.
  46.     int     DisplayPixelsWide;
  47.     int     DisplayPixelsHigh;
  48.  
  49.     // Refresh rate of the display in cycles per second.
  50.     // Currently 60Hz.
  51.     float   DisplayRefreshRate;
  52.  
  53.     // With a display resolution of 2560x1440, the pixels at the center
  54.     // of each eye cover about 0.06 degrees of visual arc. To wrap a
  55.     // full 360 degrees, about 6000 pixels would be needed and about one
  56.     // quarter of that would be needed for ~90 degrees FOV. As such, Eye
  57.     // images with a resolution of 1536x1536 result in a good 1:1 mapping
  58.     // in the center, but they need mip-maps for off center pixels. To
  59.     // avoid the need for mip-maps and for significantly improved rendering
  60.     // performance this currently returns a conservative 1024x1024.
  61.     int     SuggestedEyeResolution[2];
  62.  
  63.     // This is a product of the lens distortion and the screen size,
  64.     // but there is no truly correct answer.
  65.     //
  66.     // There is a tradeoff in resolution and coverage.
  67.     // Too small of an FOV will leave unrendered pixels visible, but too
  68.     // large wastes resolution or fill rate.  It is unreasonable to
  69.     // increase it until the corners are completely covered, but we do
  70.     // want most of the outside edges completely covered.
  71.     //
  72.     // Applications might choose to render a larger FOV when angular
  73.     // acceleration is high to reduce black pull in at the edges by
  74.     // the time warp.
  75.     //
  76.     // Currently symmetric 90.0 degrees.
  77.     float   SuggestedEyeFov[2];
  78. } ovrHmdInfo;
  79.  
  80. //-----------------------------------------------------------------
  81. // Initialization
  82. //-----------------------------------------------------------------
  83.  
  84. typedef struct
  85. {
  86.     int     MajorVersion;
  87.     int     MinorVersion;
  88.     ovrJava Java;
  89. } ovrInitParms;
  90.  
  91. //-----------------------------------------------------------------
  92. // Entering VR mode
  93. //-----------------------------------------------------------------
  94.  
  95. typedef struct
  96. {
  97.     // If true, warn and allow the app to continue at 30fps when
  98.     // throttling occurs.
  99.     // If false, display the level 2 error message which requires
  100.     // the user to undock.
  101.     bool    AllowPowerSave;
  102.  
  103.     // When an application with multiple activities moves backwards on
  104.     // the activity stack, the activity window it returns to is no longer
  105.     // flagged as fullscreen. As a result, Android will also render
  106.     // the decor view, which wastes a significant amount of bandwidth.
  107.     // By setting this flag, the fullscreen flag is reset on the window.
  108.     // Unfortunately, this causes Android life cycle events that mess up
  109.     // several NativeActivity codebases like Stratum and UE4, so this
  110.     // flag should only be set for select applications with multiple
  111.     // activities. Use "adb shell dumpsys SurfaceFlinger" to verify
  112.     // that there is only one HWC next to the FB_TARGET.
  113.     bool    ResetWindowFullscreen;
  114.  
  115.     // These are fixed clock levels.
  116.     int     CpuLevel;
  117.     int     GpuLevel;
  118.  
  119.     // These threads will get SCHED_FIFO.
  120.     int     MainThreadTid;
  121.     int     RenderThreadTid;
  122.  
  123.     // The Java VM is needed for the time warp thread to create a Java environment.
  124.     // A Java environment is needed to access various system services. The thread
  125.     // that enters VR mode is responsible for attaching and detaching the Java
  126.     // environment. The Java Activity object is needed to get the windowManager,
  127.     // packageName, systemService, etc.
  128.     ovrJava Java;
  129. } ovrModeParms;
  130.  
  131. // VR context
  132. // To allow multiple Android activities that live in the same address space
  133. // to cooperatively use the VrApi, each activity needs to maintain its own
  134. // separate contexts for a lot of the video related systems.
  135. typedef struct ovrMobile ovrMobile;
  136.  
  137. //-----------------------------------------------------------------
  138. // HMD sensor input
  139. //-----------------------------------------------------------------
  140.  
  141. typedef struct ovrVector3f_
  142. {
  143.     float x, y, z;
  144. } ovrVector3f;
  145.  
  146. // Quaternion.
  147. typedef struct ovrQuatf_
  148. {
  149.     float x, y, z, w;
  150. } ovrQuatf;
  151.  
  152. // Row-major 4x4 matrix.
  153. typedef struct ovrMatrix4f_
  154. {
  155.     float M[4][4];
  156. } ovrMatrix4f;
  157.  
  158. // Position and orientation together.
  159. typedef struct ovrPosef_
  160. {
  161.     ovrQuatf    Orientation;
  162.     ovrVector3f Position;    
  163. } ovrPosef;
  164.  
  165. // Full pose (rigid body) configuration with first and second derivatives.
  166. typedef struct ovrPoseStatef_
  167. {
  168.     ovrPosef    Pose;
  169.     ovrVector3f AngularVelocity;
  170.     ovrVector3f LinearVelocity;
  171.     ovrVector3f AngularAcceleration;
  172.     ovrVector3f LinearAcceleration;
  173.     double      TimeInSeconds;          // Absolute time of this state sample.
  174.     double      PredictionInSeconds;    // Seconds this state was predicted ahead.
  175. } ovrPoseStatef;
  176.  
  177. // Bit flags describing the current status of sensor tracking.
  178. typedef enum
  179. {
  180.     VRAPI_TRACKING_STATUS_ORIENTATION_TRACKED   = 0x0001,   // Orientation is currently tracked.
  181.     VRAPI_TRACKING_STATUS_POSITION_TRACKED      = 0x0002,   // Position is currently tracked.
  182.     VRAPI_TRACKING_STATUS_HMD_CONNECTED         = 0x0080    // HMD is available & connected.
  183. } ovrTrackingStatus;
  184.  
  185. // Tracking state at a given absolute time.
  186. typedef struct ovrTracking_
  187. {
  188.     // Sensor status described by ovrTrackingStatus flags.
  189.     unsigned int    Status;
  190.     // Predicted head configuration at the requested absolute time.
  191.     // The pose describes the head orientation and center eye position.
  192.     ovrPoseStatef   HeadPose;
  193. } ovrTracking;
  194.  
  195. //-----------------------------------------------------------------
  196. // Frame Submission
  197. //-----------------------------------------------------------------
  198.  
  199. typedef enum
  200. {
  201.     // To get gamma correct sRGB filtering of the eye textures, the textures must be
  202.     // allocated with GL_SRGB8_ALPHA8 format and the window surface must be allocated
  203.     // with these attributes:
  204.     // EGL_GL_COLORSPACE_KHR,  EGL_GL_COLORSPACE_SRGB_KHR
  205.     //
  206.     // While we can reallocate textures easily enough, we can't change the window
  207.     // colorspace without relaunching the entire application, so if you want to
  208.     // be able to toggle between gamma correct and incorrect, you must allocate
  209.     // the framebuffer as sRGB, then inhibit that processing when using normal
  210.     // textures.
  211.     VRAPI_FRAME_OPTION_INHIBIT_SRGB_FRAMEBUFFER                     = 1,
  212.     // Correct for chromatic aberration.
  213.     VRAPI_FRAME_OPTION_INHIBIT_CHROMATIC_ABERRATION_CORRECTION      = 2,
  214.     // Enable / disable the sliced warp.
  215.     VRAPI_FRAME_OPTION_USE_SLICED_WARP                              = 4,
  216.     // Flush the warp swap pipeline so the images show up immediately.
  217.     // This is expensive and should only be used when an immediate transition
  218.     // is needed like displaying black when resetting the HMD orientation.
  219.     VRAPI_FRAME_OPTION_FLUSH                                        = 8,
  220.     // This is the final frame. Do not accept any more frames after this.
  221.     VRAPI_FRAME_OPTION_FINAL                                        = 16,
  222.     // The overlay plane is a HUD, and should ignore head tracking.
  223.     // This is generally poor practice for VR.
  224.     VRAPI_FRAME_OPTION_FIXED_OVERLAY                                = 32,
  225.     // The third image plane is blended separately over only a small, central
  226.     // section of each eye for performance reasons, so it is enabled with
  227.     // a flag instead of a shared ovrFrameProgram.
  228.     VRAPI_FRAME_OPTION_SHOW_CURSOR                                  = 64,
  229.     // Use default images. This is used for showing black and the loading icon.
  230.     VRAPI_FRAME_OPTION_USE_DEFAULT_IMAGES                           = 128,
  231.     // Draw the axis lines after warp to show the skew with the pre-warp lines.
  232.     VRAPI_FRAME_OPTION_DRAW_CALIBRATION_LINES                       = 256
  233. } ovrFrameOption;
  234.  
  235. typedef enum
  236. {
  237.     VRAPI_FRAME_LAYER_EYE_LEFT,
  238.     VRAPI_FRAME_LAYER_EYE_RIGHT,
  239.     VRAPI_FRAME_LAYER_EYE_MAX
  240. } ovrFrameLayerEye;
  241.  
  242. typedef enum
  243. {
  244.     VRAPI_FRAME_LAYER_IMAGE_TYPE_2D,                    // Simple 2D texture.
  245.     VRAPI_FRAME_LAYER_IMAGE_TYPE_2D_EXTERNAL,           // External 2D texture.
  246.     VRAPI_FRAME_LAYER_IMAGE_TYPE_2D_ARRAY,              // The image is a layer of a texture array.
  247.     VRAPI_FRAME_LAYER_IMAGE_TYPE_2D_ARRAY_FOVEATED,     // The image is a layer of a texture array.
  248.     VRAPI_FRAME_LAYER_IMAGE_TYPE_CUBE,                  // Cube map.
  249.     // Special built-in images.
  250.     VRAPI_FRAME_LAYER_IMAGE_TYPE_BLACK,                 // Use black image.
  251.     VRAPI_FRAME_LAYER_IMAGE_TYPE_LOADING_ICON           // Use default loading icon image.
  252. } ovrFrameLayerImageType;
  253.  
  254. typedef enum
  255. {
  256.     VRAPI_FRAME_LAYER_BLEND_ZERO,
  257.     VRAPI_FRAME_LAYER_BLEND_ONE,
  258.     VRAPI_FRAME_LAYER_BLEND_SRC_ALPHA,
  259.     VRAPI_FRAME_LAYER_BLEND_DST_ALPHA,
  260.     VRAPI_FRAME_LAYER_BLEND_ONE_MINUS_DST_ALPHA,
  261.     VRAPI_FRAME_LAYER_BLEND_ONE_MINUS_SRC_ALPHA
  262. } ovrFrameLayerBlend;
  263.  
  264. typedef enum
  265. {
  266.     VRAPI_FRAME_LAYER_TYPE_WORLD,
  267.     VRAPI_FRAME_LAYER_TYPE_OVERLAY,
  268.     VRAPI_FRAME_LAYER_TYPE_CURSOR,
  269.     VRAPI_FRAME_LAYER_TYPE_USER,
  270.     VRAPI_FRAME_LAYER_TYPE_MAX
  271. } ovrFrameLayerType;
  272.  
  273. typedef enum
  274. {
  275.     VRAPI_FRAME_PROGRAM_SIMPLE,
  276.     VRAPI_FRAME_PROGRAM_MASKED_PLANE,           // overlay plane shows through masked areas in eyes
  277.     VRAPI_FRAME_PROGRAM_MASKED_PLANE_EXTERNAL,  // overlay plane shows through masked areas in eyes, using external texture as source
  278.     VRAPI_FRAME_PROGRAM_MASKED_CUBE,            // overlay cube shows through masked areas in eyes
  279.     VRAPI_FRAME_PROGRAM_CUBE,                   // overlay cube only, no main scene (for power savings)
  280.     VRAPI_FRAME_PROGRAM_LOADING_ICON,           // overlay loading icon
  281.     VRAPI_FRAME_PROGRAM_MIDDLE_CLAMP,           // UE4 stereo in a single texture
  282.     VRAPI_FRAME_PROGRAM_OVERLAY_PLANE,          // world shows through transparent parts of overlay plane
  283.     VRAPI_FRAME_PROGRAM_OVERLAY_PLANE_SHOW_LOD, // debug tool to color tint based on mip levels
  284.     VRAPI_FRAME_PROGRAM_CAMERA,
  285.     VRAPI_FRAME_PROGRAM_VIDEO_CUBE,             // static cube map + video texture on -Z face
  286.     VRAPI_FRAME_PROGRAM_PROGRAM_MAX
  287. } ovrFrameProgram;
  288.  
  289. typedef struct ovrRectf_
  290. {
  291.     float x;
  292.     float y;
  293.     float width;
  294.     float height;
  295. } ovrRectf;
  296.  
  297. // Note that any layer images that are dynamic must be triple buffered.
  298. typedef struct
  299. {
  300.     // One of the ovrFrameLayerImageType.
  301.     ovrFrameLayerImageType  ImageType;
  302.  
  303.     // If TexId == 0, this image is disabled.
  304.     // Most applications will have the overlay image
  305.     // disabled.
  306.     //
  307.     // Because OpenGL ES does not support clampToBorder,
  308.     // it is the application's responsibility to make sure
  309.     // that all mip levels of the texture have a black border
  310.     // that will show up when time warp pushes the texture partially
  311.     // off screen.
  312.     //
  313.     // Overlap textures will only show through where alpha on the
  314.     // primary texture is not 1.0, so they do not require a border.
  315.     unsigned int            TexId;
  316.  
  317.     // Experimental separate R/G/B cube maps
  318.     unsigned int            PlanarTexId[3];
  319.  
  320.     // Points on the screen are mapped by a distortion correction
  321.     // function into ( TanX, TanY, -1, 1 ) vectors that are transformed
  322.     // by this matrix to get ( S, T, Q, _ ) vectors that are looked
  323.     // up with texture2dproj() to get texels.
  324.     ovrMatrix4f             TexCoordsFromTanAngles;
  325.  
  326.     // Only texels within this range should be drawn.
  327.     // This is a sub-rectangle of the [(0,0)-(1,1)] texture coordinate range.
  328.     ovrRectf                TextureRect;
  329.  
  330.     // The tracking state for which ModelViewMatrix is correct.
  331.     // It is ok to update the orientation for each eye, which
  332.     // can help minimize black edge pull-in, but the position
  333.     // must remain the same for both eyes, or the position would
  334.     // seem to judder "backwards in time" if a frame is dropped.
  335.     ovrPoseStatef           HeadPose;
  336. } ovrFrameLayerImage;
  337.  
  338. typedef struct
  339. {
  340.     // Image used for each eye.
  341.     ovrFrameLayerImage      Images[VRAPI_FRAME_LAYER_EYE_MAX];
  342.  
  343.     // Layer blend function.
  344.     ovrFrameLayerBlend      SrcBlend;
  345.     ovrFrameLayerBlend      DstBlend;
  346.  
  347.     // Set to true if this layer should write alpha.
  348.     bool                    WriteAlpha;
  349.  
  350.     // The layer is a HUD, and should ignore head tracking.
  351.     // This is generally poor practice for VR.
  352.     bool                    FixedToView;
  353. } ovrFrameLayer;
  354.  
  355. typedef struct
  356. {
  357.     // Layers composited in the time warp.
  358.     ovrFrameLayer           Layers[VRAPI_FRAME_LAYER_TYPE_MAX];
  359.     int                     LayerCount;
  360.  
  361.     // Combination of ovrFrameOption flags.
  362.     int                     WarpOptions;
  363.  
  364.     // Which program to run with these layers.
  365.     ovrFrameProgram         WarpProgram;
  366.  
  367.     // Program-specific tuning values.
  368.     float                   ProgramParms[4];
  369.  
  370.     // Application controlled frame index that uniquely identifies this particular frame.
  371.     // This must be the same frame index that was passed to vrapi_GetPredictedDisplayTime()
  372.     // when synthesis of this frame started.
  373.     long long               FrameIndex;
  374.  
  375.     // WarpSwap will not return until at least this many V-syncs have
  376.     // passed since the previous WarpSwap returned.
  377.     // Setting to 2 will reduce power consumption and may make animation
  378.     // more regular for applications that can't hold full frame rate.
  379.     int                     MinimumVsyncs;
  380.  
  381.     // Rotation from a joypad can be added on generated frames to reduce
  382.     // judder in FPS style experiences when the application framerate is
  383.     // lower than the V-sync rate.
  384.     // This will be applied to the view space distorted
  385.     // eye vectors before applying the rest of the time warp.
  386.     // This will only be added when the same ovrFrameParms is used for
  387.     // more than one V-sync.
  388.     ovrMatrix4f             ExternalVelocity;
  389.  
  390.     // jobject that will be updated before each eye for minimal
  391.     // latency with VRAPI_FRAME_PROGRAM_MASKED_PLANE_EXTERNAL.
  392.     // IMPORTANT: This should be a JNI weak reference to the object.
  393.     // The system will try to convert it into a global reference before
  394.     // calling SurfaceTexture->Update, which allows it to be safely
  395.     // freed by the application.
  396.     jobject                 SurfaceTextureObject;
  397.  
  398.     // For handling HMD events and power level state changes.
  399.     ovrJava                 Java;
  400. } ovrFrameParms;
  401.  
  402. //-----------------------------------------------------------------
  403. // Head Model
  404. //-----------------------------------------------------------------
  405.  
  406. typedef struct
  407. {
  408.     float   InterpupillaryDistance; // Distance between eyes.
  409.     float   EyeHeight;              // Eye height relative to the ground.
  410.     float   HeadModelDepth;         // Eye offset forward from the head center at EyeHeight.
  411.     float   HeadModelHeight;        // Neck joint offset down from the head center at EyeHeight.
  412. } ovrHeadModelParms;
  413.  
  414. //-----------------------------------------------------------------
  415. // Device Status
  416. //-----------------------------------------------------------------
  417.  
  418. typedef enum    // VRAPI_BATTERY_STATE_?
  419. {
  420.     BATTERY_STATUS_CHARGING,
  421.     BATTERY_STATUS_DISCHARGING,
  422.     BATTERY_STATUS_FULL,
  423.     BATTERY_STATUS_NOT_CHARGING,
  424.     BATTERY_STATUS_UNKNOWN
  425. } ovrBatteryState;
  426.  
  427. typedef enum    // VRAPI_WIFI_STATE_?
  428. {
  429.     WIFI_STATE_DISABLING,
  430.     WIFI_STATE_DISABLED,
  431.     WIFI_STATE_ENABLING,
  432.     WIFI_STATE_ENABLED,
  433.     WIFI_STATE_UNKNOWN
  434. } ovrWifiState;
  435.  
  436. typedef enum    // VRAPI_CELLULAR_STATE_?
  437. {
  438.     CELLULAR_STATE_IN_SERVICE,
  439.     CELLULAR_STATE_OUT_OF_SERVICE,
  440.     CELLULAR_STATE_EMERGENCY_ONLY,
  441.     CELLULAR_STATE_POWER_OFF
  442. } ovrCellularState;
  443.  
  444. //-----------------------------------------------------------------
  445. // Device Properties
  446. //-----------------------------------------------------------------
  447.  
  448. typedef enum
  449. {
  450.     VRAPI_DEVICE_TYPE_NOTE4,
  451.     VRAPI_DEVICE_TYPE_S6,
  452.     VRAPI_MAX_DEVICE_TYPES
  453. } ovrDeviceType;
  454.  
  455. typedef enum
  456. {
  457.     VRAPI_SYS_PROP_DEVICE_TYPE,
  458.     VRAPI_SYS_PROP_EXTERNAL_SDCARD,
  459.     VRAPI_SYS_PROP_MAX_FULLSPEED_FRAMEBUFFER_SAMPLES
  460. } ovrSystemProperty;
  461.  
  462. //-----------------------------------------------------------------
  463. // System Activity Commands
  464. //-----------------------------------------------------------------
  465.  
  466. #define PUI_GLOBAL_MENU             "globalMenu"
  467. #define PUI_GLOBAL_MENU_TUTORIAL    "globalMenuTutorial"
  468. #define PUI_CONFIRM_QUIT            "confirmQuit"
  469. #define PUI_THROTTLED1              "throttled1"    // Warn that Power Save Mode has been activated
  470. #define PUI_THROTTLED2              "throttled2"    // Warn that Minimum Mode has been activated
  471. #define PUI_HMT_UNMOUNT             "HMT_unmount"   // the HMT has been taken off the head
  472. #define PUI_HMT_MOUNT               "HMT_mount"     // the HMT has been placed on the head
  473. #define PUI_WARNING                 "warning"       // the HMT has been placed on the head and a warning message shows
  474. #define PUI_FAIL_MENU               "failMenu"      // display a FAIL() message in the System Activities
  475.  
  476. typedef enum
  477. {
  478.     FINISH_NONE,        // This will not exit the activity at all -- normally used for starting the platform UI activity
  479.     FINISH_NORMAL,      // This will finish the current activity.
  480.     FINISH_AFFINITY     // This will finish all activities on the stack.
  481. } ovrFinishType;
  482.  
  483. //-----------------------------------------------------------------
  484. // Error handling
  485. //-----------------------------------------------------------------
  486.  
  487. typedef enum
  488. {
  489.     ERROR_OUT_OF_MEMORY,
  490.     ERROR_OUT_OF_STORAGE,
  491.     ERROR_OSIG,
  492.     ERROR_MISC
  493. } ovrError;
  494.  
  495. #define ERROR_MSG_OUT_OF_MEMORY     "failOutOfMemory"
  496. #define ERROR_MSG_OUT_OF_STORAGE    "failOutOfStorage"
  497. #define ERROR_MSG_OSIG              "failOSig"
  498.  
  499. //-----------------------------------------------------------------
  500. // FIXME:VRAPI remove this once all simulation code uses VrFrame::PredictedDisplayTimeInSeconds and perf timing uses LOGCPUTIME
  501. //-----------------------------------------------------------------
  502.  
  503. #if defined( __cplusplus )
  504. extern "C" {
  505. #endif
  506. double vrapi_GetTimeInSeconds();
  507. #if defined( __cplusplus )
  508. }   // extern "C"
  509. #endif
  510.  
  511. #endif  // OVR_VrApi_Types_h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement