2017-03-11 58 views
2

当我运行我的测试JOGL应用程序时,它说当我的系统根据OpenGl Extensions Viewer支持OpenGL 4.1时,线程上只有GL2可用。卡支持OpenGL 4.1,但线程上没有GL4实现?

有没有人看到任何明显的为什么只有GL2会在线程中被支持?

我使用的是2015年中的Macbook Pro,配备了Intel Iris和AMD Radeon R9显卡。

Intel Iris

AMD Radeon R9

这是一本书[计算机图形学的编程在OpenGL与Java]的第一个练习。 4

Java版本:Java8

JOGL版本:2.3.2

GlueGen版本:2.3.2

import java.nio.*; 
import javax.swing.*; 
import static com.jogamp.opengl.GL4.*; 
import com.jogamp.opengl.*; 
import com.jogamp.opengl.awt.GLCanvas; 
import com.jogamp.common.nio.Buffers; 

public class Code extends JFrame implements GLEventListener { 
    private GLCanvas myCanvas; 

    public Code() { 
     setTitle("Chapter 2 - program1"); 
     setSize(600, 400); 
     setLocation(200, 200); 
     myCanvas = new GLCanvas(); 
     myCanvas.addGLEventListener(this); 
     this.add(myCanvas); 
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setVisible(true); 
    } 

    public void display(GLAutoDrawable drawable) { 
     GL4 gl = (GL4) GLContext.getCurrentGL(); 
     drawable.setGL(new DebugGL4(gl)); 
     float bkg[] = { 1.0f, 0.0f, 0.0f, 1.0f }; 
     FloatBuffer bkgBuffer = Buffers.newDirectFloatBuffer(bkg); 
     gl.glClearBufferfv(GL_COLOR, 0, bkgBuffer); 
    } 

    public static void main(String[] args) { 
     new Code(); 
    } 

    public void init(GLAutoDrawable drawable) { 
     GL4 gl = drawable.getGL().getGL4(); // This is where the code fails 
     String version = gl.glGetString(GL4.GL_VERSION); 
     String shaderversion = gl.glGetString(GL4.GL_SHADING_LANGUAGE_VERSION); 
     System.out.println("GLVERSION: " + version + " shading language: " + shaderversion); 
    } 

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } 
    public void dispose(GLAutoDrawable drawable) { } 
} 

例外:

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -classpath /private/var/folders/rd/tltb7sk928x_n429dyctdt8c0000gn/T/classpath1.jar -Dfile.encoding=UTF-8 com.intellij.rt.execution.application.AppMain Code 
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Not a GL4 implementation on thread AWT-EventQueue-0 
    at com.jogamp.opengl.GLException.newGLException(GLException.java:76) 
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327) 
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147) 
    at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1438) 
    at com.jogamp.opengl.Threading.invoke(Threading.java:223) 
    at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505) 
    at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:559) 
    at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264) 
    at sun.lwawt.LWRepaintArea.paintComponent(LWRepaintArea.java:59) 
    at sun.awt.RepaintArea.paint(RepaintArea.java:240) 
    at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1314) 
    at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1198) 
    at java.awt.Component.dispatchEventImpl(Component.java:4965) 
    at java.awt.Component.dispatchEvent(Component.java:4711) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) 
    at java.awt.EventQueue.access$500(EventQueue.java:97) 
    at java.awt.EventQueue$3.run(EventQueue.java:709) 
    at java.awt.EventQueue$3.run(EventQueue.java:703) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) 
    at java.awt.EventQueue$4.run(EventQueue.java:731) 
    at java.awt.EventQueue$4.run(EventQueue.java:729) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 
Caused by: com.jogamp.opengl.GLException: Not a GL4 implementation 
    at jogamp.opengl.gl4.GL4bcImpl.getGL4(GL4bcImpl.java:40464) 
    at Code.init(Code.java:38) 
    at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:644) 
    at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:667) 
    at com.jogamp.opengl.awt.GLCanvas$10.run(GLCanvas.java:1407) 
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1291) 
    ... 30 more 
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_OPERATION (1282 0x502), on thread AWT-EventQueue-0 
    at com.jogamp.opengl.GLException.newGLException(GLException.java:76) 
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327) 
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147) 
    at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1438) 
    at com.jogamp.opengl.Threading.invoke(Threading.java:223) 
    at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505) 
    at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:559) 
    at com.jogamp.opengl.awt.GLCanvas.update(GLCanvas.java:866) 
    at sun.awt.RepaintArea.updateComponent(RepaintArea.java:255) 
    at sun.lwawt.LWRepaintArea.updateComponent(LWRepaintArea.java:47) 
    at sun.awt.RepaintArea.paint(RepaintArea.java:232) 
    at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1314) 
    at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1198) 
    at java.awt.Component.dispatchEventImpl(Component.java:4965) 
    at java.awt.Component.dispatchEvent(Component.java:4711) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) 
    at java.awt.EventQueue.access$500(EventQueue.java:97) 
    at java.awt.EventQueue$3.run(EventQueue.java:709) 
    at java.awt.EventQueue$3.run(EventQueue.java:703) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86) 
    at java.awt.EventQueue$4.run(EventQueue.java:731) 
    at java.awt.EventQueue$4.run(EventQueue.java:729) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) 
Caused by: com.jogamp.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_OPERATION (1282 0x502), 
    at com.jogamp.opengl.DebugGL4bc.writeGLError(DebugGL4bc.java:31803) 
    at com.jogamp.opengl.DebugGL4bc.glActiveTexture(DebugGL4bc.java:232) 
    at jogamp.opengl.GLFBODrawableImpl.swapFBOImpl(GLFBODrawableImpl.java:471) 
    at jogamp.opengl.GLFBODrawableImpl.swapBuffersImpl(GLFBODrawableImpl.java:426) 
    at jogamp.opengl.GLDrawableImpl.swapBuffers(GLDrawableImpl.java:88) 
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1295) 
    ... 31 more 

Process finished with exit code 0 
+0

这很有趣,'glxinfo'返回只支持OpenGL 2.1(OpenGL版本字符串:2.1 ATI-1.42.15),但根据Apple(https://support.apple.com/zh-cn/HT202823) ,4。1应该被支持。 – collenjones

回答

4

事实证明,OSX回落到OpenGL 2.1,因此您需要自己设置核心配置文件。

$ glxinfo | grep OpenGL 
OpenGL vendor string: ATI Technologies Inc. 
OpenGL renderer string: AMD Radeon R9 M370X OpenGL Engine 
OpenGL version string: 2.1 ATI-1.42.15 
OpenGL shading language version string: 1.20 

我能够通过将GLCapabilities传递给GLCanvas构造函数来设置核心版本(OpenGL 4.1)。

这里是新的,固定的构造函数:

public Code() { 
    setTitle("Chapter 2 - program1"); 
    setSize(600, 400); 
    setLocation(200, 200); 

    // This was the fix 
    GLProfile glp = GLProfile.getMaxProgrammableCore(true); 
    GLCapabilities caps = new GLCapabilities(glp); 
    myCanvas = new GLCanvas(caps); 

    myCanvas.addGLEventListener(this); 
    this.add(myCanvas); 
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    setVisible(true); 
} 
+1

这不是一个真正的修复。使用JOGL时选择一个配置文件是一个好习惯,它避免依赖于默认配置文件。 – gouessej

1

对于Mac上运行书上的例子,我已经把这个网站上的说明:http://athena.ecs.csus.edu/~gordonvs/errataMac.html

总之,你需要:

  • 确保您安装了最新的Java SE
  • 将相关的JOGL库放入Sys tem/Library/Java/Extensions(以上网站列出了所需的具体内容)
  • 添加上述Julien代码(谢谢!)
  • 将着色器的版本号更改为410(或任何Mac支持)
  • 在使用纹理的例子中,在着色器来glUniform1i适当的()调用的Java应用程序4.1版本)取代结合布局预选赛(兼容

如果有更多的特质被识别,我会将它们添加到网站上的说明中。

+0

不要将任何库放入System/Library/Java/Extensions中,这是一种不好的做法,因为扩展机制将从Java 1.9中移除,并且会影响系统中的所有应用程序和applet,因为存储在此目录中的库在应用程序的类路径中的库。例如,假设您将JOGL 2.3.2放入此目录,而特定应用程序需要JOGL 2.4,则可能无法运行,因为JOGL 2.3.2将首先加载。这种机制很麻烦,容易出错,请不要使用它。 – gouessej

+0

我建议你阅读:https://blogs.oracle.com/java-platform-group/planning-safe-removal-of-under-used-endorsed-extension-directories http://openjdk.java.net/jeps/220 http://docs.oracle.com/javase/8/docs/technotes/guides/extensions/index.html“此功能已被弃用,将在未来版本中删除” – gouessej

+0

对不起 - 我们错误地认为Apple的扩展文件夹会继续。看起来你是对的。猜猜这意味着我的第二个项目符号应该说是将jar添加到您的类路径中,或者使用-cp选项将它包含在java命令行中。我将修改该页面。 –