mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
update openal
This commit is contained in:
parent
62f3b93ff9
commit
6721a6b021
287 changed files with 33851 additions and 27325 deletions
|
|
@ -2,13 +2,14 @@
|
|||
#define ALHELPERS_H
|
||||
|
||||
#include "AL/al.h"
|
||||
#include "AL/alc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Some helper functions to get the name from the format enums. */
|
||||
const char *FormatName(ALenum type);
|
||||
const char *FormatName(ALenum format);
|
||||
|
||||
/* Easy device init/deinit functions. InitAL returns 0 on success. */
|
||||
int InitAL(char ***argv, int *argc);
|
||||
|
|
@ -33,6 +34,54 @@ void al_nssleep(unsigned long nsec);
|
|||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "alspan.h"
|
||||
|
||||
int InitAL(al::span<std::string_view> &args)
|
||||
{
|
||||
ALCdevice *device{};
|
||||
|
||||
/* Open and initialize a device */
|
||||
if(args.size() > 1 && args[0] == "-device")
|
||||
{
|
||||
device = alcOpenDevice(std::string{args[1]}.c_str());
|
||||
if(!device)
|
||||
std::cerr<< "Failed to open \""<<args[1]<<"\", trying default\n";
|
||||
args = args.subspan(2);
|
||||
}
|
||||
if(!device)
|
||||
device = alcOpenDevice(nullptr);
|
||||
if(!device)
|
||||
{
|
||||
std::fprintf(stderr, "Could not open a device!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
ALCcontext *ctx{alcCreateContext(device, nullptr)};
|
||||
if(!ctx || alcMakeContextCurrent(ctx) == ALC_FALSE)
|
||||
{
|
||||
if(ctx)
|
||||
alcDestroyContext(ctx);
|
||||
alcCloseDevice(device);
|
||||
std::fprintf(stderr, "Could not set a context!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const ALCchar *name{};
|
||||
if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT"))
|
||||
name = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER);
|
||||
if(!name || alcGetError(device) != AL_NO_ERROR)
|
||||
name = alcGetString(device, ALC_DEVICE_SPECIFIER);
|
||||
std::printf("Opened \"%s\"\n", name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ALHELPERS_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue