File tree Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Expand file tree Collapse file tree 2 files changed +66
-2
lines changed Original file line number Diff line number Diff line change 5
5
extern "C" {
6
6
#endif
7
7
8
- int gl_layer_init (int gl_version_major , int gl_version_minor );
8
+ int gl_layer_init (unsigned int gl_version_major , unsigned int gl_version_minor );
9
9
void gl_layer_terminate ();
10
10
11
11
void gl_layer_callback (const char * name , void * func_ptr , int num_args , ...);
12
12
13
+ typedef void (* GLLayerOutputFun )(const char * text );
14
+ void gl_layer_set_output_callback (GLLayerOutputFun callback );
15
+
13
16
#ifdef __cplusplus
14
17
};
15
18
#endif
Original file line number Diff line number Diff line change 1
- #include < gl_layer/context.h>
1
+ #include < gl_layer/context.h>
2
+
3
+ #include < cstdio>
4
+
5
+ namespace gl_layer {
6
+
7
+ void default_output_func (const char * text) {
8
+ printf (" %s" , text);
9
+ }
10
+
11
+ struct Version {
12
+ unsigned int major = 0 ;
13
+ unsigned int minor = 0 ;
14
+ };
15
+
16
+ class Context {
17
+ public:
18
+ explicit Context (Version gl_version) : gl_version(gl_version) {
19
+
20
+ }
21
+
22
+ void set_output_callback (GLLayerOutputFun callback) {
23
+ output_fun = callback;
24
+ }
25
+
26
+ private:
27
+ Version gl_version;
28
+ GLLayerOutputFun output_fun = &default_output_func;
29
+ };
30
+
31
+
32
+ namespace {
33
+ Context* g_context = nullptr ;
34
+ }
35
+
36
+ } // namespace gl_layer
37
+
38
+ int gl_layer_init (unsigned int gl_version_major, unsigned int gl_version_minor) {
39
+ gl_layer::g_context = new gl_layer::Context (gl_layer::Version{ gl_version_major, gl_version_minor });
40
+ if (gl_layer::g_context) return 0 ;
41
+
42
+ return -1 ;
43
+ }
44
+
45
+ void gl_layer_terminate () {
46
+ delete gl_layer::g_context;
47
+ }
48
+
49
+ void gl_layer_callback (const char * name, void * func_ptr, int num_args, ...) {
50
+ if (!gl_layer::g_context) {
51
+ // Report error: context not initialized.
52
+ return ;
53
+ }
54
+ }
55
+
56
+ void gl_layer_set_output_callback (GLLayerOutputFun callback) {
57
+ if (!gl_layer::g_context) {
58
+ // Report error: context not initialized.
59
+ return ;
60
+ }
61
+ gl_layer::g_context->set_output_callback (callback);
62
+ }
You can’t perform that action at this time.
0 commit comments