Page 1 of 1

Integration with existing GL context

Posted: 13 Oct 2020, 17:24
by lemmy101
So we have a java game that's using the lwjgl library to provide opengl support. Never been happy with our proprietry ui support and looking into options.

I'm looking into if noesis will work for us, however the samples don't seem to answer my question. I looked at Integration, Integration GLUT etc, but can't see any evidence of a way to use another pre-existing opengl context for noesis. To be clear, since lwjgl is an external library, I'm assuming we'd need to ship in a pointer to the existing gl context to get it to render the ui onto the game's framebuffer? It's not really practical for us to get noesis to create the gl context and pass it into lwjgl without making big changes to it.

I'll admit I'm really more familiar with how DX works, so am I misunderstanding something about how opengl operates and this will all just magically work without the need to do this? as it seems the RenderDevice class creates a new device / context internally and has no options to do otherwise.

Ideally we'd do:

lwjgl native: creates opengl context, passes handle to java.
java: passes handle to dll that will interact with noesis
noesis integration dll: initializes noesis with the passed handle.

Re: Integration with existing GL context

Posted: 13 Oct 2020, 17:43
by jsantos
In our architecture, a RenderDevice does not create a context (OpenGL context, D3D11 device), it is passed at creation time.
D3D11RenderDevice(ID3D11DeviceContext* context, bool sRGB = false);
GLRenderDevice(bool sRGB = false);
In the case of OpenGL, the context cannot be passed, it is assumed to be already active. This is exactly, what the Integration GLUT sample is doing. The context is created by GLUT, not Noesis.

For the rest of examples, we use our Application Framework, our application framework (optional, not part of the core) exposes a 'RenderContext' base class for implementing the initialization needed for each renderer.

Re: Integration with existing GL context

Posted: 13 Oct 2020, 19:03
by lemmy101
Great thanks for the information!

Re: Integration with existing GL context

Posted: 14 Oct 2020, 11:11
by jsantos
Please, let us know if you need more help with the renderer integration.

Re: Integration with existing GL context

Posted: 15 Oct 2020, 12:18
by lemmy101
Thanks! I called the native code from the NoesisInit function in the glut integration demo, after lwjgl initializes the window and openGL, and all seemed to work ok with the noesis calls - but then I get a JVM crash a little later after leaving the native code, during initialization of unrelated java stuff for the game, that I can only imagine is something to do with threading (the point the JVM dies is random and is happening in native code while java is processing lines 100% unrelated to gfx that differ each run.)

Sadly I don't really have much to go on here. Java's jvm crash reports are rather opaque. No information on where in native code is going wrong, just that its an access violation exception. I can only assume that lwjgl's native code is doing something noesis doesn't like, or noesis has set up something that it doesn't like, so am not really sure I can progress with this idea at this point.

I hate java lol biggest regret that we used it for this game.

Re: Integration with existing GL context

Posted: 15 Oct 2020, 14:34
by jsantos
Sorry about it, I can't help you with Java crashes but I would try commenting all lines in native code and add incrementally to discover what's causing the crash.

Good luck! 😉

Re: Integration with existing GL context

Posted: 15 Oct 2020, 15:32
by lemmy101
Thanks! Of course I'd never have expected you to help with java side of things. Unfortunately the line that causes the crash later is:

_view->GetRenderer()->Init(NoesisApp::GLFactory::CreateDevice(false));

;) so pretty much the most important line of the bunch.

Re: Integration with existing GL context

Posted: 15 Oct 2020, 19:05
by jsantos
Yes, I see...

Inside that Init, we are creating GPU resources and changing the state, maybe you need to restore it?