LWJGL 3 with Oculus Rift

Started by BrickFarmer, February 12, 2015, 11:55:48

Previous topic - Next topic

Mickelukas

Quote from: BrickFarmer on July 29, 2015, 17:12:31
Thanks!!  Well I downloaded the nightly and it took me 10 mins to update a few API changes and implement the new performance HUD from the latest SDK (F11 in my demo) so that's already a much easier process :)

Could you share your build of the ovr natives? Does anything need to change in the jar as well or is 3.0.0b build 9 enough? I upgraded to LWJGL 3 just because of libOVR after you told me that it was getting along nicely :)

Spasi, when do you think that you will have time to add the 0.7.0 api? It looks like a great SDK version with several simplifications.

spasi

I'll work on 0.7.0 tomorrow.

Mickelukas

Quote from: spasi on August 28, 2015, 15:55:44
I'll work on 0.7.0 tomorrow.

You chose GLFW for (among other things) great support. We stick with LWJGL because of you!  ;D

spasi

The latest nightly build (3.0.0b #22) includes updated LibOVR bindings for the 0.7.0 Oculus SDK.

Quote from: Mickelukas on August 28, 2015, 16:30:44You chose GLFW for (among other things) great support. We stick with LWJGL because of you!  ;D

<3

Mickelukas

Amazing! Brickfarmer, as you already have the build environment up and running, do you mind building the dll and share it? There's only a 64 bit version nowadays I saw.

BrickFarmer

Quote from: spasi on August 29, 2015, 09:50:32
The latest nightly build (3.0.0b #22) includes updated LibOVR bindings for the 0.7.0 Oculus SDK.

Nice! I was just on my way over here to ask about that :)  I will get my demo updated. 
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon

BrickFarmer

Quote from: Mickelukas on August 29, 2015, 11:28:17
Amazing! Brickfarmer, as you already have the build environment up and running, do you mind building the dll and share it? There's only a 64 bit version nowadays I saw.

I think that's correct, the Oculus runtime is 64bit only now.  So the dll that's included in the LWJGL 3 build mentioned above should work fine without a custom build.
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon

BrickFarmer

Ok. so I worked out most of the changes I think, but at runtime I'm seeing a failed to load library jemalloc.dll

I'm using the SharedLibraryLoader approach, which seems to locate the libOVR with no problem.
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon

spasi

I don't think SharedLibrarryLoader has been updated to handle jemalloc. In any case, LWJGL has a fallback if jemalloc is not available, does that fail too?

BrickFarmer

well the create seems to pass, but then the OVRHmdDesc is giving back 0x0 resolution.  Although it might be to do with this new Luid parameter on the create, since I only pass a buffer from a created instance of OVRGraphicsLuid, ie I'm not populating it.

[edit] actually reading the change log the luid is passed back from the call, so the only other change I can see that might be related is this:

"Changed ovrHmd from a struct pointer to an opaque pointer and left ovrHmdDesc as a separate struct."
https://developer.oculus.com/history/

Could it be related to empty/corrupt values in the desc?
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon

spasi

Quote from: BrickFarmer on August 30, 2015, 15:00:11"Changed ovrHmd from a struct pointer to an opaque pointer and left ovrHmdDesc as a separate struct."
https://developer.oculus.com/history/

Could it be related to empty/corrupt values in the desc?

I don't think so, ovrHmdDesc is also a struct returned from LibOVR (from ovr_GetHmdDesc(hmd)), you don't have to set anything in it. The change to ovrHmd is a change at the native side only, the Java API didn't change from 0.6 to 0.7.

Other than Resolution being set to 0x0, are you having other problems?

BrickFarmer

Quote from: spasi on August 30, 2015, 18:28:31
Other than Resolution being set to 0x0, are you having other problems?

To me it seems like the desc struct has not populated.  Anyway if I hack in some dimensions, then the code just fails a bit further along with some d3d swap chain creation error, ie something internal to the SDK.

Any tip on how I can resolve the jemalloc error, maybe it's just that causing these problem. Is that a new dependency from libOVR or something from LWJGL?
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon

Kai

Quote from: BrickFarmer on August 31, 2015, 08:22:48
...along with some d3d swap chain creation error, ie something internal to the SDK.
D3D swap chain? Is libOVR using DirectX/Direct3D?? o_O
Thought it would use OpenGL. Do they use Direct3D internally (which would explain why it's Windows-only) and just want the application to blit the framebuffer into an OpenGL texture, which they then display via Direct3D?

spasi

Quote from: BrickFarmer on August 31, 2015, 08:22:48To me it seems like the desc struct has not populated.  Anyway if I hack in some dimensions, then the code just fails a bit further along with some d3d swap chain creation error, ie something internal to the SDK.

Could you share your init code? From the 0.7.0 OpenGL sample:

ovrHmd HMD;
ovrGraphicsLuid luid;
ovrResult result = ovr_Create(&HMD, &luid);
if (!OVR_SUCCESS(result))
    return retryCreate;

ovrHmdDesc hmdDesc = ovr_GetHmdDesc(HMD);

// Setup Window and Graphics
// Note: the mirror window can be any size, for this sample we use 1/2 the HMD resolution
ovrSizei windowSize = { hmdDesc.Resolution.w / 2, hmdDesc.Resolution.h / 2 };


Looks simple enough. Btw, have you updated the Oculus Runtime to 0.7.0 on your machine?

Quote from: BrickFarmer on August 31, 2015, 08:22:48Any tip on how I can resolve the jemalloc error, maybe it's just that causing these problem. Is that a new dependency from libOVR or something from LWJGL?

No, jemalloc has nothing to do with LibOVR. See this topic for details.

Since you're using maven/gradle + SharedLibraryLoader, you need to update it to handle the jemalloc binaries. It currently only handles the lwjgl and openal binaries. Note that, at some point before the 3.0 release, I'll add SharedLibraryLoader (or something like it) to LWJGL and it will always be up-to-date.

In any case, it shouldn't be a problem. When LWJGL fails to load jemalloc, it falls back to the standard C library malloc functions. Functionally it's the same thing, except slower.

BrickFarmer

Here is my init code:

        // step 1 - hmd init
        System.out.println("step 1 - hmd init");
        OVRLogCallback callback = new OVRLogCallback() {
            @Override
            public void invoke(long userData, int level, long message) {
                System.out.println("LibOVR [" + userData + "] [" +  level + "] " + memDecodeASCII(message));
            }
        };
        OVRInitParams initParams = new OVRInitParams();
        initParams.setLogCallback(callback.getPointer());
       // initParams.setFlags(ovrInit_Debug);
        if  (ovr_Initialize(initParams.buffer()) != ovrSuccess) {
            System.out.println("init failed");
        }
        System.out.println("OVR SDK " + ovr_GetVersionString());
        
        // step 2 - hmd create
        System.out.println("step 2 - hmd create");
        PointerBuffer pHmd = BufferUtils.createPointerBuffer(1);
        OVRGraphicsLuid luid = new OVRGraphicsLuid();
        if (ovr_Create(pHmd, luid.buffer()) != ovrSuccess) {
            System.out.println("create failed, try debug");
            //debug headset is now enabled via the Oculus Configuration util . tools -> Service -> Configure
            return;
        }

        // step 3 - hmdDesc queries
        System.out.println("step 3 - hmdDesc queries");
        hmd = pHmd.get(0);
        hmdDesc = new OVRHmdDesc(MemoryUtil.memByteBuffer(hmd, OVRHmdDesc.SIZEOF));
        
        
        System.out.println(hmdDesc.getProductNameString()+"-"+hmdDesc.getType());
        
        if(hmdDesc.getType() == ovrHmd_None) {
            System.out.println("missing init");
        }
        
        resolutionW = hmdDesc.getResolutionW();
        resolutionH = hmdDesc.getResolutionH();
        canvasRatio = (float)resolutionW/resolutionH;
        System.out.println("resolution W=" + resolutionW + ", H=" + resolutionH);


https://github.com/WhiteHexagon/example-lwjgl3-rift/blob/master/src/main/java/com/sunshineapps/rift/experimental/RiftWindow0700.java

Yes my system is now 0700 and I checked there is no old version there.  The oculus config demo scene works fine.  I will  ignore the jemalloc for now, but maybe the exception could be caught going forwards?

Java 1.8.0_45
LWJGL lwjgl-3.0.0b
step 0 - create rift
step 1 - hmd init
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.lwjgl.system.MemoryManage.getInstance(MemoryManage.java:24)
	at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:60)
	at org.lwjgl.system.libffi.Closure.<clinit>(Closure.java:44)
	at com.sunshineapps.rift.experimental.RiftWindow0700.<init>(RiftWindow0700.java:130)
	at com.sunshineapps.rift.experimental.Client.run(Client.java:28)
	at com.sunshineapps.rift.experimental.Client.main(Client.java:88)
Caused by: java.lang.ExceptionInInitializerError
	at org.lwjgl.system.jemalloc.JEmalloc.getInstance(JEmalloc.java:79)
	... 10 more
Caused by: java.lang.RuntimeException: Failed to load library: jemalloc.dll (error code = 126)
	at org.lwjgl.system.windows.WindowsUtil.windowsThrowException(WindowsUtil.java:28)
	at org.lwjgl.system.windows.WindowsLibrary.<init>(WindowsLibrary.java:34)
	at org.lwjgl.system.APIUtil.apiCreateLibrary(APIUtil.java:54)
	at org.lwjgl.LWJGLUtil.loadLibraryNative(LWJGLUtil.java:164)
	at org.lwjgl.system.jemalloc.LibJEmalloc.create(LibJEmalloc.java:35)
	at org.lwjgl.system.jemalloc.LibJEmalloc.create(LibJEmalloc.java:26)
	at org.lwjgl.system.jemalloc.LibJEmalloc.<clinit>(LibJEmalloc.java:19)
	... 11 more
LibOVR [0] [1] 09/01/15 11:06:30: [CAPI] LibOVR module is located at C:\Windows\system32\LibOVRRT64_0_7.dll

OVR SDK 0.7.0.0
step 2 - hmd create
step 3 - hmdDesc queries
y-1381376115
resolution W=0, H=0
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon