go-tg-screenshot-bot
302 строки · 7.2 Кб
1// Copyright 2011 The win Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build windows
6
7package win
8
9import (
10"golang.org/x/sys/windows"
11"syscall"
12"unsafe"
13)
14
15// for second parameter of WglSwapLayerBuffers
16const (
17WGL_SWAP_MAIN_PLANE = (1 << 0)
18WGL_SWAP_OVERLAY1 = (1 << 1)
19WGL_SWAP_OVERLAY2 = (1 << 2)
20WGL_SWAP_OVERLAY3 = (1 << 3)
21WGL_SWAP_OVERLAY4 = (1 << 4)
22WGL_SWAP_OVERLAY5 = (1 << 5)
23WGL_SWAP_OVERLAY6 = (1 << 6)
24WGL_SWAP_OVERLAY7 = (1 << 7)
25WGL_SWAP_OVERLAY8 = (1 << 8)
26WGL_SWAP_OVERLAY9 = (1 << 9)
27WGL_SWAP_OVERLAY10 = (1 << 10)
28WGL_SWAP_OVERLAY11 = (1 << 11)
29WGL_SWAP_OVERLAY12 = (1 << 12)
30WGL_SWAP_OVERLAY13 = (1 << 13)
31WGL_SWAP_OVERLAY14 = (1 << 14)
32WGL_SWAP_OVERLAY15 = (1 << 15)
33WGL_SWAP_UNDERLAY1 = (1 << 16)
34WGL_SWAP_UNDERLAY2 = (1 << 17)
35WGL_SWAP_UNDERLAY3 = (1 << 18)
36WGL_SWAP_UNDERLAY4 = (1 << 19)
37WGL_SWAP_UNDERLAY5 = (1 << 20)
38WGL_SWAP_UNDERLAY6 = (1 << 21)
39WGL_SWAP_UNDERLAY7 = (1 << 22)
40WGL_SWAP_UNDERLAY8 = (1 << 23)
41WGL_SWAP_UNDERLAY9 = (1 << 24)
42WGL_SWAP_UNDERLAY10 = (1 << 25)
43WGL_SWAP_UNDERLAY11 = (1 << 26)
44WGL_SWAP_UNDERLAY12 = (1 << 27)
45WGL_SWAP_UNDERLAY13 = (1 << 28)
46WGL_SWAP_UNDERLAY14 = (1 << 29)
47WGL_SWAP_UNDERLAY15 = (1 << 30)
48)
49
50type (
51HGLRC HANDLE
52)
53
54type LAYERPLANEDESCRIPTOR struct {
55NSize uint16
56NVersion uint16
57DwFlags uint32
58IPixelType uint8
59CColorBits uint8
60CRedBits uint8
61CRedShift uint8
62CGreenBits uint8
63CGreenShift uint8
64CBlueBits uint8
65CBlueShift uint8
66CAlphaBits uint8
67CAlphaShift uint8
68CAccumBits uint8
69CAccumRedBits uint8
70CAccumGreenBits uint8
71CAccumBlueBits uint8
72CAccumAlphaBits uint8
73CDepthBits uint8
74CStencilBits uint8
75CAuxBuffers uint8
76ILayerType uint8
77BReserved uint8
78CrTransparent COLORREF
79}
80
81type POINTFLOAT struct {
82X, Y float32
83}
84
85type GLYPHMETRICSFLOAT struct {
86GmfBlackBoxX float32
87GmfBlackBoxY float32
88GmfptGlyphOrigin POINTFLOAT
89GmfCellIncX float32
90GmfCellIncY float32
91}
92
93var (
94// Library
95lib *windows.LazyDLL
96
97// Functions
98wglCopyContext *windows.LazyProc
99wglCreateContext *windows.LazyProc
100wglCreateLayerContext *windows.LazyProc
101wglDeleteContext *windows.LazyProc
102wglDescribeLayerPlane *windows.LazyProc
103wglGetCurrentContext *windows.LazyProc
104wglGetCurrentDC *windows.LazyProc
105wglGetLayerPaletteEntries *windows.LazyProc
106wglGetProcAddress *windows.LazyProc
107wglMakeCurrent *windows.LazyProc
108wglRealizeLayerPalette *windows.LazyProc
109wglSetLayerPaletteEntries *windows.LazyProc
110wglShareLists *windows.LazyProc
111wglSwapLayerBuffers *windows.LazyProc
112wglUseFontBitmaps *windows.LazyProc
113wglUseFontOutlines *windows.LazyProc
114)
115
116func init() {
117// Library
118lib = windows.NewLazySystemDLL("opengl32.dll")
119
120// Functions
121wglCopyContext = lib.NewProc("wglCopyContext")
122wglCreateContext = lib.NewProc("wglCreateContext")
123wglCreateLayerContext = lib.NewProc("wglCreateLayerContext")
124wglDeleteContext = lib.NewProc("wglDeleteContext")
125wglDescribeLayerPlane = lib.NewProc("wglDescribeLayerPlane")
126wglGetCurrentContext = lib.NewProc("wglGetCurrentContext")
127wglGetCurrentDC = lib.NewProc("wglGetCurrentDC")
128wglGetLayerPaletteEntries = lib.NewProc("wglGetLayerPaletteEntries")
129wglGetProcAddress = lib.NewProc("wglGetProcAddress")
130wglMakeCurrent = lib.NewProc("wglMakeCurrent")
131wglRealizeLayerPalette = lib.NewProc("wglRealizeLayerPalette")
132wglSetLayerPaletteEntries = lib.NewProc("wglSetLayerPaletteEntries")
133wglShareLists = lib.NewProc("wglShareLists")
134wglSwapLayerBuffers = lib.NewProc("wglSwapLayerBuffers")
135wglUseFontBitmaps = lib.NewProc("wglUseFontBitmapsW")
136wglUseFontOutlines = lib.NewProc("wglUseFontOutlinesW")
137}
138
139func WglCopyContext(hglrcSrc, hglrcDst HGLRC, mask uint) bool {
140ret, _, _ := syscall.Syscall(wglCopyContext.Addr(), 3,
141uintptr(hglrcSrc),
142uintptr(hglrcDst),
143uintptr(mask))
144
145return ret != 0
146}
147
148func WglCreateContext(hdc HDC) HGLRC {
149ret, _, _ := syscall.Syscall(wglCreateContext.Addr(), 1,
150uintptr(hdc),
1510,
1520)
153
154return HGLRC(ret)
155}
156
157func WglCreateLayerContext(hdc HDC, iLayerPlane int) HGLRC {
158ret, _, _ := syscall.Syscall(wglCreateLayerContext.Addr(), 2,
159uintptr(hdc),
160uintptr(iLayerPlane),
1610)
162
163return HGLRC(ret)
164}
165
166func WglDeleteContext(hglrc HGLRC) bool {
167ret, _, _ := syscall.Syscall(wglDeleteContext.Addr(), 1,
168uintptr(hglrc),
1690,
1700)
171
172return ret != 0
173}
174
175func WglDescribeLayerPlane(hdc HDC, iPixelFormat, iLayerPlane int, nBytes uint8, plpd *LAYERPLANEDESCRIPTOR) bool {
176ret, _, _ := syscall.Syscall6(wglDescribeLayerPlane.Addr(), 5,
177uintptr(hdc),
178uintptr(iPixelFormat),
179uintptr(iLayerPlane),
180uintptr(nBytes),
181uintptr(unsafe.Pointer(plpd)),
1820)
183
184return ret != 0
185}
186
187func WglGetCurrentContext() HGLRC {
188ret, _, _ := syscall.Syscall(wglGetCurrentContext.Addr(), 0,
1890,
1900,
1910)
192
193return HGLRC(ret)
194}
195
196func WglGetCurrentDC() HDC {
197ret, _, _ := syscall.Syscall(wglGetCurrentDC.Addr(), 0,
1980,
1990,
2000)
201
202return HDC(ret)
203}
204
205func WglGetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int {
206ret, _, _ := syscall.Syscall6(wglGetLayerPaletteEntries.Addr(), 5,
207uintptr(hdc),
208uintptr(iLayerPlane),
209uintptr(iStart),
210uintptr(cEntries),
211uintptr(unsafe.Pointer(pcr)),
2120)
213
214return int(ret)
215}
216
217func WglGetProcAddress(lpszProc *byte) uintptr {
218ret, _, _ := syscall.Syscall(wglGetProcAddress.Addr(), 1,
219uintptr(unsafe.Pointer(lpszProc)),
2200,
2210)
222
223return uintptr(ret)
224}
225
226func WglMakeCurrent(hdc HDC, hglrc HGLRC) bool {
227ret, _, _ := syscall.Syscall(wglMakeCurrent.Addr(), 2,
228uintptr(hdc),
229uintptr(hglrc),
2300)
231
232return ret != 0
233}
234
235func WglRealizeLayerPalette(hdc HDC, iLayerPlane int, bRealize bool) bool {
236ret, _, _ := syscall.Syscall(wglRealizeLayerPalette.Addr(), 3,
237uintptr(hdc),
238uintptr(iLayerPlane),
239uintptr(BoolToBOOL(bRealize)))
240
241return ret != 0
242}
243
244func WglSetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int {
245ret, _, _ := syscall.Syscall6(wglSetLayerPaletteEntries.Addr(), 5,
246uintptr(hdc),
247uintptr(iLayerPlane),
248uintptr(iStart),
249uintptr(cEntries),
250uintptr(unsafe.Pointer(pcr)),
2510)
252
253return int(ret)
254}
255
256func WglShareLists(hglrc1, hglrc2 HGLRC) bool {
257ret, _, _ := syscall.Syscall(wglShareLists.Addr(), 2,
258uintptr(hglrc1),
259uintptr(hglrc2),
2600)
261
262return ret != 0
263}
264
265func WglSwapLayerBuffers(hdc HDC, fuPlanes uint) bool {
266ret, _, _ := syscall.Syscall(wglSwapLayerBuffers.Addr(), 2,
267uintptr(hdc),
268uintptr(fuPlanes),
2690)
270
271return ret != 0
272}
273
274func WglUseFontBitmaps(hdc HDC, first, count, listbase uint32) bool {
275ret, _, _ := syscall.Syscall6(wglUseFontBitmaps.Addr(), 4,
276uintptr(hdc),
277uintptr(first),
278uintptr(count),
279uintptr(listbase),
2800,
2810)
282
283return ret != 0
284}
285
286func WglUseFontOutlines(hdc HDC, first, count, listbase uint32, deviation, extrusion float32, format int, pgmf *GLYPHMETRICSFLOAT) bool {
287ret, _, _ := syscall.Syscall12(wglUseFontBitmaps.Addr(), 8,
288uintptr(hdc),
289uintptr(first),
290uintptr(count),
291uintptr(listbase),
292uintptr(deviation),
293uintptr(extrusion),
294uintptr(format),
295uintptr(unsafe.Pointer(pgmf)),
2960,
2970,
2980,
2990)
300
301return ret != 0
302}
303