]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_entrypoints.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_entrypoints.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
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 // File: vogl_entrypoints.h
27 #ifndef VOGL_ENTRYPOINTS_H
28 #define VOGL_ENTRYPOINTS_H
29
30 #include "vogl_hash_map.h"
31
32 //----------------------------------------------------------------------------------------------------------------------
33 // define GL/GLX function pointer typedefs, i.e. glXGetProcAddress_func_ptr_t
34 //----------------------------------------------------------------------------------------------------------------------
35 #define DEF_PROTO(exported, category, ret, ret_type, num_params, name, args, params) typedef ret(*name##_func_ptr_t) args;
36 #define DEF_PROTO_VOID(exported, category, ret, ret_type, num_params, name, args, params) typedef ret(*name##_func_ptr_t) args;
37 #include "gl_glx_protos.inc"
38 #undef DEF_PROTO
39 #undef DEF_PROTO_VOID
40
41 // structure containing the actual gl/glx driver entrypoints
42 struct actual_gl_entrypoints_t
43 {
44 // The "direct" func pointers refer DIRECTLY to the driver's GL entrypoints. DO NOT call them unless you know why you need to.
45 #define DEF_PROTO(exported, category, ret, ret_type, num_params, name, args, params) name##_func_ptr_t m_##name##_direct;
46 #define DEF_PROTO_VOID(exported, category, ret, ret_type, num_params, name, args, params) name##_func_ptr_t m_##name##_direct;
47 #include "gl_glx_protos.inc"
48
49 // The non-direct func pointers (use these by default) pointer to wrappers funcs in vogl_entrypoints.cpp which call our global prolog function before calling the direct func ptr, then the epilog.
50 #define DEF_PROTO(exported, category, ret, ret_type, num_params, name, args, params) name##_func_ptr_t m_##name;
51 #define DEF_PROTO_VOID(exported, category, ret, ret_type, num_params, name, args, params) name##_func_ptr_t m_##name;
52 #include "gl_glx_protos.inc"
53 };
54
55 extern actual_gl_entrypoints_t g_vogl_actual_gl_entrypoints;
56
57 #define GL_ENTRYPOINT(x) g_vogl_actual_gl_entrypoints.m_##x
58
59 // The "direct" entrypoints are the REAL driver entrypoints, i.e. they skip our GL func prolog/epilog callbacks.
60 // Don't use this unless you know exactly why you need to.
61 #define DIRECT_GL_ENTRYPOINT(x) g_vogl_actual_gl_entrypoints.m_##x##_direct
62
63 //----------------------------------------------------------------------------------------------------------------------
64 // gl/glx entrypoint enum, enum format is VOGL_ENTRYPOINT_##name
65 //----------------------------------------------------------------------------------------------------------------------
66 #define DEF_PROTO_EXPORTED_VOID
67 #define DEF_PROTO_EXPORTED
68 #define DEF_PROTO_INTERNAL_VOID
69 #define DEF_PROTO_INTERNAL
70 #define DEF_FUNCTION_BEGIN(exported, category, ret, ret_type, num_params, name, args, params) VOGL_ENTRYPOINT_##name,
71 #define DEF_FUNCTION_INFO(namespace_index, return_spectype, category, version, profile, deprecated, is_whitelisted, is_nullable, whitelisted_for_displaylists, listable)
72 #define DEF_FUNCTION_BEGIN_PARAMS
73 #define DEF_FUNCTION_IN_VALUE_PARAM(namespace_index, spectype, type, ctype, name)
74 #define DEF_FUNCTION_IN_REFERENCE_PARAM(namespace_index, spectype, type, ctype, name)
75 #define DEF_FUNCTION_IN_ARRAY_PARAM(namespace_index, spectype, type, ctype, name, size)
76 #define DEF_FUNCTION_OUT_REFERENCE_PARAM(namespace_index, spectype, type, ctype, name)
77 #define DEF_FUNCTION_OUT_ARRAY_PARAM(namespace_index, spectype, type, ctype, name, size)
78 #define DEF_FUNCTION_END_PARAMS
79 #define DEF_FUNCTION_RETURN(spectype, type, ctype)
80 #define DEF_FUNCTION_END(exported, category, ret, ret_type, num_params, name, args, params)
81
82 enum gl_entrypoint_id_t
83 {
84     VOGL_ENTRYPOINT_INVALID = -1,
85
86 #include "gl_glx_func_descs.inc"
87
88     VOGL_NUM_ENTRYPOINTS
89 };
90
91 //----------------------------------------------------------------------------------------------------------------------
92 // gl/glx entrypoint description/parameter table
93 //----------------------------------------------------------------------------------------------------------------------
94 enum gl_entrypoint_param_class_t
95 {
96     VOGL_VALUE_PARAM,
97     VOGL_REF_PARAM,
98     VOGL_ARRAY_PARAM,
99     VOGL_TOTAL_PARAM_CLASSES
100 };
101
102 //----------------------------------------------------------------------------------------------------------------------
103 // struct gl_entrypoint_param_desc_t
104 //----------------------------------------------------------------------------------------------------------------------
105 struct gl_entrypoint_param_desc_t
106 {
107     // Be careful modifying the order of these members - they are initialized via macros in vogl_entrypoints.cpp.
108     const char *m_pName;
109     const char *m_pSpec_type;
110     vogl_ctype_t m_ctype;
111     // Important: params marked as "reference" are not always to be trusted, the spec file sometimes marks things as ref params (like glxgetprocaddres's procname) that are really arrays.
112     // Also, the serialized class values may differ from the param classes (i.e. an array of ubytes will be serialized as an array, not a ref)
113     gl_entrypoint_param_class_t m_class;
114     bool m_input;
115     const char *m_pSize;
116     vogl_namespace_t m_namespace;
117     bool m_has_custom_array_size_macro;
118     bool m_custom_array_size_macro_is_missing;
119 };
120
121 #define VOGL_MAX_ENTRYPOINT_PARAMETERS 24
122
123 //----------------------------------------------------------------------------------------------------------------------
124 // enum gl_entrypoint_flags_t
125 //----------------------------------------------------------------------------------------------------------------------
126 enum gl_entrypoint_flags_t
127 {
128     cGLEFPrintedUnimplementedWarning = 1
129 };
130
131 //----------------------------------------------------------------------------------------------------------------------
132 // struct gl_entrypoint_desc_t
133 // Beware, order matters in here!
134 // IMPORTANT: If you modify this struct, also modify the DEF_FUNCTION_BEGIN/DEF_FUNCTION_END macros.
135 // TODO:
136 //  Add entrypoint prefix enum (glX, wgl, egl, gl) and member field here, like voglgen uses. Right now we have to keep on poking at the API prefix string, which is silly at runtime.
137 //  Split this struct up into two structs: static stuff (from the .inc file) and dynamic members (modified at runtime)
138 //----------------------------------------------------------------------------------------------------------------------
139 struct gl_entrypoint_desc_t
140 {
141     const char *m_pName;
142     bool m_exported;
143     vogl_ctype_t m_return_ctype; // will be VOGL_VOID if the func has no return
144     uint32_t m_num_params;
145     const char *m_pParam_str;
146     vogl_void_func_ptr_t m_pWrapper_func;
147
148     vogl_namespace_t m_return_namespace;
149     const char *m_pReturn_spec_type;
150     const char *m_pCategory;
151     const char *m_pVersion;
152     const char *m_pProfile;
153     const char *m_pDeprecated;
154     bool m_is_whitelisted;
155     bool m_is_nullable;
156     bool m_whitelisted_for_displaylists;
157     bool m_is_listable;
158
159     bool m_has_custom_func_handler;
160     bool m_custom_array_size_macro_is_missing;
161     bool m_custom_return_param_array_size_macro_is_missing;
162     atomic64_t m_trace_call_counter;
163     uint64_t m_flags; // gl_entrypoint_flags_t
164
165     const char *m_pAPI_prefix; // "GLX", "GL", "WGL", "EGL", etc.
166 };
167
168 //----------------------------------------------------------------------------------------------------------------------
169 // Global entrypoint/parameter description tables
170 //----------------------------------------------------------------------------------------------------------------------
171 extern gl_entrypoint_desc_t g_vogl_entrypoint_descs[VOGL_NUM_ENTRYPOINTS];
172
173 extern gl_entrypoint_param_desc_t g_vogl_entrypoint_param_descs[VOGL_NUM_ENTRYPOINTS][VOGL_MAX_ENTRYPOINT_PARAMETERS];
174
175 typedef vogl::hash_map<dynamic_string, gl_entrypoint_id_t, hasher<dynamic_string>, dynamic_string_equal_to_case_sensitive> entrypoint_name_hash_map_t;
176 extern entrypoint_name_hash_map_t g_vogl_entrypoint_hashmap;
177
178 extern vogl_void_func_ptr_t g_vogl_actual_gl_entrypoint_direct_func_ptrs[VOGL_NUM_ENTRYPOINTS];
179 extern vogl_void_func_ptr_t g_vogl_actual_gl_entrypoint_func_ptrs[VOGL_NUM_ENTRYPOINTS];
180
181 //----------------------------------------------------------------------------------------------------------------------
182 // Typedefs/Functions
183 //----------------------------------------------------------------------------------------------------------------------
184 typedef vogl_void_func_ptr_t (*vogl_gl_get_proc_address_helper_func_ptr_t)(const char *pName);
185
186 // pGet_proc_address_helper_func must be valid
187 void vogl_init_actual_gl_entrypoints(vogl_gl_get_proc_address_helper_func_ptr_t pGet_proc_address_helper_func, bool wrap_all_gl_calls = true);
188
189 typedef void (*vogl_gl_func_prolog_epilog_func_t)(gl_entrypoint_id_t entrypoint_id, void *pUser_data, void **pStack_data);
190 void vogl_set_direct_gl_func_prolog(vogl_gl_func_prolog_epilog_func_t pFunc, void *pUser_data);
191 void vogl_set_direct_gl_func_epilog(vogl_gl_func_prolog_epilog_func_t pFunc, void *pUser_data);
192
193 void vogl_init_gl_entrypoint_descs();
194
195 // Returns VOGL_ENTRYPOINT_INVALID if the func name can't be found.
196 gl_entrypoint_id_t vogl_find_entrypoint(const dynamic_string &name);
197
198 bool vogl_does_entrypoint_refer_to_namespace(gl_entrypoint_id_t entrypoint_id, vogl_namespace_t namespace_id);
199
200 #endif // VOGL_ENTRYPOINTS_H