Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
180 changes: 180 additions & 0 deletions jme3-core/src/main/java/com/jme3/renderer/GpuInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*
* Copyright (c) 2009-2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.renderer;

/**
* Holds information about the GPU hardware and drivers.
* This information can be used to detect device capabilities
* and adjust performance settings accordingly.
*
* @author jMonkeyEngine
*/
public class GpuInfo {

private final String vendor;
private final String renderer;
private final String version;
private final String glslVersion;
private final String profile;

/**
* Creates a new GpuInfo instance.
*
* @param vendor The GPU vendor (e.g., "NVIDIA Corporation", "AMD", "Intel")
* @param renderer The GPU renderer string (e.g., "GeForce GTX 1080")
* @param version The OpenGL version string
* @param glslVersion The GLSL version string
* @param profile The OpenGL profile ("Core" or "Compatibility")
*/
public GpuInfo(String vendor, String renderer, String version, String glslVersion, String profile) {
this.vendor = vendor != null ? vendor : "Unknown";
this.renderer = renderer != null ? renderer : "Unknown";
this.version = version != null ? version : "Unknown";
this.glslVersion = glslVersion != null ? glslVersion : "Unknown";
this.profile = profile != null ? profile : "Unknown";
}

/**
* Gets the GPU vendor name.
*
* @return The vendor name (e.g., "NVIDIA Corporation", "AMD", "Intel")
*/
public String getVendor() {
return vendor;
}

/**
* Gets the GPU renderer name.
*
* @return The renderer name (e.g., "GeForce GTX 1080", "Radeon RX 580")
*/
public String getRenderer() {
return renderer;
}

/**
* Gets the OpenGL version string.
*
* @return The OpenGL version
*/
public String getVersion() {
return version;
}

/**
* Gets the GLSL (OpenGL Shading Language) version string.
*
* @return The GLSL version
*/
public String getGlslVersion() {
return glslVersion;
}

/**
* Gets the OpenGL profile being used.
*
* @return "Core", "Compatibility", or "Unknown"
*/
public String getProfile() {
return profile;
}

/**
* Checks if this appears to be a low-end GPU based on vendor and renderer strings.
* This is a heuristic method that may not be 100% accurate.
*
* @return true if this appears to be a low-end GPU
*/
public boolean isLowEndGpu() {
String lowerVendor = vendor.toLowerCase();
String lowerRenderer = renderer.toLowerCase();

// Intel integrated graphics (most are considered low-end for gaming)
if (lowerVendor.contains("intel") &&
(lowerRenderer.contains("hd graphics") ||
lowerRenderer.contains("uhd graphics") ||
lowerRenderer.contains("iris") ||
lowerRenderer.contains("integrated"))) {
return true;
}

// Software rendering
if (lowerRenderer.contains("software") ||
lowerRenderer.contains("llvmpipe") ||
lowerRenderer.contains("mesa")) {
return true;
}

// Very old or low-end discrete GPUs
if (lowerRenderer.contains("geforce") &&
(lowerRenderer.contains("gt ") || lowerRenderer.contains("mx "))) {
return true;
}

return false;
}

@Override
public String toString() {
return "GpuInfo{" +
"vendor='" + vendor + '\'' +
", renderer='" + renderer + '\'' +
", version='" + version + '\'' +
", glslVersion='" + glslVersion + '\'' +
", profile='" + profile + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

GpuInfo gpuInfo = (GpuInfo) o;

if (!vendor.equals(gpuInfo.vendor)) return false;
if (!renderer.equals(gpuInfo.renderer)) return false;
if (!version.equals(gpuInfo.version)) return false;
if (!glslVersion.equals(gpuInfo.glslVersion)) return false;
return profile.equals(gpuInfo.profile);
}

@Override
public int hashCode() {
int result = vendor.hashCode();
result = 31 * result + renderer.hashCode();
result = 31 * result + version.hashCode();
result = 31 * result + glslVersion.hashCode();
result = 31 * result + profile.hashCode();
return result;
}
}
7 changes: 7 additions & 0 deletions jme3-core/src/main/java/com/jme3/renderer/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public interface Renderer {
*/
public EnumMap<Limits, Integer> getLimits();

/**
* Gets information about the GPU hardware and drivers.
*
* @return The GPU information, or null if not available
*/
public GpuInfo getGpuInfo();

/**
* Copies the render statistics.
*
Expand Down
24 changes: 17 additions & 7 deletions jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public final class GLRenderer implements Renderer {
private final NativeObjectManager objManager = new NativeObjectManager();
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
private final EnumMap<Limits, Integer> limits = new EnumMap<>(Limits.class);
private GpuInfo gpuInfo = null;

private FrameBuffer mainFbOverride = null;
private int defaultFBO = 0;
Expand Down Expand Up @@ -177,6 +178,11 @@ public EnumMap<Limits, Integer> getLimits() {
return limits;
}

@Override
public GpuInfo getGpuInfo() {
return gpuInfo;
}

private HashSet<String> loadExtensions() {
HashSet<String> extensionSet = new HashSet<>(64);
if (caps.contains(Caps.OpenGL30)) {
Expand Down Expand Up @@ -629,20 +635,24 @@ private void loadCapabilitiesCommon() {
caps.add(Caps.GLDebug);
}

// Gather GPU information
String vendor = gl.glGetString(GL.GL_VENDOR);
String renderer = gl.glGetString(GL.GL_RENDERER);
String version = gl.glGetString(GL.GL_VERSION);
String glslVersion = gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION);
String profile = caps.contains(Caps.CoreProfile) ? "Core" : "Compatibility";

// Store GPU info for API access
gpuInfo = new GpuInfo(vendor, renderer, version, glslVersion, profile);

// Print context information
logger.log(Level.INFO, "OpenGL Renderer Information\n" +
" * Vendor: {0}\n" +
" * Renderer: {1}\n" +
" * OpenGL Version: {2}\n" +
" * GLSL Version: {3}\n" +
" * Profile: {4}",
new Object[]{
gl.glGetString(GL.GL_VENDOR),
gl.glGetString(GL.GL_RENDERER),
gl.glGetString(GL.GL_VERSION),
gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION),
caps.contains(Caps.CoreProfile) ? "Core" : "Compatibility"
});
new Object[]{vendor, renderer, version, glslVersion, profile});

// Print capabilities (if fine logging is enabled)
if (logger.isLoggable(Level.FINE)) {
Expand Down
6 changes: 6 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/NullRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix4f;
import com.jme3.renderer.Caps;
import com.jme3.renderer.GpuInfo;
import com.jme3.renderer.Limits;
import com.jme3.renderer.Renderer;
import com.jme3.renderer.Statistics;
Expand Down Expand Up @@ -77,6 +78,11 @@ public EnumSet<Caps> getCaps() {
return caps;
}

@Override
public GpuInfo getGpuInfo() {
return null; // No GPU info available for null renderer
}

@Override
public Statistics getStatistics() {
return stats;
Expand Down
Loading
Loading