-
Notifications
You must be signed in to change notification settings - Fork 13
/
vertex_declaration_windows.go
89 lines (80 loc) · 1.93 KB
/
vertex_declaration_windows.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
package d3d9
import (
"syscall"
"unsafe"
)
// VertexDeclaration and its methods are used to encapsulate the vertex shader
// declaration.
type VertexDeclaration struct {
vtbl *vertexDeclarationVtbl
}
type vertexDeclarationVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetDevice uintptr
GetDeclaration uintptr
}
// AddRef increments the reference count for an interface on an object. This
// method should be called for every new copy of a pointer to an interface on an
// object.
func (obj *VertexDeclaration) AddRef() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddRef,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// Release has to be called when finished using the object to free its
// associated resources.
func (obj *VertexDeclaration) Release() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// GetDevice retrieves the associated device.
// Call Release on the returned device when finished using it.
func (obj *VertexDeclaration) GetDevice() (device *Device, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDevice,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&device)),
0,
)
err = toErr(ret)
return
}
// GetDeclaration returns the vertex shader declaration.
func (obj *VertexDeclaration) GetDeclaration() (decl []VERTEXELEMENT, err Error) {
// first pass nil for the elements to get the count
var elemCount uint
ret, _, _ := syscall.Syscall(
obj.vtbl.GetDeclaration,
3,
uintptr(unsafe.Pointer(obj)),
0,
uintptr(unsafe.Pointer(&elemCount)),
)
if err := toErr(ret); err != nil {
return nil, err
}
decl = make([]VERTEXELEMENT, elemCount)
ret, _, _ = syscall.Syscall(
obj.vtbl.GetDeclaration,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&decl[0])),
uintptr(unsafe.Pointer(&elemCount)),
)
err = toErr(ret)
return
}