]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_ctypes.h
Initial vogl checkin
[vogl] / src / voglcommon / vogl_ctypes.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_ctypes.h
27 #ifndef VOGL_CTYPES_H
28 #define VOGL_CTYPES_H
29
30 //----------------------------------------------------------------------------------------------------------------------
31 // typedefs/helpers
32 //----------------------------------------------------------------------------------------------------------------------
33 typedef void (*vogl_void_func_ptr_t)(void);
34
35 template <typename T>
36 struct gl_ctype_sizeof
37 {
38     enum
39     {
40         size = sizeof(T)
41     };
42 };
43 template <>
44 struct gl_ctype_sizeof<void>
45 {
46     enum
47     {
48         size = 0
49     };
50 };
51 template <>
52 struct gl_ctype_sizeof<_XDisplay>
53 {
54     enum
55     {
56         size = -1
57     };
58 };
59 template <>
60 struct gl_ctype_sizeof<_cl_context>
61 {
62     enum
63     {
64         size = -1
65     };
66 };
67 template <>
68 struct gl_ctype_sizeof<_cl_event>
69 {
70     enum
71     {
72         size = -1
73     };
74 };
75
76 // vogl_trace_ptr_value is large enough to hold any trace pointer, or any trace GLintptr, GLsizeiptr, or ptrdiff_t
77 typedef uint64_t vogl_trace_ptr_value;
78
79 //----------------------------------------------------------------------------------------------------------------------
80 // ctype enum
81 //----------------------------------------------------------------------------------------------------------------------
82 // gl/glx type enums
83 enum vogl_ctype_t
84 {
85 #define DEF_TYPE(name, ctype) name,
86 #include "gl_glx_ctypes.inc"
87 #undef DEF_TYPE
88     VOGL_NUM_CTYPES
89 };
90
91 //----------------------------------------------------------------------------------------------------------------------
92 // ctype desc struct
93 //----------------------------------------------------------------------------------------------------------------------
94 struct vogl_ctype_desc_t
95 {
96     vogl_ctype_t m_ctype;
97     vogl_ctype_t m_pointee_ctype; // will be VOGL_VOID if not valid
98     const char *m_pName;
99     const char *m_pCType;
100     int m_size; // will be 0 for void, -1 for opaque types, note this is the size of the ctype in the current process!
101
102     uint m_loki_type_flags; // see loki::TypeTraits::typeFlags
103
104     bool m_is_pointer;
105     bool m_is_opaque_pointer; // true if the pointer points to an opaque type of unknown/undefind size
106     bool m_is_pointer_diff;   // true if the size of this ctype varies depending on 32/64-bit compilation (intptr_t, or ptrdiff_t)
107     bool m_is_opaque_type;    // true if the data type is opaque (not well defined or useful to tracing/replaying, probably varies in size in 32-bit vs 64-bit)
108 };
109
110 //----------------------------------------------------------------------------------------------------------------------
111 // class vogl_ctypes
112 //----------------------------------------------------------------------------------------------------------------------
113 class vogl_ctypes
114 {
115 public:
116     vogl_ctypes(); // purposely do nothing here, because this object is initialized before global construction time
117     vogl_ctypes(uint trace_ptr_size)
118     {
119         init(trace_ptr_size);
120     }
121
122     void init();
123     void init(uint trace_ptr_size);
124
125     inline uint get_pointer_size() const
126     {
127         return m_pointer_size;
128     }
129
130     void change_pointer_sizes(uint trace_ptr_size);
131
132     inline const vogl_ctype_desc_t &operator[](vogl_ctype_t ctype) const
133     {
134         VOGL_ASSERT(ctype < VOGL_NUM_CTYPES);
135         return m_vogl_ctype_descs[ctype];
136     }
137     inline vogl_ctype_desc_t &operator[](vogl_ctype_t ctype)
138     {
139         VOGL_ASSERT(ctype < VOGL_NUM_CTYPES);
140         return m_vogl_ctype_descs[ctype];
141     }
142
143     inline const vogl_ctype_desc_t &get_desc(vogl_ctype_t ctype) const
144     {
145         return (*this)[ctype];
146     }
147     inline vogl_ctype_desc_t &get_desc(vogl_ctype_t ctype)
148     {
149         return (*this)[ctype];
150     }
151
152     // Returns VOGL_VOID if not valid
153     inline vogl_ctype_t get_pointee_ctype(vogl_ctype_t ctype) const
154     {
155         return (*this)[ctype].m_pointee_ctype;
156     }
157
158     inline const char *get_name(vogl_ctype_t ctype) const
159     {
160         return (*this)[ctype].m_pName;
161     }
162     inline const char *get_ctype_name(vogl_ctype_t ctype) const
163     {
164         return (*this)[ctype].m_pCType;
165     }
166     inline int get_size(vogl_ctype_t ctype) const
167     {
168         return (*this)[ctype].m_size;
169     }
170     inline uint get_loki_type_flags(vogl_ctype_t ctype) const
171     {
172         return (*this)[ctype].m_loki_type_flags;
173     }
174     inline bool is_pointer(vogl_ctype_t ctype) const
175     {
176         return (*this)[ctype].m_is_pointer;
177     }
178     inline bool is_opaque_pointer(vogl_ctype_t ctype) const
179     {
180         return (*this)[ctype].m_is_opaque_pointer;
181     }
182
183     vogl_ctypes &operator=(const vogl_ctypes &other);
184
185 private:
186     vogl_ctype_desc_t m_vogl_ctype_descs[VOGL_NUM_CTYPES];
187     uint m_pointer_size;
188 };
189
190 extern vogl_ctypes g_vogl_process_gl_ctypes;
191
192 //----------------------------------------------------------------------------------------------------------------------
193 // Functions
194 //----------------------------------------------------------------------------------------------------------------------
195 void vogl_dump_gl_ctypes();
196 void vogl_init_gl_ctypes();
197
198 #endif // VOGL_CTYPES_H