Search code examples
javalwjglopenal

OpeanAL buffers


According to my understanding of OpenAL objects, a OpenAL Buffer belongs to a device, and not a context. If I want to create a buffer I do so with alGenBuffers(), but I am not sure which device this buffer will be created on. How do I choose which device to create the buffer on?


Solution

  • OpenAL Buffer belongs to a device, and not a context

    When you create a buffer using alGenBuffers(), then the buffer is indeed created on a specific device. In short, when calling alGenBuffers() it gets the active context's device. The buffer is then created on that device.

    How do I choose which device to create the buffer on?

    Thus, you need to get another device and create a new context with that device:

    ALCdevice *device = alcOpenDevice(...);
    ALCcontext *context = alcCreateContext(device, NULL);
    

    Then make this new context the current active context:

    alcMakeContextCurrent(context);
    

    Now any alGenBuffers(), alBufferData(), etc. is applied to that active context and in turn applied to the active context's device.