-
Notifications
You must be signed in to change notification settings - Fork 13
/
pixel_shader_windows.go
88 lines (79 loc) · 1.84 KB
/
pixel_shader_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
package d3d9
import (
"syscall"
"unsafe"
)
// PixelShader and its methods are used to manipulate a pixel shader resource.
type PixelShader struct {
vtbl *pixelShaderVtbl
}
type pixelShaderVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetDevice uintptr
GetFunction 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 *PixelShader) 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 *PixelShader) 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 *PixelShader) 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
}
// GetFunction returns the shader data.
func (obj *PixelShader) GetFunction() (data []byte, err Error) {
// first get the needed buffer size, pass nil as the data pointer
var sizeInBytes uint
ret, _, _ := syscall.Syscall(
obj.vtbl.GetFunction,
3,
uintptr(unsafe.Pointer(obj)),
0,
uintptr(unsafe.Pointer(&sizeInBytes)),
)
if err := toErr(ret); err != nil {
return nil, err
}
data = make([]byte, sizeInBytes)
ret, _, _ = syscall.Syscall(
obj.vtbl.GetFunction,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&data[0])),
uintptr(unsafe.Pointer(&sizeInBytes)),
)
err = toErr(ret)
return
}