// Package gsk was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gsk import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject" "github.com/bnema/puregotk/v4/gobject/types" "github.com/bnema/puregotk/v4/graphene" ) type GLShaderClass struct { _ structs.HostLayout ParentClass gobject.ObjectClass } func (x *GLShaderClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // Builds the uniforms data for a `GskGLShader`. type ShaderArgsBuilder struct { _ structs.HostLayout } var xShaderArgsBuilderGLibType func() types.GType func ShaderArgsBuilderGLibType() types.GType { return xShaderArgsBuilderGLibType() } func (x *ShaderArgsBuilder) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } var xNewShaderArgsBuilder func(uintptr, *glib.Bytes) *ShaderArgsBuilder // Allocates a builder that can be used to construct a new uniform data // chunk. func NewShaderArgsBuilder(ShaderVar *GLShader, InitialValuesVar *glib.Bytes) *ShaderArgsBuilder { cret := xNewShaderArgsBuilder(ShaderVar.GoPointer(), InitialValuesVar) return cret } var xShaderArgsBuilderFreeToArgs func(uintptr) *glib.Bytes // Creates a new `GBytes` args from the current state of the // given @builder, and frees the @builder instance. // // Any uniforms of the shader that have not been explicitly set // on the @builder are zero-initialized. func (x *ShaderArgsBuilder) FreeToArgs() *glib.Bytes { cret := xShaderArgsBuilderFreeToArgs(x.GoPointer()) return cret } var xShaderArgsBuilderRef func(uintptr) *ShaderArgsBuilder // Increases the reference count of a `GskShaderArgsBuilder` by one. func (x *ShaderArgsBuilder) Ref() *ShaderArgsBuilder { cret := xShaderArgsBuilderRef(x.GoPointer()) return cret } var xShaderArgsBuilderSetBool func(uintptr, int, bool) // Sets the value of the uniform @idx. // // The uniform must be of bool type. func (x *ShaderArgsBuilder) SetBool(IdxVar int, ValueVar bool) { xShaderArgsBuilderSetBool(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderSetFloat func(uintptr, int, float32) // Sets the value of the uniform @idx. // // The uniform must be of float type. func (x *ShaderArgsBuilder) SetFloat(IdxVar int, ValueVar float32) { xShaderArgsBuilderSetFloat(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderSetInt func(uintptr, int, int32) // Sets the value of the uniform @idx. // // The uniform must be of int type. func (x *ShaderArgsBuilder) SetInt(IdxVar int, ValueVar int32) { xShaderArgsBuilderSetInt(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderSetUint func(uintptr, int, uint32) // Sets the value of the uniform @idx. // // The uniform must be of uint type. func (x *ShaderArgsBuilder) SetUint(IdxVar int, ValueVar uint32) { xShaderArgsBuilderSetUint(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderSetVec2 func(uintptr, int, *graphene.Vec2) // Sets the value of the uniform @idx. // // The uniform must be of vec2 type. func (x *ShaderArgsBuilder) SetVec2(IdxVar int, ValueVar *graphene.Vec2) { xShaderArgsBuilderSetVec2(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderSetVec3 func(uintptr, int, *graphene.Vec3) // Sets the value of the uniform @idx. // // The uniform must be of vec3 type. func (x *ShaderArgsBuilder) SetVec3(IdxVar int, ValueVar *graphene.Vec3) { xShaderArgsBuilderSetVec3(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderSetVec4 func(uintptr, int, *graphene.Vec4) // Sets the value of the uniform @idx. // // The uniform must be of vec4 type. func (x *ShaderArgsBuilder) SetVec4(IdxVar int, ValueVar *graphene.Vec4) { xShaderArgsBuilderSetVec4(x.GoPointer(), IdxVar, ValueVar) } var xShaderArgsBuilderToArgs func(uintptr) *glib.Bytes // Creates a new `GBytes` args from the current state of the // given @builder. // // Any uniforms of the shader that have not been explicitly set on // the @builder are zero-initialized. // // The given `GskShaderArgsBuilder` is reset once this function returns; // you cannot call this function multiple times on the same @builder instance. // // This function is intended primarily for bindings. C code should use // [method@Gsk.ShaderArgsBuilder.free_to_args]. func (x *ShaderArgsBuilder) ToArgs() *glib.Bytes { cret := xShaderArgsBuilderToArgs(x.GoPointer()) return cret } var xShaderArgsBuilderUnref func(uintptr) // Decreases the reference count of a `GskShaderArgBuilder` by one. // // If the resulting reference count is zero, frees the builder. func (x *ShaderArgsBuilder) Unref() { xShaderArgsBuilderUnref(x.GoPointer()) } // Implements a fragment shader using GLSL. // // A fragment shader gets the coordinates being rendered as input and // produces the pixel values for that particular pixel. Additionally, // the shader can declare a set of other input arguments, called // uniforms (as they are uniform over all the calls to your shader in // each instance of use). A shader can also receive up to 4 // textures that it can use as input when producing the pixel data. // // `GskGLShader` is usually used with gtk_snapshot_push_gl_shader() // to produce a [class@Gsk.GLShaderNode] in the rendering hierarchy, // and then its input textures are constructed by rendering the child // nodes to textures before rendering the shader node itself. (You can // pass texture nodes as children if you want to directly use a texture // as input). // // The actual shader code is GLSL code that gets combined with // some other code into the fragment shader. Since the exact // capabilities of the GPU driver differs between different OpenGL // drivers and hardware, GTK adds some defines that you can use // to ensure your GLSL code runs on as many drivers as it can. // // If the OpenGL driver is GLES, then the shader language version // is set to 100, and GSK_GLES will be defined in the shader. // // Otherwise, if the OpenGL driver does not support the 3.2 core profile, // then the shader will run with language version 110 for GL2 and 130 for GL3, // and GSK_LEGACY will be defined in the shader. // // If the OpenGL driver supports the 3.2 code profile, it will be used, // the shader language version is set to 150, and GSK_GL3 will be defined // in the shader. // // The main function the shader must implement is: // // ```glsl // // void mainImage(out vec4 fragColor, // in vec2 fragCoord, // in vec2 resolution, // in vec2 uv) // // ``` // // Where the input @fragCoord is the coordinate of the pixel we're // currently rendering, relative to the boundary rectangle that was // specified in the `GskGLShaderNode`, and @resolution is the width and // height of that rectangle. This is in the typical GTK coordinate // system with the origin in the top left. @uv contains the u and v // coordinates that can be used to index a texture at the // corresponding point. These coordinates are in the [0..1]x[0..1] // region, with 0, 0 being in the lower left corder (which is typical // for OpenGL). // // The output @fragColor should be a RGBA color (with // premultiplied alpha) that will be used as the output for the // specified pixel location. Note that this output will be // automatically clipped to the clip region of the glshader node. // // In addition to the function arguments the shader can define // up to 4 uniforms for textures which must be called u_textureN // (i.e. u_texture1 to u_texture4) as well as any custom uniforms // you want of types int, uint, bool, float, vec2, vec3 or vec4. // // All textures sources contain premultiplied alpha colors, but if some // there are outer sources of colors there is a gsk_premultiply() helper // to compute premultiplication when needed. // // Note that GTK parses the uniform declarations, so each uniform has to // be on a line by itself with no other code, like so: // // ```glsl // uniform float u_time; // uniform vec3 u_color; // uniform sampler2D u_texture1; // uniform sampler2D u_texture2; // ``` // // GTK uses the "gsk" namespace in the symbols it uses in the // shader, so your code should not use any symbols with the prefix gsk // or GSK. There are some helper functions declared that you can use: // // ```glsl // vec4 GskTexture(sampler2D sampler, vec2 texCoords); // ``` // // This samples a texture (e.g. u_texture1) at the specified // coordinates, and contains some helper ifdefs to ensure that // it works on all OpenGL versions. // // You can compile the shader yourself using [method@Gsk.GLShader.compile], // otherwise the GSK renderer will do it when it handling the glshader // node. If errors occurs, the returned @error will include the glsl // sources, so you can see what GSK was passing to the compiler. You // can also set GSK_DEBUG=shaders in the environment to see the sources // and other relevant information about all shaders that GSK is handling. // // # An example shader // // ```glsl // uniform float position; // uniform sampler2D u_texture1; // uniform sampler2D u_texture2; // // void mainImage(out vec4 fragColor, // // in vec2 fragCoord, // in vec2 resolution, // in vec2 uv) { // vec4 source1 = GskTexture(u_texture1, uv); // vec4 source2 = GskTexture(u_texture2, uv); // // fragColor = position * source1 + (1.0 - position) * source2; // } // // ``` type GLShader struct { gobject.Object } var xGLShaderGLibType func() types.GType func GLShaderGLibType() types.GType { return xGLShaderGLibType() } func GLShaderNewFromInternalPtr(ptr uintptr) *GLShader { cls := &GLShader{} cls.Ptr = ptr return cls } var xNewGLShaderFromBytes func(*glib.Bytes) uintptr // Creates a `GskGLShader` that will render pixels using the specified code. func NewGLShaderFromBytes(SourcecodeVar *glib.Bytes) *GLShader { var cls *GLShader cret := xNewGLShaderFromBytes(SourcecodeVar) if cret == 0 { return nil } cls = &GLShader{} cls.Ptr = cret return cls } var xNewGLShaderFromResource func(string) uintptr // Creates a `GskGLShader` that will render pixels using the specified code. func NewGLShaderFromResource(ResourcePathVar string) *GLShader { var cls *GLShader cret := xNewGLShaderFromResource(ResourcePathVar) if cret == 0 { return nil } cls = &GLShader{} cls.Ptr = cret return cls } var xGLShaderCompile func(uintptr, uintptr, **glib.Error) bool // Tries to compile the @shader for the given @renderer. // // If there is a problem, this function returns %FALSE and reports // an error. You should use this function before relying on the shader // for rendering and use a fallback with a simpler shader or without // shaders if it fails. // // Note that this will modify the rendering state (for example // change the current GL context) and requires the renderer to be // set up. This means that the widget has to be realized. Commonly you // want to call this from the realize signal of a widget, or during // widget snapshot. func (x *GLShader) Compile(RendererVar *Renderer) (bool, error) { var cerr *glib.Error cret := xGLShaderCompile(x.GoPointer(), RendererVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xGLShaderFindUniformByName func(uintptr, string) int // Looks for a uniform by the name @name, and returns the index // of the uniform, or -1 if it was not found. func (x *GLShader) FindUniformByName(NameVar string) int { cret := xGLShaderFindUniformByName(x.GoPointer(), NameVar) return cret } var xGLShaderFormatArgs func(uintptr, ...interface{}) *glib.Bytes // Formats the uniform data as needed for feeding the named uniforms // values into the shader. // // The argument list is a list of pairs of names, and values for the types // that match the declared uniforms (i.e. double/int/guint/gboolean for // primitive values and `graphene_vecN_t *` for vecN uniforms). // // Any uniforms of the shader that are not included in the argument list // are zero-initialized. func (x *GLShader) FormatArgs(varArgs ...interface{}) *glib.Bytes { cret := xGLShaderFormatArgs(x.GoPointer(), varArgs...) return cret } var xGLShaderFormatArgsVa func(uintptr, []interface{}) *glib.Bytes // Formats the uniform data as needed for feeding the named uniforms // values into the shader. // // The argument list is a list of pairs of names, and values for the // types that match the declared uniforms (i.e. double/int/guint/gboolean // for primitive values and `graphene_vecN_t *` for vecN uniforms). // // It is an error to pass a uniform name that is not declared by the shader. // // Any uniforms of the shader that are not included in the argument list // are zero-initialized. func (x *GLShader) FormatArgsVa(UniformsVar []interface{}) *glib.Bytes { cret := xGLShaderFormatArgsVa(x.GoPointer(), UniformsVar) return cret } var xGLShaderGetArgBool func(uintptr, *glib.Bytes, int) bool // Gets the value of the uniform @idx in the @args block. // // The uniform must be of bool type. func (x *GLShader) GetArgBool(ArgsVar *glib.Bytes, IdxVar int) bool { cret := xGLShaderGetArgBool(x.GoPointer(), ArgsVar, IdxVar) return cret } var xGLShaderGetArgFloat func(uintptr, *glib.Bytes, int) float32 // Gets the value of the uniform @idx in the @args block. // // The uniform must be of float type. func (x *GLShader) GetArgFloat(ArgsVar *glib.Bytes, IdxVar int) float32 { cret := xGLShaderGetArgFloat(x.GoPointer(), ArgsVar, IdxVar) return cret } var xGLShaderGetArgInt func(uintptr, *glib.Bytes, int) int32 // Gets the value of the uniform @idx in the @args block. // // The uniform must be of int type. func (x *GLShader) GetArgInt(ArgsVar *glib.Bytes, IdxVar int) int32 { cret := xGLShaderGetArgInt(x.GoPointer(), ArgsVar, IdxVar) return cret } var xGLShaderGetArgUint func(uintptr, *glib.Bytes, int) uint32 // Gets the value of the uniform @idx in the @args block. // // The uniform must be of uint type. func (x *GLShader) GetArgUint(ArgsVar *glib.Bytes, IdxVar int) uint32 { cret := xGLShaderGetArgUint(x.GoPointer(), ArgsVar, IdxVar) return cret } var xGLShaderGetArgVec2 func(uintptr, *glib.Bytes, int, *graphene.Vec2) // Gets the value of the uniform @idx in the @args block. // // The uniform must be of vec2 type. func (x *GLShader) GetArgVec2(ArgsVar *glib.Bytes, IdxVar int, OutValueVar *graphene.Vec2) { xGLShaderGetArgVec2(x.GoPointer(), ArgsVar, IdxVar, OutValueVar) } var xGLShaderGetArgVec3 func(uintptr, *glib.Bytes, int, *graphene.Vec3) // Gets the value of the uniform @idx in the @args block. // // The uniform must be of vec3 type. func (x *GLShader) GetArgVec3(ArgsVar *glib.Bytes, IdxVar int, OutValueVar *graphene.Vec3) { xGLShaderGetArgVec3(x.GoPointer(), ArgsVar, IdxVar, OutValueVar) } var xGLShaderGetArgVec4 func(uintptr, *glib.Bytes, int, *graphene.Vec4) // Gets the value of the uniform @idx in the @args block. // // The uniform must be of vec4 type. func (x *GLShader) GetArgVec4(ArgsVar *glib.Bytes, IdxVar int, OutValueVar *graphene.Vec4) { xGLShaderGetArgVec4(x.GoPointer(), ArgsVar, IdxVar, OutValueVar) } var xGLShaderGetArgsSize func(uintptr) uint // Get the size of the data block used to specify arguments for this shader. func (x *GLShader) GetArgsSize() uint { cret := xGLShaderGetArgsSize(x.GoPointer()) return cret } var xGLShaderGetNTextures func(uintptr) int // Returns the number of textures that the shader requires. // // This can be used to check that the a passed shader works // in your usecase. It is determined by looking at the highest // u_textureN value that the shader defines. func (x *GLShader) GetNTextures() int { cret := xGLShaderGetNTextures(x.GoPointer()) return cret } var xGLShaderGetNUniforms func(uintptr) int // Get the number of declared uniforms for this shader. func (x *GLShader) GetNUniforms() int { cret := xGLShaderGetNUniforms(x.GoPointer()) return cret } var xGLShaderGetResource func(uintptr) string // Gets the resource path for the GLSL sourcecode being used // to render this shader. func (x *GLShader) GetResource() string { cret := xGLShaderGetResource(x.GoPointer()) return cret } var xGLShaderGetSource func(uintptr) *glib.Bytes // Gets the GLSL sourcecode being used to render this shader. func (x *GLShader) GetSource() *glib.Bytes { cret := xGLShaderGetSource(x.GoPointer()) return cret } var xGLShaderGetUniformName func(uintptr, int) string // Get the name of the declared uniform for this shader at index @idx. func (x *GLShader) GetUniformName(IdxVar int) string { cret := xGLShaderGetUniformName(x.GoPointer(), IdxVar) return cret } var xGLShaderGetUniformOffset func(uintptr, int) int // Get the offset into the data block where data for this uniforms is stored. func (x *GLShader) GetUniformOffset(IdxVar int) int { cret := xGLShaderGetUniformOffset(x.GoPointer(), IdxVar) return cret } var xGLShaderGetUniformType func(uintptr, int) GLUniformType // Get the type of the declared uniform for this shader at index @idx. func (x *GLShader) GetUniformType(IdxVar int) GLUniformType { cret := xGLShaderGetUniformType(x.GoPointer(), IdxVar) return cret } func (c *GLShader) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *GLShader) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // SetPropertyResource sets the "resource" property. // Resource containing the source code for the shader. // // If the shader source is not coming from a resource, this // will be %NULL. func (x *GLShader) SetPropertyResource(value string) { var v gobject.Value v.Init(gobject.TypeStringVal) v.SetString(&value) x.SetProperty("resource", &v) } // GetPropertyResource gets the "resource" property. // Resource containing the source code for the shader. // // If the shader source is not coming from a resource, this // will be %NULL. func (x *GLShader) GetPropertyResource() string { var v gobject.Value x.GetProperty("resource", &v) return v.GetString() } // SetPropertySource sets the "source" property. // The source code for the shader, as a `GBytes`. func (x *GLShader) SetPropertySource(value uintptr) { var v gobject.Value v.Init(gobject.TypePointerVal) v.SetPointer(value) x.SetProperty("source", &v) } // GetPropertySource gets the "source" property. // The source code for the shader, as a `GBytes`. func (x *GLShader) GetPropertySource() uintptr { var v gobject.Value x.GetProperty("source", &v) return v.GetPointer() } func init() { core.SetPackageName("GSK", "gtk4") core.SetSharedLibraries("GSK", []string{"libgtk-4.so.1"}) var libs []uintptr for _, libPath := range core.GetPaths("GSK") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xShaderArgsBuilderGLibType, libs, "gsk_shader_args_builder_get_type") core.PuregoSafeRegister(&xNewShaderArgsBuilder, libs, "gsk_shader_args_builder_new") core.PuregoSafeRegister(&xShaderArgsBuilderFreeToArgs, libs, "gsk_shader_args_builder_free_to_args") core.PuregoSafeRegister(&xShaderArgsBuilderRef, libs, "gsk_shader_args_builder_ref") core.PuregoSafeRegister(&xShaderArgsBuilderSetBool, libs, "gsk_shader_args_builder_set_bool") core.PuregoSafeRegister(&xShaderArgsBuilderSetFloat, libs, "gsk_shader_args_builder_set_float") core.PuregoSafeRegister(&xShaderArgsBuilderSetInt, libs, "gsk_shader_args_builder_set_int") core.PuregoSafeRegister(&xShaderArgsBuilderSetUint, libs, "gsk_shader_args_builder_set_uint") core.PuregoSafeRegister(&xShaderArgsBuilderSetVec2, libs, "gsk_shader_args_builder_set_vec2") core.PuregoSafeRegister(&xShaderArgsBuilderSetVec3, libs, "gsk_shader_args_builder_set_vec3") core.PuregoSafeRegister(&xShaderArgsBuilderSetVec4, libs, "gsk_shader_args_builder_set_vec4") core.PuregoSafeRegister(&xShaderArgsBuilderToArgs, libs, "gsk_shader_args_builder_to_args") core.PuregoSafeRegister(&xShaderArgsBuilderUnref, libs, "gsk_shader_args_builder_unref") core.PuregoSafeRegister(&xGLShaderGLibType, libs, "gsk_gl_shader_get_type") core.PuregoSafeRegister(&xNewGLShaderFromBytes, libs, "gsk_gl_shader_new_from_bytes") core.PuregoSafeRegister(&xNewGLShaderFromResource, libs, "gsk_gl_shader_new_from_resource") core.PuregoSafeRegister(&xGLShaderCompile, libs, "gsk_gl_shader_compile") core.PuregoSafeRegister(&xGLShaderFindUniformByName, libs, "gsk_gl_shader_find_uniform_by_name") core.PuregoSafeRegister(&xGLShaderFormatArgs, libs, "gsk_gl_shader_format_args") core.PuregoSafeRegister(&xGLShaderFormatArgsVa, libs, "gsk_gl_shader_format_args_va") core.PuregoSafeRegister(&xGLShaderGetArgBool, libs, "gsk_gl_shader_get_arg_bool") core.PuregoSafeRegister(&xGLShaderGetArgFloat, libs, "gsk_gl_shader_get_arg_float") core.PuregoSafeRegister(&xGLShaderGetArgInt, libs, "gsk_gl_shader_get_arg_int") core.PuregoSafeRegister(&xGLShaderGetArgUint, libs, "gsk_gl_shader_get_arg_uint") core.PuregoSafeRegister(&xGLShaderGetArgVec2, libs, "gsk_gl_shader_get_arg_vec2") core.PuregoSafeRegister(&xGLShaderGetArgVec3, libs, "gsk_gl_shader_get_arg_vec3") core.PuregoSafeRegister(&xGLShaderGetArgVec4, libs, "gsk_gl_shader_get_arg_vec4") core.PuregoSafeRegister(&xGLShaderGetArgsSize, libs, "gsk_gl_shader_get_args_size") core.PuregoSafeRegister(&xGLShaderGetNTextures, libs, "gsk_gl_shader_get_n_textures") core.PuregoSafeRegister(&xGLShaderGetNUniforms, libs, "gsk_gl_shader_get_n_uniforms") core.PuregoSafeRegister(&xGLShaderGetResource, libs, "gsk_gl_shader_get_resource") core.PuregoSafeRegister(&xGLShaderGetSource, libs, "gsk_gl_shader_get_source") core.PuregoSafeRegister(&xGLShaderGetUniformName, libs, "gsk_gl_shader_get_uniform_name") core.PuregoSafeRegister(&xGLShaderGetUniformOffset, libs, "gsk_gl_shader_get_uniform_offset") core.PuregoSafeRegister(&xGLShaderGetUniformType, libs, "gsk_gl_shader_get_uniform_type") }