gpt4 book ai didi

opengl - 卡支持 OpenGL 4.1 但线程上没有 GL4 实现?

转载 作者:行者123 更新时间:2023-12-01 23:14:56 25 4
gpt4 key购买 nike

当我运行测试 JOGL 应用程序时,它说当我的系统支持 OpenGL 4.1 时,线程上只有 GL2 可用(根据 OpenGl Extensions Viewer) .

有人看出为什么线程中只支持 GL2 的明显原因吗?

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

Intel Iris

AMD Radeon R9

这是《使用 Java 进行 OpenGL 计算机图形编程》一书中的第一个练习。 4

Java Version: Java8

JOGL Version: 2.3.2

GlueGen Version: 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) { }
}

异常(exception):

/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

最佳答案

事实证明,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

我能够通过将 GLCapability 传递到 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);
}

关于opengl - 卡支持 OpenGL 4.1 但线程上没有 GL4 实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42739985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com