Hello Guest

Mixing LWJGL with native OpenGL?

  • 2 Replies
  • 311 Views
Mixing LWJGL with native OpenGL?
« on: March 08, 2018, 10:54:38 »
Hey all! First of all we've not moved to LWJGL 3 yet, though it's planned in the short to midterm future, so any info on LWJGL 2 would be much appreciated too.

I'm wondering if its possible / easy for a native DLL using openGL directly within a LWJGL project to work alongside LWJGL without conflict?

Basically, I want to write a native renderer backend for dealing with the low level openGL calls with command lists and the like, and while I've considered doing this in java, I would really like to take advantage of c++ language features such as being able to use unmanaged native memory more efficiently for blocks of data.

However, before I start, I'm aware I won't have access to LWJGL from within the native library, and will be interacting with OpenGL directly. Has anyone done this before, and are direct calls to the openGL library going to feed into the same GL context, and if so are they going to conflict or screw with LWJGL in the process by changing states without its knowledge?

Thanks!

Chris

*

Offline spasi

  • *****
  • 2016
    • WebHotelier
Re: Mixing LWJGL with native OpenGL?
« Reply #1 on: March 08, 2018, 11:27:37 »
It's possible, easy and safe. There's no difference between a native DLL doing OpenGL calls and LWJGL doing OpenGL calls. Technically it's the same thing, the LWJGL bindings use JNI to delegate the function calling to a DLL. The same function pointers are used, with the same handles and parameter values.

In general, OpenGL functions are "thread-local", they're processed by the OpenGL context that is current in the current thread. You can make a thread current in native code and do OpenGL calls in the same thread from Java, and vice-versa.

being able to use unmanaged native memory more efficiently for blocks of data.

Please note that LWJGL 3 has powerful mechanisms for off-heap memory management. There are three different memory allocators to choose from, there's a stack allocation API for efficient local allocations and there are debugging utilities (e.g. memory leak tracking). More details here:

Memory management in LWJGL 3

Re: Mixing LWJGL with native OpenGL?
« Reply #2 on: March 08, 2018, 11:51:02 »
Great stuff! Thanks for the info! :) will look into the LWJGL 3 stuff when we finally get the port complete.