forked from inkyblackness/imgui-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawList.go
85 lines (73 loc) · 3.21 KB
/
DrawList.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
package imgui
// #include "DrawListWrapper.h"
import "C"
import "unsafe"
// DrawList is a draw-command list.
// This is the low-level list of polygons that ImGui functions are filling.
// At the end of the frame, all command lists are passed to your render function for rendering.
//
// Each ImGui window contains its own DrawList. You can use GetWindowDrawList() to access
// the current window draw list and draw custom primitives.
//
// You can interleave normal ImGui calls and adding primitives to the current draw list.
//
// All positions are generally in pixel coordinates (top-left at (0,0), bottom-right at io.DisplaySize),
// however you are totally free to apply whatever transformation matrix to want to the data
// (if you apply such transformation you'll want to apply it to ClipRect as well)
//
// Important: Primitives are always added to the list and not culled (culling is done at
// higher-level by ImGui functions), if you use this API a lot consider coarse culling your drawn objects.
type DrawList uintptr
func (list DrawList) handle() C.IggDrawList {
return C.IggDrawList(list)
}
// Commands returns the list of draw commands.
// Typically 1 command = 1 GPU draw call, unless the command is a callback.
func (list DrawList) Commands() []DrawCommand {
count := int(C.iggDrawListGetCommandCount(list.handle()))
commands := make([]DrawCommand, count)
for i := 0; i < count; i++ {
commands[i] = DrawCommand(C.iggDrawListGetCommand(list.handle(), C.int(i)))
}
return commands
}
// VertexBufferLayout returns the byte sizes necessary to select fields in a vertex buffer of a DrawList.
func VertexBufferLayout() (entrySize int, posOffset int, uvOffset int, colOffset int) {
var entrySizeArg C.size_t
var posOffsetArg C.size_t
var uvOffsetArg C.size_t
var colOffsetArg C.size_t
C.iggGetVertexBufferLayout(&entrySizeArg, &posOffsetArg, &uvOffsetArg, &colOffsetArg)
entrySize = int(entrySizeArg)
posOffset = int(posOffsetArg)
uvOffset = int(uvOffsetArg)
colOffset = int(colOffsetArg)
return
}
// VertexBuffer returns the handle information of the whole vertex buffer.
// Returned are the handle pointer and the total byte size.
// The buffer is a packed array of vertex entries, each consisting of a 2D position vector, a 2D UV vector,
// and a 4-byte color value. To determine the byte size and offset values, call VertexBufferLayout.
func (list DrawList) VertexBuffer() (unsafe.Pointer, int) {
var data unsafe.Pointer
var size C.int
C.iggDrawListGetRawVertexBuffer(list.handle(), &data, &size)
return data, int(size)
}
// IndexBufferLayout returns the byte size necessary to select fields in an index buffer of DrawList.
func IndexBufferLayout() (entrySize int) {
var entrySizeArg C.size_t
C.iggGetIndexBufferLayout(&entrySizeArg)
entrySize = int(entrySizeArg)
return
}
// IndexBuffer returns the handle information of the whole index buffer.
// Returned are the handle pointer and the total byte size.
// The buffer is a packed array of index entries, each consisting of an integer offset.
// To determine the byte size, call IndexBufferLayout.
func (list DrawList) IndexBuffer() (unsafe.Pointer, int) {
var data unsafe.Pointer
var size C.int
C.iggDrawListGetRawIndexBuffer(list.handle(), &data, &size)
return data, int(size)
}