-
Notifications
You must be signed in to change notification settings - Fork 13
/
cube_texture_windows.go
364 lines (337 loc) · 8.2 KB
/
cube_texture_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
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
package d3d9
import (
"syscall"
"unsafe"
)
// CubeTexture and its methods are used to manipulate a cube texture resource.
type CubeTexture struct {
vtbl *cubeTextureVtbl
}
type cubeTextureVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
GetDevice uintptr
SetPrivateData uintptr
GetPrivateData uintptr
FreePrivateData uintptr
SetPriority uintptr
GetPriority uintptr
PreLoad uintptr
GetType uintptr
SetLOD uintptr
GetLOD uintptr
GetLevelCount uintptr
SetAutoGenFilterType uintptr
GetAutoGenFilterType uintptr
GenerateMipSubLevels uintptr
GetLevelDesc uintptr
GetCubeMapSurface uintptr
LockRect uintptr
UnlockRect uintptr
AddDirtyRect uintptr
}
func (obj *CubeTexture) baseTexturePointer() uintptr {
return uintptr(unsafe.Pointer(obj))
}
// 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 *CubeTexture) 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 *CubeTexture) Release() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.Release,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// GetDevice retrieves the device associated with a resource.
// Call Release on the returned device when finished using it.
func (obj *CubeTexture) 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
}
// SetPrivateData associates data with the resource that is intended for use by
// the application, not by Direct3D. Data is passed by value, and multiple sets
// of data can be associated with a single resource.
func (obj *CubeTexture) SetPrivateData(
refguid GUID,
data uintptr,
sizeOfData uint32,
flags uint32,
) Error {
ret, _, _ := syscall.Syscall6(
obj.vtbl.SetPrivateData,
5,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
data,
uintptr(sizeOfData),
uintptr(flags),
0,
)
return toErr(ret)
}
// SetPrivateDataBytes associates data with the resource that is intended for
// use by the application, not by Direct3D. Data is passed by value, and
// multiple sets of data can be associated with a single resource.
func (obj *CubeTexture) SetPrivateDataBytes(
refguid GUID,
data []byte,
flags uint32,
) Error {
return obj.SetPrivateData(
refguid,
uintptr(unsafe.Pointer(&data[0])),
uint32(len(data)),
flags,
)
}
// GetPrivateData copies the private data associated with the resource to a
// provided buffer.
func (obj *CubeTexture) GetPrivateData(refguid GUID) (data []byte, err Error) {
// first get the data size by passing nil as the data pointer
var sizeInBytes uint
ret, _, _ := syscall.Syscall6(
obj.vtbl.GetPrivateData,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
0,
uintptr(unsafe.Pointer(&sizeInBytes)),
0,
0,
)
if err := toErr(ret); err != nil {
return nil, err
}
data = make([]byte, sizeInBytes)
ret, _, _ = syscall.Syscall6(
obj.vtbl.GetPrivateData,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
uintptr(unsafe.Pointer(&data[0])),
uintptr(unsafe.Pointer(&sizeInBytes)),
0,
0,
)
return data, toErr(ret)
}
// FreePrivateData frees the specified private data associated with this
// resource.
func (obj *CubeTexture) FreePrivateData(refguid GUID) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.FreePrivateData,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(unsafe.Pointer(&refguid)),
0,
)
return toErr(ret)
}
// SetPriority assigns the priority of a resource for scheduling purposes.
func (obj *CubeTexture) SetPriority(priorityNew uint32) uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetPriority,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(priorityNew),
0,
)
return uint32(ret)
}
// GetPriority retrieves the priority for this resource.
func (obj *CubeTexture) GetPriority() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetPriority,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// PreLoad preloads a managed resource.
func (obj *CubeTexture) PreLoad() {
syscall.Syscall(
obj.vtbl.PreLoad,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
}
// GetType returns the type of the resource.
func (obj *CubeTexture) GetType() RESOURCETYPE {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetType,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return RESOURCETYPE(ret)
}
// SetLOD sets the most detailed level-of-detail for a managed texture.
func (obj *CubeTexture) SetLOD(lodNew uint32) uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetLOD,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(lodNew),
0,
)
return uint32(ret)
}
// GetLOD returns a value clamped to the maximum level-of-detail set for a
// managed texture (this method is not supported for an unmanaged texture).
func (obj *CubeTexture) GetLOD() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetLOD,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// GetLevelCount returns the number of texture levels in a multilevel texture.
func (obj *CubeTexture) GetLevelCount() uint32 {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetLevelCount,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return uint32(ret)
}
// SetAutoGenFilterType sets the filter type that is used for automatically
// generated mipmap sublevels.
func (obj *CubeTexture) SetAutoGenFilterType(typ TEXTUREFILTERTYPE) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.SetAutoGenFilterType,
2,
uintptr(unsafe.Pointer(obj)),
uintptr(typ),
0,
)
return toErr(ret)
}
// GetAutoGenFilterType returns the filter type that is used for automatically
// generated mipmap sublevels.
func (obj *CubeTexture) GetAutoGenFilterType() TEXTUREFILTERTYPE {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetAutoGenFilterType,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
return TEXTUREFILTERTYPE(ret)
}
// GenerateMipSubLevels generates mip sub levels.
func (obj *CubeTexture) GenerateMipSubLevels() {
syscall.Syscall(
obj.vtbl.GenerateMipSubLevels,
1,
uintptr(unsafe.Pointer(obj)),
0,
0,
)
}
// GetLevelDesc retrieves a description of one face of the specified cube
// texture level.
func (obj *CubeTexture) GetLevelDesc(level uint) (desc SURFACE_DESC, err Error) {
ret, _, _ := syscall.Syscall(
obj.vtbl.GetLevelDesc,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(level),
uintptr(unsafe.Pointer(&desc)),
)
err = toErr(ret)
return
}
// GetCubeMapSurface retrieves a cube texture map surface.
func (obj *CubeTexture) GetCubeMapSurface(
faceType CUBEMAP_FACES,
level uint,
) (surface *Surface, err Error) {
ret, _, _ := syscall.Syscall6(
obj.vtbl.GetCubeMapSurface,
4,
uintptr(unsafe.Pointer(obj)),
uintptr(faceType),
uintptr(level),
uintptr(unsafe.Pointer(&surface)),
0,
0,
)
err = toErr(ret)
return
}
// LockRect locks a rectangle on a cube texture resource.
func (obj *CubeTexture) LockRect(
faceType CUBEMAP_FACES,
level uint,
rect *RECT,
flags uint32,
) (lockedRect LOCKED_RECT, err Error) {
ret, _, _ := syscall.Syscall6(
obj.vtbl.LockRect,
6,
uintptr(unsafe.Pointer(obj)),
uintptr(faceType),
uintptr(level),
uintptr(unsafe.Pointer(&lockedRect)),
uintptr(unsafe.Pointer(rect)),
uintptr(flags),
)
err = toErr(ret)
return
}
// UnlockRect unlocks a rectangle on a cube texture resource.
func (obj *CubeTexture) UnlockRect(faceType CUBEMAP_FACES, level uint) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.UnlockRect,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(faceType),
uintptr(level),
)
return toErr(ret)
}
// AddDirtyRect adds a dirty region to a cube texture resource.
func (obj *CubeTexture) AddDirtyRect(faceType CUBEMAP_FACES, dirtyRect *RECT) Error {
ret, _, _ := syscall.Syscall(
obj.vtbl.AddDirtyRect,
3,
uintptr(unsafe.Pointer(obj)),
uintptr(faceType),
uintptr(unsafe.Pointer(dirtyRect)),
)
return toErr(ret)
}