FastUIDraw
gl_binding.hpp
Go to the documentation of this file.
1 /*!
2  * \file gl_binding.hpp
3  * \brief file gl_binding.hpp
4  *
5  * Adapted from: ngl_backend.hpp of WRATH:
6  *
7  * Copyright 2013 by Nomovok Ltd.
8  * Contact: info@nomovok.com
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@nomovok.com>
16  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
17  *
18  */
19 
20 #ifndef FASTUIDRAW_GL_BINDING_HPP
21 #define FASTUIDRAW_GL_BINDING_HPP
22 
23 #include <fastuidraw/util/util.hpp>
25 
26 namespace fastuidraw {
27 
28 
29 /*!\addtogroup GLUtility
30  * @{
31  */
32 
33 /*!
34  * \brief
35  * Provides interface for application to use GL where function pointers
36  * are auto-resolved transparently and under debug provides error checking.
37  * Built as a part of a seperate library; for GL it is libNGL; for GLES
38  * it is NGLES. The header defines for each GL/GLES function, glFoo, the
39  * macro fastuidraw_glFoo.
40  *
41  * Short version:
42  * - application should call fastuidraw::gl_binding::get_proc_function()
43  * to set the function which will be used to fetch GL function pointers.
44  * - If an application wishes, it can include <fastuidraw/gl_backend/ngl_header.hpp>.
45  * The header will add the GL function-macros and an application can
46  * issue GL calls without needing to fetch the GL functions via
47  * fastuidraw_glFoo where glFoo is the GL funcion to all. Under release,
48  * the macros are defined to function pointers that automatically set
49  * themselves up correcty. For debug, the macros preceed and postceed each
50  * GL function call with error checking call backs so an application writer
51  * can quickly know what line/file triggered an GL error. If an application does
52  * not wish to use the macro system (and will also need to fetch function pointers
53  * itself) it can just include <fastuidraw/gl_backend/gl_header.hpp> which
54  * will include the correct system GL/GLES headers.
55  *
56  * Long Version:
57  *
58  * The namespace gl_binding provides an interface for an application
59  * to specify how to fetch GL function pointers (see
60  * fastuidraw::gl_binding::get_proc_function()) and additional
61  * functionality of where to write/store GL error messages. An application
62  * can also use this functionality by including <fastuidraw/gl_backend/ngl_header.hpp>.
63  * The header will create a macro fastuidraw_glFoo for each GL function
64  * glFoo. If FASTUIDRAW_DEBUG is defined, each GL call will be preceded
65  * by a callback and postceeded by another call back. The preceed callback
66  * to the GL call will call the implementation of CallbackGL::pre_call() of
67  * each active CallbackGL object. The post-process callback will repeatedly
68  * call glGetError (until it returns no error) to build an error-string. If
69  * the error string is non-empty, it is printed to stderr. In addition,
70  * regardless if the error-string is non-empty, CallbackGL::post_call() of
71  * each active CallbackGL is called.
72  *
73  * The gl_binding system requires that an application provides
74  * a function which the binding system uses to fetch function
75  * pointers for the GL API, this is set via
76  * gl_binding::get_proc_function().
77  *
78  * Lastly, before using a GL (or GLES) function, an application should
79  * check the GL implementation supports the named function by examining
80  * the GL version and/or extensions itself before using the function.
81  */
82 namespace gl_binding {
83 
84 /*!
85  * \brief
86  * A CallbackGL defines the interface (via its base class)
87  * for callbacks before and after each GL call.
88  */
90 {
91 public:
92  CallbackGL(void);
93 };
94 
95 /*!
96  * Sets the function that the system uses
97  * to fetch the function pointers for GL or GLES.
98  * \param get_proc value to use, default is nullptr.
99  * \param fetch_functions if true, fetch all GL functions
100  * immediately instead of fetching on
101  * first call.
102  */
103 void
105  bool fetch_functions = true);
106 /*!
107  * Sets the function that the system uses
108  * to fetch the function pointers for GL or GLES.
109  * \param datum data pointer passed to get_proc when invoked
110  * \param get_proc value to use, default is nullptr.
111  * \param fetch_functions if true, fetch all GL functions
112  * immediately instead of fetching on
113  * first call.
114  */
115 void
116 get_proc_function(void *datum,
117  void* (*get_proc)(void*, c_string),
118  bool fetch_functions = true);
119 
120 /*!
121  * Fetches a GL function using the function fetcher
122  * passed to get_proc_function().
123  * \param function name of function to fetch
124  */
125 void*
126 get_proc(c_string function);
127 
128 /*!
129  * Function that implements \ref FASTUIDRAW_GL_MESSAGE
130  */
131 void
132 message(c_string message, c_string src_file, int src_line);
133 }
134 
135 /*!\def FASTUIDRAW_GL_MESSAGE
136  * Use this macro to emit a string to each of the
137  * gl_binding::CallbackGL objects that are active.
138  */
139 #define FASTUIDRAW_GL_MESSAGE(X) \
140  gl_binding::message(X, __FILE__, __LINE__)
141 
142 /*! @} */
143 }
144 
145 #endif
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
void get_proc_function(void *(*get_proc)(c_string), bool fetch_functions=true)
file util.hpp
file api_callback.hpp
const char * c_string
Conveniant typedef for C-style strings.
Definition: util.hpp:135
void * get_proc(c_string function)
virtual void message(c_string message, c_string src_file, int src_line)=0
A CallbackGL defines the interface (via its base class) for callbacks before and after each GL call...
Definition: gl_binding.hpp:89