1 /**
2  * Copyright 2010 JogAmp Community. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  *    1. Redistributions of source code must retain the above copyright notice, this list of
8  *       conditions and the following disclaimer.
9  *
10  *    2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *       of conditions and the following disclaimer in the documentation and/or other materials
12  *       provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  * or implied, of JogAmp Community.
27  */
28 
29 package com.jogamp.opengl;
30 
31 import com.jogamp.common.GlueGenVersion;
32 
33 import com.jogamp.common.os.Platform;
34 import com.jogamp.common.util.VersionUtil;
35 import com.jogamp.common.util.JogampVersion;
36 
37 import java.util.List;
38 import java.util.jar.Manifest;
39 import com.jogamp.nativewindow.AbstractGraphicsDevice;
40 
41 public class JoglVersion extends JogampVersion {
42 
43     protected static volatile JoglVersion jogampCommonVersionInfo;
44 
JoglVersion(final String packageName, final Manifest mf)45     protected JoglVersion(final String packageName, final Manifest mf) {
46         super(packageName, mf);
47     }
48 
getInstance()49     public static JoglVersion getInstance() {
50         if(null == jogampCommonVersionInfo) { // volatile: ok
51             synchronized(JoglVersion.class) {
52                 if( null == jogampCommonVersionInfo ) {
53                     final String packageName = "com.jogamp.opengl";
54                     final Manifest mf = VersionUtil.getManifest(JoglVersion.class.getClassLoader(), packageName);
55                     jogampCommonVersionInfo = new JoglVersion(packageName, mf);
56                 }
57             }
58         }
59         return jogampCommonVersionInfo;
60     }
61 
toString(final GL gl, StringBuilder sb)62     public StringBuilder toString(final GL gl, StringBuilder sb) {
63         sb = super.toString(sb).append(Platform.getNewline());
64         getGLInfo(gl, sb);
65         return sb;
66     }
67 
toString(final GL gl)68     public String toString(final GL gl) {
69         return toString(gl, null).toString();
70     }
71 
getAvailableCapabilitiesInfo(final GLDrawableFactory factory, final AbstractGraphicsDevice device, StringBuilder sb)72     public static StringBuilder getAvailableCapabilitiesInfo(final GLDrawableFactory factory, final AbstractGraphicsDevice device, StringBuilder sb) {
73         if(null==sb) {
74             sb = new StringBuilder();
75         }
76         boolean done = false;
77         if(null!=factory) {
78             try {
79                 final List<GLCapabilitiesImmutable> availCaps = factory.getAvailableCapabilities(device);
80                 if(null != availCaps && availCaps.size()>0) {
81                     for(int i=0; i<availCaps.size(); i++) {
82                         sb.append("\t").append(availCaps.get(i)).append(Platform.getNewline());
83                     }
84                     done = true;
85                 }
86             } catch (final GLException gle) { /* n/a */ }
87         }
88         if(!done) {
89             sb.append("\tnone").append(Platform.getNewline());
90         }
91         sb.append(Platform.getNewline());
92         return sb;
93     }
94 
getAllAvailableCapabilitiesInfo(AbstractGraphicsDevice device, StringBuilder sb)95     public static StringBuilder getAllAvailableCapabilitiesInfo(AbstractGraphicsDevice device, StringBuilder sb) {
96         if(null==sb) {
97             sb = new StringBuilder();
98         }
99         if(null == device) {
100             device = GLProfile.getDefaultDevice();
101         }
102         sb.append(Platform.getNewline()).append(Platform.getNewline());
103         sb.append("Desktop Capabilities: ").append(Platform.getNewline());
104         getAvailableCapabilitiesInfo(GLDrawableFactory.getDesktopFactory(), device, sb);
105         sb.append("EGL Capabilities: ").append(Platform.getNewline());
106         getAvailableCapabilitiesInfo(GLDrawableFactory.getEGLFactory(), device, sb);
107         return sb;
108     }
109 
getDefaultOpenGLInfo(AbstractGraphicsDevice device, StringBuilder sb, final boolean withCapabilitiesInfo)110     public static StringBuilder getDefaultOpenGLInfo(AbstractGraphicsDevice device, StringBuilder sb, final boolean withCapabilitiesInfo) {
111         if(null==sb) {
112             sb = new StringBuilder();
113         }
114         if(null == device) {
115             device = GLProfile.getDefaultDevice();
116         }
117         sb.append("GLProfiles on device ").append(device).append(Platform.getNewline());
118         if(null!=device) {
119             GLProfile.glAvailabilityToString(device, sb, "\t", 1);
120         } else {
121             sb.append("none");
122         }
123         if(withCapabilitiesInfo) {
124             sb = getAllAvailableCapabilitiesInfo(device, sb);
125         }
126         return sb;
127     }
128 
getGLInfo(final GL gl, final StringBuilder sb)129     public static StringBuilder getGLInfo(final GL gl, final StringBuilder sb) {
130         return getGLInfo(gl, sb, false);
131     }
getGLInfo(final GL gl, final StringBuilder sb, final boolean withCapabilitiesAndExtensionInfo)132     public static StringBuilder getGLInfo(final GL gl, final StringBuilder sb, final boolean withCapabilitiesAndExtensionInfo) {
133         return getGLInfo(gl, sb, true, withCapabilitiesAndExtensionInfo, withCapabilitiesAndExtensionInfo);
134     }
135 
getGLInfo(final GL gl, StringBuilder sb, final boolean withAvailabilityInfo, final boolean withCapabilitiesInfo, final boolean withExtensionInfo)136     public static StringBuilder getGLInfo(final GL gl, StringBuilder sb,
137                                           final boolean withAvailabilityInfo,
138                                           final boolean withCapabilitiesInfo,
139                                           final boolean withExtensionInfo) {
140         final AbstractGraphicsDevice device = gl.getContext().getGLDrawable().getNativeSurface()
141                                             .getGraphicsConfiguration().getScreen().getDevice();
142         if(null==sb) {
143             sb = new StringBuilder();
144         }
145 
146         sb.append(VersionUtil.SEPERATOR).append(Platform.getNewline());
147         sb.append(device.getClass().getSimpleName()).append("[type ")
148                 .append(device.getType()).append(", connection ").append(device.getConnection()).append("]: ").append(Platform.getNewline());
149         if( withAvailabilityInfo ) {
150             GLProfile.glAvailabilityToString(device, sb, "\t", 1);
151         }
152         sb.append(Platform.getNewline());
153 
154         sb = getGLStrings(gl, sb, withExtensionInfo);
155 
156         if( withCapabilitiesInfo ) {
157             sb = getAllAvailableCapabilitiesInfo(device, sb);
158         }
159         return sb;
160     }
161 
getGLStrings(final GL gl, final StringBuilder sb)162     public static StringBuilder getGLStrings(final GL gl, final StringBuilder sb) {
163         return getGLStrings(gl, sb, true);
164     }
165 
getGLStrings(final GL gl, StringBuilder sb, final boolean withExtensions)166     public static StringBuilder getGLStrings(final GL gl, StringBuilder sb, final boolean withExtensions) {
167         if(null==sb) {
168             sb = new StringBuilder();
169         }
170         final GLContext ctx = gl.getContext();
171         sb.append("Swap Interval  ").append(gl.getSwapInterval());
172         sb.append(Platform.getNewline());
173         sb.append("GL Profile     ").append(gl.getGLProfile());
174         sb.append(Platform.getNewline());
175         sb.append("GL Version     ").append(ctx.getGLVersion()).append(" [GL ").append(ctx.getGLVersionNumber()).append(", vendor ").append(ctx.getGLVendorVersionNumber()).append("]");
176         sb.append(Platform.getNewline());
177         sb.append("Quirks         ").append(ctx.getRendererQuirks());
178         sb.append(Platform.getNewline());
179         sb.append("Impl. class    ").append(gl.getClass().getCanonicalName());
180         sb.append(Platform.getNewline());
181         sb.append("GL_VENDOR      ").append(gl.glGetString(GL.GL_VENDOR));
182         sb.append(Platform.getNewline());
183         sb.append("GL_RENDERER    ").append(gl.glGetString(GL.GL_RENDERER));
184         sb.append(Platform.getNewline());
185         sb.append("GL_VERSION     ").append(gl.glGetString(GL.GL_VERSION));
186         sb.append(Platform.getNewline());
187         sb.append("GLSL           ").append(gl.hasGLSL()).append(", has-compiler-func: ").append(gl.isFunctionAvailable("glCompileShader"));
188         if(gl.hasGLSL()) {
189             sb.append(", version: ").append(gl.glGetString(GL2ES2.GL_SHADING_LANGUAGE_VERSION)).append(" / ").append(ctx.getGLSLVersionNumber());
190         }
191         sb.append(Platform.getNewline());
192         sb.append("GL FBO: basic ").append(gl.hasBasicFBOSupport()).append(", full ").append(gl.hasFullFBOSupport());
193         sb.append(Platform.getNewline());
194         sb.append("GL_EXTENSIONS  ").append(ctx.getGLExtensionCount());
195         sb.append(Platform.getNewline());
196         if( withExtensions ) {
197             sb.append("               ").append(ctx.getGLExtensionsString());
198             sb.append(Platform.getNewline());
199         }
200         sb.append("GLX_EXTENSIONS ").append(ctx.getPlatformExtensionCount());
201         sb.append(Platform.getNewline());
202         if( withExtensions ) {
203             sb.append("               ").append(ctx.getPlatformExtensionsString());
204             sb.append(Platform.getNewline());
205         }
206         sb.append(VersionUtil.SEPERATOR);
207 
208         return sb;
209     }
210 
getBriefOSGLBuildInfo(final GL gl, StringBuilder sb)211     public StringBuilder getBriefOSGLBuildInfo(final GL gl, StringBuilder sb) {
212         if(null==sb) {
213             sb = new StringBuilder();
214         }
215         sb.append("OS: ").append(Platform.getOSName()).append(", version ").append(Platform.getOSVersion()).append(", arch ").append(Platform.getArchName());
216         sb.append(Platform.getNewline());
217         sb.append("GL_VENDOR     ").append(gl.glGetString(GL.GL_VENDOR));
218         sb.append(Platform.getNewline());
219         sb.append("GL_RENDERER   ").append(gl.glGetString(GL.GL_RENDERER));
220         sb.append(Platform.getNewline());
221         sb.append("GL_VERSION    ").append(gl.glGetString(GL.GL_VERSION));
222         sb.append(Platform.getNewline());
223         sb.append("JOGL GIT sha1 ").append(getImplementationCommit());
224         sb.append(Platform.getNewline());
225         return sb;
226     }
227 
main(final String args[])228     public static void main(final String args[]) {
229         System.err.println(VersionUtil.getPlatformInfo());
230         System.err.println(GlueGenVersion.getInstance());
231         // System.err.println(NativeWindowVersion.getInstance());
232         System.err.println(JoglVersion.getInstance());
233     }
234 }
235 
236