-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathg2d_windows.go
More file actions
747 lines (709 loc) · 22.8 KB
/
Copy pathg2d_windows.go
File metadata and controls
747 lines (709 loc) · 22.8 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*
* Copyright 2025, Vitali Baumtrok.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
package g2d
// #cgo CFLAGS: -DG2D_WIN32 -DUNICODE
// #cgo LDFLAGS: -luser32 -lgdi32 -lOpenGL32
// #cgo noescape g2d_gfx_draw
// #cgo noescape g2d_window_props
// #cgo nocallback g2d_gfx_draw
// #cgo nocallback g2d_window_props
// #include "g2d.h"
import "C"
import (
"errors"
"fmt"
"runtime"
"strconv"
"unsafe"
)
const (
functionFailedDummy = "dummy window %s failed"
loadFunctionFailed = "load %s function failed"
functionFailedWindow = "window %s failed"
functionFailedGraphics = "graphics %s failed"
functionFailedG2D = "%s failed"
)
// Init initialized the g2d framework.
func Init() {
mutex.Lock()
if !initialized {
var numbers [5]C.int
var err1, err2 C.longlong
var errInfo *C.char
C.g2d_init(&numbers[0], &err1, &err2, &errInfo)
if err1 == 0 {
Err = nil
MaxTexSize, MaxTexUnits, MaxTextures = int(numbers[0]), int(numbers[1]), int(numbers[2])
VSyncAvailable, AVSyncAvailable = (numbers[3] != 0), (numbers[4] != 0)
initialized, initFailed, quitting = true, false, false
} else {
initFailed = true
Err = toError(err1, err2, errInfo)
}
mutex.Unlock()
} else {
mutex.Unlock()
panic("g2d engine is already initialized")
}
}
// MainLoop processes events and will initialize and show mainWindow.
func MainLoop(mainWindow Window) {
if mainWindow != nil {
mutex.Lock()
if !initFailed {
if initialized {
if !running {
running = true
wnds = make([]*tWindow, 0, 2)
wndNextId = make([]int, 0, 2)
requests = make([]tRequest, 0, 2)
appTime.Reset()
wnd := newWindow(mainWindow)
go wnd.logicThread()
mutex.Unlock()
C.g2d_main_loop()
mutex.Lock()
running = false
mutex.Unlock()
cleanUp()
} else {
mutex.Unlock()
panic(alreadyRunning)
}
} else {
mutex.Unlock()
panic(notInitialized)
}
} else {
mutex.Unlock()
}
} else {
panic(mustNotBeNil)
}
}
func (props *Properties) update(data unsafe.Pointer, title string) {
var mx, my, x, y, w, h, wn, hn, wx, hx, b, d, r, f, l C.int
C.g2d_window_props(data, &mx, &my, &x, &y, &w, &h, &wn, &hn, &wx, &hx, &b, &d, &r, &f, &l)
props.MouseX = int(mx)
props.MouseY = int(my)
props.ClientX = int(x)
props.ClientY = int(y)
props.ClientWidth = int(w)
props.ClientHeight = int(h)
props.ClientWidthMin = int(wn)
props.ClientHeightMin = int(hn)
props.ClientWidthMax = int(wx)
props.ClientHeightMax = int(hx)
props.Borderless = bool(b != 0)
props.Dragable = bool(d != 0)
props.Resizable = bool(r != 0)
props.Fullscreen = bool(f != 0)
props.MouseLocked = bool(l != 0)
props.Title = title
}
func (wnd *tWindow) graphicsThread() {
var err1, err2 C.longlong
var errInfo *C.char
runtime.LockOSThread()
C.g2d_gfx_init(wnd.data, &err1, &err2, &errInfo)
if err1 == 0 {
wnd.impl.Gfx.running = true
for wnd.impl.Gfx.running {
event := <-wnd.impl.Gfx.eventsChan
if event != nil {
if event.err == nil {
switch event.typeId {
case refreshType:
wnd.onGfxRefresh()
case wndResizeType:
wnd.impl.Gfx.w, wnd.impl.Gfx.h = event.valA, event.valB
case leaveType:
wnd.impl.Gfx.running = false
case textureType:
wnd.onGfxTexture(event.valC.(Texture), event.valD)
}
} else {
postRequest(&tErrorRequest{err: event.err})
}
}
}
C.g2d_gfx_release(wnd.data, &err1, &err2)
if err1 != 0 {
postRequest(&tErrorRequest{err: toError(err1, err2, nil)})
}
} else {
postRequest(&tErrorRequest{err: toError(err1, err2, errInfo)})
}
wnd.impl.Gfx.quittedChan <- true
}
func (wnd *tWindow) onGfxRefresh() {
var err1, err2 C.longlong
wnd.impl.Gfx.mutex.Lock()
wnd.impl.Gfx.updating = false
read := wnd.impl.Gfx.getReadBuffer()
wnd.impl.Gfx.mutex.Unlock()
batches, lengths, procs := read.batchesPtrs, read.lengths, read.procs
w, h, i, r, g, b := read.w, read.h, read.sw, read.r, read.g, read.b
if len(batches) > 0 {
// calling with &batches[0] may cause "pointer to unpinned Go pointer" error
// https://github.com/PowerDNS/lmdb-go/issues/28
var pinner runtime.Pinner
for _, batch := range batches {
pinner.Pin(batch)
}
C.g2d_gfx_draw(wnd.data, w, h, i, r, b, g, &batches[0], &lengths[0], &procs[0], C.int(len(batches)), &err1, &err2)
pinner.Unpin()
} else {
// just draw background
C.g2d_gfx_draw(wnd.data, w, h, i, r, b, g, nil, nil, nil, 0, &err1, &err2)
}
wnd.eventsChan <- &tLogicEvent{typeId: refreshType, time: appTime.Millis()}
}
func (wnd *tWindow) onGfxTexture(texture Texture, rgbaBytes []byte) {
var err1 C.longlong
var texData unsafe.Pointer
texUnit := texture.Id()
glTexId := C.int(wnd.impl.Gfx.glTexIds[texUnit])
texWidth, texHeight := texture.Dimensions()
if len(rgbaBytes) > 0 {
texData = unsafe.Pointer(&rgbaBytes[0])
}
genMM, isMM, fLin := boolToCInt3(texture.GenMipMap(), texture.IsMipMap(), texture.FilterLinear())
C.g2d_gfx_gen_tex(wnd.data, texData, genMM, isMM, fLin, C.int(texWidth), C.int(texHeight), &glTexId, C.int(texUnit), &err1)
if err1 == 0 {
dimIndex := texUnit * 2
wnd.impl.Gfx.glTexIds[texUnit] = int(glTexId)
wnd.impl.Gfx.texDims[dimIndex+0] = texWidth
wnd.impl.Gfx.texDims[dimIndex+1] = texHeight
wnd.eventsChan <- &tLogicEvent{typeId: textureType, obj: texture, time: appTime.Millis()}
} else {
postRequest(&tErrorRequest{err: toError(err1, 0, nil)})
}
}
func (layer *RectanglesLayer) getBatch(layers []Layer, texDims []int, buffer []C.float) ([]Layer, []C.float, C.int, unsafe.Pointer) {
var count int
for len(layers) > 0 {
if curr, ok := layers[0].(*RectanglesLayer); ok {
if curr.Enabled && curr.count > 0 {
var index int
buffer = ensureCFloatLen(buffer, 48+(count+curr.count)*16)
if layer.texMap == nil {
layer.texMap = make([]int, 16, 16)
}
// texture references (16)
for index = 0; index < 16; index++ {
buffer[index] = C.float(layer.texMap[index])
}
// dimensions of textures (2*16)
for index = 16; index < 48; index++ {
buffer[index] = C.float(texDims[index-16])
}
for _, entity := range layer.entities {
if entity.Enabled {
buffer[index+0] = C.float(entity.X)
buffer[index+1] = C.float(entity.Y)
buffer[index+2] = C.float(entity.Width)
buffer[index+3] = C.float(entity.Height)
buffer[index+4] = C.float(entity.R)
buffer[index+5] = C.float(entity.G)
buffer[index+6] = C.float(entity.B)
buffer[index+7] = C.float(entity.A)
if entity.TexRef >= 0 && entity.TexRef <= 15 {
buffer[index+8] = C.float(entity.TexRef)
} else {
buffer[index+8] = -1.0
}
buffer[index+9] = C.float(entity.TexX)
buffer[index+10] = C.float(entity.TexY)
buffer[index+11] = C.float(entity.TexWidth)
buffer[index+12] = C.float(entity.TexHeight)
buffer[index+13] = C.float(entity.X + entity.RotX)
buffer[index+14] = C.float(entity.Y + entity.RotY)
buffer[index+15] = C.float(entity.RotAlpha)
index += 16
count++
}
}
}
layers = layers[1:]
} else {
break
}
}
return layers, buffer, C.int(count), unsafe.Pointer(C.g2d_gfx_draw_rectangles)
}
func (request *tConfigWindowRequest) process() {
wnd := newWindow(request.window)
go wnd.logicThread()
wnd.eventsChan <- &tLogicEvent{typeId: configType, time: appTime.Millis()}
}
func (request *tCreateWindowRequest) process() {
var err1, err2 C.longlong
var data unsafe.Pointer
var t unsafe.Pointer
var ts C.size_t
x := C.int(request.config.ClientX)
y := C.int(request.config.ClientY)
w := C.int(request.config.ClientWidth)
h := C.int(request.config.ClientHeight)
wn := C.int(request.config.ClientWidthMin)
hn := C.int(request.config.ClientHeightMin)
wx := C.int(request.config.ClientWidthMax)
hx := C.int(request.config.ClientHeightMax)
c, l, b, d, r, f := request.config.boolsToCInt()
if len(request.config.Title) > 0 {
bytes := *(*[]byte)(unsafe.Pointer(&(request.config.Title)))
t, ts = unsafe.Pointer(&bytes[0]), C.size_t(len(request.config.Title))
}
C.g2d_window_create(&data, C.int(request.wndId), x, y, w, h, wn, hn, wx, hx, b, d, r, f, l, c, t, ts, &err1, &err2)
if err1 == 0 {
wnd := wnds[request.wndId]
wnd.data = data
wnd.title = request.config.Title
event := &tLogicEvent{typeId: createType, time: appTime.Millis()}
event.props.update(data, wnd.title)
wnd.eventsChan <- event
} else {
Err = toError(err1, err2, nil)
}
}
func (request *tShowWindowRequest) process() {
var err1, err2 C.longlong
wnd := wnds[request.wndId]
C.g2d_window_show(wnd.data, &err1, &err2)
if err1 == 0 {
event := &tLogicEvent{typeId: showType, time: appTime.Millis()}
event.props.update(wnd.data, wnd.title)
wnd.eventsChan <- event
} else {
Err = toError(err1, err2, nil)
}
}
func (request *tCloseWindowRequest) process() {
wnd := wnds[request.wndId]
event := &tLogicEvent{typeId: closeType, time: appTime.Millis()}
event.props.update(wnd.data, wnd.title)
wnd.eventsChan <- event
}
func (request *tDestroyWindowRequest) process() {
var err1, err2 C.longlong
wnd := wnds[request.wndId]
wnd.eventsChan <- &tLogicEvent{typeId: destroyType, time: appTime.Millis()}
<-wnd.quittedChan
C.g2d_window_destroy(wnd.data, &err1, &err2)
wnd.data = nil
unregisterWnd(wnd.id).impl = nil
if err1 != 0 {
(&tErrorRequest{err: toError(err1, err2, nil)}).process()
}
}
func (request *tCustomRequest) process() {
wnd := wnds[request.wndId]
event := &tLogicEvent{typeId: customType, obj: request.obj}
event.props.update(wnd.data, wnd.title)
wnd.eventsChan <- event
}
func (request *tSetPropertiesRequest) process() {
var err1, err2 C.longlong
wnd := wnds[request.wndId]
if request.modPosSize {
C.g2d_window_pos_size_set(wnd.data, C.int(request.props.ClientX), C.int(request.props.ClientY), C.int(request.props.ClientWidth), C.int(request.props.ClientHeight))
}
if request.modStyle || request.modFullscreen {
wn := C.int(request.props.ClientWidthMin)
hn := C.int(request.props.ClientHeightMin)
wx := C.int(request.props.ClientWidthMax)
hx := C.int(request.props.ClientHeightMax)
l, b, d, r, f := request.props.boolsToCInt()
C.g2d_window_style_set(wnd.data, wn, hn, wx, hx, b, d, r, f, l)
}
if request.modFullscreen {
C.g2d_window_fullscreen_set(wnd.data, &err1, &err2)
} else if request.modStyle && !request.props.Fullscreen {
C.g2d_window_pos_apply(wnd.data, &err1, &err2)
} else if request.modPosSize {
C.g2d_window_move(wnd.data, &err1, &err2)
}
if request.modTitle {
var t unsafe.Pointer
var ts C.size_t
if len(request.props.Title) > 0 {
bytes := *(*[]byte)(unsafe.Pointer(&(request.props.Title)))
t, ts = unsafe.Pointer(&bytes[0]), C.size_t(len(request.props.Title))
}
wnd.title = request.props.Title
C.g2d_window_title_set(wnd.data, t, ts, &err1, &err2)
}
if request.modMouse {
C.g2d_mouse_pos_set(wnd.data, C.int(request.props.MouseX), C.int(request.props.MouseY), &err1, &err2)
}
}
func (request *tErrorRequest) process() {
if Err == nil {
Err = request.err
}
if running {
var err1, err2 C.longlong
C.g2d_post_quit(&err1, &err2)
if err1 != 0 {
if Err == nil {
Err = toError(err1, err2, nil)
}
}
}
}
func postRequest(request tRequest) {
var err1, err2 C.longlong
mutex.Lock()
requests = append(requests, request)
C.g2d_post_request(&err1, &err2)
if err1 != 0 {
(&tErrorRequest{err: toError(err1, err2, nil)}).process()
}
mutex.Unlock()
}
func cleanUp() {
for _, wnd := range wnds {
if wnd != nil {
var err1, err2 C.longlong
if wnd.data != nil {
wnd.eventsChan <- &tLogicEvent{typeId: destroyType, err: Err, time: appTime.Millis()}
<-wnd.quittedChan
C.g2d_window_destroy(wnd.data, &err1, &err2)
wnd.data = nil
if err1 != 0 {
(&tErrorRequest{err: toError(err1, err2, nil)}).process()
}
} else {
wnd.eventsChan <- &tLogicEvent{typeId: leaveType, time: appTime.Millis()}
<-wnd.quittedChan
}
unregisterWnd(wnd.id).impl = nil
}
}
C.g2d_clean_up()
}
func postLogicEvent(id C.int, event *tLogicEvent) {
if !processingRequests {
mutex.Lock()
}
wnd := wnds[id]
event.props.update(wnd.data, wnd.title)
wnd.eventsChan <- event
if !processingRequests {
mutex.Unlock()
}
}
//export g2dMainLoopStarted
func g2dMainLoopStarted() {
wnds[0].eventsChan <- &tLogicEvent{typeId: configType, time: appTime.Millis()}
}
//export g2dProcessRequest
func g2dProcessRequest() {
mutex.Lock()
processingRequests = true
for _, request := range requests {
if Err == nil {
request.process()
}
}
requests = requests[:0]
processingRequests = false
mutex.Unlock()
}
//export g2dClose
func g2dClose(id C.int) {
postLogicEvent(id, &tLogicEvent{typeId: closeType, time: appTime.Millis()})
}
//export g2dKeyDown
func g2dKeyDown(id, code C.int, repeated C.uint) {
postLogicEvent(id, &tLogicEvent{typeId: keyDownType, valA: int(code), repeated: uint(repeated), time: appTime.Millis()})
}
//export g2dKeyUp
func g2dKeyUp(id, code C.int) {
postLogicEvent(id, &tLogicEvent{typeId: keyUpType, valA: int(code), time: appTime.Millis()})
}
//export g2dMouseMove
func g2dMouseMove(id C.int) {
postLogicEvent(id, &tLogicEvent{typeId: msMoveType, time: appTime.Millis()})
}
//export g2dWindowMove
func g2dWindowMove(id C.int) {
postLogicEvent(id, &tLogicEvent{typeId: wndMoveType, time: appTime.Millis()})
}
//export g2dWindowResize
func g2dWindowResize(id C.int) {
if !processingRequests {
mutex.Lock()
}
wnd := wnds[id]
event := &tLogicEvent{typeId: wndResizeType, time: appTime.Millis()}
event.props.update(wnd.data, wnd.title)
wnd.eventsChan <- event
if !processingRequests {
mutex.Unlock()
}
}
//export g2dButtonDown
func g2dButtonDown(id, code, doubleClick C.int) {
postLogicEvent(id, &tLogicEvent{typeId: buttonDownType, valA: int(code), repeated: uint(doubleClick), time: appTime.Millis()})
}
//export g2dButtonUp
func g2dButtonUp(id, code, doubleClick C.int) {
postLogicEvent(id, &tLogicEvent{typeId: buttonUpType, valA: int(code), repeated: uint(doubleClick), time: appTime.Millis()})
}
//export g2dWheel
func g2dWheel(id C.int, wheel C.float) {
postLogicEvent(id, &tLogicEvent{typeId: wheelType, valC: float32(wheel), time: appTime.Millis()})
}
//export g2dWindowMinimize
func g2dWindowMinimize(id C.int) {
postLogicEvent(id, &tLogicEvent{typeId: minimizeType, time: appTime.Millis()})
}
//export g2dWindowRestore
func g2dWindowRestore(id C.int) {
postLogicEvent(id, &tLogicEvent{typeId: restoreType, time: appTime.Millis()})
}
//export g2dOnFocus
func g2dOnFocus(id, focus C.int) {
postLogicEvent(id, &tLogicEvent{typeId: focusType, valA: int(focus), time: appTime.Millis()})
}
func toError(err1, err2 C.longlong, errInfo *C.char) error {
var err error
if err1 > 0 {
var errStr, info string
if err1 < 1000001 {
errStr = "memory allocation failed"
} else if err1 < 1000101 {
switch err1 {
case 1000001:
errStr = "g2d GetModuleHandle failed"
case 1000002:
errStr = fmt.Sprintf(functionFailedDummy, "RegisterClassEx")
case 1000003:
errStr = fmt.Sprintf(functionFailedDummy, "CreateWindow")
case 1000004:
errStr = fmt.Sprintf(functionFailedDummy, "GetDC")
case 1000005:
errStr = fmt.Sprintf(functionFailedDummy, "ChoosePixelFormat")
case 1000006:
errStr = fmt.Sprintf(functionFailedDummy, "SetPixelFormat")
case 1000007:
errStr = fmt.Sprintf(functionFailedDummy, "wglCreateContext")
case 1000008:
errStr = fmt.Sprintf(functionFailedDummy, "wglMakeCurrent")
case 1000009:
errStr = fmt.Sprintf(functionFailedDummy, "wglMakeCurrent")
case 1000010:
errStr = fmt.Sprintf(functionFailedDummy, "wglDeleteContext")
case 1000011:
errStr = fmt.Sprintf(functionFailedDummy, "DestroyWindow")
case 1000012:
errStr = fmt.Sprintf(functionFailedDummy, "UnregisterClass")
}
} else if err1 < 1001001 {
switch err1 {
case 1000101:
errStr = fmt.Sprintf(loadFunctionFailed, "WGL")
case 1000102:
errStr = fmt.Sprintf(loadFunctionFailed, "OpenGL")
}
} else if err1 < 1002001 {
if err1 < 1001007 {
switch err1 {
case 1001001:
errStr = fmt.Sprintf(functionFailedWindow, "RegisterClassEx")
case 1001002:
errStr = fmt.Sprintf(functionFailedWindow, "CreateWindow")
case 1001003:
errStr = fmt.Sprintf(functionFailedWindow, "GetDC")
case 1001004:
errStr = fmt.Sprintf(functionFailedWindow, "wglChoosePixelFormatARB")
case 1001005:
errStr = fmt.Sprintf(functionFailedWindow, "SetPixelFormat")
case 1001006:
errStr = fmt.Sprintf(functionFailedWindow, "wglCreateContextAttribsARB")
}
} else if err1 < 1001015 {
errStr = fmt.Sprintf(functionFailedWindow, "set fullscreen")
} else {
switch err1 {
case 1001015:
errStr = fmt.Sprintf(functionFailedWindow, "wglDeleteContext")
case 1001016:
errStr = fmt.Sprintf(functionFailedWindow, "DestroyWindow")
case 1001017:
errStr = fmt.Sprintf(functionFailedWindow, "UnregisterClass")
case 1001018:
errStr = fmt.Sprintf(functionFailedWindow, "set position")
case 1001019:
errStr = fmt.Sprintf(functionFailedWindow, "set position")
case 1001020:
errStr = fmt.Sprintf(functionFailedWindow, "move")
case 1001021:
errStr = fmt.Sprintf(functionFailedWindow, "set title")
case 1001022:
errStr = fmt.Sprintf(functionFailedG2D, "set mouse position")
}
}
} else {
switch err1 {
case 1002001:
errStr = fmt.Sprintf(functionFailedGraphics, "wglMakeCurrent")
case 1002002:
errStr = fmt.Sprintf(functionFailedG2D, "create vertex shader")
case 1002003:
errStr = fmt.Sprintf(functionFailedG2D, "create vertex shader")
case 1002004:
errStr = fmt.Sprintf(functionFailedG2D, "create fragment shader")
case 1002005:
errStr = fmt.Sprintf(functionFailedG2D, "create fragment shader")
case 1002006:
errStr = fmt.Sprintf(functionFailedG2D, "attach vertex shader")
case 1002007:
errStr = fmt.Sprintf(functionFailedG2D, "attach vertex shader")
case 1002008:
errStr = fmt.Sprintf(functionFailedG2D, "attach fragment shader")
case 1002009:
errStr = fmt.Sprintf(functionFailedG2D, "attach fragment shader")
case 1002010:
errStr = fmt.Sprintf(functionFailedG2D, "link shader program")
case 1002011:
errStr = fmt.Sprintf(functionFailedG2D, "create shader program")
case 1002012:
errStr = fmt.Sprintf(functionFailedG2D, "use shader program")
case 1002013:
errStr = fmt.Sprintf(functionFailedG2D, "use shader program")
case 1002014:
errStr = fmt.Sprintf(functionFailedG2D, "bind vertex array")
case 1002015:
errStr = fmt.Sprintf(functionFailedG2D, "bind buffer")
case 1002016:
errStr = fmt.Sprintf(functionFailedG2D, "bind buffer")
case 1002017:
errStr = fmt.Sprintf(functionFailedG2D, "draw rectangles")
case 1002018:
errStr = fmt.Sprintf(functionFailedG2D, "draw rectangles")
case 1002019:
errStr = fmt.Sprintf(functionFailedG2D, "draw rectangles")
case 1002020:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002021:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002022:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002023:
errStr = fmt.Sprintf(functionFailedG2D, "get attribute location")
case 1002024:
errStr = fmt.Sprintf(functionFailedG2D, "get attribute location")
case 1002025:
errStr = fmt.Sprintf(functionFailedG2D, "get uniform location")
case 1002026:
errStr = fmt.Sprintf(functionFailedG2D, "get uniform location")
case 1002027:
errStr = fmt.Sprintf(functionFailedG2D, "bind vertex array")
case 1002028:
errStr = fmt.Sprintf(functionFailedG2D, "enable attribute")
case 1002029:
errStr = fmt.Sprintf(functionFailedG2D, "enable attribute")
case 1002030:
errStr = fmt.Sprintf(functionFailedG2D, "enable attribute")
case 1002031:
errStr = fmt.Sprintf(functionFailedG2D, "enable attribute")
case 1002032:
errStr = fmt.Sprintf(functionFailedG2D, "bind buffer")
case 1002033:
errStr = fmt.Sprintf(functionFailedG2D, "bind buffer")
case 1002034:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002035:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002036:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002037:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002038:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002039:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002040:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002041:
errStr = fmt.Sprintf(functionFailedG2D, "set buffer data")
case 1002042:
errStr = fmt.Sprintf(functionFailedG2D, "set vertex data")
case 1002043:
errStr = fmt.Sprintf(functionFailedG2D, "set vertex data")
case 1002044:
errStr = fmt.Sprintf(functionFailedG2D, "set vertex data")
case 1002045:
errStr = fmt.Sprintf(functionFailedG2D, "set vertex data")
case 1002046:
errStr = fmt.Sprintf(functionFailedG2D, "set vertex data")
case 1002047:
errStr = fmt.Sprintf(functionFailedG2D, "set vertex data")
case 1002048:
errStr = fmt.Sprintf(functionFailedG2D, "bind buffer")
case 1002049:
errStr = fmt.Sprintf(functionFailedG2D, "bind buffer")
case 1002050:
errStr = fmt.Sprintf(functionFailedGraphics, "SwapBuffers")
case 1002051:
errStr = fmt.Sprintf(functionFailedGraphics, "wglMakeCurrent")
case 1002052:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002053:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002054:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002055:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002056:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002057:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002058:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002059:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
case 1002060:
errStr = fmt.Sprintf(functionFailedG2D, "load texture")
}
}
if len(errStr) == 0 {
errStr = "unknown"
}
errStr = errStr + " (" + strconv.FormatInt(int64(err1), 10)
if err2 == 0 {
errStr = errStr + ")"
} else {
errStr = errStr + ", " + strconv.FormatInt(int64(err2), 10) + ")"
}
if errInfo != nil {
info = C.GoString(errInfo)
if err1 != 1000101 && err1 != 1000102 {
C.g2d_free(unsafe.Pointer(errInfo))
}
}
if len(info) > 0 {
errStr = errStr + "; " + info
}
for len(errStr) > 0 && (errStr[len(errStr)-1] == '\n' || errStr[len(errStr)-1] == '\r') {
errStr = errStr[:len(errStr)-1]
}
err = errors.New(errStr)
}
return err
}
//export goDebug
func goDebug(a, b C.int, c, d C.longlong) {
fmt.Println(a, b, c, d)
}
//export goDebugMessage
func goDebugMessage(code C.ulong, strC *C.char) {
fmt.Println("Msg:", C.GoString(strC), code)
}