From eda5e983da38d13b0694f2d5793829138712ab39 Mon Sep 17 00:00:00 2001 From: shadowislord Date: Mon, 9 Feb 2015 21:06:50 -0500 Subject: [PATCH] context/renderer: let renderer print out graphics hardware info --- .../java/com/jme3/renderer/opengl/GL.java | 2 + .../com/jme3/renderer/opengl/GLRenderer.java | 47 ++++++++++++++++--- .../com/jme3/system/lwjgl/LwjglContext.java | 26 +++------- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java index 54eb14687..9cbf2f65d 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java @@ -115,6 +115,7 @@ public interface GL { public static final int GL_OUT_OF_MEMORY = 0x505; public static final int GL_POINTS = 0x0; public static final int GL_POLYGON_OFFSET_FILL = 0x8037; + public static final int GL_RENDERER = 0x1F01; public static final int GL_REPEAT = 0x2901; public static final int GL_REPLACE = 0x1E01; public static final int GL_RGB = 0x1907; @@ -171,6 +172,7 @@ public interface GL { public static final int GL_UNSIGNED_SHORT = 0x1403; public static final int GL_UNSIGNED_SHORT_5_6_5 = 0x8363; public static final int GL_UNSIGNED_SHORT_5_5_5_1 = 0x8034; + public static final int GL_VENDOR = 0x1F00; public static final int GL_VERSION = 0x1F02; public static final int GL_VERTEX_SHADER = 0x8B31; public static final int GL_ZERO = 0x0; diff --git a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java index f4e1976f9..883ec11e1 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java +++ b/jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java @@ -129,6 +129,11 @@ public class GLRenderer implements Renderer { public EnumSet getCaps() { return caps; } + + // Not making public yet ... + public EnumMap getLimits() { + return limits; + } private static HashSet loadExtensions(String extensions) { HashSet extensionSet = new HashSet(64); @@ -418,13 +423,33 @@ public class GLRenderer implements Renderer { caps.add(Caps.SeamlessCubemap); } - if (hasExtension("GL_ARB_get_program_binary")) { - // OK .. - int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS); - System.out.println("Binary Formats: " + binaryFormats); - } +// if (hasExtension("GL_ARB_get_program_binary")) { +// int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS); +// } - logger.log(Level.FINE, "Caps: {0}", caps); + // Print context information + logger.log(Level.INFO, "OpenGL Renderer Information\n" + + " * Vendor: {0}\n" + + " * Renderer: {1}\n" + + " * OpenGL Version: {2}\n" + + " * GLSL Version: {3}", + new Object[]{ + gl.glGetString(GL.GL_VENDOR), + gl.glGetString(GL.GL_RENDERER), + gl.glGetString(GL.GL_VERSION), + gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION) + }); + + // Print capabilities (if fine logging is enabled) + if (logger.isLoggable(Level.FINE)) { + StringBuilder sb = new StringBuilder(); + sb.append("Supported capabilities: \n"); + for (Caps cap : caps) + { + sb.append("\t").append(cap.toString()).append("\n"); + } + logger.log(Level.FINE, sb.toString()); + } texUtil.initialize(caps); } @@ -1094,14 +1119,22 @@ public class GLRenderer implements Renderer { needRegister = true; } + // If using GLSL 1.5, we bind the outputs for the user + // For versions 3.3 and up, user should use layout qualifiers instead. + boolean bindFragDataRequired = false; + for (ShaderSource source : shader.getSources()) { if (source.isUpdateNeeded()) { updateShaderSourceData(source); } + if (source.getType() == ShaderType.Fragment + && source.getLanguage().equals("GLSL150")) { + bindFragDataRequired = true; + } gl.glAttachShader(id, source.getId()); } - if (caps.contains(Caps.OpenGL30) && gl3 != null) { + if (bindFragDataRequired) { // Check if GLSL version is 1.5 for shader gl3.glBindFragDataLocation(id, 0, "outFragColor"); // For MRT diff --git a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java index 12da0bbca..e318d24a2 100644 --- a/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java +++ b/jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java @@ -84,25 +84,13 @@ public abstract class LwjglContext implements JmeContext { } protected void printContextInitInfo() { - logger.log(Level.INFO, "Lwjgl {0} context running on thread {1}", - new Object[]{Sys.getVersion(), Thread.currentThread().getName()}); - - logger.log(Level.INFO, "Adapter: {0}", Display.getAdapter()); - logger.log(Level.INFO, "Driver Version: {0}", Display.getVersion()); - - String vendor = GL11.glGetString(GL11.GL_VENDOR); - logger.log(Level.INFO, "Vendor: {0}", vendor); - - String version = GL11.glGetString(GL11.GL_VERSION); - logger.log(Level.INFO, "OpenGL Version: {0}", version); - - String renderGl = GL11.glGetString(GL11.GL_RENDERER); - logger.log(Level.INFO, "Renderer: {0}", renderGl); - - if (GLContext.getCapabilities().OpenGL20){ - String shadingLang = GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION); - logger.log(Level.INFO, "GLSL Ver: {0}", shadingLang); - } + logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n" + + " * Graphics Adapter: {2}\n" + + " * Driver Version: {3}\n" + + " * Scaling Factor: {4}", + new Object[]{ Sys.getVersion(), Thread.currentThread().getName(), + Display.getAdapter(), Display.getVersion(), + Display.getPixelScaleFactor() }); } protected ContextAttribs createContextAttribs() {