blob: 51a59545754047aecb15b12fb5035637736844f0 [file] [log] [blame]
José Fonseca1b3d3752011-07-15 10:15:19 +01001/**************************************************************************
2 *
3 * Copyright 2011 Jose Fonseca
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 **************************************************************************/
25
26
27#include <string.h>
28#include <stdlib.h>
29
30#include <string>
31#include <map>
32
33#include "gltrace.hpp"
34
35
36namespace gltrace {
37
38
39typedef std::map<std::string, const char *> ExtensionsMap;
40
41// Cache of the translated extensions strings
42static ExtensionsMap extensionsMap;
43
44
45// Additional extensions to be advertised
46const char extra_extensions[] =
47 "GL_GREMEDY_string_marker "
48 "GL_GREMEDY_frame_terminator "
49;
50
51
52/**
53 * Translate the GL extensions string, adding new extensions.
54 */
55const char *
56translateExtensionsString(const char *extensions)
57{
58 ExtensionsMap::const_iterator it = extensionsMap.find(extensions);
59 if (it != extensionsMap.end()) {
60 return it->second;
61 }
62
63 size_t extensions_len = strlen(extensions);
64
65 char *new_extensions = (char *)malloc(extensions_len + 1 + sizeof extra_extensions);
66 if (!new_extensions) {
67 return extensions;
68 }
69
70 if (extensions_len) {
71 memcpy(new_extensions, extensions, extensions_len);
72
73 // Add space separator if necessary
74 if (new_extensions[extensions_len - 1] != ' ') {
75 new_extensions[extensions_len++] = ' ';
76 }
77 }
78
79 memcpy(new_extensions + extensions_len, extra_extensions, sizeof extra_extensions);
80
81 extensionsMap[extensions] = new_extensions;
82
83 return new_extensions;
84}
85
86
87} /* namespace gltrace */
88