1// Package gdk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gdk
3
4import (
5 "github.com/ebitengine/purego"
6
7 "github.com/bnema/puregotk/pkg/core"
8 "github.com/bnema/puregotk/v4/glib"
9 "github.com/bnema/puregotk/v4/gobject"
10 "github.com/bnema/puregotk/v4/gobject/types"
11)
12
13var xGlErrorQuark func() glib.Quark
14
15// Registers an error quark for [class@Gdk.GLContext] errors.
16func GlErrorQuark() glib.Quark {
17
18 cret := xGlErrorQuark()
19 return cret
20}
21
22// Represents a platform-specific OpenGL draw context.
23//
24// `GdkGLContext`s are created for a surface using
25// [method@Gdk.Surface.create_gl_context], and the context will match
26// the characteristics of the surface.
27//
28// A `GdkGLContext` is not tied to any particular normal framebuffer.
29// For instance, it cannot draw to the surface back buffer. The GDK
30// repaint system is in full control of the painting to that. Instead,
31// you can create render buffers or textures and use [func@cairo_draw_from_gl]
32// in the draw function of your widget to draw them. Then GDK will handle
33// the integration of your rendering with that of other widgets.
34//
35// Support for `GdkGLContext` is platform-specific and context creation
36// can fail, returning %NULL context.
37//
38// A `GdkGLContext` has to be made "current" in order to start using
39// it, otherwise any OpenGL call will be ignored.
40//
41// ## Creating a new OpenGL context
42//
43// In order to create a new `GdkGLContext` instance you need a `GdkSurface`,
44// which you typically get during the realize call of a widget.
45//
46// A `GdkGLContext` is not realized until either [method@Gdk.GLContext.make_current]
47// or [method@Gdk.GLContext.realize] is called. It is possible to specify
48// details of the GL context like the OpenGL version to be used, or whether
49// the GL context should have extra state validation enabled after calling
50// [method@Gdk.Surface.create_gl_context] by calling [method@Gdk.GLContext.realize].
51// If the realization fails you have the option to change the settings of
52// the `GdkGLContext` and try again.
53//
54// ## Using a GdkGLContext
55//
56// You will need to make the `GdkGLContext` the current context before issuing
57// OpenGL calls; the system sends OpenGL commands to whichever context is current.
58// It is possible to have multiple contexts, so you always need to ensure that
59// the one which you want to draw with is the current one before issuing commands:
60//
61// ```c
62// gdk_gl_context_make_current (context);
63// ```
64//
65// You can now perform your drawing using OpenGL commands.
66//
67// You can check which `GdkGLContext` is the current one by using
68// [func@Gdk.GLContext.get_current]; you can also unset any `GdkGLContext`
69// that is currently set by calling [func@Gdk.GLContext.clear_current].
70type GLContext struct {
71 DrawContext
72}
73
74var xGLContextGLibType func() types.GType
75
76func GLContextGLibType() types.GType {
77 return xGLContextGLibType()
78}
79
80func GLContextNewFromInternalPtr(ptr uintptr) *GLContext {
81 cls := &GLContext{}
82 cls.Ptr = ptr
83 return cls
84}
85
86var xGLContextGetAllowedApis func(uintptr) GLAPI
87
88// Gets the allowed APIs set via gdk_gl_context_set_allowed_apis().
89func (x *GLContext) GetAllowedApis() GLAPI {
90
91 cret := xGLContextGetAllowedApis(x.GoPointer())
92 return cret
93}
94
95var xGLContextGetApi func(uintptr) GLAPI
96
97// Gets the API currently in use.
98//
99// If the renderer has not been realized yet, 0 is returned.
100func (x *GLContext) GetApi() GLAPI {
101
102 cret := xGLContextGetApi(x.GoPointer())
103 return cret
104}
105
106var xGLContextGetDebugEnabled func(uintptr) bool
107
108// Retrieves whether the context is doing extra validations and runtime checking.
109//
110// See [method@Gdk.GLContext.set_debug_enabled].
111func (x *GLContext) GetDebugEnabled() bool {
112
113 cret := xGLContextGetDebugEnabled(x.GoPointer())
114 return cret
115}
116
117var xGLContextGetDisplay func(uintptr) uintptr
118
119// Retrieves the display the @context is created for
120func (x *GLContext) GetDisplay() *Display {
121 var cls *Display
122
123 cret := xGLContextGetDisplay(x.GoPointer())
124
125 if cret == 0 {
126 return nil
127 }
128 gobject.IncreaseRef(cret)
129 cls = &Display{}
130 cls.Ptr = cret
131 return cls
132}
133
134var xGLContextGetForwardCompatible func(uintptr) bool
135
136// Retrieves whether the context is forward-compatible.
137//
138// See [method@Gdk.GLContext.set_forward_compatible].
139func (x *GLContext) GetForwardCompatible() bool {
140
141 cret := xGLContextGetForwardCompatible(x.GoPointer())
142 return cret
143}
144
145var xGLContextGetRequiredVersion func(uintptr, *int, *int)
146
147// Retrieves required OpenGL version set as a requirement for the @context
148// realization. It will not change even if a greater OpenGL version is supported
149// and used after the @context is realized. See
150// [method@Gdk.GLContext.get_version] for the real version in use.
151//
152// See [method@Gdk.GLContext.set_required_version].
153func (x *GLContext) GetRequiredVersion(MajorVar *int, MinorVar *int) {
154
155 xGLContextGetRequiredVersion(x.GoPointer(), MajorVar, MinorVar)
156
157}
158
159var xGLContextGetSharedContext func(uintptr) uintptr
160
161// Used to retrieves the `GdkGLContext` that this @context share data with.
162//
163// As many contexts can share data now and no single shared context exists
164// anymore, this function has been deprecated and now always returns %NULL.
165func (x *GLContext) GetSharedContext() *GLContext {
166 var cls *GLContext
167
168 cret := xGLContextGetSharedContext(x.GoPointer())
169
170 if cret == 0 {
171 return nil
172 }
173 gobject.IncreaseRef(cret)
174 cls = &GLContext{}
175 cls.Ptr = cret
176 return cls
177}
178
179var xGLContextGetSurface func(uintptr) uintptr
180
181// Retrieves the surface used by the @context.
182func (x *GLContext) GetSurface() *Surface {
183 var cls *Surface
184
185 cret := xGLContextGetSurface(x.GoPointer())
186
187 if cret == 0 {
188 return nil
189 }
190 gobject.IncreaseRef(cret)
191 cls = &Surface{}
192 cls.Ptr = cret
193 return cls
194}
195
196var xGLContextGetUseEs func(uintptr) bool
197
198// Checks whether the @context is using an OpenGL or OpenGL ES profile.
199func (x *GLContext) GetUseEs() bool {
200
201 cret := xGLContextGetUseEs(x.GoPointer())
202 return cret
203}
204
205var xGLContextGetVersion func(uintptr, *int, *int)
206
207// Retrieves the OpenGL version of the @context.
208//
209// The @context must be realized prior to calling this function.
210func (x *GLContext) GetVersion(MajorVar *int, MinorVar *int) {
211
212 xGLContextGetVersion(x.GoPointer(), MajorVar, MinorVar)
213
214}
215
216var xGLContextIsLegacy func(uintptr) bool
217
218// Whether the `GdkGLContext` is in legacy mode or not.
219//
220// The `GdkGLContext` must be realized before calling this function.
221//
222// When realizing a GL context, GDK will try to use the OpenGL 3.2 core
223// profile; this profile removes all the OpenGL API that was deprecated
224// prior to the 3.2 version of the specification. If the realization is
225// successful, this function will return %FALSE.
226//
227// If the underlying OpenGL implementation does not support core profiles,
228// GDK will fall back to a pre-3.2 compatibility profile, and this function
229// will return %TRUE.
230//
231// You can use the value returned by this function to decide which kind
232// of OpenGL API to use, or whether to do extension discovery, or what
233// kind of shader programs to load.
234func (x *GLContext) IsLegacy() bool {
235
236 cret := xGLContextIsLegacy(x.GoPointer())
237 return cret
238}
239
240var xGLContextIsShared func(uintptr, uintptr) bool
241
242// Checks if the two GL contexts can share resources.
243//
244// When they can, the texture IDs from @other can be used in @self. This
245// is particularly useful when passing `GdkGLTexture` objects between
246// different contexts.
247//
248// Contexts created for the same display with the same properties will
249// always be compatible, even if they are created for different surfaces.
250// For other contexts it depends on the GL backend.
251//
252// Both contexts must be realized for this check to succeed. If either one
253// is not, this function will return %FALSE.
254func (x *GLContext) IsShared(OtherVar *GLContext) bool {
255
256 cret := xGLContextIsShared(x.GoPointer(), OtherVar.GoPointer())
257 return cret
258}
259
260var xGLContextMakeCurrent func(uintptr)
261
262// Makes the @context the current one.
263func (x *GLContext) MakeCurrent() {
264
265 xGLContextMakeCurrent(x.GoPointer())
266
267}
268
269var xGLContextRealize func(uintptr) bool
270
271// Realizes the given `GdkGLContext`.
272//
273// It is safe to call this function on a realized `GdkGLContext`.
274func (x *GLContext) Realize() (bool, error) {
275 var cerr *glib.Error
276
277 cret := xGLContextRealize(x.GoPointer())
278 if cerr == nil {
279 return cret, nil
280 }
281 return cret, cerr
282
283}
284
285var xGLContextSetAllowedApis func(uintptr, GLAPI)
286
287// Sets the allowed APIs. When gdk_gl_context_realize() is called, only the
288// allowed APIs will be tried. If you set this to 0, realizing will always fail.
289//
290// If you set it on a realized context, the property will not have any effect.
291// It is only relevant during gdk_gl_context_realize().
292//
293// By default, all APIs are allowed.
294func (x *GLContext) SetAllowedApis(ApisVar GLAPI) {
295
296 xGLContextSetAllowedApis(x.GoPointer(), ApisVar)
297
298}
299
300var xGLContextSetDebugEnabled func(uintptr, bool)
301
302// Sets whether the `GdkGLContext` should perform extra validations and
303// runtime checking.
304//
305// This is useful during development, but has additional overhead.
306//
307// The `GdkGLContext` must not be realized or made current prior to
308// calling this function.
309func (x *GLContext) SetDebugEnabled(EnabledVar bool) {
310
311 xGLContextSetDebugEnabled(x.GoPointer(), EnabledVar)
312
313}
314
315var xGLContextSetForwardCompatible func(uintptr, bool)
316
317// Sets whether the `GdkGLContext` should be forward-compatible.
318//
319// Forward-compatible contexts must not support OpenGL functionality that
320// has been marked as deprecated in the requested version; non-forward
321// compatible contexts, on the other hand, must support both deprecated and
322// non deprecated functionality.
323//
324// The `GdkGLContext` must not be realized or made current prior to calling
325// this function.
326func (x *GLContext) SetForwardCompatible(CompatibleVar bool) {
327
328 xGLContextSetForwardCompatible(x.GoPointer(), CompatibleVar)
329
330}
331
332var xGLContextSetRequiredVersion func(uintptr, int, int)
333
334// Sets the major and minor version of OpenGL to request.
335//
336// Setting @major and @minor to zero will use the default values.
337//
338// Setting @major and @minor lower than the minimum versions required
339// by GTK will result in the context choosing the minimum version.
340//
341// The @context must not be realized or made current prior to calling
342// this function.
343func (x *GLContext) SetRequiredVersion(MajorVar int, MinorVar int) {
344
345 xGLContextSetRequiredVersion(x.GoPointer(), MajorVar, MinorVar)
346
347}
348
349var xGLContextSetUseEs func(uintptr, int)
350
351// Requests that GDK create an OpenGL ES context instead of an OpenGL one.
352//
353// Not all platforms support OpenGL ES.
354//
355// The @context must not have been realized.
356//
357// By default, GDK will attempt to automatically detect whether the
358// underlying GL implementation is OpenGL or OpenGL ES once the @context
359// is realized.
360//
361// You should check the return value of [method@Gdk.GLContext.get_use_es]
362// after calling [method@Gdk.GLContext.realize] to decide whether to use
363// the OpenGL or OpenGL ES API, extensions, or shaders.
364func (x *GLContext) SetUseEs(UseEsVar int) {
365
366 xGLContextSetUseEs(x.GoPointer(), UseEsVar)
367
368}
369
370func (c *GLContext) GoPointer() uintptr {
371 if c == nil {
372 return 0
373 }
374 return c.Ptr
375}
376
377func (c *GLContext) SetGoPointer(ptr uintptr) {
378 c.Ptr = ptr
379}
380
381var xGLContextClearCurrent func()
382
383// Clears the current `GdkGLContext`.
384//
385// Any OpenGL call after this function returns will be ignored
386// until [method@Gdk.GLContext.make_current] is called.
387func GLContextClearCurrent() {
388
389 xGLContextClearCurrent()
390
391}
392
393var xGLContextGetCurrent func() uintptr
394
395// Retrieves the current `GdkGLContext`.
396func GLContextGetCurrent() *GLContext {
397 var cls *GLContext
398
399 cret := xGLContextGetCurrent()
400
401 if cret == 0 {
402 return nil
403 }
404 gobject.IncreaseRef(cret)
405 cls = &GLContext{}
406 cls.Ptr = cret
407 return cls
408}
409
410func init() {
411 core.SetPackageName("GDK", "gtk4")
412 core.SetSharedLibraries("GDK", []string{"libgtk-4.so.1"})
413 var libs []uintptr
414 for _, libPath := range core.GetPaths("GDK") {
415 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
416 if err != nil {
417 panic(err)
418 }
419 libs = append(libs, lib)
420 }
421
422 core.PuregoSafeRegister(&xGlErrorQuark, libs, "gdk_gl_error_quark")
423
424 core.PuregoSafeRegister(&xGLContextGLibType, libs, "gdk_gl_context_get_type")
425
426 core.PuregoSafeRegister(&xGLContextGetAllowedApis, libs, "gdk_gl_context_get_allowed_apis")
427 core.PuregoSafeRegister(&xGLContextGetApi, libs, "gdk_gl_context_get_api")
428 core.PuregoSafeRegister(&xGLContextGetDebugEnabled, libs, "gdk_gl_context_get_debug_enabled")
429 core.PuregoSafeRegister(&xGLContextGetDisplay, libs, "gdk_gl_context_get_display")
430 core.PuregoSafeRegister(&xGLContextGetForwardCompatible, libs, "gdk_gl_context_get_forward_compatible")
431 core.PuregoSafeRegister(&xGLContextGetRequiredVersion, libs, "gdk_gl_context_get_required_version")
432 core.PuregoSafeRegister(&xGLContextGetSharedContext, libs, "gdk_gl_context_get_shared_context")
433 core.PuregoSafeRegister(&xGLContextGetSurface, libs, "gdk_gl_context_get_surface")
434 core.PuregoSafeRegister(&xGLContextGetUseEs, libs, "gdk_gl_context_get_use_es")
435 core.PuregoSafeRegister(&xGLContextGetVersion, libs, "gdk_gl_context_get_version")
436 core.PuregoSafeRegister(&xGLContextIsLegacy, libs, "gdk_gl_context_is_legacy")
437 core.PuregoSafeRegister(&xGLContextIsShared, libs, "gdk_gl_context_is_shared")
438 core.PuregoSafeRegister(&xGLContextMakeCurrent, libs, "gdk_gl_context_make_current")
439 core.PuregoSafeRegister(&xGLContextRealize, libs, "gdk_gl_context_realize")
440 core.PuregoSafeRegister(&xGLContextSetAllowedApis, libs, "gdk_gl_context_set_allowed_apis")
441 core.PuregoSafeRegister(&xGLContextSetDebugEnabled, libs, "gdk_gl_context_set_debug_enabled")
442 core.PuregoSafeRegister(&xGLContextSetForwardCompatible, libs, "gdk_gl_context_set_forward_compatible")
443 core.PuregoSafeRegister(&xGLContextSetRequiredVersion, libs, "gdk_gl_context_set_required_version")
444 core.PuregoSafeRegister(&xGLContextSetUseEs, libs, "gdk_gl_context_set_use_es")
445
446 core.PuregoSafeRegister(&xGLContextClearCurrent, libs, "gdk_gl_context_clear_current")
447 core.PuregoSafeRegister(&xGLContextGetCurrent, libs, "gdk_gl_context_get_current")
448
449}