glbinding  3.3.0.0
A C++ binding for the OpenGL API, generated using the gl.xml specification.
Loading...
Searching...
No Matches
Function.inl
Go to the documentation of this file.
1
2#pragma once
3
4
5#include <utility>
6#include <functional>
7#include <cassert>
8
9#include <glbinding/Value.h>
12
13#include <glbinding/Boolean8.h>
14
15
16
17namespace glbinding
18{
19
20
21template <typename ReturnType, typename... Arguments>
22struct BasicCallHelper
23{
24 inline static ReturnType call(const glbinding::Function<ReturnType, Arguments...> * function, Arguments&&... arguments)
25 {
26 return reinterpret_cast<typename glbinding::Function<ReturnType, Arguments...>::Signature>(function->address())(std::forward<Arguments>(arguments)...);
27 }
28};
29
30
31// Special case for booleans because of MSVC differing behavior
32
33
34template <typename... Arguments>
35struct BasicCallHelper<glbinding::Boolean8, Arguments...>
36{
37 inline static glbinding::Boolean8 call(const glbinding::Function<glbinding::Boolean8, Arguments...> * function, Arguments&&... arguments)
38 {
39 return reinterpret_cast<typename glbinding::Function<glbinding::Boolean8::underlying_type, Arguments...>::Signature>(function->address())(std::forward<Arguments>(arguments)...);
40 }
41};
42
43
44
45template <typename ReturnType, typename... Arguments>
47{
49 {
51
52 if (function->isAnyEnabled(glbinding::CallbackMask::Parameters))
53 {
54 functionCall.parameters = glbinding::createValues(std::forward<Arguments>(arguments)...);
55 }
56
57 if (function->isEnabled(glbinding::CallbackMask::Before))
58 {
60
61 if (function->beforeCallback())
62 {
63 function->beforeCallback()(std::forward<Arguments>(arguments)...);
64 }
65 }
66
67 auto value = BasicCallHelper<ReturnType, Arguments ...>::call(function, std::forward<Arguments>(arguments)...);
68
69 if (function->isAnyEnabled(glbinding::CallbackMask::ReturnValue))
70 {
71 functionCall.returnValue = glbinding::createValue(value);
72 }
73
74 if (function->isEnabled(glbinding::CallbackMask::After))
75 {
77
78 if (function->afterCallback())
79 {
80 function->afterCallback()(value, std::forward<Arguments>(arguments)...);
81 }
82 }
83
84 if (function->isEnabled(glbinding::CallbackMask::Logging))
85 {
87 }
88
89 return value;
90 }
91};
92
93
94template <typename... Arguments>
96{
97 inline static void call(const glbinding::Function<void, Arguments...> * function, Arguments&&... arguments)
98 {
100
101 if (function->isAnyEnabled(glbinding::CallbackMask::Parameters))
102 {
103 functionCall.parameters = glbinding::createValues(std::forward<Arguments>(arguments)...);
104 }
105
106 if (function->isEnabled(glbinding::CallbackMask::Before))
107 {
110 if (function->beforeCallback())
111 {
112 function->beforeCallback()(std::forward<Arguments>(arguments)...);
113 }
114 }
115
116 BasicCallHelper<void, Arguments ...>::call(function, std::forward<Arguments>(arguments)...);
117
118 if (function->isEnabled(glbinding::CallbackMask::After))
119 {
120 AbstractFunction::after(functionCall);
121
122 if (function->afterCallback())
123 {
124 function->afterCallback()(std::forward<Arguments>(arguments)...);
125 }
126 }
127
128 if (function->isEnabled(glbinding::CallbackMask::Logging))
129 {
130 AbstractFunction::log(std::move(functionCall));
131 }
132 }
133};
134
135
136template <typename ReturnType, typename... Arguments>
139, m_beforeCallback{nullptr}
140, m_afterCallback{nullptr}
141{
142}
143
144template <typename ReturnType, typename... Arguments>
149
150template <typename ReturnType, typename... Arguments>
152{
153 const auto myAddress = address();
154
155 if (myAddress == nullptr)
156 {
158 {
160 }
161 else
162 {
163 // Trying to call a function without check if it is resolvable is considered a programming error.
164 // You may try to call AbstractFunction::resolve first and check the address for validity (a pointer
165 // unequal to nullptr is considered valid) or check the exposition of associated extensions.
166 assert(false);
167 }
168
169 return ReturnType();
170 }
171
173 {
174 return FunctionHelper<ReturnType, Arguments...>::call(this, std::forward<Arguments>(arguments)...);
176 else
177 {
178 return BasicCallHelper<ReturnType, Arguments...>::call(this, std::forward<Arguments>(arguments)...);
179 }
180}
181
182template <typename ReturnType, typename... Arguments>
185 if (address() == nullptr)
186 {
187 return ReturnType();
188 }
189
190 return BasicCallHelper<ReturnType, Arguments...>::call(this, std::forward<Arguments>(arguments)...);
191}
192
193template <typename ReturnType, typename... Arguments>
196 m_beforeCallback = std::move(callback);
197}
199template <typename ReturnType, typename... Arguments>
202 m_beforeCallback = nullptr;
203}
204
205template <typename ReturnType, typename... Arguments>
210
211template <typename ReturnType, typename... Arguments>
213{
214 m_afterCallback = nullptr;
215}
216
217template <typename ReturnType, typename... Arguments>
219{
220 return m_beforeCallback;
221}
222
223template <typename ReturnType, typename... Arguments>
225{
226 return m_afterCallback;
227}
228
229template <typename ReturnType, typename... Arguments>
234
235template <typename ReturnType, typename... Arguments>
237{
238 return pos > -1 && AbstractFunction::maxPos() <= pos;
239}
240
241template <typename ReturnType, typename... Arguments>
246
247template <typename ReturnType, typename... Arguments>
249{
251 assert(pos > -1);
252
253 return m_states.at(pos);
254}
255
256template <typename ReturnType, typename... Arguments>
258{
259 m_states.resize(static_cast<std::size_t>(count));
260}
261
262
263} // namespace glbinding
The AbstractFunction represents an OpenGL API function by its name and entry point after dynamic addr...
Definition AbstractFunction.h:30
static void unresolved(const AbstractFunction *function)
Call unresolved callback.
static void before(const FunctionCall &call)
Call before callback.
static int currentPos()
Get index of current state.
static int maxPos()
Get highest state index currently used.
static void log(FunctionCall &&call)
Call log callback.
static void after(const FunctionCall &call)
Call after callback.
The State struct represents the configuration of a single OpenGL function for one thread....
Definition AbstractState.h:21
Boolean type based on an 8-bit integer.
Definition Boolean8.h:20
A FunctionCall represents a function call of an OpenGL API function, including the parameter and retu...
Definition FunctionCall.h:27
The Function represents an OpenGL API function with additional features.
Definition Function.h:78
void setAfterCallback(AfterCallback callback)
Register a callback that is triggered after a function call to the OpenGL driver.
Definition Function.inl:206
AfterCallback afterCallback() const
The accessor for the afterCallback.
Definition Function.inl:224
ReturnType operator()(Arguments &... arguments) const
Executes a function call on the resolved function pointer and passes the arguments.
Definition Function.inl:145
ReturnType call(Arguments &... arguments) const
Executes a function call on the resolved function pointer and passes the arguments.
Definition Function.inl:151
ReturnType directCall(Arguments... arguments) const
Executes a function call on the resolved function pointer and passes the arguments.
Definition Function.inl:183
typename CallbackType< ReturnType, Arguments... >::type AfterCallback
The callback type for the after callback.
Definition Function.h:84
virtual AbstractState & state() const override
Get current state.
Definition Function.inl:242
Function(const char *name)
Constructor.
Definition Function.inl:137
void setBeforeCallback(BeforeCallback callback)
Register a callback that is triggered before a function call to the OpenGL driver.
Definition Function.inl:194
void clearBeforeCallback()
Clears any previously registered before callback.
Definition Function.inl:200
void clearAfterCallback()
Clears any previously registered after callback.
Definition Function.inl:212
virtual void resizeStates(int count) override
Resize internal cache of states.
Definition Function.inl:257
BeforeCallback beforeCallback() const
The accessor for the beforeCallback.
Definition Function.inl:218
virtual bool hasState() const override
Checks for existence of the current configured state.
Definition Function.inl:230
typename CallbackType< void, Arguments... >::type BeforeCallback
The callback type for the before callback.
Definition Function.h:83
The Value class represents a printable wrapper around an OpenGL data type.
Definition Value.h:30
Contains all the classes of glbinding.
std::vector< std::unique_ptr< AbstractValue > > createValues(Arguments &&... arguments)
A wrapper around the creation of a vector of arguments.
Definition Value.inl:64
@ Parameters
Enables the provision of parameter values in the before and after callbacks.
@ Unresolved
Enables the callback for unresolved function calls.
@ After
Enables the after callbacks.
@ Logging
Enables logging.
@ Before
Enables the before callbacks.
@ ReturnValue
Enables the provision of a return value in the after callback.
std::unique_ptr< AbstractValue > createValue(const Argument &argument)
A wrapper around the type deduction and memory allocation of a specific argument.
Definition Value.inl:58
Helper struct for calling GL functions and registered callbacks.
Definition Function.inl:47
static ReturnType call(const glbinding::Function< ReturnType, Arguments... > *function, Arguments &&... arguments)
Definition Function.inl:48