-
Notifications
You must be signed in to change notification settings - Fork 7
/
DebugBuilder.go
63 lines (50 loc) · 2.05 KB
/
DebugBuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package opengl
// DebuggingEntryFunc is a function to be called on function entry.
type DebuggingEntryFunc func(name string, param ...interface{})
// DebuggingExitFunc is a function to be called after an OpenGL function has returned.
// result may be several parameters for functions with multiple return values.
type DebuggingExitFunc func(name string, result ...interface{})
// DebuggingErrorFunc is a function which is called if a previous OpenGL call caused an error state.
type DebuggingErrorFunc func(name string, errorCodes []uint32)
// DebugBuilder is a builder for an OpenGL implementation for debugging.
type DebugBuilder struct {
wrapped OpenGL
onEntry DebuggingEntryFunc
onExit DebuggingExitFunc
onError DebuggingErrorFunc
}
// NewDebugBuilder wraps the provided OpenGL instance and returns a new builder
// instance.
func NewDebugBuilder(wrapped OpenGL) *DebugBuilder {
builder := &DebugBuilder{
wrapped: wrapped,
onEntry: func(string, ...interface{}) {},
onExit: func(string, ...interface{}) {},
onError: func(string, []uint32) {}}
return builder
}
// Build creates a new instance of the debugging OpenGL implementation.
// The builder can be reused to create another instance with different parameters.
func (builder *DebugBuilder) Build() OpenGL {
opengl := &debuggingOpenGL{
gl: builder.wrapped,
onEntry: builder.onEntry,
onExit: builder.onExit,
onError: builder.onError}
return opengl
}
// OnEntry registers a callback function to be called before an OpenGL function is called.
func (builder *DebugBuilder) OnEntry(callback DebuggingEntryFunc) *DebugBuilder {
builder.onEntry = callback
return builder
}
// OnExit registers a callback function to be called after an OpenGL function returned.
func (builder *DebugBuilder) OnExit(callback DebuggingExitFunc) *DebugBuilder {
builder.onExit = callback
return builder
}
// OnError registers a callback function to be called when an OpenGL function set an error state.
func (builder *DebugBuilder) OnError(callback DebuggingErrorFunc) *DebugBuilder {
builder.onError = callback
return builder
}