Home > Blockchain >  Can an OpenAL source ever be 0?
Can an OpenAL source ever be 0?

Time:02-14

Can an OpenAL source generated by alGenSources() ever be 0?

Because I would like to store NULL as source whenever the source has stopped playing.

It is stored as an ALuint.

I couldn't find it in the Programmers guide.

CodePudding user response:

Unfortunately, you cannot rely on 0 being reserved as invalid, as it is allowed id by specs (up to implementation to decide).

According to OpenAL 1.1 specs:

2.12. Requesting Object Names

OpenAL provides calls to obtain object names. The application requests a number of objects of a given category using alGen{Object}s. The actual values of the names returned are implementation dependent. No guarantees on range or value are made.
...
void alGenBuffers (ALsizei n, ALuint *bufferNames);
void alGenSources (ALsizei n, ALuint *sourceNames);

From the other side, if you don't care about other OpenAL implementations, OpenAL soft (as for 1.17) internally returns values starting from 1, though this should be considered as implementation detail:

AL_API ALvoid AL_APIENTRY alGenSources(ALsizei n, ALuint *sources)
{
        ...
        err = NewThunkEntry(&source->id);
        ...
        sources[cur] = source->id;
}

ALenum NewThunkEntry(ALuint *index)
{
    ...
    *index = i 1;
    return AL_NO_ERROR;
}
  • Related