LWJGL Forum

Programming => OpenAL => Topic started by: bobjob on January 05, 2016, 10:34:21

Title: [SOLVED] Does OpenAL need to be on the main thread?
Post by: bobjob on January 05, 2016, 10:34:21
Just wondering if OpenAL is required to load/run on the same main thread along with OpenGL on any OS?
Title: Re: Does OpenAL need to be on the main thread?
Post by: Kai on January 05, 2016, 10:39:01
Neither OpenGL nor OpenAL need to run on the main thread. You can "render" graphics and sound on any thread.
What you probably mean by "OpenGL" is the need for window creation and window message processing to be on the main thread with some OS'es.
Title: Re: Does OpenAL need to be on the main thread?
Post by: bobjob on January 07, 2016, 07:50:31
When I used LWJGL 2 i had to make sure all GL calls were on the same Thread. I thought that LWJGL3 was the same, and that maybe OpenAL.

My issue is one of dynamic loading. I wanted to know how much resource loading I can get away with by loading it on another Thread. In this case making calls to bind the buffer.
Title: Re: Does OpenAL need to be on the main thread?
Post by: spasi on January 07, 2016, 11:14:39
OpenGL has the concept of current contexts. You can only call OpenGL functions in threads where a context is current (but that doesn't mean you can't have multiple contexts in multiple threads).

OpenAL normally has a process-wide context. You can call OpenAL functions from any thread. Unless you use the ALC_EXT_thread_local_context (http://kcat.strangesoft.net/openal-extensions/EXT_thread_local_context.txt) extension, in which case it operates more like OpenGL.

In terms of performance, it does make sense to use a separate thread for OpenAL. Especially with OpenAL Soft that LWJGL ships with, all sound processing happens on the CPU. It may be trivial for plain stereo playback, but depending on the features/extensions used (e.g. ALC_EXT_EFX or ALC_SOFT_HRTF (http://kcat.strangesoft.net/openal-extensions/SOFT_HRTF.txt)), it can get costly.
Title: Re: Does OpenAL need to be on the main thread?
Post by: bobjob on January 07, 2016, 13:24:04
thanks, that helps a lot.