aboutsummaryrefslogtreecommitdiffstats
path: root/al/extension.cpp
blob: c442fa05b85fd1751e204a0e03db4199a9439abd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/**
 * OpenAL cross platform audio library
 * Copyright (C) 1999-2007 by authors.
 * This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the
 *  Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 * Or go to http://www.gnu.org/copyleft/lgpl.html
 */

#include "config.h"

#include <cctype>
#include <cstdlib>
#include <cstring>

#include "AL/al.h"
#include "AL/alc.h"

#include "alc/context.h"
#include "alstring.h"
#include "core/except.h"
#include "opthelpers.h"

#ifdef ALSOFT_EAX
#include "eax_globals.h"
#include "eax_x_ram.h"
#endif // ALSOFT_EAX

AL_API ALboolean AL_APIENTRY alIsExtensionPresent(const ALchar *extName)
START_API_FUNC
{
    ContextRef context{GetContextRef()};
    if(unlikely(!context)) return AL_FALSE;

    if(!extName)
        SETERR_RETURN(context, AL_INVALID_VALUE, AL_FALSE, "NULL pointer");

    size_t len{strlen(extName)};
#ifdef ALSOFT_EAX
    if (al::strcasecmp(eax_v2_0_ext_name_1, extName) == 0 ||
        al::strcasecmp(eax_v2_0_ext_name_2, extName) == 0 ||
        al::strcasecmp(eax_v3_0_ext_name, extName) == 0 ||
        al::strcasecmp(eax_v4_0_ext_name, extName) == 0 ||
        al::strcasecmp(eax_v5_0_ext_name, extName) == 0)
    {
        const auto is_present = eax_g_is_enabled && context->eax_is_capable();
        return is_present ? AL_TRUE : AL_FALSE;
    }

    if (al::strcasecmp(eax_x_ram_ext_name, extName) == 0)
    {
        const auto is_present = eax_g_is_enabled;
        return is_present ? AL_TRUE : AL_FALSE;
    }
#endif // ALSOFT_EAX
    const char *ptr{context->mExtensionList};
    while(ptr && *ptr)
    {
        if(al::strncasecmp(ptr, extName, len) == 0 && (ptr[len] == '\0' || isspace(ptr[len])))
            return AL_TRUE;

        if((ptr=strchr(ptr, ' ')) != nullptr)
        {
            do {
                ++ptr;
            } while(isspace(*ptr));
        }
    }

    return AL_FALSE;
}
END_API_FUNC


AL_API ALvoid* AL_APIENTRY alGetProcAddress(const ALchar *funcName)
START_API_FUNC
{
    if(!funcName) return nullptr;
#ifdef ALSOFT_EAX
    if (al::strcasecmp(funcName, eax_eax_set_func_name) == 0)
    {
        if (!eax_g_is_enabled)
        {
            return nullptr;
        }

        ContextRef context{GetContextRef()};

        if (!context || !context->eax_is_capable())
        {
            return nullptr;
        }

        return reinterpret_cast<ALvoid*>(EAXSet);
    }

    if (al::strcasecmp(funcName, eax_eax_get_func_name) == 0)
    {
        if (!eax_g_is_enabled)
        {
            return nullptr;
        }

        ContextRef context{GetContextRef()};

        if (!context || !context->eax_is_capable())
        {
            return nullptr;
        }

        return reinterpret_cast<ALvoid*>(EAXGet);
    }

    if (al::strcasecmp(funcName, eax_eax_set_buffer_mode_func_name) == 0)
    {
        if (!eax_g_is_enabled)
        {
            return nullptr;
        }

        ContextRef context{GetContextRef()};

        if (!context)
        {
            return nullptr;
        }

        return reinterpret_cast<ALvoid*>(EAXSetBufferMode);
    }

    if (al::strcasecmp(funcName, eax_eax_get_buffer_mode_func_name) == 0)
    {
        if (!eax_g_is_enabled)
        {
            return nullptr;
        }

        ContextRef context{GetContextRef()};

        if (!context)
        {
            return nullptr;
        }

        return reinterpret_cast<ALvoid*>(EAXGetBufferMode);
    }
#endif // ALSOFT_EAX
    return alcGetProcAddress(nullptr, funcName);
}
END_API_FUNC

AL_API ALenum AL_APIENTRY alGetEnumValue(const ALchar *enumName)
START_API_FUNC
{
    if(!enumName) return static_cast<ALenum>(0);
#ifdef ALSOFT_EAX
    if (eax_g_is_enabled)
    {
        struct Descriptor
        {
            const char* name;
            ALenum value;
        }; // Descriptor

        constexpr Descriptor descriptors[] =
        {
            Descriptor{AL_EAX_RAM_SIZE_NAME, AL_EAX_RAM_SIZE},
            Descriptor{AL_EAX_RAM_FREE_NAME, AL_EAX_RAM_FREE},

            Descriptor{AL_STORAGE_AUTOMATIC_NAME, AL_STORAGE_AUTOMATIC},
            Descriptor{AL_STORAGE_HARDWARE_NAME, AL_STORAGE_HARDWARE},
            Descriptor{AL_STORAGE_ACCESSIBLE_NAME, AL_STORAGE_ACCESSIBLE},
        }; // descriptors

        for (const auto& descriptor : descriptors)
        {
            if (strcmp(descriptor.name, enumName) == 0)
            {
                return descriptor.value;
            }
        }
    }
#endif // ALSOFT_EAX
    return alcGetEnumValue(nullptr, enumName);
}
END_API_FUNC