Use real, not stub, values in VRViewManagerOculus
This commit is contained in:
parent
0844c9da04
commit
f0b4c13515
@ -32,6 +32,7 @@
|
|||||||
package com.jme3.util;
|
package com.jme3.util;
|
||||||
|
|
||||||
import com.jme3.app.VREnvironment;
|
import com.jme3.app.VREnvironment;
|
||||||
|
import com.jme3.input.vr.OculusVR;
|
||||||
import com.jme3.input.vr.VRAPI;
|
import com.jme3.input.vr.VRAPI;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
@ -39,13 +40,12 @@ import com.jme3.renderer.Camera;
|
|||||||
import com.jme3.renderer.ViewPort;
|
import com.jme3.renderer.ViewPort;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.texture.*;
|
import com.jme3.texture.*;
|
||||||
|
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.lwjgl.PointerBuffer;
|
|
||||||
|
|
||||||
import static com.jme3.util.VRViewManager.LEFT_VIEW_NAME;
|
import org.lwjgl.PointerBuffer;
|
||||||
import static com.jme3.util.VRViewManager.RIGHT_VIEW_NAME;
|
|
||||||
|
|
||||||
import org.lwjgl.ovr.*;
|
import org.lwjgl.ovr.*;
|
||||||
|
|
||||||
@ -63,13 +63,12 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
private static final Logger LOG = Logger.getLogger(VRViewManagerOculus.class.getName());
|
private static final Logger LOG = Logger.getLogger(VRViewManagerOculus.class.getName());
|
||||||
|
|
||||||
private final VREnvironment environment;
|
private final VREnvironment environment;
|
||||||
|
private final OculusVR hardware;
|
||||||
|
|
||||||
// The size of the texture drawn onto the HMD
|
// The size of the texture drawn onto the HMD
|
||||||
private int textureW;
|
private int textureW;
|
||||||
private int textureH;
|
private int textureH;
|
||||||
|
|
||||||
long session = 0; // TODO take from OculusVR input
|
|
||||||
|
|
||||||
// Layers to render into
|
// Layers to render into
|
||||||
private PointerBuffer layers;
|
private PointerBuffer layers;
|
||||||
private OVRLayerEyeFov layer0;
|
private OVRLayerEyeFov layer0;
|
||||||
@ -77,12 +76,7 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
/**
|
/**
|
||||||
* Chain texture set thing.
|
* Chain texture set thing.
|
||||||
*/
|
*/
|
||||||
long chain;
|
private long chain;
|
||||||
|
|
||||||
/**
|
|
||||||
* The definitions of the up/down/left/right parts of the FOV for each eye.
|
|
||||||
*/
|
|
||||||
private final OVRFovPort fovPorts[] = new OVRFovPort[2];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frame buffers we can draw into.
|
* Frame buffers we can draw into.
|
||||||
@ -92,6 +86,13 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
public VRViewManagerOculus(VREnvironment environment) {
|
public VRViewManagerOculus(VREnvironment environment) {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
|
|
||||||
|
VRAPI hardware = environment.getVRHardware();
|
||||||
|
if (!(hardware instanceof OculusVR)) {
|
||||||
|
throw new IllegalStateException("Cannot use Oculus VR view manager on non-Oculus hardware state!");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.hardware = (OculusVR) hardware;
|
||||||
|
|
||||||
if (!environment.compositorAllowed()) {
|
if (!environment.compositorAllowed()) {
|
||||||
throw new UnsupportedOperationException("Cannot render without compositor on LibOVR");
|
throw new UnsupportedOperationException("Cannot render without compositor on LibOVR");
|
||||||
}
|
}
|
||||||
@ -101,36 +102,23 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
setupCamerasAndViews();
|
setupCamerasAndViews();
|
||||||
|
|
||||||
OVRHmdDesc hmdDesc = null; // TODO take from OculusVR input
|
|
||||||
|
|
||||||
for (int eye = 0; eye < 2; eye++) {
|
|
||||||
fovPorts[eye] = hmdDesc.DefaultEyeFov(eye);
|
|
||||||
System.out.println("eye " + eye + " = "
|
|
||||||
+ fovPorts[eye].UpTan() + ", "
|
|
||||||
+ fovPorts[eye].DownTan() + ", "
|
|
||||||
+ fovPorts[eye].LeftTan() + ", "
|
|
||||||
+ fovPorts[eye].RightTan()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
findHMDTextureSize();
|
findHMDTextureSize();
|
||||||
setupTextureChain();
|
|
||||||
setupLayers();
|
setupLayers();
|
||||||
setupFramebuffers();
|
setupFramebuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findHMDTextureSize() {
|
private void findHMDTextureSize() {
|
||||||
OVRFovPort fovPorts[] = null;
|
OVRFovPort fovPorts[] = hardware.getFovPorts();
|
||||||
|
|
||||||
// Texture sizes
|
// Texture sizes
|
||||||
float pixelScaling = 1.0f; // pixelsPerDisplayPixel
|
float pixelScaling = 1.0f; // pixelsPerDisplayPixel
|
||||||
|
|
||||||
OVRSizei leftTextureSize = OVRSizei.malloc();
|
OVRSizei leftTextureSize = OVRSizei.malloc();
|
||||||
ovr_GetFovTextureSize(session, ovrEye_Left, fovPorts[ovrEye_Left], pixelScaling, leftTextureSize);
|
ovr_GetFovTextureSize(session(), ovrEye_Left, fovPorts[ovrEye_Left], pixelScaling, leftTextureSize);
|
||||||
System.out.println("leftTextureSize W=" + leftTextureSize.w() + ", H=" + leftTextureSize.h());
|
System.out.println("leftTextureSize W=" + leftTextureSize.w() + ", H=" + leftTextureSize.h());
|
||||||
|
|
||||||
OVRSizei rightTextureSize = OVRSizei.malloc();
|
OVRSizei rightTextureSize = OVRSizei.malloc();
|
||||||
ovr_GetFovTextureSize(session, ovrEye_Right, fovPorts[ovrEye_Right], pixelScaling, rightTextureSize);
|
ovr_GetFovTextureSize(session(), ovrEye_Right, fovPorts[ovrEye_Right], pixelScaling, rightTextureSize);
|
||||||
System.out.println("rightTextureSize W=" + rightTextureSize.w() + ", H=" + rightTextureSize.h());
|
System.out.println("rightTextureSize W=" + rightTextureSize.w() + ", H=" + rightTextureSize.h());
|
||||||
|
|
||||||
textureW = leftTextureSize.w() + rightTextureSize.w();
|
textureW = leftTextureSize.w() + rightTextureSize.w();
|
||||||
@ -140,6 +128,10 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
rightTextureSize.free();
|
rightTextureSize.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long session() {
|
||||||
|
return hardware.getSessionPointer();
|
||||||
|
}
|
||||||
|
|
||||||
private PointerBuffer setupTextureChain() {
|
private PointerBuffer setupTextureChain() {
|
||||||
// Set up the information for the texture buffer chain thing
|
// Set up the information for the texture buffer chain thing
|
||||||
OVRTextureSwapChainDesc swapChainDesc = OVRTextureSwapChainDesc.calloc()
|
OVRTextureSwapChainDesc swapChainDesc = OVRTextureSwapChainDesc.calloc()
|
||||||
@ -154,7 +146,7 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
|
|
||||||
// Create the chain
|
// Create the chain
|
||||||
PointerBuffer textureSetPB = createPointerBuffer(1);
|
PointerBuffer textureSetPB = createPointerBuffer(1);
|
||||||
if (OVRGL.ovr_CreateTextureSwapChainGL(session, swapChainDesc, textureSetPB) != ovrSuccess) {
|
if (OVRGL.ovr_CreateTextureSwapChainGL(session(), swapChainDesc, textureSetPB) != ovrSuccess) {
|
||||||
throw new RuntimeException("Failed to create Swap Texture Set");
|
throw new RuntimeException("Failed to create Swap Texture Set");
|
||||||
}
|
}
|
||||||
chain = textureSetPB.get(0);
|
chain = textureSetPB.get(0);
|
||||||
@ -181,7 +173,7 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
|
|
||||||
layer0.ColorTexture(chainPtr);
|
layer0.ColorTexture(chainPtr);
|
||||||
layer0.Viewport(eye, viewport);
|
layer0.Viewport(eye, viewport);
|
||||||
layer0.Fov(eye, fovPorts[eye]);
|
layer0.Fov(eye, hardware.getFovPorts()[eye]);
|
||||||
|
|
||||||
viewport.free();
|
viewport.free();
|
||||||
// we update pose only when we have it in the render loop
|
// we update pose only when we have it in the render loop
|
||||||
@ -197,7 +189,7 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
private void setupFramebuffers() {
|
private void setupFramebuffers() {
|
||||||
// Find the chain length
|
// Find the chain length
|
||||||
IntBuffer length = BufferUtils.createIntBuffer(1);
|
IntBuffer length = BufferUtils.createIntBuffer(1);
|
||||||
ovr_GetTextureSwapChainLength(session, chain, length);
|
ovr_GetTextureSwapChainLength(session(), chain, length);
|
||||||
int chainLength = length.get();
|
int chainLength = length.get();
|
||||||
|
|
||||||
System.out.println("chain length=" + chainLength);
|
System.out.println("chain length=" + chainLength);
|
||||||
@ -207,12 +199,17 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
for (int i = 0; i < chainLength; i++) {
|
for (int i = 0; i < chainLength; i++) {
|
||||||
// find the GL texture ID for this texture
|
// find the GL texture ID for this texture
|
||||||
IntBuffer textureIdB = BufferUtils.createIntBuffer(1);
|
IntBuffer textureIdB = BufferUtils.createIntBuffer(1);
|
||||||
OVRGL.ovr_GetTextureSwapChainBufferGL(session, chain, i, textureIdB);
|
OVRGL.ovr_GetTextureSwapChainBufferGL(session(), chain, i, textureIdB);
|
||||||
int textureId = textureIdB.get();
|
int textureId = textureIdB.get();
|
||||||
|
|
||||||
// TODO less hacky way of getting our texture into JMonkeyEngine
|
// TODO less hacky way of getting our texture into JMonkeyEngine
|
||||||
Texture2D tex = new Texture2D(new Image());
|
Image img = new Image();
|
||||||
tex.getImage().setId(textureId);
|
img.setId(textureId);
|
||||||
|
img.setFormat(Image.Format.RGBA8);
|
||||||
|
img.setWidth(textureW);
|
||||||
|
img.setHeight(textureH);
|
||||||
|
|
||||||
|
Texture2D tex = new Texture2D(img);
|
||||||
|
|
||||||
FrameBuffer buffer = new FrameBuffer(textureW, textureH, 1);
|
FrameBuffer buffer = new FrameBuffer(textureW, textureH, 1);
|
||||||
buffer.setDepthBuffer(Image.Format.Depth);
|
buffer.setDepthBuffer(Image.Format.Depth);
|
||||||
@ -235,7 +232,7 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
// layer0.RenderPose(eye, eyePose);
|
// layer0.RenderPose(eye, eyePose);
|
||||||
|
|
||||||
IntBuffer currentIndexB = BufferUtils.createIntBuffer(1);
|
IntBuffer currentIndexB = BufferUtils.createIntBuffer(1);
|
||||||
ovr_GetTextureSwapChainCurrentIndex(session, chain, currentIndexB);
|
ovr_GetTextureSwapChainCurrentIndex(session(), chain, currentIndexB);
|
||||||
int index = currentIndexB.get();
|
int index = currentIndexB.get();
|
||||||
|
|
||||||
(eye == 0 ? leftViewPort : rightViewPort).setOutputFrameBuffer(framebuffers[index]);
|
(eye == 0 ? leftViewPort : rightViewPort).setOutputFrameBuffer(framebuffers[index]);
|
||||||
@ -247,10 +244,10 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
@Override
|
@Override
|
||||||
public void postRender() {
|
public void postRender() {
|
||||||
// We're done with our textures now - the game is done drawing into them.
|
// We're done with our textures now - the game is done drawing into them.
|
||||||
ovr_CommitTextureSwapChain(session, chain);
|
ovr_CommitTextureSwapChain(session(), chain);
|
||||||
|
|
||||||
// Send the result to the HMD
|
// Send the result to the HMD
|
||||||
int result = ovr_SubmitFrame(session, 0, null, layers);
|
int result = ovr_SubmitFrame(session(), 0, null, layers);
|
||||||
if (result != ovrSuccess) {
|
if (result != ovrSuccess) {
|
||||||
throw new IllegalStateException("Failed to submit frame!");
|
throw new IllegalStateException("Failed to submit frame!");
|
||||||
}
|
}
|
||||||
@ -261,6 +258,7 @@ public class VRViewManagerOculus extends AbstractVRViewManager {
|
|||||||
* Show's over, now it's just boring camera stuff etc. *
|
* Show's over, now it's just boring camera stuff etc. *
|
||||||
*********************************************************
|
*********************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the cameras and views for each eye and the mirror display.
|
* Set up the cameras and views for each eye and the mirror display.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user