use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method setupViewBuffers.
private ViewPort setupViewBuffers(Camera cam, String viewName) {
if (environment != null) {
if (environment.getApplication() != null) {
// create offscreen framebuffer
FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
//offBufferLeft.setSrgb(true);
//setup framebuffer's texture
Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBufferLeft.setDepthBuffer(Image.Format.Depth);
offBufferLeft.setColorTexture(offTex);
ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
viewPort.attachScene(spatialIter.next());
}
//set viewport to render to offscreen framebuffer
viewPort.setOutputFrameBuffer(offBufferLeft);
return viewPort;
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOSVR method initialize.
/**
* Initialize the VR view manager.
*/
public void initialize() {
logger.config("Initializing VR view manager.");
if (environment != null) {
initTextureSubmitStructs();
setupCamerasAndViews();
setupVRScene();
moveScreenProcessingToEyes();
if (environment.hasTraditionalGUIOverlay()) {
environment.getVRMouseManager().initialize();
// update the pose to position the gui correctly on start
update(0f);
environment.getVRGUIManager().positionGui();
}
if (environment.getApplication() != null) {
// if we are OSVR, our primary mirror window needs to be the same size as the render manager's output...
if (environment.getVRHardware() instanceof OSVR) {
int origWidth = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth();
int origHeight = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight();
long window = ((LwjglWindow) environment.getApplication().getContext()).getWindowHandle();
Vector2f windowSize = new Vector2f();
((OSVR) environment.getVRHardware()).getRenderSize(windowSize);
windowSize.x = Math.max(windowSize.x * 2f, leftCamera.getWidth());
org.lwjgl.glfw.GLFW.glfwSetWindowSize(window, (int) windowSize.x, (int) windowSize.y);
environment.getApplication().getContext().getSettings().setResolution((int) windowSize.x, (int) windowSize.y);
if (environment.getApplication().getRenderManager() != null) {
environment.getApplication().getRenderManager().notifyReshape((int) windowSize.x, (int) windowSize.y);
}
org.lwjgl.glfw.GLFW.glfwSetWindowPos(window, origWidth - (int) windowSize.x, 32);
org.lwjgl.glfw.GLFW.glfwFocusWindow(window);
org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0);
logger.config("Initialized VR view manager [SUCCESS]");
} else {
throw new IllegalStateException("Underlying VR hardware should be " + OSVR.class.getSimpleName());
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method prepareCameraSize.
/**
* Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
* @param cam the {@link Camera camera} to prepare.
* @param xMult the camera width multiplier.
*/
private void prepareCameraSize(Camera cam, float xMult) {
if (environment != null) {
if (environment.getApplication() != null) {
Vector2f size = new Vector2f();
VRAPI vrhmd = environment.getVRHardware();
if (vrhmd == null) {
size.x = 1280f;
size.y = 720f;
} else {
vrhmd.getRenderSize(size);
}
if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
size.x = environment.getApplication().getContext().getSettings().getWidth();
}
if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
size.y = environment.getApplication().getContext().getSettings().getHeight();
}
if (environment.isInstanceRendering()) {
size.x *= 2f;
}
// other adjustments
size.x *= xMult;
size.x *= getResolutionMuliplier();
size.y *= getResolutionMuliplier();
if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
cam.resize((int) size.x, (int) size.y, false);
}
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method setupMirrorBuffers.
private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {
if (environment != null) {
if (environment.getApplication() != null) {
Camera clonecam = cam.clone();
ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
clonecam.setParallelProjection(true);
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
Picture pic = new Picture("fullscene");
pic.setLocalTranslation(-0.75f, -0.5f, 0f);
if (expand) {
pic.setLocalScale(3f, 1f, 1f);
} else {
pic.setLocalScale(1.5f, 1f, 1f);
}
pic.setQueueBucket(Bucket.Opaque);
pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false);
viewPort.attachScene(pic);
viewPort.setOutputFrameBuffer(null);
pic.updateGeometricState();
return viewPort;
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.
the class VRViewManagerOpenVR method setupViewBuffers.
private ViewPort setupViewBuffers(Camera cam, String viewName) {
if (environment != null) {
if (environment.getApplication() != null) {
// create offscreen framebuffer
FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
//offBufferLeft.setSrgb(true);
//setup framebuffer's texture
Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBufferLeft.setDepthBuffer(Image.Format.Depth);
offBufferLeft.setColorTexture(offTex);
ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
viewPort.setClearFlags(true, true, true);
viewPort.setBackgroundColor(ColorRGBA.Black);
Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
while (spatialIter.hasNext()) {
viewPort.attachScene(spatialIter.next());
}
//set viewport to render to offscreen framebuffer
viewPort.setOutputFrameBuffer(offBufferLeft);
return viewPort;
} else {
throw new IllegalStateException("This VR environment is not attached to any application.");
}
} else {
throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
}
}
Aggregations