-
Notifications
You must be signed in to change notification settings - Fork 75
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
ImperatorS79
wants to merge
30
commits into
PhoenicisOrg:master
Choose a base branch
from
ImperatorS79:graphicsprop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+343
−0
Open
Changes from all 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 ff9b79c
Merge pull request #2 from PhoenicisOrg/master
ImperatorS79 0774f93
Update pom.xml
ImperatorS79 1610c5e
Add files via upload
ImperatorS79 0adb378
Update ToolsConfiguration.java
ImperatorS79 f9095d5
Update GraphicsProperties.java
ImperatorS79 ec9a3ef
Update GraphicsPropertiesFetcher.java
ImperatorS79 3e6eeab
Update GraphicsPropertiesFetcher.java
ImperatorS79 a424044
Update GraphicsPropertiesFetcher.java
ImperatorS79 090bd4e
Fix OpenGL library not being loadable multiple times
ImperatorS79 1d5b026
Update GraphicsProperties.java
ImperatorS79 cd869f3
Update GraphicsPropertiesFetcher.java
ImperatorS79 e3bb0f8
Update GraphicsProperties.java
ImperatorS79 121ae07
Update GraphicsProperties.java
ImperatorS79 7cb22be
Update GraphicsPropertiesFetcher.java
ImperatorS79 2030616
Update GraphicsPropertiesFetcher.java
ImperatorS79 3678f8f
Fix travis and tr
ImperatorS79 1d70003
Also fetch core context Version
ImperatorS79 f40bf65
Update GraphicsPropertiesFetcher.java
ImperatorS79 386ecc0
Codacy I saw you
ImperatorS79 13fb641
Update pom.xml
ImperatorS79 986beaf
Update pom.xml
ImperatorS79 5d50f1c
Update GraphicsProperties.java
ImperatorS79 62faa23
Update GraphicsPropertiesFetcher.java
ImperatorS79 0d1559c
Update GraphicsPropertiesFetcher.java
ImperatorS79 10ddec0
Merge pull request #3 from PhoenicisOrg/master
ImperatorS79 35e9b1e
It builds
ImperatorS79 8ebc6ca
Update pom.xml
ImperatorS79 a50e013
Update pom.xml
ImperatorS79 36b1b4f
Test
ImperatorS79 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
phoenicis-tools/src/main/java/org/phoenicis/tools/system/GraphicsProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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 | ||
/** | ||
* This class contains some information about the graphics capabilities of the GPU: | ||
* the GPU vendor, name (renderer), the OpenGL and Vulkan version | ||
*/ | ||
public class GraphicsProperties { | ||
private String vendor; | ||
private String renderer; | ||
private String openglVersion; | ||
private String openglCoreVersion; | ||
private String vulkanVersion; | ||
|
||
public GraphicsProperties() { | ||
ImperatorS79 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.vendor = "Unknown"; | ||
this.renderer = "Unknown"; | ||
this.openglVersion = "Unsupported"; | ||
this.openglCoreVersion = "Unsupported"; | ||
this.vulkanVersion = "Unsupported"; | ||
} | ||
|
||
public void setVendor(String vendor) { | ||
this.vendor = vendor; | ||
} | ||
|
||
public void setRenderer(String renderer) { | ||
this.renderer = renderer; | ||
} | ||
|
||
public void setOpenGLVersion(String openglVersion) { | ||
this.openglVersion = openglVersion; | ||
} | ||
|
||
public void setOpenGLCoreVersion(String openglCoreVersion) { | ||
this.openglCoreVersion = openglCoreVersion; | ||
} | ||
|
||
public void setVulkanVersion(String vulkanVersion) { | ||
this.vulkanVersion = vulkanVersion; | ||
} | ||
|
||
public String getVendor() { | ||
return this.vendor; | ||
} | ||
|
||
public String getRenderer() { | ||
return this.renderer; | ||
} | ||
|
||
public String getOpenGLVersion() { | ||
return this.openglVersion; | ||
} | ||
|
||
public String getOpenGLCoreVersion() { | ||
return this.openglCoreVersion; | ||
} | ||
|
||
public String getVulkanVersion() { | ||
return this.vulkanVersion; | ||
} | ||
} |
179 changes: 179 additions & 0 deletions
179
phoenicis-tools/src/main/java/org/phoenicis/tools/system/GraphicsPropertiesFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* 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.phoenicis.tools.system.ArchitectureFetcher; | ||
import org.phoenicis.tools.system.OperatingSystemFetcher; | ||
import org.phoenicis.entities.Architecture; | ||
import org.phoenicis.entities.OperatingSystem; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import static org.phoenicis.configuration.localisation.Localisation.tr; | ||
|
||
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 | ||
/** | ||
* This class fetch the required properties to fill the class GraphicsProperties, | ||
* using LWJGL to create a dummy window and context in order to access OpenGL and Vulkan properties. | ||
*/ | ||
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 infos will be retrieved | ||
*/ | ||
private void init(GraphicsProperties graphicsProperties) { | ||
GLFWErrorCallback.createPrint(System.err).set(); | ||
|
||
if (!glfwInit()) | ||
throw new IllegalStateException(tr("Unable to initialize GLFW for testing graphic card capabilities")); | ||
|
||
// We will now fetch maximum supported OpenGL core context version (3.2 -> 4.6) | ||
ArrayList<ArrayList<Integer>> openglCoreVersion = new ArrayList<ArrayList<Integer>>(); // Versions that | ||
// distinguish core and | ||
// compatibility | ||
|
||
openglCoreVersion.add(new ArrayList<Integer>(Arrays.asList(6, 5, 4, 3, 2, 1, 0))); // OpenGL 4.x | ||
openglCoreVersion.add(new ArrayList<Integer>(Arrays.asList(3, 2))); // OpenGL 3.x | ||
|
||
// We run through the versions than should provide a core context | ||
boolean found = false; | ||
for (int i = 0; i < openglCoreVersion.size(); ++i) { | ||
if (!found) { | ||
for (int j = 0; i < openglCoreVersion.get(i).size(); ++j) { | ||
glfwDefaultWindowHints(); | ||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, -i + 4); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, openglCoreVersion.get(i).get(j)); | ||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | ||
|
||
this.window = glfwCreateWindow(300, 300, "Test Window", NULL, NULL); | ||
|
||
if (this.window != NULL) { | ||
// We found a working core context | ||
found = true; | ||
graphicsProperties.setOpenGLCoreVersion(String.valueOf(-i + 4) + "." | ||
+ String.valueOf(openglCoreVersion.get(i).get(j))); | ||
glfwFreeCallbacks(this.window); | ||
glfwDestroyWindow(this.window); | ||
this.window = NULL; | ||
break; | ||
} | ||
|
||
// No core context found, the context is then 3.1 or less, see fetchVendorRendererOpenGLVersion | ||
} | ||
} | ||
} | ||
|
||
glfwDefaultWindowHints(); | ||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); | ||
|
||
this.window = glfwCreateWindow(300, 300, "Test Window", NULL, NULL); | ||
if (this.window == NULL) | ||
throw new IllegalStateException( | ||
tr("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) { | ||
// Allow LWJGL to connect with the glfw OpenGL context and to use gl* function | ||
glfwMakeContextCurrent(this.window); | ||
GL.createCapabilities(); | ||
|
||
graphicsProperties.setVendor(glGetString(GL_VENDOR)); | ||
graphicsProperties.setRenderer(glGetString(GL_RENDERER)); | ||
graphicsProperties.setOpenGLVersion(glGetString(GL_VERSION)); // The version can be inferior to | ||
// openglCoreVersion | ||
// If the compatibiltity context is not available | ||
// for large OpenGL version | ||
graphicsProperties.setOpenGLVersion(graphicsProperties.getOpenGLVersion().substring(0, | ||
graphicsProperties.getOpenGLVersion().indexOf(' '))); // We only take to version number | ||
} | ||
|
||
/** | ||
* Fetch Vulkan version | ||
*/ | ||
private void fetchVulkanVersion(GraphicsProperties graphicsProperties) { | ||
if (!glfwVulkanSupported()) { | ||
return; | ||
} | ||
|
||
// Gets normally maximum Vulkan version fully supported | ||
int version = VK.getInstanceVersionSupported(); | ||
|
||
// Convert the uint32 into a readable String (source: vulkaninfo source code) | ||
graphicsProperties.setVulkanVersion(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() { | ||
final GraphicsProperties graphicsProperties = new GraphicsProperties(); | ||
|
||
final OperatingSystemFetcher operatingSystemFetcher = new OperatingSystemFetcher(); | ||
OperatingSystem os = operatingSystemFetcher.fetchCurrentOperationSystem(); | ||
|
||
final ArchitectureFetcher architectureFetcher = new ArchitectureFetcher(operatingSystemFetcher); | ||
Architecture arch = architectureFetcher.fetchCurrentArchitecture(); | ||
|
||
if (arch == Architecture.AMD64 && (os == OperatingSystem.LINUX || os == OperatingSystem.MACOSX)) { | ||
init(graphicsProperties); | ||
|
||
fetchVendorRendererOpenGLVersion(graphicsProperties); | ||
fetchVulkanVersion(graphicsProperties); | ||
|
||
terminate(); | ||
} | ||
|
||
return graphicsProperties; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?