/
raylib.go
1217 lines (1093 loc) · 31.6 KB
/
raylib.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
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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Package raylib - Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
raylib is highly inspired by Borland BGI graphics lib and by XNA framework.
raylib could be useful for prototyping, tools development, graphic applications, embedded systems and education.
NOTE for ADVENTURERS: raylib is a programming library to learn videogames programming; no fancy interface, no visual helpers, no auto-debugging... just coding in the most pure spartan-programmers way.
*/
package rl
import (
"image/color"
"io"
"runtime"
"unsafe"
)
func init() {
// Make sure the main goroutine is bound to the main thread.
runtime.LockOSThread()
}
// Wave type, defines audio wave data
type Wave struct {
// Number of samples
FrameCount uint32
// Frequency (samples per second)
SampleRate uint32
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
SampleSize uint32
// Number of channels (1-mono, 2-stereo)
Channels uint32
// Buffer data pointer
data unsafe.Pointer
}
// NewWave - Returns new Wave
func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data []byte) Wave {
d := unsafe.Pointer(&data[0])
return Wave{sampleCount, sampleRate, sampleSize, channels, d}
}
// AudioCallback function.
type AudioCallback func(data []float32, frames int)
// Sound source type
type Sound struct {
Stream AudioStream
FrameCount uint32
_ [4]byte
}
// Music type (file streaming from memory)
// NOTE: Anything longer than ~10 seconds should be streamed
type Music struct {
Stream AudioStream
FrameCount uint32
Looping bool
CtxType int32
CtxData unsafe.Pointer
}
// AudioStream type
// NOTE: Useful to create custom audio streams not bound to a specific file
type AudioStream struct {
// Buffer
Buffer *AudioBuffer
// Processor
Processor *AudioProcessor
// Frequency (samples per second)
SampleRate uint32
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
SampleSize uint32
// Number of channels (1-mono, 2-stereo)
Channels uint32
_ [4]byte
}
type maDataConverter struct {
FormatIn uint32
FormatOut uint32
ChannelsIn uint32
ChannelsOut uint32
SampleRateIn uint32
SampleRateOut uint32
DitherMode uint32
ExecutionPath uint32
ChannelConverter maChannelConverter
Resampler maResampler
HasPreFormatConversion uint8
HasPostFormatConversion uint8
HasChannelConverter uint8
HasResampler uint8
IsPassthrough uint8
X_ownsHeap uint8
X_pHeap *byte
}
type maChannelConverter struct {
Format uint32
ChannelsIn uint32
ChannelsOut uint32
MixingMode uint32
ConversionPath uint32
PChannelMapIn *uint8
PChannelMapOut *uint8
PShuffleTable *uint8
Weights [8]byte
X_pHeap *byte
X_ownsHeap uint32
Pad_cgo_0 [4]byte
}
type maResampler struct {
PBackend *byte
PBackendVTable *maResamplingBackendVtable
PBackendUserData *byte
Format uint32
Channels uint32
SampleRateIn uint32
SampleRateOut uint32
State [136]byte
X_pHeap *byte
X_ownsHeap uint32
Pad_cgo_0 [4]byte
}
type maResamplingBackendVtable struct {
OnGetHeapSize *[0]byte
OnInit *[0]byte
OnUninit *[0]byte
OnProcess *[0]byte
OnSetRate *[0]byte
OnGetInputLatency *[0]byte
OnGetOutputLatency *[0]byte
OnGetRequiredInputFrameCount *[0]byte
OnGetExpectedOutputFrameCount *[0]byte
OnReset *[0]byte
}
type AudioBuffer struct {
Converter maDataConverter
Callback *[0]byte
Processor *AudioProcessor
Volume float32
Pitch float32
Pan float32
Playing bool
Paused bool
Looping bool
Usage int32
IsSubBufferProcessed [2]bool
SizeInFrames uint32
FrameCursorPos uint32
FramesProcessed uint32
Data *uint8
Next *AudioBuffer
Prev *AudioBuffer
}
type AudioProcessor struct {
Process *[0]byte
Next *AudioProcessor
Prev *AudioProcessor
}
// AutomationEvent - Automation event
type AutomationEvent struct {
Frame uint32
Type uint32
Params [4]int32
}
// AutomationEventList - Automation event list
type AutomationEventList struct {
Capacity uint32
Count uint32
Events *AutomationEvent
}
// CameraMode type
type CameraMode int32
// Camera system modes
const (
CameraCustom CameraMode = iota
CameraFree
CameraOrbital
CameraFirstPerson
CameraThirdPerson
)
// CameraProjection type
type CameraProjection int32
// Camera projection modes
const (
CameraPerspective CameraProjection = iota
CameraOrthographic
)
// Some basic Defines
const (
Pi = 3.1415927
Deg2rad = 0.017453292
Rad2deg = 57.295776
// Raylib Config Flags
// Set to try enabling V-Sync on GPU
FlagVsyncHint = 0x00000040
// Set to run program in fullscreen
FlagFullscreenMode = 0x00000002
// Set to allow resizable window
FlagWindowResizable = 0x00000004
// Set to disable window decoration (frame and buttons)
FlagWindowUndecorated = 0x00000008
// Set to hide window
FlagWindowHidden = 0x00000080
// Set to minimize window (iconify)
FlagWindowMinimized = 0x00000200
// Set to maximize window (expanded to monitor)
FlagWindowMaximized = 0x00000400
// Set to window non focused
FlagWindowUnfocused = 0x00000800
// Set to window always on top
FlagWindowTopmost = 0x00001000
// Set to allow windows running while minimized
FlagWindowAlwaysRun = 0x00000100
// Set to allow transparent window
FlagWindowTransparent = 0x00000010
// Set to support HighDPI
FlagWindowHighdpi = 0x00002000
// Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED
FlagWindowMousePassthrough = 0x00004000
// Set to run program in borderless windowed mode
FlagBorderlessWindowedMode = 0x00008000
// Set to try enabling MSAA 4X
FlagMsaa4xHint = 0x00000020
// Set to try enabling interlaced video format (for V3D)
FlagInterlacedHint = 0x00010000
// KeyNull is used for no key pressed
KeyNull = 0
// Keyboard Function Keys
KeySpace = 32
KeyEscape = 256
KeyEnter = 257
KeyTab = 258
KeyBackspace = 259
KeyInsert = 260
KeyDelete = 261
KeyRight = 262
KeyLeft = 263
KeyDown = 264
KeyUp = 265
KeyPageUp = 266
KeyPageDown = 267
KeyHome = 268
KeyEnd = 269
KeyCapsLock = 280
KeyScrollLock = 281
KeyNumLock = 282
KeyPrintScreen = 283
KeyPause = 284
KeyF1 = 290
KeyF2 = 291
KeyF3 = 292
KeyF4 = 293
KeyF5 = 294
KeyF6 = 295
KeyF7 = 296
KeyF8 = 297
KeyF9 = 298
KeyF10 = 299
KeyF11 = 300
KeyF12 = 301
KeyLeftShift = 340
KeyLeftControl = 341
KeyLeftAlt = 342
KeyLeftSuper = 343
KeyRightShift = 344
KeyRightControl = 345
KeyRightAlt = 346
KeyRightSuper = 347
KeyKbMenu = 348
KeyLeftBracket = 91
KeyBackSlash = 92
KeyRightBracket = 93
KeyGrave = 96
// Keyboard Number Pad Keys
KeyKp0 = 320
KeyKp1 = 321
KeyKp2 = 322
KeyKp3 = 323
KeyKp4 = 324
KeyKp5 = 325
KeyKp6 = 326
KeyKp7 = 327
KeyKp8 = 328
KeyKp9 = 329
KeyKpDecimal = 330
KeyKpDivide = 331
KeyKpMultiply = 332
KeyKpSubtract = 333
KeyKpAdd = 334
KeyKpEnter = 335
KeyKpEqual = 336
// Keyboard Alpha Numeric Keys
KeyApostrophe = 39
KeyComma = 44
KeyMinus = 45
KeyPeriod = 46
KeySlash = 47
KeyZero = 48
KeyOne = 49
KeyTwo = 50
KeyThree = 51
KeyFour = 52
KeyFive = 53
KeySix = 54
KeySeven = 55
KeyEight = 56
KeyNine = 57
KeySemicolon = 59
KeyEqual = 61
KeyA = 65
KeyB = 66
KeyC = 67
KeyD = 68
KeyE = 69
KeyF = 70
KeyG = 71
KeyH = 72
KeyI = 73
KeyJ = 74
KeyK = 75
KeyL = 76
KeyM = 77
KeyN = 78
KeyO = 79
KeyP = 80
KeyQ = 81
KeyR = 82
KeyS = 83
KeyT = 84
KeyU = 85
KeyV = 86
KeyW = 87
KeyX = 88
KeyY = 89
KeyZ = 90
// Android keys
KeyBack = 4
KeyMenu = 82
KeyVolumeUp = 24
KeyVolumeDown = 25
MouseLeftButton = MouseButtonLeft
MouseRightButton = MouseButtonRight
MouseMiddleButton = MouseButtonMiddle
)
// Mouse Buttons
const (
MouseButtonLeft = iota
MouseButtonRight
MouseButtonMiddle
MouseButtonSide
MouseButtonExtra
MouseButtonForward
MouseButtonBack
)
// Mouse cursor
type MouseCursor = int32
const (
MouseCursorDefault MouseCursor = iota // Default pointer shape
MouseCursorArrow // Arrow shape
MouseCursorIBeam // Text writing cursor shape
MouseCursorCrosshair // Cross shape
MouseCursorPointingHand // Pointing hand cursor
MouseCursorResizeEW // Horizontal resize/move arrow shape
MouseCursorResizeNS // Vertical resize/move arrow shape
MouseCursorResizeNWSE // Top-left to bottom-right diagonal resize/move arrow shape
MouseCursorResizeNESW // The top-right to bottom-left diagonal resize/move arrow shape
MouseCursorResizeAll // The omni-directional resize/move cursor shape
MouseCursorNotAllowed // The operation-not-allowed shape
)
// Gamepad Buttons
const (
GamepadButtonUnknown = iota // Unknown button, just for error checking
GamepadButtonLeftFaceUp // Gamepad left DPAD up button
GamepadButtonLeftFaceRight // Gamepad left DPAD right button
GamepadButtonLeftFaceDown // Gamepad left DPAD down button
GamepadButtonLeftFaceLeft // Gamepad left DPAD left button
GamepadButtonRightFaceUp // Gamepad right button up (i.e. PS3: Triangle, Xbox: Y)
GamepadButtonRightFaceRight // Gamepad right button right (i.e. PS3: Square, Xbox: X)
GamepadButtonRightFaceDown // Gamepad right button down (i.e. PS3: Cross, Xbox: A)
GamepadButtonRightFaceLeft // Gamepad right button left (i.e. PS3: Circle, Xbox: B)
GamepadButtonLeftTrigger1 // Gamepad top/back trigger left (first), it could be a trailing button
GamepadButtonLeftTrigger2 // Gamepad top/back trigger left (second), it could be a trailing button
GamepadButtonRightTrigger1 // Gamepad top/back trigger right (one), it could be a trailing button
GamepadButtonRightTrigger2 // Gamepad top/back trigger right (second), it could be a trailing button
GamepadButtonMiddleLeft // Gamepad center buttons, left one (i.e. PS3: Select)
GamepadButtonMiddle // Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX)
GamepadButtonMiddleRight // Gamepad center buttons, right one (i.e. PS3: Start)
GamepadButtonLeftThumb // Gamepad joystick pressed button left
GamepadButtonRightThumb // Gamepad joystick pressed button right
)
// Gamepad Axis
const (
GamepadAxisLeftX = iota // Gamepad left stick X axis
GamepadAxisLeftY // Gamepad left stick Y axis
GamepadAxisRightX // Gamepad right stick X axis
GamepadAxisRightY // Gamepad right stick Y axis
GamepadAxisLeftTrigger // Gamepad back trigger left, pressure level: [1..-1]
GamepadAxisRightTrigger // Gamepad back trigger right, pressure level: [1..-1]
)
// Some Basic Colors
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
var (
// Light Gray
LightGray = NewColor(200, 200, 200, 255)
// Gray
Gray = NewColor(130, 130, 130, 255)
// Dark Gray
DarkGray = NewColor(80, 80, 80, 255)
// Yellow
Yellow = NewColor(253, 249, 0, 255)
// Gold
Gold = NewColor(255, 203, 0, 255)
// Orange
Orange = NewColor(255, 161, 0, 255)
// Pink
Pink = NewColor(255, 109, 194, 255)
// Red
Red = NewColor(230, 41, 55, 255)
// Maroon
Maroon = NewColor(190, 33, 55, 255)
// Green
Green = NewColor(0, 228, 48, 255)
// Lime
Lime = NewColor(0, 158, 47, 255)
// Dark Green
DarkGreen = NewColor(0, 117, 44, 255)
// Sky Blue
SkyBlue = NewColor(102, 191, 255, 255)
// Blue
Blue = NewColor(0, 121, 241, 255)
// Dark Blue
DarkBlue = NewColor(0, 82, 172, 255)
// Purple
Purple = NewColor(200, 122, 255, 255)
// Violet
Violet = NewColor(135, 60, 190, 255)
// Dark Purple
DarkPurple = NewColor(112, 31, 126, 255)
// Beige
Beige = NewColor(211, 176, 131, 255)
// Brown
Brown = NewColor(127, 106, 79, 255)
// Dark Brown
DarkBrown = NewColor(76, 63, 47, 255)
// White
White = NewColor(255, 255, 255, 255)
// Black
Black = NewColor(0, 0, 0, 255)
// Blank (Transparent)
Blank = NewColor(0, 0, 0, 0)
// Magenta
Magenta = NewColor(255, 0, 255, 255)
// Ray White (RayLib Logo White)
RayWhite = NewColor(245, 245, 245, 255)
)
// Vector2 type
type Vector2 struct {
X float32
Y float32
}
// NewVector2 - Returns new Vector2
func NewVector2(x, y float32) Vector2 {
return Vector2{x, y}
}
// Vector3 type
type Vector3 struct {
X float32
Y float32
Z float32
}
// NewVector3 - Returns new Vector3
func NewVector3(x, y, z float32) Vector3 {
return Vector3{x, y, z}
}
// Vector4 type
type Vector4 struct {
X float32
Y float32
Z float32
W float32
}
// NewVector4 - Returns new Vector4
func NewVector4(x, y, z, w float32) Vector4 {
return Vector4{x, y, z, w}
}
// Matrix type (OpenGL style 4x4 - right handed, column major)
type Matrix struct {
M0, M4, M8, M12 float32
M1, M5, M9, M13 float32
M2, M6, M10, M14 float32
M3, M7, M11, M15 float32
}
// NewMatrix - Returns new Matrix
func NewMatrix(m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15 float32) Matrix {
return Matrix{m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15}
}
// Mat2 type (used for polygon shape rotation matrix)
type Mat2 struct {
M00 float32
M01 float32
M10 float32
M11 float32
}
// NewMat2 - Returns new Mat2
func NewMat2(m0, m1, m10, m11 float32) Mat2 {
return Mat2{m0, m1, m10, m11}
}
// Quaternion, 4 components (Vector4 alias)
type Quaternion = Vector4
// NewQuaternion - Returns new Quaternion
func NewQuaternion(x, y, z, w float32) Quaternion {
return Quaternion{x, y, z, w}
}
// Color type, RGBA (32bit)
// TODO remove later, keep type for now to not break code
type Color = color.RGBA
// NewColor - Returns new Color
func NewColor(r, g, b, a uint8) color.RGBA {
return color.RGBA{r, g, b, a}
}
// Rectangle type
type Rectangle struct {
X float32
Y float32
Width float32
Height float32
}
// NewRectangle - Returns new Rectangle
func NewRectangle(x, y, width, height float32) Rectangle {
return Rectangle{x, y, width, height}
}
// ToInt32 converts rectangle to int32 variant
func (r *Rectangle) ToInt32() RectangleInt32 {
rect := RectangleInt32{}
rect.X = int32(r.X)
rect.Y = int32(r.Y)
rect.Width = int32(r.Width)
rect.Height = int32(r.Height)
return rect
}
// RectangleInt32 type
type RectangleInt32 struct {
X int32
Y int32
Width int32
Height int32
}
// ToFloat32 converts rectangle to float32 variant
func (r *RectangleInt32) ToFloat32() Rectangle {
rect := Rectangle{}
rect.X = float32(r.X)
rect.Y = float32(r.Y)
rect.Width = float32(r.Width)
rect.Height = float32(r.Height)
return rect
}
// Camera3D type, defines a camera position/orientation in 3d space
type Camera3D struct {
// Camera position
Position Vector3
// Camera target it looks-at
Target Vector3
// Camera up vector (rotation over its axis)
Up Vector3
// Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
Fovy float32
// Camera type, controlling projection type, either CameraPerspective or CameraOrthographic.
Projection CameraProjection
}
// Camera type fallback, defaults to Camera3D
type Camera = Camera3D
// NewCamera3D - Returns new Camera3D
func NewCamera3D(pos, target, up Vector3, fovy float32, ct CameraProjection) Camera3D {
return Camera3D{pos, target, up, fovy, ct}
}
// Camera2D type, defines a 2d camera
type Camera2D struct {
// Camera offset (displacement from target)
Offset Vector2
// Camera target (rotation and zoom origin)
Target Vector2
// Camera rotation in degrees
Rotation float32
// Camera zoom (scaling), should be 1.0f by default
Zoom float32
}
// NewCamera2D - Returns new Camera2D
func NewCamera2D(offset, target Vector2, rotation, zoom float32) Camera2D {
return Camera2D{offset, target, rotation, zoom}
}
// BoundingBox type
type BoundingBox struct {
// Minimum vertex box-corner
Min Vector3
// Maximum vertex box-corner
Max Vector3
}
// NewBoundingBox - Returns new BoundingBox
func NewBoundingBox(min, max Vector3) BoundingBox {
return BoundingBox{min, max}
}
// Asset file
type Asset interface {
io.ReadSeeker
io.Closer
}
// Gestures type
type Gestures int32
// Gestures types
// NOTE: It could be used as flags to enable only some gestures
const (
GestureNone Gestures = 0
GestureTap Gestures = 1
GestureDoubletap Gestures = 2
GestureHold Gestures = 4
GestureDrag Gestures = 8
GestureSwipeRight Gestures = 16
GestureSwipeLeft Gestures = 32
GestureSwipeUp Gestures = 64
GestureSwipeDown Gestures = 128
GesturePinchIn Gestures = 256
GesturePinchOut Gestures = 512
)
// Shader location point type
const (
ShaderLocVertexPosition = iota
ShaderLocVertexTexcoord01
ShaderLocVertexTexcoord02
ShaderLocVertexNormal
ShaderLocVertexTangent
ShaderLocVertexColor
ShaderLocMatrixMvp
ShaderLocMatrixView
ShaderLocMatrixProjection
ShaderLocMatrixModel
ShaderLocMatrixNormal
ShaderLocVectorView
ShaderLocColorDiffuse
ShaderLocColorSpecular
ShaderLocColorAmbient
ShaderLocMapAlbedo
ShaderLocMapMetalness
ShaderLocMapNormal
ShaderLocMapRoughness
ShaderLocMapOcclusion
ShaderLocMapEmission
ShaderLocMapHeight
ShaderLocMapCubemap
ShaderLocMapIrradiance
ShaderLocMapPrefilter
ShaderLocMapBrdf
ShaderLocMapDiffuse = ShaderLocMapAlbedo
ShaderLocMapSpecular = ShaderLocMapMetalness
)
// ShaderUniformDataType type
type ShaderUniformDataType int32
// ShaderUniformDataType enumeration
const (
ShaderUniformFloat ShaderUniformDataType = iota
ShaderUniformVec2
ShaderUniformVec3
ShaderUniformVec4
ShaderUniformInt
ShaderUniformIvec2
ShaderUniformIvec3
ShaderUniformIvec4
ShaderUniformSampler2d
)
// Material map index
const (
MapAlbedo = iota
MapMetalness
MapNormal
MapRoughness
MapOcclusion
MapEmission
MapHeight
MapBrdg
MapCubemap
MapIrradiance
MapPrefilter
MapBrdf
MapDiffuse = MapAlbedo
MapSpecular = MapMetalness
)
// Shader and material limits
const (
// Maximum number of predefined locations stored in shader struct
MaxShaderLocations = 32
// Maximum number of texture maps stored in shader struct
MaxMaterialMaps = 12
)
// Mesh - Vertex data definning a mesh
type Mesh struct {
// Number of vertices stored in arrays
VertexCount int32
// Number of triangles stored (indexed or not)
TriangleCount int32
// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
Vertices *float32
// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
Texcoords *float32
// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
Texcoords2 *float32
// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
Normals *float32
// Vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
Tangents *float32
// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
Colors *uint8
// Vertex indices (in case vertex data comes indexed)
Indices *uint16
// AnimVertices
AnimVertices *float32
// AnimNormals
AnimNormals *float32
// BoneIds
BoneIds *int32
// BoneWeights
BoneWeights *float32
// OpenGL Vertex Array Object id
VaoID uint32
// OpenGL Vertex Buffer Objects id (7 types of vertex data)
VboID *uint32
}
// Material type
type Material struct {
// Shader
Shader Shader
// Maps
Maps *MaterialMap
// Generic parameters (if required)
Params [4]float32
}
// GetMap - Get pointer to MaterialMap by map type
func (mt Material) GetMap(index int32) *MaterialMap {
return (*MaterialMap)(unsafe.Pointer(uintptr(unsafe.Pointer(mt.Maps)) + uintptr(index)*unsafe.Sizeof(MaterialMap{})))
}
// MaterialMap type
type MaterialMap struct {
// Texture
Texture Texture2D
// Color
Color color.RGBA
// Value
Value float32
}
// Model is struct of model, meshes, materials and animation data
type Model struct {
// Local transform matrix
Transform Matrix
// Number of meshes
MeshCount int32
// Number of materials
MaterialCount int32
// Meshes array (c array)
//
// Use Model.GetMeshes instead (go slice)
Meshes *Mesh
// Materials array (c array)
//
// Use Model.GetMaterials instead (go slice)
Materials *Material
// Mesh material number
MeshMaterial *int32
// Number of bones
BoneCount int32
// Bones information (skeleton) (c array)
//
// Use Model.GetBones instead (go slice)
Bones *BoneInfo
// Bones base transformation (pose) (c array)
//
// Use Model.GetBindPose instead (go slice)
BindPose *Transform
}
// GetMeshes returns the meshes of a model as go slice
func (m Model) GetMeshes() []Mesh {
return unsafe.Slice(m.Meshes, m.MeshCount)
}
// GetMaterials returns the materials of a model as go slice
func (m Model) GetMaterials() []Material {
return unsafe.Slice(m.Materials, m.MaterialCount)
}
// GetBones returns the bones information (skeleton) of a model as go slice
func (m Model) GetBones() []BoneInfo {
return unsafe.Slice(m.Bones, m.BoneCount)
}
// GetBindPose returns the bones base transformation of a model as go slice
func (m Model) GetBindPose() []Transform {
return unsafe.Slice(m.BindPose, m.BoneCount)
}
// BoneInfo type
type BoneInfo struct {
Name [32]int8
Parent int32
}
// Transform type
type Transform struct {
Translation Vector3
Rotation Vector4
Scale Vector3
}
// Ray type (useful for raycast)
type Ray struct {
// Ray position (origin)
Position Vector3
// Ray direction
Direction Vector3
}
// NewRay - Returns new Ray
func NewRay(position, direction Vector3) Ray {
return Ray{position, direction}
}
// ModelAnimation type
type ModelAnimation struct {
BoneCount int32
FrameCount int32
Bones *BoneInfo
FramePoses **Transform
Name [32]int8
}
// RayCollision type - ray hit information
type RayCollision struct {
Hit bool
Distance float32
Point Vector3
Normal Vector3
}
// NewRayCollision - Returns new RayCollision
func NewRayCollision(hit bool, distance float32, point, normal Vector3) RayCollision {
return RayCollision{hit, distance, point, normal}
}
// BlendMode type
type BlendMode int32
// Color blending modes (pre-defined)
const (
BlendAlpha BlendMode = iota // Blend textures considering alpha (default)
BlendAdditive // Blend textures adding colors
BlendMultiplied // Blend textures multiplying colors
BlendAddColors // Blend textures adding colors (alternative)
BlendSubtractColors // Blend textures subtracting colors (alternative)
BlendAlphaPremultiply // Blend premultiplied textures considering alpha
BlendCustom // Blend textures using custom src/dst factors
BlendCustomSeparate // Blend textures using custom rgb/alpha separate src/dst factors
)
// Shader type (generic shader)
type Shader struct {
// Shader program id
ID uint32
// Shader locations array
Locs *int32
}
// NewShader - Returns new Shader
func NewShader(id uint32, locs *int32) Shader {
return Shader{id, locs}
}
// GetLocation - Get shader value's location
func (sh Shader) GetLocation(index int32) int32 {
return *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(sh.Locs)) + uintptr(index*4)))
}
// UpdateLocation - Update shader value's location
func (sh Shader) UpdateLocation(index int32, loc int32) {
*(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(sh.Locs)) + uintptr(index*4))) = loc
}
// GlyphInfo - Font character info
type GlyphInfo struct {
// Character value (Unicode)
Value int32
// Character offset X when drawing
OffsetX int32
// Character offset Y when drawing
OffsetY int32
// Character advance position X
AdvanceX int32
// Character image data
Image Image
}
// NewGlyphInfo - Returns new CharInfo
func NewGlyphInfo(value int32, offsetX, offsetY, advanceX int32, image Image) GlyphInfo {
return GlyphInfo{value, offsetX, offsetY, advanceX, image}
}
// Font type, includes texture and charSet array data
type Font struct {
// Base size (default chars height)
BaseSize int32
// Number of characters
CharsCount int32
// Padding around the chars
CharsPadding int32
// Characters texture atlas
Texture Texture2D
// Characters rectangles in texture
Recs *Rectangle
// Characters info data
Chars *GlyphInfo
}
// Font type, defines generation method
const (
FontDefault = iota // Default font generation, anti-aliased
FontBitmap // Bitmap font generation, no anti-aliasing
FontSdf // SDF font generation, requires external shader
)
// PixelFormat - Texture format
type PixelFormat int32