Audio: Fix loading of OpenAL extensions (pointers are context-local)
This commit is contained in:
@@ -22,7 +22,7 @@ namespace Nz
|
||||
class NAZARA_AUDIO_API OpenALBuffer final : public AudioBuffer
|
||||
{
|
||||
public:
|
||||
inline OpenALBuffer(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint bufferId);
|
||||
inline OpenALBuffer(std::shared_ptr<AudioDevice> device, ALuint bufferId);
|
||||
OpenALBuffer(const OpenALBuffer&) = delete;
|
||||
OpenALBuffer(OpenALBuffer&&) = delete;
|
||||
~OpenALBuffer();
|
||||
@@ -44,7 +44,6 @@ namespace Nz
|
||||
const OpenALDevice& GetDevice() const;
|
||||
|
||||
ALuint m_bufferId;
|
||||
OpenALLibrary& m_library;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline OpenALBuffer::OpenALBuffer(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint bufferId) :
|
||||
inline OpenALBuffer::OpenALBuffer(std::shared_ptr<AudioDevice> device, ALuint bufferId) :
|
||||
AudioBuffer(std::move(device)),
|
||||
m_bufferId(bufferId),
|
||||
m_library(library)
|
||||
m_bufferId(bufferId)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,13 @@ namespace Nz
|
||||
Max = SourceLatency
|
||||
};
|
||||
|
||||
using ALFunction = void(*)(void);
|
||||
|
||||
class NAZARA_AUDIO_API OpenALDevice : public AudioDevice
|
||||
{
|
||||
friend OpenALLibrary;
|
||||
struct SymbolLoader;
|
||||
friend SymbolLoader;
|
||||
|
||||
public:
|
||||
OpenALDevice(OpenALLibrary& library, ALCdevice* device);
|
||||
@@ -41,11 +45,18 @@ namespace Nz
|
||||
OpenALDevice(OpenALDevice&&) = delete;
|
||||
~OpenALDevice();
|
||||
|
||||
bool ClearErrorFlag() const;
|
||||
|
||||
std::shared_ptr<AudioBuffer> CreateBuffer() override;
|
||||
std::shared_ptr<AudioSource> CreateSource() override;
|
||||
|
||||
inline bool DidLastCallSucceed() const;
|
||||
|
||||
float GetDopplerFactor() const override;
|
||||
inline ALFunction GetFunctionByIndex(std::size_t funcIndex) const;
|
||||
float GetGlobalVolume() const override;
|
||||
inline OpenALLibrary& GetLibrary();
|
||||
inline const OpenALLibrary& GetLibrary() const;
|
||||
Vector3f GetListenerDirection(Vector3f* up = nullptr) const override;
|
||||
Vector3f GetListenerPosition() const override;
|
||||
Quaternionf GetListenerRotation() const override;
|
||||
@@ -58,6 +69,9 @@ namespace Nz
|
||||
|
||||
void MakeContextCurrent() const;
|
||||
|
||||
template<typename... Args> void PrintFunctionCall(std::size_t funcIndex, Args... args) const;
|
||||
bool ProcessErrorFlag() const;
|
||||
|
||||
void SetDopplerFactor(float dopplerFactor) override;
|
||||
void SetGlobalVolume(float volume) override;
|
||||
void SetListenerDirection(const Vector3f& direction, const Vector3f& up = Vector3f::Up()) override;
|
||||
@@ -70,14 +84,30 @@ namespace Nz
|
||||
OpenALDevice& operator=(const OpenALDevice&) = delete;
|
||||
OpenALDevice& operator=(OpenALDevice&&) = delete;
|
||||
|
||||
// We give each device its own set of function pointer, even though regular OpenAL extensions are always the same (for a set library).
|
||||
// This makes it easier to wrap them (for error handling), and extension pointers are device-local anyway.
|
||||
#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) decltype(&::name) name;
|
||||
#include <Nazara/Audio/OpenALFunctions.hpp>
|
||||
|
||||
private:
|
||||
EnumArray<AudioFormat, ALenum> m_audioFormatValues;
|
||||
EnumArray<OpenALExtension, ALenum> m_extensionStatus;
|
||||
enum class FunctionIndex
|
||||
{
|
||||
#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) name,
|
||||
#include <Nazara/Audio/OpenALFunctions.hpp>
|
||||
|
||||
Count
|
||||
};
|
||||
|
||||
std::array<ALFunction, UnderlyingCast(FunctionIndex::Count)> m_originalFunctionPointer;
|
||||
std::string m_renderer;
|
||||
std::string m_vendor;
|
||||
EnumArray<AudioFormat, ALenum> m_audioFormatValues;
|
||||
EnumArray<OpenALExtension, ALenum> m_extensionStatus;
|
||||
OpenALLibrary& m_library;
|
||||
MovablePtr<ALCcontext> m_context;
|
||||
MovablePtr<ALCdevice> m_device;
|
||||
mutable bool m_didCollectErrors;
|
||||
mutable bool m_hadAnyError;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,30 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline bool OpenALDevice::DidLastCallSucceed() const
|
||||
{
|
||||
if (!m_didCollectErrors)
|
||||
ProcessErrorFlag();
|
||||
|
||||
return !m_hadAnyError;
|
||||
}
|
||||
|
||||
inline ALFunction OpenALDevice::GetFunctionByIndex(std::size_t funcIndex) const
|
||||
{
|
||||
assert(funcIndex < m_originalFunctionPointer.size());
|
||||
return m_originalFunctionPointer[funcIndex];
|
||||
}
|
||||
|
||||
inline OpenALLibrary& OpenALDevice::GetLibrary()
|
||||
{
|
||||
return m_library;
|
||||
}
|
||||
|
||||
inline const OpenALLibrary& OpenALDevice::GetLibrary() const
|
||||
{
|
||||
return m_library;
|
||||
}
|
||||
|
||||
inline bool OpenALDevice::IsExtensionSupported(OpenALExtension extension) const
|
||||
{
|
||||
return m_extensionStatus[extension];
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Nz
|
||||
OpenALLibrary& operator=(OpenALLibrary&&) = delete;
|
||||
|
||||
#define NAZARA_AUDIO_AL_ALC_FUNCTION(name) decltype(&::name) name;
|
||||
#define NAZARA_AUDIO_AL_EXT_FUNCTION(name)
|
||||
#include <Nazara/Audio/OpenALFunctions.hpp>
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Nz
|
||||
class NAZARA_AUDIO_API OpenALSource final : public AudioSource
|
||||
{
|
||||
public:
|
||||
inline OpenALSource(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint sourceId);
|
||||
inline OpenALSource(std::shared_ptr<AudioDevice> device, ALuint sourceId);
|
||||
OpenALSource(const OpenALSource&) = delete;
|
||||
OpenALSource(OpenALSource&&) = delete;
|
||||
~OpenALSource();
|
||||
@@ -76,7 +76,6 @@ namespace Nz
|
||||
std::shared_ptr<OpenALBuffer> m_currentBuffer;
|
||||
std::vector<std::shared_ptr<OpenALBuffer>> m_queuedBuffers;
|
||||
ALuint m_sourceId;
|
||||
OpenALLibrary& m_library;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline OpenALSource::OpenALSource(std::shared_ptr<AudioDevice> device, OpenALLibrary& library, ALuint sourceId) :
|
||||
inline OpenALSource::OpenALSource(std::shared_ptr<AudioDevice> device, ALuint sourceId) :
|
||||
AudioSource(std::move(device)),
|
||||
m_sourceId(sourceId),
|
||||
m_library(library)
|
||||
m_sourceId(sourceId)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user