Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a GraphicsPropertiesFetcher class #2071

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
13691a3
Merge pull request #1 from PhoenicisOrg/master
ImperatorS79 Jan 21, 2019
ff9b79c
Merge pull request #2 from PhoenicisOrg/master
ImperatorS79 Aug 25, 2019
0774f93
Update pom.xml
ImperatorS79 Aug 25, 2019
1610c5e
Add files via upload
ImperatorS79 Aug 25, 2019
0adb378
Update ToolsConfiguration.java
ImperatorS79 Aug 25, 2019
f9095d5
Update GraphicsProperties.java
ImperatorS79 Aug 25, 2019
ec9a3ef
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 25, 2019
3e6eeab
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 25, 2019
a424044
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 25, 2019
090bd4e
Fix OpenGL library not being loadable multiple times
ImperatorS79 Aug 25, 2019
1d5b026
Update GraphicsProperties.java
ImperatorS79 Aug 25, 2019
cd869f3
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 25, 2019
e3bb0f8
Update GraphicsProperties.java
ImperatorS79 Aug 25, 2019
121ae07
Update GraphicsProperties.java
ImperatorS79 Aug 25, 2019
7cb22be
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 25, 2019
2030616
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 25, 2019
3678f8f
Fix travis and tr
ImperatorS79 Aug 25, 2019
1d70003
Also fetch core context Version
ImperatorS79 Aug 27, 2019
f40bf65
Update GraphicsPropertiesFetcher.java
ImperatorS79 Aug 27, 2019
386ecc0
Codacy I saw you
ImperatorS79 Aug 27, 2019
13fb641
Update pom.xml
ImperatorS79 Aug 27, 2019
986beaf
Update pom.xml
ImperatorS79 Aug 27, 2019
5d50f1c
Update GraphicsProperties.java
ImperatorS79 Sep 6, 2019
62faa23
Update GraphicsPropertiesFetcher.java
ImperatorS79 Sep 6, 2019
0d1559c
Update GraphicsPropertiesFetcher.java
ImperatorS79 Oct 3, 2019
10ddec0
Merge pull request #3 from PhoenicisOrg/master
ImperatorS79 Oct 3, 2019
35e9b1e
It builds
ImperatorS79 Oct 3, 2019
8ebc6ca
Update pom.xml
ImperatorS79 Oct 5, 2019
a50e013
Update pom.xml
ImperatorS79 Oct 5, 2019
36b1b4f
Test
ImperatorS79 Jan 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions phoenicis-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<artifactId>phoenicis-tools</artifactId>
<properties>
<project.root>${project.basedir}/../</project.root>
<lwjgl.version>3.2.2</lwjgl.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -126,5 +127,71 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-vulkan</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-glfw</artifactId>
<version>${lwjgl.version}</version>
<classifier>${lwjgl.natives}</classifier>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-opengl</artifactId>
<version>${lwjgl.version}</version>
<classifier>${lwjgl.natives}</classifier>
</dependency>
</dependencies>
<profiles>
<profile>
<id>lwjgl-natives-linux-amd64</id>
<activation>
<os>
<family>unix</family>
<arch>amd64</arch>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we limiting us in any way if we specify amd64 here?

Copy link
Contributor Author

@ImperatorS79 ImperatorS79 Aug 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comes straight from LWJGL website so I do not know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On linux and macOS LWJGL is only available in 64 bits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you run the code with Linux 32 bit or an older mac?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would not work, obviously. De we really want to support such old architecture ? If so, the only possible solution is to write that as an external C++ code or to simply use glxinfo/vulkaninfo as stated in #2061.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to support as many platforms as we comfortably can. In my opinion it is likely that quite a lot of people still use older 32 bit hardware, with an older Linux 32 bit OS, but i think we should ask for some more opinions, @plata @qparis what do you think about this?

</os>
</activation>
<properties>
<lwjgl.natives>natives-linux</lwjgl.natives>
<lwjgl.natives.vulkan></lwjgl.natives.vulkan>
</properties>
</profile>
<profile>
<id>lwjgl-natives-macos-amd64</id>
<activation>
<os>
<family>mac</family>
<arch>amd64</arch>
</os>
</activation>
<properties>
<lwjgl.natives>natives-macos</lwjgl.natives>
<lwjgl.natives.vulkan>natives-macos</lwjgl.natives.vulkan>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.phoenicis.tools.system.ArchitectureFetcher;
import org.phoenicis.tools.system.OperatingSystemFetcher;
import org.phoenicis.tools.system.ScreenManager;
import org.phoenicis.tools.system.GraphicsPropertiesFetcher;
import org.phoenicis.tools.system.SystemConfiguration;
import org.phoenicis.tools.system.opener.AutomaticOpener;
import org.phoenicis.tools.system.opener.Opener;
Expand Down Expand Up @@ -167,4 +168,9 @@ public LnkParser lnkParser() {
public ScreenManager screenManager() {
return new ScreenManager();
}

@Bean
public GraphicsPropertiesFetcher graphicsPropertiesFetcher() {
return new GraphicsPropertiesFetcher();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2015-2017 PÂRIS Quentin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.phoenicis.tools.system;

import org.phoenicis.configuration.security.Safe;

@Safe
public class GraphicsProperties {
public String vendor;
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
public String renderer;
public String openGLVersion;
public String vulkanVersion;

public GraphicsProperties() {
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
vendor = "Unknown";
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
renderer = "Unknown";
openGLVersion = "Unsupported";
vulkanVersion = "Unsupported";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2015-2017 PÂRIS Quentin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.phoenicis.tools.system;

import org.phoenicis.configuration.security.Safe;
import org.phoenicis.tools.system.GraphicsProperties;

import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.vulkan.*;

import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.glfw.GLFWVulkan.*;

// Code from LWJGL tutorial
@Safe
public class GraphicsPropertiesFetcher {
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
private long window = NULL;

/**
* Create an invisible glfx window and context, from which info will be retrieved
*/
private void init() {
GLFWErrorCallback.createPrint(System.err).set();

if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");

glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);

this.window = glfwCreateWindow(300, 300, "Test Window", NULL, NULL);
if (this.window == NULL)
throw new RuntimeException("Failed to create the GLFW window for testing graphic card capabilities");
}

/**
* Destroy glfw window and context
*/
private void terminate() {
glfwFreeCallbacks(this.window);
glfwDestroyWindow(this.window);

glfwTerminate();
glfwSetErrorCallback(null).free();
this.window = NULL;
}

/**
* Fetch graphics card vendor and OpenGL version
*/
private void FetchVendorRendererOpenGLVersion(GraphicsProperties graphicsProperties) {
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
glfwMakeContextCurrent(this.window);

GL.createCapabilities();

graphicsProperties.vendor = glGetString(GL_VENDOR);
graphicsProperties.renderer = glGetString(GL_RENDERER);
graphicsProperties.openGLVersion = glGetString(GL_VERSION);
graphicsProperties.openGLVersion = graphicsProperties.openGLVersion.substring(0,
graphicsProperties.openGLVersion.indexOf(' '));
}

/**
* Fetch Vulkan version
*/
private void FetchVulkanVersion(GraphicsProperties graphicsProperties) {
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
if (!glfwVulkanSupported()) {
return;
}

int version = VK.getInstanceVersionSupported();

graphicsProperties.vulkanVersion = String.valueOf(version >> 22) + "." +
String.valueOf((version >> 12) & 0x3ff) + "." +
String.valueOf(version & 0xfff);
}

/**
* Fetch the current graphics properties (vendor, OpenGL version, Vulkan version) of the system
*
* @return The current graphics properties inside a GraphicsProperties object
*/
public GraphicsProperties GetProperties() {
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved
GraphicsProperties graphicsProperties = new GraphicsProperties();
ImperatorS79 marked this conversation as resolved.
Show resolved Hide resolved

init();

FetchVendorRendererOpenGLVersion(graphicsProperties);
FetchVulkanVersion(graphicsProperties);

terminate();

return graphicsProperties;
}
}