-
Notifications
You must be signed in to change notification settings - Fork 73
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.
Open
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 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
36 changes: 36 additions & 0 deletions
36
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,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"; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
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,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; | ||
} | ||
} |
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?