use of gaiasky.vr.openvr.VRContext in project gaiasky by langurmonkey.
the class GaiaSky method createVR.
/**
* Attempt to create a VR context. This operation will only succeed if an HMD is connected
* and detected via OpenVR
*/
private VRStatus createVR() {
if (vr) {
// is not installed.
try {
// OpenVRQuery.queryOpenVr();
settings.runtime.openVr = true;
Constants.initialize(settings.scene.distanceScaleVr);
vrContext = new VRContext();
vrContext.pollEvents();
final VRDevice hmd = vrContext.getDeviceByType(VRDeviceType.HeadMountedDisplay);
logger.info("Initialization of VR successful");
if (hmd == null) {
logger.info("HMD device is null!");
} else {
logger.info("HMD device is not null: " + vrContext.getDeviceByType(VRDeviceType.HeadMountedDisplay).toString());
}
vrDeviceToModel = new HashMap<>();
if (settings.graphics.resolution[0] != vrContext.getWidth()) {
logger.info("Warning, resizing according to VRSystem values: [" + settings.graphics.resolution[0] + "x" + settings.graphics.resolution[1] + "] -> [" + vrContext.getWidth() + "x" + vrContext.getHeight() + "]");
// Do not resize the screen!
settings.graphics.backBufferResolution[1] = vrContext.getHeight();
settings.graphics.backBufferResolution[0] = vrContext.getWidth();
// this.resizeImmediate(vrContext.getWidth(), vrContext.getHeight(), true, true, true);
}
settings.graphics.vsync = false;
graphics.setWindowedMode(settings.graphics.resolution[0], settings.graphics.resolution[1]);
graphics.setVSync(settings.graphics.vsync);
vrLoadingLeftFb = new FrameBuffer(Format.RGBA8888, vrContext.getWidth(), vrContext.getHeight(), true);
vrLoadingLeftTex = org.lwjgl.openvr.Texture.create();
vrLoadingLeftTex.set(vrLoadingLeftFb.getColorBufferTexture().getTextureObjectHandle(), VR.ETextureType_TextureType_OpenGL, VR.EColorSpace_ColorSpace_Gamma);
vrLoadingRightFb = new FrameBuffer(Format.RGBA8888, vrContext.getWidth(), vrContext.getHeight(), true);
vrLoadingRightTex = org.lwjgl.openvr.Texture.create();
vrLoadingRightTex.set(vrLoadingRightFb.getColorBufferTexture().getTextureObjectHandle(), VR.ETextureType_TextureType_OpenGL, VR.EColorSpace_ColorSpace_Gamma);
// Sprite batch for VR - uses back buffer resolution
globalResources.setSpriteBatchVR(new SpriteBatch(500, globalResources.getSpriteShader()));
globalResources.getSpriteBatchVR().getProjectionMatrix().setToOrtho2D(0, 0, settings.graphics.backBufferResolution[0], settings.graphics.backBufferResolution[1]);
// Enable visibility of 'Others' if off (for VR controllers)
if (!settings.scene.visibility.get(ComponentType.Others.name())) {
EventManager.publish(Event.TOGGLE_VISIBILITY_CMD, this, "element.others", false);
}
return VRStatus.OK;
} catch (Exception e) {
// If initializing the VRContext failed
settings.runtime.openVr = false;
logger.error(e);
logger.error("Initialisation of VR context failed");
return VRStatus.ERROR_NO_CONTEXT;
}
} else {
// Desktop mode
settings.runtime.openVr = false;
Constants.initialize(settings.scene.distanceScaleDesktop);
}
return VRStatus.NO_VR;
}
use of gaiasky.vr.openvr.VRContext in project gaiasky by langurmonkey.
the class CrashReporter method appendSystemInfo.
private static void appendSystemInfo(Array<String> strArray) {
/* Gaia Sky info */
if (Settings.settings.version != null) {
strArray.add("");
strArray.add("## GAIA SKY INFORMATION");
strArray.add("Version: " + Settings.settings.version.version);
strArray.add("Build: " + Settings.settings.version.build);
strArray.add("Builder: " + Settings.settings.version.builder);
strArray.add("System: " + Settings.settings.version.system);
strArray.add("Build time: " + Settings.settings.version.buildTime);
}
/* Java info */
strArray.add("");
strArray.add("## JAVA INFORMATION");
strArray.add("Java version: " + System.getProperty("java.version"));
strArray.add("Java runtime name: " + System.getProperty("java.runtime.name"));
strArray.add("Java VM name: " + System.getProperty("java.vm.name"));
strArray.add("Java VM version: " + System.getProperty("java.vm.version"));
strArray.add("Java VM vendor: " + System.getProperty("java.vm.vendor"));
/* System information */
strArray.add("");
strArray.add("## SYSTEM INFORMATION");
try {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
CentralProcessor cp = hal.getProcessor();
strArray.add("CPU: " + cp.getProcessorIdentifier().getName());
strArray.add(cp.getProcessorIdentifier().getIdentifier());
strArray.add("Proc ID: " + cp.getProcessorIdentifier().getProcessorID());
strArray.add("CPU Family: " + cp.getProcessorIdentifier().getFamily());
strArray.add(cp.getPhysicalPackageCount() + " physical CPU package(s)");
strArray.add(cp.getPhysicalProcessorCount() + " physical CPU core(s)");
int nLp = cp.getLogicalProcessorCount();
strArray.add(nLp + " logical CPU(s)");
} catch (Error e) {
strArray.add("Could not get CPU information!");
}
String mbUnits = " MB";
strArray.add("Java used memory: " + MemInfo.getUsedMemory() + mbUnits);
strArray.add("Java free memory: " + MemInfo.getFreeMemory() + mbUnits);
strArray.add("Java total memory: " + MemInfo.getTotalMemory() + mbUnits);
strArray.add("Java max memory (-Xmx): " + MemInfo.getMaxMemory() + mbUnits);
strArray.add("Total system RAM: " + MemInfo.getTotalRam() + mbUnits);
File[] roots = File.listRoots();
for (File root : roots) {
strArray.add(" # File system root: " + root.getAbsolutePath());
strArray.add(" Total space: " + (root.getTotalSpace() * Constants.BYTE_TO_MB) + mbUnits);
strArray.add(" Free space: " + (root.getFreeSpace() * Constants.BYTE_TO_MB) + mbUnits);
strArray.add(" Usable space: " + (root.getUsableSpace() * Constants.BYTE_TO_MB) + mbUnits);
}
/* OS info */
strArray.add("");
strArray.add("## OS INFORMATION");
try {
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
strArray.add("OS name: " + os.toString());
strArray.add("OS version: " + System.getProperty("os.version"));
strArray.add("OS architecture: " + System.getProperty("os.arch"));
strArray.add("Booted: " + Instant.ofEpochSecond(os.getSystemBootTime()));
strArray.add("Uptime: " + FormatUtil.formatElapsedSecs(si.getOperatingSystem().getSystemUptime()));
} catch (Exception e) {
strArray.add("OS name: " + System.getProperty("os.name"));
strArray.add("OS version: " + System.getProperty("os.version"));
strArray.add("OS architecture: " + System.getProperty("os.arch"));
}
try {
/* GL info */
strArray.add("");
strArray.add("## GL INFORMATION");
strArray.add("Graphcis device: " + Gdx.gl.glGetString(GL20.GL_RENDERER));
strArray.add("GL vendor: " + Gdx.gl.glGetString(GL20.GL_VENDOR));
strArray.add("GL version: " + Gdx.gl.glGetString(GL20.GL_VERSION));
strArray.add("GLSL version: " + Gdx.gl.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
String extensions = Gdx.gl.glGetString(GL20.GL_EXTENSIONS);
IntBuffer buf = BufferUtils.newIntBuffer(16);
if (extensions == null || extensions.isEmpty()) {
Gdx.gl.glGetIntegerv(GL30.GL_NUM_EXTENSIONS, buf);
int next = buf.get(0);
String[] extensionsString = new String[next];
for (int i = 0; i < next; i++) {
extensionsString[i] = Gdx.gl30.glGetStringi(GL30.GL_EXTENSIONS, i);
}
extensions = TextUtils.arrayToStr(extensionsString, "", "", " ");
}
strArray.add("GL extensions: " + extensions);
Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, buf);
int maxSize = buf.get(0);
strArray.add("GL max texture size: " + maxSize);
} catch (Exception e) {
strArray.add("## GL INFORMATION not available");
}
if (Settings.settings.runtime.openVr) {
VRContext vrContext = GaiaSky.instance.vrContext;
if (vrContext != null) {
/* VR info **/
strArray.add("");
strArray.add("## VR INFORMATION");
strArray.add("VR resolution: " + vrContext.getWidth() + "x" + vrContext.getHeight());
Array<VRDevice> devices = vrContext.getDevices();
for (VRDevice device : devices) {
strArray.add("Device: " + device.renderModelName);
strArray.add(" Model number: " + device.modelNumber);
strArray.add(" Manufacturer: " + device.manufacturerName);
strArray.add(" Role: " + device.getControllerRole());
strArray.add(" Type: " + device.getType());
strArray.add(" Index: " + (device.getPose() != null ? device.getPose().getIndex() : "null"));
}
}
}
}
use of gaiasky.vr.openvr.VRContext in project gaiasky by langurmonkey.
the class GaiaSky method create.
@Override
public void create() {
startTime = TimeUtils.millis();
// Log level
Gdx.app.setLogLevel(debugMode ? Application.LOG_DEBUG : Application.LOG_INFO);
Logger.level = debugMode ? Logger.LoggerLevel.DEBUG : Logger.LoggerLevel.INFO;
consoleLogger = new ConsoleLogger();
if (debugMode)
logger.debug("Logging level set to DEBUG");
// Init graphics and window
graphics = Gdx.graphics;
window = headless ? null : ((Lwjgl3Graphics) graphics).getWindow();
// Basic info
logger.info(settings.version.version, I18n.txt("gui.build", settings.version.build));
logger.info("Display mode", graphics.getWidth() + "x" + graphics.getHeight(), "Fullscreen: " + Gdx.graphics.isFullscreen());
logger.info("Device", GL30.glGetString(GL30.GL_RENDERER));
logger.info(I18n.txt("notif.glversion", GL30.glGetString(GL30.GL_VERSION)));
logger.info(I18n.txt("notif.glslversion", GL30.glGetString(GL30.GL_SHADING_LANGUAGE_VERSION)));
logger.info(I18n.txt("notif.javaversion", System.getProperty("java.version"), System.getProperty("java.vendor")));
// Frame buffer map
frameBufferMap = new HashMap<>();
// Disable all kinds of input
EventManager.publish(Event.INPUT_ENABLED_CMD, this, false);
if (!settings.initialized) {
logger.error(new RuntimeException(I18n.txt("notif.error", "global configuration not initialized")));
return;
}
// Initialise times
final ITimeFrameProvider clock = new GlobalClock(1, Instant.now());
final ITimeFrameProvider real = new RealTimeClock();
time = settings.runtime.realTime ? real : clock;
t = 0;
// Initialise i18n
I18n.initialize();
// Tooltips
TooltipManager.getInstance().initialTime = 1f;
TooltipManager.getInstance().hideAll();
// Initialise asset manager
final FileHandleResolver internalResolver = new InternalFileHandleResolver();
final FileHandleResolver dataResolver = fileName -> settings.data.dataFileHandle(fileName);
assetManager = new AssetManager(internalResolver);
assetManager.setLoader(com.badlogic.gdx.graphics.Texture.class, ".pfm", new PFMTextureLoader(dataResolver));
assetManager.setLoader(PFMData.class, new PFMDataLoader(dataResolver));
assetManager.setLoader(ISceneGraph.class, new SGLoader(dataResolver));
assetManager.setLoader(PointCloudData.class, new OrbitDataLoader(dataResolver));
assetManager.setLoader(GaiaAttitudeServer.class, new GaiaAttitudeLoader(dataResolver));
assetManager.setLoader(ExtShaderProgram.class, new ShaderProgramProvider(internalResolver, ".vertex.glsl", ".fragment.glsl"));
assetManager.setLoader(BitmapFont.class, new BitmapFontLoader(internalResolver));
assetManager.setLoader(AtmosphereShaderProvider.class, new AtmosphereShaderProviderLoader<>(internalResolver));
assetManager.setLoader(GroundShaderProvider.class, new GroundShaderProviderLoader<>(internalResolver));
assetManager.setLoader(TessellationShaderProvider.class, new TessellationShaderProviderLoader<>(internalResolver));
assetManager.setLoader(RelativisticShaderProvider.class, new RelativisticShaderProviderLoader<>(internalResolver));
assetManager.setLoader(IntModel.class, ".obj", new OwnObjLoader(new RegularInputStreamProvider(), internalResolver));
assetManager.setLoader(IntModel.class, ".obj.gz", new OwnObjLoader(new GzipInputStreamProvider(), internalResolver));
assetManager.setLoader(IntModel.class, ".g3dj", new G3dModelLoader(new JsonReader(), internalResolver));
assetManager.setLoader(IntModel.class, ".g3db", new G3dModelLoader(new UBJsonReader(), internalResolver));
// Remove Model loaders
// Init global resources
this.globalResources = new GlobalResources(assetManager);
// Initialize screenshots manager
new ScreenshotsManager(globalResources);
// Catalog manager
this.catalogManager = new CatalogManager();
this.scripting = new EventScriptingInterface(this.assetManager, this.catalogManager);
// Initialise master manager
MasterManager.initialize();
// Load slave assets
SlaveManager.load(assetManager);
// Initialise dataset updater
this.executorService = new GaiaSkyExecutorService();
// Bookmarks
this.bookmarksManager = new BookmarksManager();
// Location log
LocationLogManager.initialize();
// Init timer thread
Timer.instance();
// Initialise Cameras
cameraManager = new CameraManager(assetManager, CameraMode.FOCUS_MODE, vr, globalResources);
// Set asset manager to asset bean
AssetBean.setAssetManager(assetManager);
// Create vr context if possible
final VRStatus vrStatus = createVR();
cameraManager.updateFrustumPlanes();
// Tooltip to 1s
TooltipManager.getInstance().initialTime = 1f;
// Initialise Gaia attitudes
assetManager.load(Constants.ATTITUDE_FOLDER, GaiaAttitudeServer.class, new GaiaAttitudeLoaderParameter());
// Initialise hidden helper user
HiddenHelperUser.initialize();
// Initialise gravitational waves helper
RelativisticEffectsManager.initialize(time);
// GUI
guis = new ArrayList<>(3);
// Post-processor
postProcessor = PostProcessorFactory.instance.getPostProcessor();
// Scene graph renderer
sgr = new SceneGraphRenderer(vrContext, globalResources);
sgr.initialize(assetManager);
// Initialise scripting gateway server
if (!noScripting)
ScriptingServer.initialize();
// Tell the asset manager to load all the assets
final Set<AssetBean> assets = AssetBean.getAssets();
for (AssetBean ab : assets) {
ab.load(assetManager);
}
renderBatch = globalResources.getSpriteBatch();
EventManager.instance.subscribe(this, Event.LOAD_DATA_CMD);
welcomeGui = new WelcomeGui(globalResources.getSkin(), graphics, 1f / settings.program.ui.scale, skipWelcome, vrStatus);
welcomeGui.initialize(assetManager, globalResources.getSpriteBatch());
Gdx.input.setInputProcessor(welcomeGui.getGuiStage());
if (settings.runtime.openVr) {
welcomeGuiVR = new VRGui<>(WelcomeGuiVR.class, (int) (settings.graphics.backBufferResolution[0] / 2f), globalResources.getSkin(), graphics, 1f / settings.program.ui.scale);
welcomeGuiVR.initialize(assetManager, globalResources.getSpriteBatch());
}
// GL clear state
Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClearDepthf(1f);
}
Aggregations