Hi!
I have been using headless lwjgl 2 in an eclipse plugin and it have worked flawlessly for several years. When I modify and save shader files in my java projects the plugin automatically compile and mark error lines in the shader files. This is a fast way to detect simple typos and error without having to run any programs.
Was going to implements some new features and decided to change the plugin to lwjgl 3 since I use the new lwjgl for everything else. But I get some weird problems with crashing jvm's and buffer overflows. The only thing I have changed is the initialization and how to make a context current.
I this the right way to port the LWJGL 2 to 3 for same functionality?
First this is how I initialize and make the opengl context current in the eclipse builder thread:
LWJGL 2:
private static final Pbuffer buff;
static
{
try
{
final PixelFormat format = new PixelFormat();
buff = new Pbuffer(1, 1, format, null);
}
catch( Throwable e )
{
ObiGLBuilderPlugin.logError( "Failed to initialize OpenGL context", e );
throw new RuntimeException( e );
}
}
public static void bind()
throws CoreException
{
try
{
buff.makeCurrent();
}
catch( LWJGLException e )
{
throw new CoreException( new Status( IStatus.ERROR, ObiGLBuilder.BUILDER_ID, "Failed to make OpenGL context current", e ) );
}
}
public static void release()
throws CoreException
{
try
{
buff.releaseContext();
}
catch( LWJGLException e )
{
throw new CoreException( new Status( IStatus.ERROR, ObiGLBuilder.BUILDER_ID, "Failed to release OpenGL context", e ) );
}
}
LWJGL 3:
private static long offscreen_context;
private static GLCapabilities caps;
static
{
try
{
GLFW.glfwInit();
GLFW.glfwWindowHint( GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE );
offscreen_context = GLFW.glfwCreateWindow( 16, 16, "headless", MemoryUtil.NULL, MemoryUtil.NULL );
GLFW.glfwMakeContextCurrent( offscreen_context );
caps = GL.createCapabilities();
}
catch( final Throwable e )
{
Activator.logError( "Failed to initialize OpenGL context", e );
throw new RuntimeException( e );
}
}
public static void bind()
throws CoreException
{
GLFW.glfwMakeContextCurrent( offscreen_context );
GL.setCapabilities( caps );
}
public static void release()
throws CoreException
{
GLFW.glfwMakeContextCurrent( MemoryUtil.NULL );
}
The error I keep getting right now is that when my plugin compile shaders, the following command sometimes return seemingly random values for length.
final int length = GL20.glGetShaderi( id, GL20.GL_INFO_LOG_LENGTH );
Anyone running lwjgl 3 headless and/or in eclipse plugins?
Is my take on context handling with LWJGL 3 correct?