Class: Gsk::GLShader

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Constructor Details

#initialize(resource_path) ⇒ Gsk::GLShader

Creates a GskGLShader that will render pixels using the specified code.

Parameters:

  • resource_path (String)

    path to a resource that contains the GLSL sourcecode for the shader

Instance Method Details

#args_sizeInteger

Get the size of the data block used to specify arguments for this shader.

Returns:

  • (Integer)

    The size of the data block

#compile(renderer) ⇒ Boolean

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.

Parameters:

Returns:

  • (Boolean)

    true on success, false if an error occurred

#find_uniform_by_name(name) ⇒ Integer

Looks for a uniform by the name name, and returns the index of the uniform, or -1 if it was not found.

Parameters:

  • name (String)

    uniform name

Returns:

  • (Integer)

    The index of the uniform, or -1

#format_args(array) ⇒ 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.

Parameters:

  • array (Array)

    name-Value pairs for the uniforms of shader, ending with a nil name

Returns:

  • (GLib::Bytes)

    A newly allocated block of data which can be passed to [ctorGsk.GLShaderNode.new].

#format_args_va(uniforms) ⇒ 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.

Parameters:

  • uniforms (Gsk::va_list)

    name-Value pairs for the uniforms of shader, ending with a nil name

Returns:

  • (GLib::Bytes)

    A newly allocated block of data which can be passed to [ctorGsk.GLShaderNode.new].

#get_arg_bool(args, idx) ⇒ Boolean

Gets the value of the uniform idx in the args block.

The uniform must be of bool type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

Returns:

  • (Boolean)

    The value

#get_arg_float(args, idx) ⇒ Gsk::gfloat

Gets the value of the uniform idx in the args block.

The uniform must be of float type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

Returns:

  • (Gsk::gfloat)

    The value

#get_arg_int(args, idx) ⇒ Integer

Gets the value of the uniform idx in the args block.

The uniform must be of int type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

Returns:

  • (Integer)

    The value

#get_arg_uint(args, idx) ⇒ Integer

Gets the value of the uniform idx in the args block.

The uniform must be of uint type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

Returns:

  • (Integer)

    The value

#get_arg_vec2(args, idx, out_value) ⇒ nil

Gets the value of the uniform idx in the args block.

The uniform must be of vec2 type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

  • out_value (Graphene::Vec2)

    location to store the uniform value in

Returns:

  • (nil)

#get_arg_vec3(args, idx, out_value) ⇒ nil

Gets the value of the uniform idx in the args block.

The uniform must be of vec3 type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

  • out_value (Graphene::Vec3)

    location to store the uniform value in

Returns:

  • (nil)

#get_arg_vec4(args, idx, out_value) ⇒ nil

Gets the value of the uniform idx in the args block.

The uniform must be of vec4 type.

Parameters:

  • args (GLib::Bytes)

    uniform arguments

  • idx (Integer)

    index of the uniform

  • out_value (Graphene::Vec4)

    location to store set the uniform value in

Returns:

  • (nil)

#get_uniform_name(idx) ⇒ String

Get the name of the declared uniform for this shader at index idx.

Parameters:

  • idx (Integer)

    index of the uniform

Returns:

  • (String)

    The name of the declared uniform

#get_uniform_offset(idx) ⇒ Integer

Get the offset into the data block where data for this uniforms is stored.

Parameters:

  • idx (Integer)

    index of the uniform

Returns:

  • (Integer)

    The data offset

#get_uniform_type(idx) ⇒ Gsk::GLUniformType

Get the type of the declared uniform for this shader at index idx.

Parameters:

  • idx (Integer)

    index of the uniform

Returns:

#n_texturesInteger

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.

Returns:

  • (Integer)

    The number of texture inputs required by shader

#n_uniformsInteger

Get the number of declared uniforms for this shader.

Returns:

  • (Integer)

    The number of declared uniforms

#resourceString

Resource containing the source code for the shader.

If the shader source is not coming from a resource, this will be nil.

Returns:

  • (String)

    resource

#resource=(resource) ⇒ String

Resource containing the source code for the shader.

If the shader source is not coming from a resource, this will be nil.

Parameters:

  • resource (String)

Returns:

  • (String)

    resource

  • (String)

    resource

#sourceGLib::Bytes

Returns source.

Returns:

  • (GLib::Bytes)

    source

#source=(source) ⇒ GLib::Bytes

Parameters:

  • source (GLib::Bytes)

Returns:

  • (GLib::Bytes)

    source

  • (GLib::Bytes)

    source