Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 7.06 KB | None | 0 0
  1. module Rift
  2.  
  3.  import Base: zero
  4.  
  5.  const DK1              = 3
  6.  const DKHD             = 4
  7.  const DK2              = 6
  8.  
  9.  
  10.  const ovrHmdCap_Present           = 0x0001
  11.  const ovrHmdCap_Available         = 0x0002
  12.  const ovrHmdCap_Captured          = 0x0004
  13.  const ovrHmdCap_ExtendDesktop     = 0x0008
  14.  const ovrHmdCap_NoMirrorToWindow  = 0x2000
  15.  const ovrHmdCap_DisplayOff        = 0x0040
  16.  const ovrHmdCap_LowPersistence    = 0x0080
  17.  const ovrHmdCap_DynamicPrediction = 0x0200
  18.  const ovrHmdCap_NoVSync           = 0x1000
  19.  
  20.  const ovrHmdCap_Writable_Mask     = 0x33F0
  21.  const ovrHmdCap_Service_Mask      = 0x23F0
  22.  
  23.  immutable ovrFovPort
  24.     UpTan::Float32
  25.     DownTan::Float32
  26.     LeftTan::Float32
  27.     RightTan::Float32
  28.  end
  29.  zero(::Type{ovrFovPort}) = ovrFovPort(0.0f1,0.0f1,0.0f1,0.0f1)
  30.  
  31.  immutable ovrSizei
  32.     w::Cint
  33.     h::Cint
  34.  end
  35.  zero(::Type{ovrSizei}) = ovrSizei(0,0)
  36.  
  37.  immutable ovrVector2i
  38.     x::Cint
  39.     y::Cint
  40.  end
  41.  zero(::Type{ovrVector2i}) = ovrVector2i(0,0)
  42.  
  43.  immutable ovrRecti
  44.     Pos::ovrVector2i
  45.     Size::ovrSizei
  46.  end
  47.  zero(::Type{ovrRecti}) = ovrRecti(zero(ovrVector2i),zero(ovrSizei))
  48.  
  49.  immutable ovrVector2f
  50.     x::Float32
  51.     y::Float32
  52.  end
  53.  zero(::Type{ovrVector2f}) = ovrVector2f(0.0f1,0.0f1)
  54.  
  55.  immutable ovrVector3f
  56.     x::Float32
  57.     y::Float32
  58.     z::Float32
  59.  end
  60.  zero(::Type{ovrVector3f}) = ovrVector3f(0.0f1,0.0f1,0.0f1)
  61.  
  62.  immutable ovrQuatf
  63.     x::Float32
  64.     y::Float32
  65.     z::Float32
  66.     w::Float32
  67.  end
  68.  zero(::Type{ovrQuatf}) = ovrQuatf(0.0f1,0.0f1,0.0f1,0.0f1)
  69.  
  70.  immutable ovrPosef
  71.     Orientation::ovrQuatf
  72.     Position::ovrVector3f
  73.  end
  74.  zero(::Type{ovrPosef}) = ovrPosef(zero(ovrQuatf),zero(ovrVector3f))
  75.  
  76.  immutable ovrHmdDesc
  77.     handle::Ptr{Void}
  78.     Type::Cint
  79.     ProductName::Ptr{UInt8}
  80.     Manufacturer::Ptr{UInt8}
  81.  
  82.     VendorID::UInt16
  83.     ProductId::UInt16
  84.     SerialNumber1::UInt128
  85.     SerialNumber2::UInt64
  86.  
  87.     FirmwareMajor::UInt16
  88.     FirmwareMinor::UInt16
  89.  
  90.     CameraFrustumHFovInRadians::Float32
  91.     CameraFrustumVFovInRadians::Float32
  92.     CameraFrustumNearZInMeters::Float32
  93.     CameraFrustumFarZInMeters::Float32
  94.  
  95.     HmdCaps::Cuint
  96.     TrackingCaps::Cuint
  97.     DistortionCaps::Cuint
  98.  
  99.     DefaultEyeFovLeft::ovrFovPort
  100.     DefaultEyeFovRight::ovrFovPort
  101.  
  102.     MaxEyeFov::ovrFovPort
  103.  
  104.     EyeRenderOrderLeft::Cint
  105.     EyeRenderOrderRight::Cint
  106.  
  107.     Resolution::ovrSizei
  108.     WindowsPos::ovrVector2i
  109.  
  110.     DisplayDeviceName::Ptr{UInt8}
  111.     DisplayId::Cint
  112.  end
  113.  
  114.  immutable ovrTimingInfo
  115.     DeltaSeconds::Float32
  116.     ThisFrameSeconds::Float64
  117.     TimewarpPointSeconds::Float64
  118.     NextFrameSeconds::Float64
  119.     ScanoutMidpointSeconds::Float64
  120.     EyeScanoutSecondsLeft::Float64
  121.     EyeScanoutSecondsRight::Float64
  122.  end
  123.  
  124.  
  125.  const ovrHmd = Ptr{ovrHmdDesc}
  126.  
  127.  
  128.  const ovrBool = UInt8
  129.  
  130.  initialize() = ccall((:ovr_Initialize,LibOVR),ovrBool,())
  131.  shutdown() = ccall((:ovr_Shutdown,LibOVR),Void,())
  132.  
  133.  immutable HMDList; end
  134.  
  135.  const HMDs = HMDList();
  136.  
  137.  import Base: length, getindex, zero, length, getindex
  138.  
  139.  length(::HMDList) = ccall((:ovrHmd_Detect,LibOVR),Cint,())
  140.  getindex(::HMDList,x) = ccall((:ovrHmd_Create,LibOVR),ovrHmd,(Cint,),x+1)
  141.  
  142.  debug_hmd(kind) = ccall((:ovrHmd_CreateDebug,LibOVR),ovrHmd,(Cint,),kind)
  143.  
  144.  function __init__()
  145.     initialize()
  146.  end
  147.  
  148.  const ovrRenderAPI_None             = 0
  149.  const ovrRenderAPI_OpenGL           = 1
  150.  const ovrRenderAPI_Android_GLES     = 2
  151.  const ovrRenderAPI_D3D9             = 3
  152.  const ovrRenderAPI_D3D10            = 4
  153.  const ovrRenderAPI_D3D11            = 5
  154.  
  155.  immutable ovrRenderAPIConfigHeader
  156.     API::Cint
  157.     RTSize::ovrSizei
  158.     Multisample::Cint
  159.  end
  160.  zero(::Type{ovrRenderAPIConfigHeader}) = ovrRenderAPIConfigHeader(0,zero(ovrSizei),0)
  161.  
  162.  immutable ovrRenderAPIConfig
  163.     Header::ovrRenderAPIConfigHeader
  164.     PlatformData1::UInt
  165.     PlatformData2::UInt
  166.     PlatformData3::UInt
  167.     PlatformData4::UInt
  168.     PlatformData5::UInt
  169.     PlatformData6::UInt
  170.     PlatformData7::UInt
  171.     PlatformData8::UInt
  172.  end
  173.  zero(::Type{ovrRenderAPIConfig}) =
  174.     ovrRenderAPIConfig(zero(ovrRenderAPIConfigHeader),0,0,0,0,0,0,0,0)
  175.  
  176.  immutable ovrTextureHeader
  177.     API::Cint
  178.     TextureSize::ovrSizei
  179.     RenderViewport::ovrRecti
  180.  end
  181.  
  182.  immutable ovrTexture
  183.     Header::ovrTextureHeader
  184.     PlatformData1::UInt
  185.     PlatformData2::UInt
  186.     PlatformData3::UInt
  187.     PlatformData4::UInt
  188.     PlatformData5::UInt
  189.     PlatformData6::UInt
  190.     PlatformData7::UInt
  191.     PlatformData8::UInt
  192.  end
  193.  
  194.  
  195.  const ovrDistortionCap_Chromatic      = 0x01 # Supports chromatic aberration correction.
  196.  const ovrDistortionCap_TimeWarp       = 0x02 # Supports timewarp.
  197.  const ovrDistortionCap_Vignette       = 0x08 # Supports vignetting around the edges of the view.
  198.  const ovrDistortionCap_NoRestore      = 0x10 #  Do not save and restore the graphics state when rendering distortion.
  199.  const ovrDistortionCap_FlipInput      = 0x20 #  Flip the vertical texture coordinate of input images.
  200.  const ovrDistortionCap_SRGB           = 0x40 #  Assume input images are in sRGB gamma-corrected color space.
  201.  const ovrDistortionCap_Overdrive      = 0x80 #  Overdrive brightness transitions to reduce artifacts on DK2+ displays
  202.  
  203.  
  204.  immutable ovrEyeRenderDesc
  205.     Eye::Cint
  206.     Fov::ovrFovPort
  207.     DistortedViewport::ovrRecti
  208.     PixelsPerTanAngleAtCenter::ovrVector2f
  209.     ViewAdjust::ovrVector3f
  210.  end
  211.  zero(::Type{ovrEyeRenderDesc}) = ovrEyeRenderDesc(0,zero(ovrFovPort),zero(ovrRecti),zero(ovrVector2f),zero(ovrVector3f))
  212.  
  213.  
  214.  function ConfigureRendering(hmdhandle::ovrHmd)
  215.     a = zeros(ovrRenderAPIConfig,1)
  216.     a[1] = ovrRenderAPIConfig(ovrRenderAPIConfigHeader(ovrRenderAPI_OpenGL,ovrSizei(1920,1080),1),0,0,0,0,0,0,0,0)
  217.  
  218.     distortionCaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette;
  219.  
  220.     Hmd = unsafe_load(hmdhandle)
  221.  
  222.     eyeFov = Array(ovrFovPort,2)
  223.     eyeFov[1] = Hmd.DefaultEyeFovLeft
  224.     eyeFov[2] = Hmd.DefaultEyeFovRight
  225.  
  226.     eyeRender = zeros(ovrEyeRenderDesc,2)
  227.  
  228.     ccall((:ovrHmd_ConfigureRendering,LibOVR),ovrBool,
  229.         (Ptr{Void},Ptr{Void},Cuint,Ptr{Void},Ptr{Void}),
  230.         hmdhandle,a,distortionCaps,eyeFov,eyeRender)
  231.  end
  232.  
  233.  enabled_caps(hmd) = ccall((:ovrHmd_GetEnabledCaps, LibOVR), Cuint, (Ptr{Void},), hmd)
  234.  
  235.  function begin_frame(hmd)
  236.     a = Array(ovrTimingInfo,1)
  237.     # This uses sret. The array above won't be needed once the appropriate
  238.     # Julia patch merges
  239.     ccall((:ovrHmd_BeginFrame,LibOVR),Void,(Ptr{Void},Ptr{Void},Cuint),a,hmd,0)
  240.  end
  241.  
  242.  function end_frame(hmd,TextureL,viewPortL,TextureR,viewPortR)
  243.     renderPose = Array(ovrPosef,2)
  244.     eyeTexture = Array(ovrTexture, 2)
  245.     eyeTexture[1] = ovrTexture(ovrTextureHeader(
  246.         ovrRenderAPI_OpenGL,
  247.         ovrSizei(TextureL.dims[1],TextureL.dims[2]),
  248.         viewPortL),
  249.         TextureL.id,0,0,0,0,0,0,0)
  250.     eyeTexture[2] = ovrTexture(ovrTextureHeader(
  251.         ovrRenderAPI_OpenGL,
  252.         ovrSizei(TextureR.dims[1],TextureR.dims[2]),
  253.         viewPortR),
  254.         TextureR.id,0,0,0,0,0,0,0)
  255.     ccall((:ovrHmd_EndFrame,LibOVR),Void,(Ptr{Void},Ptr{Void},Ptr{Void}),
  256.         hmd,renderPose,eyeTexture)
  257.  end
  258.  
  259. end # module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement