1 /**
2  * Copyright 2014 JogAmp Community. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  *    1. Redistributions of source code must retain the above copyright notice, this list of
8  *       conditions and the following disclaimer.
9  *
10  *    2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *       of conditions and the following disclaimer in the documentation and/or other materials
12  *       provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  * or implied, of JogAmp Community.
27  */
28 
29 package com.jogamp.oculusvr;
30 
31 import com.jogamp.common.GlueGenVersion;
32 import com.jogamp.common.os.Platform;
33 import com.jogamp.common.util.VersionUtil;
34 import com.jogamp.common.util.JogampVersion;
35 import com.jogamp.oculusvr.OVR;
36 import com.jogamp.oculusvr.ovrHmdDesc;
37 import com.jogamp.oculusvr.ovrSizei;
38 import com.jogamp.oculusvr.ovrVector2i;
39 
40 import java.util.jar.Manifest;
41 
42 public class OVRVersion extends JogampVersion {
43 
44     /**
45      * Default init-params for {@link OVR#ovr_Initialize(ovrInitParams)},
46      * w/ flags {@link OVR#ovrInit_ServerOptional}.
47      */
48     public static final ovrInitParams defaultInitParams;
49     static {
50         defaultInitParams = ovrInitParams.create();
51         defaultInitParams.setFlags(OVR.ovrInit_ServerOptional);
52     }
53 
54     protected static volatile OVRVersion jogampCommonVersionInfo;
55 
OVRVersion(final String packageName, final Manifest mf)56     protected OVRVersion(final String packageName, final Manifest mf) {
57         super(packageName, mf);
58     }
59 
getInstance()60     public static OVRVersion getInstance() {
61         if(null == jogampCommonVersionInfo) { // volatile: ok
62             synchronized(OVRVersion.class) {
63                 if( null == jogampCommonVersionInfo ) {
64                     final String packageName = "com.jogamp.oculusvr";
65                     final Manifest mf = VersionUtil.getManifest(OVRVersion.class.getClassLoader(), packageName);
66                     jogampCommonVersionInfo = new OVRVersion(packageName, mf);
67                 }
68             }
69         }
70         return jogampCommonVersionInfo;
71     }
72 
getAvailableCapabilitiesInfo(final int ovrHmdIndex, StringBuilder sb)73     public static StringBuilder getAvailableCapabilitiesInfo(final int ovrHmdIndex, StringBuilder sb) {
74         if(null==sb) {
75             sb = new StringBuilder();
76         }
77         if( !OVR.ovr_Initialize(defaultInitParams) ) { // recursive ..
78             sb.append("\tOVR not available").append(Platform.getNewline());
79         } else {
80             final ovrHmdDesc hmdDesc = OVR.ovrHmd_Create(ovrHmdIndex);
81             if( null != hmdDesc ) {
82                 getAvailableCapabilitiesInfo(hmdDesc, ovrHmdIndex, sb);
83                 OVR.ovrHmd_Destroy(hmdDesc);
84             } else {
85                 sb.append("\thmd."+ovrHmdIndex+" not available").append(Platform.getNewline());
86             }
87         }
88         // Nope .. ovr.ovr_Shutdown();
89         sb.append(Platform.getNewline());
90         return sb;
91     }
92     /**
93      *
94      * @param hmdDesc
95      * @param ovrHmdIndex only for informal purposes, OVR HMD index of <code>hmdDesc</code>
96      * @param sb
97      * @return
98      */
getAvailableCapabilitiesInfo(final ovrHmdDesc hmdDesc, final int ovrHmdIndex, StringBuilder sb)99     public static StringBuilder getAvailableCapabilitiesInfo(final ovrHmdDesc hmdDesc, final int ovrHmdIndex, StringBuilder sb) {
100         if(null == hmdDesc) {
101             throw new IllegalArgumentException("null hmdDesc");
102         }
103         final OvrHmdContext hmdCtx = hmdDesc.getHandle();
104         if(null == hmdCtx) {
105             throw new IllegalArgumentException("null hmdCtx");
106         }
107         if(null==sb) {
108             sb = new StringBuilder();
109         }
110         sb.append("\thmd."+ovrHmdIndex+".productName: "+hmdDesc.getProductNameAsString()).append(Platform.getNewline());
111         sb.append("\thmd."+ovrHmdIndex+".vendorName: "+hmdDesc.getManufacturerAsString()).append(Platform.getNewline());
112         sb.append("\thmd."+ovrHmdIndex+".deviceName: "+hmdDesc.getDisplayDeviceNameAsString()).append(Platform.getNewline());
113         sb.append("\thmd."+ovrHmdIndex+".productId: 0x"+Integer.toHexString(hmdDesc.getProductId())).append(Platform.getNewline());
114         sb.append("\thmd."+ovrHmdIndex+".vendorId: 0x"+Integer.toHexString(hmdDesc.getVendorId())).append(Platform.getNewline());
115         sb.append("\thmd."+ovrHmdIndex+".serial: "+hmdDesc.getSerialNumberAsString()).append(Platform.getNewline());
116         sb.append("\thmd."+ovrHmdIndex+".firmware: "+hmdDesc.getFirmwareMajor()+"."+hmdDesc.getFirmwareMinor()).append(Platform.getNewline());
117         sb.append("\thmd."+ovrHmdIndex+".type: "+hmdDesc.getType()).append(Platform.getNewline());
118         sb.append("\thmd."+ovrHmdIndex+".hmdCaps: "+toHexString(hmdDesc.getHmdCaps())).append(Platform.getNewline());
119         sb.append("\thmd."+ovrHmdIndex+".distorCaps: "+toHexString(hmdDesc.getDistortionCaps())).append(Platform.getNewline());
120         sb.append("\thmd."+ovrHmdIndex+".sensorCaps: "+toHexString(hmdDesc.getTrackingCaps())).append(Platform.getNewline());
121         final ovrSizei resolution = hmdDesc.getResolution();
122         sb.append("\thmd."+ovrHmdIndex+".resolution: "+resolution.getW()+"x"+resolution.getH()).append(Platform.getNewline());
123         final ovrVector2i winPos = hmdDesc.getWindowsPos();
124         sb.append("\thmd."+ovrHmdIndex+".winPos: "+winPos.getX()+" / "+winPos.getY()).append(Platform.getNewline());
125         sb.append("\thmd."+ovrHmdIndex+".cameraFrustum.Z: "+hmdDesc.getCameraFrustumNearZInMeters()+" - "+hmdDesc.getCameraFrustumFarZInMeters()+" meter").append(Platform.getNewline());
126         sb.append("\thmd."+ovrHmdIndex+".cameraFrustum.Fov: H "+hmdDesc.getCameraFrustumHFovInRadians()+" rad, V "+hmdDesc.getCameraFrustumVFovInRadians()+" rad").append(Platform.getNewline());
127         return sb;
128     }
toHexString(final int v)129     private static String toHexString(final int v) { return "0x"+Integer.toHexString(v); }
130 
getAllAvailableCapabilitiesInfo(StringBuilder sb)131     public static StringBuilder getAllAvailableCapabilitiesInfo(StringBuilder sb) {
132         if(null==sb) {
133             sb = new StringBuilder();
134         }
135         sb.append(Platform.getNewline()).append(Platform.getNewline());
136         sb.append("HMD.0 Capabilities: ").append(Platform.getNewline());
137         getAvailableCapabilitiesInfo(0, sb);
138         return sb;
139     }
140 
main(final String args[])141     public static void main(final String args[]) {
142         System.err.println(VersionUtil.getPlatformInfo());
143         System.err.println(GlueGenVersion.getInstance());
144         // System.err.println(NativeWindowVersion.getInstance());
145         System.err.println(OVRVersion.getInstance());
146         System.err.println(OVRVersion.getAllAvailableCapabilitiesInfo(null).toString());
147     }
148 }
149 
150